Handle case where deployment ref no longer exists

Keep-around refs for deployments were only introduced in 8.10, so any
deployment created in 8.9 could have a SHA pointing to a commit that no
longer exists in the repository. We can't do anything useful with those
deployments, so make `#includes_commit?` always return false for those.
This commit is contained in:
Sean McGivern 2016-10-13 14:19:52 +01:00
parent a053430e94
commit 776cea4c00
2 changed files with 17 additions and 1 deletions

View file

@ -40,7 +40,14 @@ class Deployment < ActiveRecord::Base
def includes_commit?(commit)
return false unless commit
project.repository.is_ancestor?(commit.id, sha)
# Before 8.10, deployments didn't have keep-around refs. Any deployment
# created before then could have a `sha` referring to a commit that no
# longer exists in the repository, so just ignore those.
begin
project.repository.is_ancestor?(commit.id, sha)
rescue Rugged::OdbError
false
end
end
def update_merge_request_metrics!

View file

@ -38,5 +38,14 @@ describe Deployment, models: true do
expect(deployment.includes_commit?(commit)).to be true
end
end
context 'when the SHA for the deployment does not exist in the repo' do
it 'returns false' do
deployment.update(sha: Gitlab::Git::BLANK_SHA)
commit = project.commit
expect(deployment.includes_commit?(commit)).to be false
end
end
end
end