public
Rubygem
Fork of mojombo/grit
Description: Grit is a Ruby library for extracting information from a git repository in an object oriented manner - this fork tries to intergrate as much pure-ruby functionality as possible
Homepage: http://grit.rubyforge.org/
Clone URL: git://github.com/schacon/grit.git
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
schacon (author)
Tue Jun 24 12:18:07 -0700 2008
commit  d12e68b82099ed241ef523bb94e1c1ca8d8484f4
tree    a3c5aeba955678305edc942b806c39e4dcba8e5e
parent  dfcfdd4847d318643449c81cd4891b01e3a50e09
...
15
16
17
18
19
20
21
 
 
 
 
 
 
22
23
24
...
15
16
17
 
 
 
 
18
19
20
21
22
23
24
25
26
0
@@ -15,10 +15,12 @@ module Grit
0
         Dir.chdir(repo.git.git_dir) do
0
           files = Dir.glob(prefix + '/**/*')
0
           files.each do |ref|
0
- id = File.read(ref).chomp
0
- name = ref.sub("#{prefix}/", '')
0
- commit = Commit.create(repo, :id => id)
0
- refs << self.new(name, commit)
5
+ if File.file?(ref)
0
+ id = File.read(ref).chomp
0
+ name = ref.sub("#{prefix}/", '')
0
+ commit = Commit.create(repo, :id => id)
0
+ refs << self.new(name, commit)
0
+ end
0
           end
0
         end
0
         
...
18
19
20
21
 
22
23
24
25
26
27
 
28
29
30
...
18
19
20
 
21
22
23
24
25
26
 
27
28
29
30
0
@@ -18,13 +18,13 @@ module Grit
0
     # g = Repo.new("/Users/tom/public/grit.git")
0
     #
0
     # Returns Grit::Repo
0
- def initialize(path)
0
+ def initialize(path, options = {})
0
       epath = File.expand_path(path)
0
       
0
       if File.exist?(File.join(epath, '.git'))
0
         self.path = File.join(epath, '.git')
0
         @bare = false
0
- elsif File.exist?(epath) && epath =~ /\.git$/
0
+ elsif File.exist?(epath) && (epath =~ /\.git$/ || options[:is_bare])
0
         self.path = epath
0
         @bare = true
0
       elsif File.exist?(epath)
...
2
3
4
5
6
 
7
8
9
10
11
12
13
 
14
15
 
16
17
18
19
20
 
 
21
22
...
2
3
4
 
 
5
6
7
8
9
10
11
 
12
13
 
14
15
16
17
 
 
18
19
20
21
0
@@ -2,21 +2,20 @@ require File.dirname(__FILE__) + '/helper'
0
 
0
 class TestHead < Test::Unit::TestCase
0
   def setup
0
- @r = Repo.new(GRIT_REPO)
0
- Git.any_instance.expects(:for_each_ref).returns(fixture('for_each_ref'))
0
+ @r = Repo.new(File.join(File.dirname(__FILE__), *%w[dot_git]), :is_bare => true)
0
   end
0
   
0
   # inspect
0
   
0
   def test_inspect
0
     head = @r.heads.first
0
- assert_equal %Q{#<Grit::Head "#{head.name}">}, head.inspect
0
+ assert_equal %Q{#<Grit::Head "master">}, head.inspect
0
   end
0
-
0
+
0
   # heads with slashes
0
 
0
   def test_heads_with_slashes
0
- head = @r.heads.last
0
- assert_equal %Q{#<Grit::Head "mojombo/master">}, head.inspect
0
+ head = @r.heads[1]
0
+ assert_equal %Q{#<Grit::Head "test/chacon">}, head.inspect
0
   end
0
 end
...
3
4
5
6
7
8
9
...
3
4
5
 
6
7
8
0
@@ -3,7 +3,6 @@ require File.dirname(__FILE__) + '/helper'
0
 class TestRemote < Test::Unit::TestCase
0
   def setup
0
     @r = Repo.new(GRIT_REPO)
0
- Git.any_instance.expects(:for_each_ref).returns(fixture('for_each_ref_remotes'))
0
   end
0
 
0
   # inspect
...
8
9
10
11
12
13
14
15
16
17
 
 
18
19
20
21
22
23
24
25
26
27
...
8
9
10
 
 
11
12
13
 
 
14
15
16
17
18
19
20
 
 
21
22
23
0
@@ -8,20 +8,16 @@ class TestTag < Test::Unit::TestCase
0
   # list_from_string
0
   
0
   def test_list_from_string
0
- Git.any_instance.expects(:for_each_ref).returns(fixture('for_each_ref_tags'))
0
-
0
     tags = @r.tags
0
     
0
     assert_equal 1, tags.size
0
- assert_equal 'v0.7.1', tags.first.name
0
- assert_equal '634396b2f541a9f2d58b00be1a07f0c358b999b3', tags.first.commit.id
0
+ assert_equal 'v0.7.0', tags.first.name
0
+ assert_equal 'f0055fda16c18fd8b27986dbf038c735b82198d7', tags.first.commit.id
0
   end
0
   
0
   # inspect
0
   
0
   def test_inspect
0
- Git.any_instance.expects(:for_each_ref).returns(fixture('for_each_ref'))
0
-
0
     tag = @r.tags.first
0
     
0
     assert_equal %Q{#<Grit::Tag "#{tag.name}">}, tag.inspect

Comments

  • defunkt Tue Jun 24 14:01:59 -0700 2008 at lib/grit/ref.rb L22

    You could also do next if File.directory?(ref) at the start of the loop to avoid another indentation level.

  • schacon Tue Jun 24 14:46:10 -0700 2008 at lib/grit/ref.rb L22

    good point – are there other file types i would have to worry about? would next if !File.file?(ref) be better? I’m not sure about symlinks, should they be there… is that an error, thus don’t read them, or possibly clever use of the ref system so do? Hm.

  • kballard Tue Jun 24 19:03:10 -0700 2008 at lib/grit/ref.rb L22

    I would suggest `next unless File.file?(ref)` rather than using if !

  • defunkt Tue Jun 24 20:38:11 -0700 2008 at lib/grit/ref.rb L22

    I’m personally moving against unless these days because of the added cognitive overhead.

  • defunkt Tue Jun 24 21:19:10 -0700 2008 at lib/grit/ref.rb L22

    BTW I added a “Preview” button because of this thread.