From 3c1b3f01465a74f7e0617c1d6f06a1f0bf684c90 Mon Sep 17 00:00:00 2001 From: scott Chacon Date: Fri, 16 Nov 2007 11:31:08 -0800 Subject: added update-ref --- lib/git/base.rb | 6 ++++++ lib/git/branch.rb | 4 ++++ lib/git/lib.rb | 5 +++++ tests/units/test_tree_ops.rb | 9 ++++++++- 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/git/base.rb b/lib/git/base.rb index 6372beb..4c5cdf5 100644 --- a/lib/git/base.rb +++ b/lib/git/base.rb @@ -6,6 +6,8 @@ module Git @repository = nil @index = nil + @lib = nil + # opens a bare Git Repository - no working directory options def self.bare(git_dir) self.new :repository => git_dir @@ -376,6 +378,10 @@ module Git commit_tree(tree, opts) end + def update_ref(branch, commit) + branch(branch).update_ref(commit) + end + def ls_files self.lib.ls_files end diff --git a/lib/git/branch.rb b/lib/git/branch.rb index f9106ab..c2ce810 100644 --- a/lib/git/branch.rb +++ b/lib/git/branch.rb @@ -75,6 +75,10 @@ module Git end end + def update_ref(commit) + @base.lib.update_ref(@full, commit) + end + def to_a [@full] end diff --git a/lib/git/lib.rb b/lib/git/lib.rb index 690043d..7742702 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -376,6 +376,11 @@ module Git command('commit-tree', arr_opts) end + def update_ref(branch, commit) + command('update-ref', [branch.to_s, commit.to_s]) + end + + # creates an archive file # # options diff --git a/tests/units/test_tree_ops.rb b/tests/units/test_tree_ops.rb index 7dba642..f8e771a 100644 --- a/tests/units/test_tree_ops.rb +++ b/tests/units/test_tree_ops.rb @@ -95,8 +95,15 @@ class TestTreeOps < Test::Unit::TestCase assert(index['b3/test-file3']) g.commit('hi') end - assert(c.commit?) + + files = g.ls_files + assert(!files['b1/example.txt']) + + g.branch('newbranch').update_ref(c) + g.checkout('newbranch') + assert(!files['b1/example.txt']) + assert_equal('b40f7a9072cdec637725700668f8fdebe39e6d38', c.gtree.sha) end -- cgit