diff --git a/lib/git_stats/git_data/repo.rb b/lib/git_stats/git_data/repo.rb index db01e9467..b5b808052 100644 --- a/lib/git_stats/git_data/repo.rb +++ b/lib/git_stats/git_data/repo.rb @@ -29,6 +29,14 @@ module GitStats end.sort_by! { |e| e.date } end + def commit_range + @first_commit ? "#{@first_commit}..#{last_commit}" : last_commit + end + + def last_commit + @last_commit ||= 'HEAD' + end + def short_stats @short_stats ||= commits.map(&:short_stat) end diff --git a/spec/repo_spec.rb b/spec/repo_spec.rb index d3f686c55..5e462d3c8 100644 --- a/spec/repo_spec.rb +++ b/spec/repo_spec.rb @@ -7,6 +7,27 @@ describe GitStats::GitData::Repo do "joe.doe@gmail.com" => build(:author, repo: repo, name: "Joe Doe", email: "joe.doe@gmail.com") } } + describe 'commit range' do + it 'should return HEAD by default' do + repo.commit_range.should == 'HEAD' + end + + it 'should return last_commit if it was given' do + repo = build(:repo, last_commit: 'abc') + repo.commit_range.should == 'abc' + end + + it 'should return range from first_commit to HEAD if first_commit was given' do + repo = build(:repo, first_commit: 'abc') + repo.commit_range.should == 'abc..HEAD' + end + + it 'should return range from first to last commit if both were given' do + repo = build(:repo, first_commit: 'abc', last_commit: 'def') + repo.commit_range.should == 'abc..def' + end + end + describe 'git output parsing' do it 'should parse git shortlog output to authors hash' do GitStats::GitData::Command.any_instance.should_receive(:run_in_repo).and_return(" 156 John Doe