mirror of
https://github.com/tomgi/git_stats.git
synced 2024-11-17 17:15:22 +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
|
end
|
||||||
|
|
||||||
def authors
|
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])
|
Author.new(repo: self, name: author[:name], email: author[:email])
|
||||||
end.extend(ByFieldFinder)
|
end.extend(ByFieldFinder)
|
||||||
end
|
end
|
||||||
|
|
||||||
def commits
|
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)
|
hash, stamp, date, author_email = commit_line.split('|').map(&:strip)
|
||||||
author = authors.by_email(author_email)
|
author = authors.by_email(author_email)
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ module GitStats
|
||||||
end
|
end
|
||||||
|
|
||||||
def commit_range
|
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
|
end
|
||||||
|
|
||||||
def last_commit_hash
|
def last_commit_hash
|
||||||
|
@ -51,7 +51,7 @@ module GitStats
|
||||||
end
|
end
|
||||||
|
|
||||||
def project_version
|
def project_version
|
||||||
@project_version ||= run('git rev-parse --short HEAD').strip
|
@project_version ||= run("git rev-parse --short #{commit_range}").strip
|
||||||
end
|
end
|
||||||
|
|
||||||
def project_name
|
def project_name
|
||||||
|
|
|
@ -26,21 +26,40 @@ describe GitStats::GitData::Repo do
|
||||||
repo = build(:repo, first_commit_hash: 'abc', last_commit_hash: 'def')
|
repo = build(:repo, first_commit_hash: 'abc', last_commit_hash: 'def')
|
||||||
repo.commit_range.should == 'abc..def'
|
repo.commit_range.should == 'abc..def'
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe 'git output parsing' do
|
describe 'git output parsing' do
|
||||||
|
context 'invoking authors command' do
|
||||||
before do
|
before do
|
||||||
repo.should_receive(:run).with('git shortlog -se HEAD').and_return(" 156 John Doe <john.doe@gmail.com>
|
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>
|
53 Joe Doe <joe.doe@gmail.com>
|
||||||
")
|
")
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should parse git shortlog output to authors hash' do
|
it 'should parse git shortlog output to authors hash' do
|
||||||
repo.authors.should == expected_authors
|
repo.authors.should == expected_authors
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should parse git revlist output to date sorted commits array' do
|
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(
|
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
|
"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
|
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
|
5eab339|1345835073|2012-08-24 21:04:33 +0200|john.doe@gmail.com
|
||||||
|
@ -59,4 +78,9 @@ ce34874|1347482927|2012-09-12 22:48:47 +0200|joe.doe@gmail.com
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
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
|
end
|
Loading…
Reference in a new issue