Commit 776cea4c authored by Sean McGivern's avatar Sean McGivern

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.
parent a053430e
......@@ -40,7 +40,14 @@ class Deployment < ActiveRecord::Base
def includes_commit?(commit)
return false unless commit
# 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!
......
......@@ -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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment