updated refs to not include directories (duh), fixed unit tests to not expect Git calls

modified initilization method to accept flag to force it to see a bare dir
This commit is contained in:
Scott Chacon 2008-06-24 12:18:07 -07:00
Родитель dfcfdd4847
Коммит d12e68b820
6 изменённых файлов: 16 добавлений и 19 удалений

Просмотреть файл

@ -15,10 +15,12 @@ module Grit
Dir.chdir(repo.git.git_dir) do
files = Dir.glob(prefix + '/**/*')
files.each do |ref|
id = File.read(ref).chomp
name = ref.sub("#{prefix}/", '')
commit = Commit.create(repo, :id => id)
refs << self.new(name, commit)
if File.file?(ref)
id = File.read(ref).chomp
name = ref.sub("#{prefix}/", '')
commit = Commit.create(repo, :id => id)
refs << self.new(name, commit)
end
end
end

Просмотреть файл

@ -18,13 +18,13 @@ module Grit
# g = Repo.new("/Users/tom/public/grit.git")
#
# Returns Grit::Repo
def initialize(path)
def initialize(path, options = {})
epath = File.expand_path(path)
if File.exist?(File.join(epath, '.git'))
self.path = File.join(epath, '.git')
@bare = false
elsif File.exist?(epath) && epath =~ /\.git$/
elsif File.exist?(epath) && (epath =~ /\.git$/ || options[:is_bare])
self.path = epath
@bare = true
elsif File.exist?(epath)

Просмотреть файл

@ -0,0 +1 @@
ca8a30f5a7f0f163bbe3b6f0abf18a6c83b0687a

Просмотреть файл

@ -2,21 +2,20 @@ require File.dirname(__FILE__) + '/helper'
class TestHead < Test::Unit::TestCase
def setup
@r = Repo.new(GRIT_REPO)
Git.any_instance.expects(:for_each_ref).returns(fixture('for_each_ref'))
@r = Repo.new(File.join(File.dirname(__FILE__), *%w[dot_git]), :is_bare => true)
end
# inspect
def test_inspect
head = @r.heads.first
assert_equal %Q{#<Grit::Head "#{head.name}">}, head.inspect
assert_equal %Q{#<Grit::Head "master">}, head.inspect
end
# heads with slashes
def test_heads_with_slashes
head = @r.heads.last
assert_equal %Q{#<Grit::Head "mojombo/master">}, head.inspect
head = @r.heads[1]
assert_equal %Q{#<Grit::Head "test/chacon">}, head.inspect
end
end

Просмотреть файл

@ -3,7 +3,6 @@ require File.dirname(__FILE__) + '/helper'
class TestRemote < Test::Unit::TestCase
def setup
@r = Repo.new(GRIT_REPO)
Git.any_instance.expects(:for_each_ref).returns(fixture('for_each_ref_remotes'))
end
# inspect

Просмотреть файл

@ -8,20 +8,16 @@ class TestTag < Test::Unit::TestCase
# list_from_string
def test_list_from_string
Git.any_instance.expects(:for_each_ref).returns(fixture('for_each_ref_tags'))
tags = @r.tags
assert_equal 1, tags.size
assert_equal 'v0.7.1', tags.first.name
assert_equal '634396b2f541a9f2d58b00be1a07f0c358b999b3', tags.first.commit.id
assert_equal 'v0.7.0', tags.first.name
assert_equal 'f0055fda16c18fd8b27986dbf038c735b82198d7', tags.first.commit.id
end
# inspect
def test_inspect
Git.any_instance.expects(:for_each_ref).returns(fixture('for_each_ref'))
tag = @r.tags.first
assert_equal %Q{#<Grit::Tag "#{tag.name}">}, tag.inspect