Skip to content

Commit

Permalink
Merge pull request #79 from tomgi/switch_short_commit_sha_to_full_sha…
Browse files Browse the repository at this point in the history
…_to_remove_ambiguity

Switched short commit SHA to full SHA to remove ambiguity
  • Loading branch information
tomgi committed Dec 1, 2017
2 parents 0c5a055 + 58a8cca commit 920514a
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 18 deletions.
4 changes: 2 additions & 2 deletions lib/git_stats/git_data/repo.rb
Expand Up @@ -46,7 +46,7 @@ def authors
end

def commits
@commits ||= run_and_parse("git rev-list --pretty=format:'%h|%at|%ai|%aE' #{commit_range} #{tree_path} | grep -v commit").map do |commit_line|
@commits ||= run_and_parse("git rev-list --pretty=format:'%H|%at|%ai|%aE' #{commit_range} #{tree_path} | grep -v commit").map do |commit_line|
Commit.new(
repo: self,
sha: commit_line[:sha],
Expand Down Expand Up @@ -116,7 +116,7 @@ def activity
end

def project_version
@project_version ||= run("git rev-parse --short #{commit_range}").strip
@project_version ||= run("git rev-parse #{commit_range}").strip
end

def project_name
Expand Down
4 changes: 2 additions & 2 deletions spec/git_data/commit_range_spec.rb
Expand Up @@ -33,12 +33,12 @@
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.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.should_receive(:run).with('git rev-parse abc..def').and_return("")
repo.project_version
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/git_data/repo_spec.rb
Expand Up @@ -19,7 +19,7 @@
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(
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
Expand All @@ -39,7 +39,7 @@
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.should_receive(:run).with('git rev-parse HEAD').and_return('xyz')
repo.project_version.should == 'xyz'
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/git_data/tree_spec.rb
Expand Up @@ -29,7 +29,7 @@

it 'should parse git revlist output to date sorted commits array' do
repo_tree.should_receive(:run).
with("git rev-list --pretty=format:'%h|%at|%ai|%aE' HEAD ./subdir_with_1_commit | grep -v commit").
with("git rev-list --pretty=format:'%H|%at|%ai|%aE' HEAD ./subdir_with_1_commit | grep -v commit").
and_return("10d1814|1395407506|2014-03-21 14:11:46 +0100|israelrevert@gmail.com")
repo_tree.commits.should ==
[ GitStats::GitData::Commit.new( repo: repo, sha: "10d1814", stamp: "1395407506",
Expand Down
13 changes: 11 additions & 2 deletions spec/integration/author_spec.rb
Expand Up @@ -8,8 +8,17 @@
let(:jd) { repo.authors.first! { |a| a.email == 'john.doe@gmail.com' } }

it 'should filter commits to author' do
tg.commits.map(&:sha).should =~ %w(b3b4f81 d60b5ec ab47ef8 2c11f5e c87ecf9 b621a5d 4e7d0e9 872955c)
jd.commits.map(&:sha).should =~ %w(fd66657 81e8bef)
tg.commits.map(&:sha).should =~ %w(
2c11f5e5224dd7d2fab27de0fca2a9a1d0ca4038
4e7d0e9e58e27e33d47f94faf4079a49a75931da
872955c3a6a4be4d7ae9b2dd4bea659979f0b457
ab47ef832c59837afcb626bfe22f0b8f0dc3717e
b3b4f819041eb66922abe79ee2513d5ddfb64691
b621a5df78e2953a040128191e47a24be9514b5c
c87ecf9c0bbdca29d73def8ed442cebf48178d92
d60b5eccf4513621bdbd65f408a0d28ff6fa9f5b
)
jd.commits.map(&:sha).should =~ %w(fd66657521139b1af6fde2927c4a383ecd6508fa 81e8bef75eaa93d772f2ce11d2a266ada1292741)
end

context 'activity' do
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/file_spec.rb
Expand Up @@ -9,7 +9,7 @@
end

it 'should retrieve correct file content for old file' do
repo.commits.first! { |c| c.sha == 'c87ecf9' }.files.first! { |f| f.filename == 'test.txt' }.content.should == "bb
repo.commits.first! { |c| c.sha == 'c87ecf9c0bbdca29d73def8ed442cebf48178d92' }.files.first! { |f| f.filename == 'test.txt' }.content.should == "bb
Expand Down
15 changes: 13 additions & 2 deletions spec/integration/repo_spec.rb
Expand Up @@ -13,15 +13,26 @@
end

it 'should gather all commits sorted by date' do
repo.commits.map(&:sha).should =~ %w(b3b4f81 d60b5ec ab47ef8 2c11f5e c87ecf9 b621a5d fd66657 81e8bef 4e7d0e9 872955c)
repo.commits.map(&:sha).should =~ %w(
2c11f5e5224dd7d2fab27de0fca2a9a1d0ca4038
4e7d0e9e58e27e33d47f94faf4079a49a75931da
81e8bef75eaa93d772f2ce11d2a266ada1292741
872955c3a6a4be4d7ae9b2dd4bea659979f0b457
ab47ef832c59837afcb626bfe22f0b8f0dc3717e
b3b4f819041eb66922abe79ee2513d5ddfb64691
b621a5df78e2953a040128191e47a24be9514b5c
c87ecf9c0bbdca29d73def8ed442cebf48178d92
d60b5eccf4513621bdbd65f408a0d28ff6fa9f5b
fd66657521139b1af6fde2927c4a383ecd6508fa
)
end

it 'should return project name from dir' do
repo.project_name.should == 'test_repo'
end

it 'should return project version as last commit hash' do
repo.project_version.should == '872955c'
repo.project_version.should == '872955c3a6a4be4d7ae9b2dd4bea659979f0b457'
end

it 'should count files in repo' do
Expand Down
19 changes: 13 additions & 6 deletions spec/integration/tree_spec.rb
Expand Up @@ -14,15 +14,19 @@
end

it 'should gather all commits sorted by date' do
repo.commits.map(&:sha).should =~ %w(10d1814 435e0ef 5fd0f5e)
repo.commits.map(&:sha).should =~ %w(
10d1814b1c4acf1496ba76d40ee4954a2e3908fb
435e0ef41e7c4917e4ba635bb44c7d36c5c7b7ad
5fd0f5ea90e0ef34a0214ec9c170728913525ff4
)
end

it 'should return project name from dir' do
repo.project_name.should == 'test_repo_tree'
end

it 'should return project version as last commit hash' do
repo.project_version.should == '5fd0f5e'
repo.project_version.should == '5fd0f5ea90e0ef34a0214ec9c170728913525ff4'
end

it 'should count files in repo' do
Expand Down Expand Up @@ -79,15 +83,15 @@
end

it 'should gather all commits sorted by date' do
repo.commits.map(&:sha).should =~ %w(10d1814)
repo.commits.map(&:sha).should =~ %w(10d1814b1c4acf1496ba76d40ee4954a2e3908fb)
end

it 'should return project name from dir' do
repo.project_name.should == 'test_repo_tree/subdir_with_1_commit'
end

it 'should return project version as last commit hash' do
repo.project_version.should == '5fd0f5e'
repo.project_version.should == '5fd0f5ea90e0ef34a0214ec9c170728913525ff4'
end

it 'should count files in repo' do
Expand Down Expand Up @@ -144,15 +148,18 @@
end

it 'should gather all commits sorted by date' do
repo.commits.map(&:sha).should =~ %w(435e0ef 5fd0f5e)
repo.commits.map(&:sha).should =~ %w(
435e0ef41e7c4917e4ba635bb44c7d36c5c7b7ad
5fd0f5ea90e0ef34a0214ec9c170728913525ff4
)
end

it 'should return project name from dir' do
repo.project_name.should == 'test_repo_tree/subdir_with_2_commits'
end

it 'should return project version as last commit hash' do
repo.project_version.should == '5fd0f5e'
repo.project_version.should == '5fd0f5ea90e0ef34a0214ec9c170728913525ff4'
end

it 'should count files in repo' do
Expand Down

0 comments on commit 920514a

Please sign in to comment.