summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README18
-rw-r--r--lib/git/base.rb5
-rw-r--r--lib/git/lib.rb8
-rw-r--r--tests/units/test_tree_ops.rb8
4 files changed, 38 insertions, 1 deletions
diff --git a/README b/README
index e2d3169..816e955 100644
--- a/README
+++ b/README
@@ -228,4 +228,20 @@ Some examples of more low-level index and tree operations
end
end
- g.set_index('/path/to/index') \ No newline at end of file
+ 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
+ \ No newline at end of file
diff --git a/lib/git/base.rb b/lib/git/base.rb
index 4c5cdf5..2986864 100644
--- a/lib/git/base.rb
+++ b/lib/git/base.rb
@@ -361,6 +361,10 @@ module Git
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 @@ module Git
branch(branch).update_ref(commit)
end
+
def ls_files
self.lib.ls_files
end
diff --git a/lib/git/lib.rb b/lib/git/lib.rb
index 7742702..dbd3d69 100644
--- a/lib/git/lib.rb
+++ b/lib/git/lib.rb
@@ -380,6 +380,14 @@ module Git
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
#
diff --git a/tests/units/test_tree_ops.rb b/tests/units/test_tree_ops.rb
index f8e771a..1b2ed1a 100644
--- a/tests/units/test_tree_ops.rb
+++ b/tests/units/test_tree_ops.rb
@@ -106,6 +106,14 @@ class TestTreeOps < Test::Unit::TestCase
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