Skip to content

Commit

Permalink
git-log support
Browse files Browse the repository at this point in the history
  • Loading branch information
defunkt committed Oct 29, 2007
1 parent 337539e commit 5f141d9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
13 changes: 12 additions & 1 deletion lib/grit/repo.rb
Expand Up @@ -93,6 +93,17 @@ def tree(treeish = 'master', paths = [])
def blob(id)
Blob.create(self, :id => id)
end

# The commit log for a treeish
#
# Returns Grit::Commit[]
def log(commit = 'master', path = nil, options = {})
default_options = {:pretty => "raw"}
actual_options = default_options.merge(options)
arg = path ? "#{commit} -- #{path}" : commit
commits = self.git.log(actual_options, arg)
Commit.list_from_string(self, commits)
end

# The diff from commit +a+ to commit +b+, optionally restricted to the given file(s)
# +a+ is the base commit
Expand Down Expand Up @@ -121,4 +132,4 @@ def inspect
end
end # Repo

end # Grit
end # Grit
16 changes: 15 additions & 1 deletion test/test_repo.rb
Expand Up @@ -127,4 +127,18 @@ def test_diff
def test_inspect
assert_equal %Q{#<Grit::Repo "#{File.expand_path(GRIT_REPO)}/.git">}, @r.inspect
end
end

# log

def test_log
Git.any_instance.expects(:log).times(2).with({:pretty => 'raw'}, 'master').returns(fixture('rev_list'))

assert_equal '4c8124ffcf4039d292442eeccabdeca5af5c5017', @r.log.first.id
assert_equal 'ab25fd8483882c3bda8a458ad2965d2248654335', @r.log.last.id
end

def test_log_with_path_and_options
Git.any_instance.expects(:log).with({:pretty => 'raw', :max_count => 1}, 'master -- file.rb').returns(fixture('rev_list'))
@r.log('master', 'file.rb', :max_count => 1)
end
end

0 comments on commit 5f141d9

Please sign in to comment.