diff options
author | Grzegorz Bizon <grzegorz@gitlab.com> | 2018-11-15 09:16:30 +0000 |
---|---|---|
committer | Grzegorz Bizon <grzegorz@gitlab.com> | 2018-11-15 09:16:30 +0000 |
commit | 7528b2d26070fcbf3d88b60d54955257dc48141e (patch) | |
tree | e3e7ab751378317c7897fdebc640198b315e7717 | |
parent | 1cccfca1dc9385d59c0ea352b2bed370eb31eaec (diff) | |
parent | 039df0267e6c3e2070aa9bf92b56bee0f0ac8ca9 (diff) | |
download | gitlab-ce-7528b2d26070fcbf3d88b60d54955257dc48141e.tar.gz |
Merge branch 'osw-fallback-on-blank-refs' into 'master'
Avoid Gitaly RPC errors when fetching diff stats
Closes gitaly#1393
See merge request gitlab-org/gitlab-ce!22995
-rw-r--r-- | changelogs/unreleased/osw-fallback-on-blank-refs.yml | 5 | ||||
-rw-r--r-- | lib/gitlab/git/repository.rb | 10 | ||||
-rw-r--r-- | spec/lib/gitlab/git/repository_spec.rb | 14 |
3 files changed, 28 insertions, 1 deletions
diff --git a/changelogs/unreleased/osw-fallback-on-blank-refs.yml b/changelogs/unreleased/osw-fallback-on-blank-refs.yml new file mode 100644 index 00000000000..039179f5829 --- /dev/null +++ b/changelogs/unreleased/osw-fallback-on-blank-refs.yml @@ -0,0 +1,5 @@ +--- +title: Avoid Gitaly RPC errors when fetching diff stats +merge_request: 22995 +author: +type: fixed diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb index 1642c4c5687..aaaf794668d 100644 --- a/lib/gitlab/git/repository.rb +++ b/lib/gitlab/git/repository.rb @@ -419,13 +419,17 @@ module Gitlab end def diff_stats(left_id, right_id) + if [left_id, right_id].any? { |ref| ref.blank? || Gitlab::Git.blank_ref?(ref) } + return empty_diff_stats + end + stats = wrapped_gitaly_errors do gitaly_commit_client.diff_stats(left_id, right_id) end Gitlab::Git::DiffStatsCollection.new(stats) rescue CommandError, TypeError - Gitlab::Git::DiffStatsCollection.new([]) + empty_diff_stats end # Returns a RefName for a given SHA @@ -962,6 +966,10 @@ module Gitlab private + def empty_diff_stats + Gitlab::Git::DiffStatsCollection.new([]) + end + def uncached_has_local_branches? wrapped_gitaly_errors do gitaly_repository_client.has_local_branches? diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb index 54291e847d8..1fe73c12fc0 100644 --- a/spec/lib/gitlab/git/repository_spec.rb +++ b/spec/lib/gitlab/git/repository_spec.rb @@ -1095,12 +1095,26 @@ describe Gitlab::Git::Repository, :seed_helper do end it 'returns no Gitaly::DiffStats when there is a nil SHA' do + expect_any_instance_of(Gitlab::GitalyClient::CommitService) + .not_to receive(:diff_stats) + collection = repository.diff_stats(nil, 'master') expect(collection).to be_a(Gitlab::Git::DiffStatsCollection) expect(collection).to be_a(Enumerable) expect(collection.to_a).to be_empty end + + it 'returns no Gitaly::DiffStats when there is a BLANK_SHA' do + expect_any_instance_of(Gitlab::GitalyClient::CommitService) + .not_to receive(:diff_stats) + + collection = repository.diff_stats(Gitlab::Git::BLANK_SHA, 'master') + + expect(collection).to be_a(Gitlab::Git::DiffStatsCollection) + expect(collection).to be_a(Enumerable) + expect(collection.to_a).to be_empty + end end describe "#ls_files" do |