diff options
author | Stan Hu <stanhu@gmail.com> | 2018-05-08 23:56:46 +0300 |
---|---|---|
committer | Filipa Lacerda <filipa@gitlab.com> | 2018-05-09 12:00:37 +0300 |
commit | 9bf4ae3d86c4bee53bfdff74c3b1d6c055e66fac (patch) | |
tree | 4f3ca4e656f2a0e47054235ad72753587b336662 /lib | |
parent | b026cf783fc971a1d25660def692e99baec750ce (diff) |
Merge branch '5750-backport-checksum-git-commanderror-exit-status-128' into 'master'
Raise InvalidRepository error for non-valid git repositories
See merge request gitlab-org/gitlab-ce!18594
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/git/repository.rb | 11 | ||||
-rw-r--r-- | lib/gitlab/gitaly_client/repository_service.rb | 2 |
2 files changed, 9 insertions, 4 deletions
diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb index bc61834ff7d..b145001a024 100644 --- a/lib/gitlab/git/repository.rb +++ b/lib/gitlab/git/repository.rb @@ -30,6 +30,7 @@ module Gitlab EMPTY_REPOSITORY_CHECKSUM = '0000000000000000000000000000000000000000'.freeze NoRepository = Class.new(StandardError) + InvalidRepository = Class.new(StandardError) InvalidBlobName = Class.new(StandardError) InvalidRef = Class.new(StandardError) GitError = Class.new(StandardError) @@ -1584,7 +1585,7 @@ module Gitlab def checksum gitaly_migrate(:calculate_checksum, - status: Gitlab::GitalyClient::MigrationStatus::OPT_OUT) do |is_enabled| + status: Gitlab::GitalyClient::MigrationStatus::OPT_OUT) do |is_enabled| if is_enabled gitaly_repository_client.calculate_checksum else @@ -2533,10 +2534,12 @@ module Gitlab output, status = run_git(args) if status.nil? || !status.zero? - # Empty repositories return with a non-zero status and an empty output. - return EMPTY_REPOSITORY_CHECKSUM if output&.empty? + # Non-valid git repositories return 128 as the status code and an error output + raise InvalidRepository if status == 128 && output.to_s.downcase =~ /not a git repository/ + # Empty repositories returns with a non-zero status and an empty output. + raise ChecksumError, output unless output.blank? - raise ChecksumError, output + return EMPTY_REPOSITORY_CHECKSUM end refs = output.split("\n") diff --git a/lib/gitlab/gitaly_client/repository_service.rb b/lib/gitlab/gitaly_client/repository_service.rb index 662b3d6cd0c..132a5947f17 100644 --- a/lib/gitlab/gitaly_client/repository_service.rb +++ b/lib/gitlab/gitaly_client/repository_service.rb @@ -292,6 +292,8 @@ module Gitlab request = Gitaly::CalculateChecksumRequest.new(repository: @gitaly_repo) response = GitalyClient.call(@storage, :repository_service, :calculate_checksum, request) response.checksum.presence + rescue GRPC::DataLoss => e + raise Gitlab::Git::Repository::InvalidRepository.new(e) end def raw_changes_between(from, to) |