summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorscott Chacon <schacon@agadorsparticus.corp.reactrix.com>2007-11-14 11:00:59 -0800
committerscott Chacon <schacon@agadorsparticus.corp.reactrix.com>2007-11-14 11:00:59 -0800
commit0e5c33282be67ef2c8c124628b7eb1f46764fdd0 (patch)
treef88d460d89fab2d38d1976eca01defa94df5deee
parentf13dfdd5f53d590378245c000c38b39ca1870ad7 (diff)
downloadthird_party-ruby-git-0e5c33282be67ef2c8c124628b7eb1f46764fdd0.zip
third_party-ruby-git-0e5c33282be67ef2c8c124628b7eb1f46764fdd0.tar.gz
third_party-ruby-git-0e5c33282be67ef2c8c124628b7eb1f46764fdd0.tar.xz
added name-rev support for commit objects
-rw-r--r--TODO5
-rw-r--r--lib/git/lib.rb5
-rw-r--r--lib/git/object.rb6
-rw-r--r--tests/units/test_object.rb4
4 files changed, 13 insertions, 7 deletions
diff --git a/TODO b/TODO
index 0a63883..a8c73d1 100644
--- a/TODO
+++ b/TODO
@@ -1,10 +1,5 @@
* more documentation
-
-* object.name (git name-rev)
-
-* git archive
-
* git revert, stash, rebase
* more low level index actions
diff --git a/lib/git/lib.rb b/lib/git/lib.rb
index 6cebc95..6bddef0 100644
--- a/lib/git/lib.rb
+++ b/lib/git/lib.rb
@@ -73,6 +73,10 @@ module Git
command('rev-parse', string)
end
+ def namerev(string)
+ command('name-rev', string).split[1]
+ end
+
def object_type(sha)
command('cat-file', ['-t', sha])
end
@@ -400,7 +404,6 @@ module Git
#puts out
#puts
if $?.exitstatus > 0
- puts $?.exitstatus
if $?.exitstatus == 1 && out == ''
return ''
end
diff --git a/lib/git/object.rb b/lib/git/object.rb
index c811810..4372463 100644
--- a/lib/git/object.rb
+++ b/lib/git/object.rb
@@ -79,7 +79,7 @@ module Git
super(base, sha)
@mode = mode
end
-
+
def children
blobs.merge(subtrees)
end
@@ -129,6 +129,10 @@ module Git
@message
end
+ def name
+ @base.lib.namerev(@sha)
+ end
+
def gtree
check_commit
Tree.new(@base, @tree)
diff --git a/tests/units/test_object.rb b/tests/units/test_object.rb
index 8b98e98..db04bd6 100644
--- a/tests/units/test_object.rb
+++ b/tests/units/test_object.rb
@@ -28,6 +28,10 @@ class TestObject < Test::Unit::TestCase
assert_equal('11-08-07', o.date.strftime("%m-%d-%y"))
assert_equal('test', o.message)
+ assert_equal('tags/v2.5', o.parent.name)
+ assert_equal('master', o.parent.parent.name)
+ assert_equal('master~1', o.parent.parent.parent.name)
+
o = @git.object('HEAD')
assert(o.is_a?(Git::Object::Commit))
assert_equal('commit', o.type)