Commit 1cbf0709 authored by Stan Hu's avatar Stan Hu

Fix destruction of projects with pipelines

If a repository were deleted, the Gitaly implementation of
list_commits_by_oid would catch a GRPC NotFound error and simply return
an empty set.

However, the Rugged implementation would throw an NoRepository
exception. This would prevent a repository from being deleted.

We make the Rugged implementation consistent with Gitaly since the
behavior of destroying projects and CI pipelines relies on the Gitaly
implementation.

Relates to https://gitlab.com/gitlab-org/gitlab/-/issues/349414

Changelog: fixed
parent 55d94517
......@@ -31,6 +31,9 @@ module Gitlab
oids.map { |oid| rugged_find(repo, oid) }
.compact
.map { |commit| decorate(repo, commit) }
# Match Gitaly's list_commits_by_oid behavior
rescue ::Gitlab::Git::Repository::NoRepository
[]
end
override :find_commit
......
......@@ -486,6 +486,16 @@ RSpec.describe Gitlab::Git::Commit, :seed_helper do
expect(commits.first.sha).to eq(SeedRepo::Commit::ID)
expect(commits.second.sha).to eq(SeedRepo::FirstCommit::ID)
end
context 'when repo does not exist' do
let(:no_repository) { Gitlab::Git::Repository.new('default', '@does-not-exist/project', '', 'bogus/project') }
it 'returns empty commits' do
commits = described_class.batch_by_oid(no_repository, oids)
expect(commits.count).to eq(0)
end
end
end
context 'when oids is empty' do
......
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