Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added checkout_index

  • Loading branch information...
commit be47ad8aea4f854fc2d6773456fb28f3e9f519e7 1 parent 613757c
scott Chacon authored
View
18 README
@@ -228,4 +228,20 @@ Some examples of more low-level index and tree operations
end
end
- g.set_index('/path/to/index')
+ g.set_index('/path/to/index')
+
+
+ g.with_index(path) do
+ # calls set_index, then switches back after
+ end
+
+ g.with_working(dir) do
+ # calls set_working, then switches back after
+ end
+
+ g.with_temp_working(dir) do
+ g.checkout_index(:prefix => dir, :path_limiter => path)
+ # do file work
+ g.commit # commits to index
+ end
+
View
5 lib/git/base.rb
@@ -361,6 +361,10 @@ def with_temp_index &blk
with_index(temp_path, &blk)
end
+ def checkout_index(opts = {})
+ self.lib.checkout_index(opts)
+ end
+
def read_tree(treeish, opts = {})
self.lib.read_tree(treeish, opts)
end
@@ -382,6 +386,7 @@ def update_ref(branch, commit)
branch(branch).update_ref(commit)
end
+
def ls_files
self.lib.ls_files
end
View
8 lib/git/lib.rb
@@ -380,6 +380,14 @@ def update_ref(branch, commit)
command('update-ref', [branch.to_s, commit.to_s])
end
+ def checkout_index(opts = {})
+ arr_opts = []
+ arr_opts << "--prefix=#{opts[:prefix]}" if opts[:prefix]
+ arr_opts << "--force" if opts[:force]
+ arr_opts << "--all" if opts[:all]
+ arr_opts << ('-- ' + opts[:path_limiter]) if opts[:path_limiter].is_a? String
+ command('checkout-index', arr_opts)
+ end
# creates an archive file
#
View
8 tests/units/test_tree_ops.rb
@@ -106,6 +106,14 @@ def test_read_tree
assert_equal('b40f7a9072cdec637725700668f8fdebe39e6d38', c.gtree.sha)
+ g.with_temp_working do
+ assert(!File.directory?('b1'))
+ g.checkout_index
+ assert(!File.directory?('b1'))
+ g.checkout_index(:all => true)
+ assert(File.directory?('b1'))
+ end
+
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.