Skip to content

Commit 3c1b3f0

Browse files
author
scott Chacon
committed
added update-ref
1 parent de071dc commit 3c1b3f0

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

lib/git/base.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ class Base
66
@repository = nil
77
@index = nil
88

9+
@lib = nil
10+
911
# opens a bare Git Repository - no working directory options
1012
def self.bare(git_dir)
1113
self.new :repository => git_dir
@@ -376,6 +378,10 @@ def write_and_commit_tree(opts = {})
376378
commit_tree(tree, opts)
377379
end
378380

381+
def update_ref(branch, commit)
382+
branch(branch).update_ref(commit)
383+
end
384+
379385
def ls_files
380386
self.lib.ls_files
381387
end

lib/git/branch.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ def merge(branch = nil, message = nil)
7575
end
7676
end
7777

78+
def update_ref(commit)
79+
@base.lib.update_ref(@full, commit)
80+
end
81+
7882
def to_a
7983
[@full]
8084
end

lib/git/lib.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,11 @@ def commit_tree(tree, opts = {})
376376
command('commit-tree', arr_opts)
377377
end
378378

379+
def update_ref(branch, commit)
380+
command('update-ref', [branch.to_s, commit.to_s])
381+
end
382+
383+
379384
# creates an archive file
380385
#
381386
# options

tests/units/test_tree_ops.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,15 @@ def test_read_tree
9595
assert(index['b3/test-file3'])
9696
g.commit('hi')
9797
end
98-
9998
assert(c.commit?)
99+
100+
files = g.ls_files
101+
assert(!files['b1/example.txt'])
102+
103+
g.branch('newbranch').update_ref(c)
104+
g.checkout('newbranch')
105+
assert(!files['b1/example.txt'])
106+
100107
assert_equal('b40f7a9072cdec637725700668f8fdebe39e6d38', c.gtree.sha)
101108

102109
end

0 commit comments

Comments
 (0)