File tree Expand file tree Collapse file tree 4 files changed +38
-1
lines changed Expand file tree Collapse file tree 4 files changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -228,4 +228,20 @@ Some examples of more low-level index and tree operations
228
228
end
229
229
end
230
230
231
- g.set_index('/path/to/index')
231
+ g.set_index('/path/to/index')
232
+
233
+
234
+ g.with_index(path) do
235
+ # calls set_index, then switches back after
236
+ end
237
+
238
+ g.with_working(dir) do
239
+ # calls set_working, then switches back after
240
+ end
241
+
242
+ g.with_temp_working(dir) do
243
+ g.checkout_index(:prefix => dir, :path_limiter => path)
244
+ # do file work
245
+ g.commit # commits to index
246
+ end
247
+
Original file line number Diff line number Diff line change @@ -361,6 +361,10 @@ def with_temp_index &blk
361
361
with_index ( temp_path , &blk )
362
362
end
363
363
364
+ def checkout_index ( opts = { } )
365
+ self . lib . checkout_index ( opts )
366
+ end
367
+
364
368
def read_tree ( treeish , opts = { } )
365
369
self . lib . read_tree ( treeish , opts )
366
370
end
@@ -382,6 +386,7 @@ def update_ref(branch, commit)
382
386
branch ( branch ) . update_ref ( commit )
383
387
end
384
388
389
+
385
390
def ls_files
386
391
self . lib . ls_files
387
392
end
Original file line number Diff line number Diff line change @@ -380,6 +380,14 @@ def update_ref(branch, commit)
380
380
command ( 'update-ref' , [ branch . to_s , commit . to_s ] )
381
381
end
382
382
383
+ def checkout_index ( opts = { } )
384
+ arr_opts = [ ]
385
+ arr_opts << "--prefix=#{ opts [ :prefix ] } " if opts [ :prefix ]
386
+ arr_opts << "--force" if opts [ :force ]
387
+ arr_opts << "--all" if opts [ :all ]
388
+ arr_opts << ( '-- ' + opts [ :path_limiter ] ) if opts [ :path_limiter ] . is_a? String
389
+ command ( 'checkout-index' , arr_opts )
390
+ end
383
391
384
392
# creates an archive file
385
393
#
Original file line number Diff line number Diff line change @@ -106,6 +106,14 @@ def test_read_tree
106
106
107
107
assert_equal ( 'b40f7a9072cdec637725700668f8fdebe39e6d38' , c . gtree . sha )
108
108
109
+ g . with_temp_working do
110
+ assert ( !File . directory? ( 'b1' ) )
111
+ g . checkout_index
112
+ assert ( !File . directory? ( 'b1' ) )
113
+ g . checkout_index ( :all => true )
114
+ assert ( File . directory? ( 'b1' ) )
115
+ end
116
+
109
117
end
110
118
end
111
119
end
You can’t perform that action at this time.
0 commit comments