summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorscott Chacon <schacon@agadorsparticus.corp.reactrix.com>2007-11-08 17:25:41 -0800
committerscott Chacon <schacon@agadorsparticus.corp.reactrix.com>2007-11-08 17:25:41 -0800
commit10045d082117d4ef35da31e1c5a825507b02dd97 (patch)
treeb418c5d28334e8514a075effc20c1ebdcbf34a25
parent1f63953f05a4afe74f881d54f69f77da513939d5 (diff)
downloadthird_party-ruby-git-10045d082117d4ef35da31e1c5a825507b02dd97.tar.gz
third_party-ruby-git-10045d082117d4ef35da31e1c5a825507b02dd97.tar.xz
third_party-ruby-git-10045d082117d4ef35da31e1c5a825507b02dd97.zip
got all the unit tests to run from either place, fixed some old functionality
-rw-r--r--lib/git/lib.rb2
-rw-r--r--lib/git/object.rb4
-rw-r--r--tests/test_helper.rb15
-rw-r--r--tests/units/test_log.rb6
-rw-r--r--tests/units/test_object.rb13
5 files changed, 32 insertions, 8 deletions
diff --git a/lib/git/lib.rb b/lib/git/lib.rb
index 595f294..681ba58 100644
--- a/lib/git/lib.rb
+++ b/lib/git/lib.rb
@@ -18,7 +18,7 @@ module Git
arr_opts << "#{opts[:between][0]}..#{opts[:between][1].to_s}" if (opts[:between] && opts[:between].size == 2)
arr_opts << opts[:file] if opts[:file].is_a? String
- command('log', arr_opts).split("\n").map { |l| Git::Commit.new(l.split.first) }
+ command('log', arr_opts).split("\n").map { |l| Git::Object::Commit.new(@base, l.split.first) }
end
def revparse(string)
diff --git a/lib/git/object.rb b/lib/git/object.rb
index 9346b87..4f8e559 100644
--- a/lib/git/object.rb
+++ b/lib/git/object.rb
@@ -25,6 +25,10 @@ module Git
raise NotImplementedError
end
+ def to_s
+ "#{@type.ljust(6)} #{@sha}"
+ end
+
end
diff --git a/tests/test_helper.rb b/tests/test_helper.rb
index 4a1cac9..fe8c34d 100644
--- a/tests/test_helper.rb
+++ b/tests/test_helper.rb
@@ -5,9 +5,18 @@ require File.dirname(__FILE__) + '/../lib/git'
class Test::Unit::TestCase
def set_file_paths
- @wdir = File.join(File.dirname(__FILE__), 'files', 'working')
- @wbare = File.join(File.dirname(__FILE__), 'files', 'working.git')
- @index = File.join(File.dirname(__FILE__), 'files', 'index')
+ cwd = `pwd`.chomp
+ if File.directory?(File.join(cwd, 'files'))
+ @test_dir = File.join(cwd, 'files')
+ elsif File.directory?(File.join(cwd, '..', 'files'))
+ @test_dir = File.join(cwd, '..', 'files')
+ elsif File.directory?(File.join(cwd, 'tests', 'files'))
+ @test_dir = File.join(cwd, 'tests', 'files')
+ end
+
+ @wdir = File.join(@test_dir, 'working')
+ @wbare = File.join(@test_dir, 'working.git')
+ @index = File.join(@test_dir, 'index')
end
def in_temp_dir
diff --git a/tests/units/test_log.rb b/tests/units/test_log.rb
index ddd4988..770c245 100644
--- a/tests/units/test_log.rb
+++ b/tests/units/test_log.rb
@@ -2,7 +2,7 @@
require File.dirname(__FILE__) + '/../test_helper'
-class TestInit < Test::Unit::TestCase
+class TestLog < Test::Unit::TestCase
def setup
set_file_paths
@git = Git.open(@wdir)
@@ -10,7 +10,7 @@ class TestInit < Test::Unit::TestCase
def test_get_log_entries
log = @git.log
- assert(log.first.is_a?(Git::Commit))
+ assert(log.first.is_a?(Git::Object::Commit))
end
def test_get_log_entries
@@ -36,7 +36,7 @@ class TestInit < Test::Unit::TestCase
assert_equal(30, l.size)
l = @git.log.between('v2.5').file('example.txt')
- assert_equal(1, l.size)
+ assert_equal(2, l.size)
l = @git.log.between('v2.5', 'test').file('example.txt')
assert_equal(1, l.size)
diff --git a/tests/units/test_object.rb b/tests/units/test_object.rb
index 610a640..b535be7 100644
--- a/tests/units/test_object.rb
+++ b/tests/units/test_object.rb
@@ -2,7 +2,7 @@
require File.dirname(__FILE__) + '/../test_helper'
-class TestInit < Test::Unit::TestCase
+class TestObject < Test::Unit::TestCase
def setup
set_file_paths
@git = Git.open(@wdir)
@@ -27,6 +27,17 @@ class TestInit < Test::Unit::TestCase
assert_equal('parent 546bec6f8872efa41d5d97a369f669165ecda0de', o.contents_array[1])
end
+ def test_object_to_s
+ o = @git.object('1cc8667014381')
+ assert_equal('commit 1cc8667014381e2788a94777532a788307f38d26', o.to_s)
+
+ o = @git.object('1cc8667014381^{tree}')
+ assert_equal('tree 94c827875e2cadb8bc8d4cdd900f19aa9e8634c7', o.to_s)
+
+ o = @git.object('v2.5:example.txt')
+ assert_equal('blob ba492c62b6227d7f3507b4dcc6e6d5f13790eabf', o.to_s)
+ end
+
def test_tree
o = @git.object('1cc8667014381^{tree}')
assert(o.is_a?(Git::Object::Tree))