mirror of
https://github.com/tomgi/git_stats.git
synced 2024-12-22 13:32:17 +01:00
invoking repo git command with correct commits range
This commit is contained in:
parent
8b4a937372
commit
4dc5165505
2 changed files with 49 additions and 25 deletions
|
@ -15,13 +15,13 @@ module GitStats
|
|||
end
|
||||
|
||||
def authors
|
||||
@authors ||= run_and_parse('git shortlog -se HEAD').map do |author|
|
||||
@authors ||= run_and_parse("git shortlog -se #{commit_range}").map do |author|
|
||||
Author.new(repo: self, name: author[:name], email: author[:email])
|
||||
end.extend(ByFieldFinder)
|
||||
end
|
||||
|
||||
def commits
|
||||
@commits ||= run('git rev-list --pretty=format:"%h|%at|%ai|%aE" HEAD | grep -v commit').lines.map do |commit_line|
|
||||
@commits ||= run("git rev-list --pretty=format:'%h|%at|%ai|%aE' #{commit_range} | grep -v commit").lines.map do |commit_line|
|
||||
hash, stamp, date, author_email = commit_line.split('|').map(&:strip)
|
||||
author = authors.by_email(author_email)
|
||||
|
||||
|
@ -35,7 +35,7 @@ module GitStats
|
|||
end
|
||||
|
||||
def commit_range
|
||||
@first_commit_hash ? "#{@first_commit_hash}..#{last_commit_hash}" : last_commit_hash
|
||||
@first_commit_hash ? "#@first_commit_hash..#{last_commit_hash}" : last_commit_hash
|
||||
end
|
||||
|
||||
def last_commit_hash
|
||||
|
@ -51,7 +51,7 @@ module GitStats
|
|||
end
|
||||
|
||||
def project_version
|
||||
@project_version ||= run('git rev-parse --short HEAD').strip
|
||||
@project_version ||= run("git rev-parse --short #{commit_range}").strip
|
||||
end
|
||||
|
||||
def project_name
|
||||
|
|
|
@ -26,37 +26,61 @@ describe GitStats::GitData::Repo do
|
|||
repo = build(:repo, first_commit_hash: 'abc', last_commit_hash: 'def')
|
||||
repo.commit_range.should == 'abc..def'
|
||||
end
|
||||
|
||||
context 'git commands using range' do
|
||||
let(:repo) { build(:repo, first_commit_hash: 'abc', last_commit_hash: 'def') }
|
||||
|
||||
it 'should affect authors command' do
|
||||
repo.should_receive(:run).with('git shortlog -se abc..def').and_return("")
|
||||
repo.authors
|
||||
end
|
||||
|
||||
it 'should affect commits command' do
|
||||
repo.should_receive(:run).with("git rev-list --pretty=format:'%h|%at|%ai|%aE' abc..def | grep -v commit").and_return("")
|
||||
repo.commits
|
||||
end
|
||||
|
||||
it 'should affect project version command' do
|
||||
repo.should_receive(:run).with('git rev-parse --short abc..def').and_return("")
|
||||
repo.project_version
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'git output parsing' do
|
||||
before do
|
||||
repo.should_receive(:run).with('git shortlog -se HEAD').and_return(" 156 John Doe <john.doe@gmail.com>
|
||||
context 'invoking authors command' do
|
||||
before do
|
||||
repo.should_receive(:run).with('git shortlog -se HEAD').and_return(" 156 John Doe <john.doe@gmail.com>
|
||||
53 Joe Doe <joe.doe@gmail.com>
|
||||
")
|
||||
end
|
||||
end
|
||||
it 'should parse git shortlog output to authors hash' do
|
||||
repo.authors.should == expected_authors
|
||||
end
|
||||
|
||||
it 'should parse git shortlog output to authors hash' do
|
||||
repo.authors.should == expected_authors
|
||||
end
|
||||
|
||||
it 'should parse git revlist output to date sorted commits array' do
|
||||
repo.should_receive(:run).with('git rev-list --pretty=format:"%h|%at|%ai|%aE" HEAD | grep -v commit').and_return(
|
||||
"e4412c3|1348603824|2012-09-25 22:10:24 +0200|john.doe@gmail.com
|
||||
it 'should parse git revlist output to date sorted commits array' do
|
||||
repo.should_receive(:run).with("git rev-list --pretty=format:'%h|%at|%ai|%aE' HEAD | grep -v commit").and_return(
|
||||
"e4412c3|1348603824|2012-09-25 22:10:24 +0200|john.doe@gmail.com
|
||||
ce34874|1347482927|2012-09-12 22:48:47 +0200|joe.doe@gmail.com
|
||||
5eab339|1345835073|2012-08-24 21:04:33 +0200|john.doe@gmail.com
|
||||
")
|
||||
|
||||
repo.commits.should == [
|
||||
GitStats::GitData::Commit.new(
|
||||
repo: repo, hash: "5eab339", stamp: "1345835073", date: DateTime.parse("2012-08-24 21:04:33 +0200"),
|
||||
author: repo.authors.by_email("john.doe@gmail.com")),
|
||||
GitStats::GitData::Commit.new(
|
||||
repo: repo, hash: "ce34874", stamp: "1347482927", date: DateTime.parse("2012-09-12 22:48:47 +0200"),
|
||||
author: repo.authors.by_email("joe.doe@gmail.com")),
|
||||
GitStats::GitData::Commit.new(
|
||||
repo: repo, hash: "e4412c3", stamp: "1348603824", date: DateTime.parse("2012-09-25 22:10:24 +0200"),
|
||||
author: repo.authors.by_email("john.doe@gmail.com"))
|
||||
]
|
||||
repo.commits.should == [
|
||||
GitStats::GitData::Commit.new(
|
||||
repo: repo, hash: "5eab339", stamp: "1345835073", date: DateTime.parse("2012-08-24 21:04:33 +0200"),
|
||||
author: repo.authors.by_email("john.doe@gmail.com")),
|
||||
GitStats::GitData::Commit.new(
|
||||
repo: repo, hash: "ce34874", stamp: "1347482927", date: DateTime.parse("2012-09-12 22:48:47 +0200"),
|
||||
author: repo.authors.by_email("joe.doe@gmail.com")),
|
||||
GitStats::GitData::Commit.new(
|
||||
repo: repo, hash: "e4412c3", stamp: "1348603824", date: DateTime.parse("2012-09-25 22:10:24 +0200"),
|
||||
author: repo.authors.by_email("john.doe@gmail.com"))
|
||||
]
|
||||
end
|
||||
end
|
||||
it 'should parse git rev-parse command to project version' do
|
||||
repo.should_receive(:run).with('git rev-parse --short HEAD').and_return('xyz')
|
||||
repo.project_version.should == 'xyz'
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue