Commit 1874990f authored by Vasilii Iakliushin's avatar Vasilii Iakliushin

Merge branch 'improve-default-branch-for-empty-projects' into 'master'

Improve retrieving default branch of empty repos

See merge request gitlab-org/gitlab!70116
parents 70a33833 c5ccb926
......@@ -72,12 +72,10 @@ module HasRepository
end
def default_branch
@default_branch ||= repository.root_ref || default_branch_from_preferences
@default_branch ||= repository.empty? ? default_branch_from_preferences : repository.root_ref
end
def default_branch_from_preferences
return unless empty_repo?
(default_branch_from_group_preferences || Gitlab::CurrentSettings.default_branch_name).presence
end
......
......@@ -14,7 +14,7 @@ RSpec.describe Resolvers::ScanExecutionPolicyResolver do
let(:policy) { build(:scan_execution_policy, name: 'Run DAST in every pipeline') }
let(:policy_yaml) { build(:scan_execution_policy_yaml, policies: [policy]) }
let(:repository) { instance_double(Repository, root_ref: 'master') }
let(:repository) { instance_double(Repository, root_ref: 'master', empty?: false) }
describe '#resolve' do
subject(:resolve_scan_policies) { resolve(described_class, obj: project, ctx: { current_user: user }) }
......
......@@ -101,6 +101,7 @@ RSpec.describe EE::Gitlab::Checks::PushRuleCheck do
it "sets the git env correctly for all hooks", :request_store do
expect(Gitaly::Repository).to receive(:new)
.at_least(:once)
.with(a_hash_including(git_object_directory: "objects"))
.and_call_original
......
......@@ -10,7 +10,7 @@ RSpec.describe Security::OrchestrationPolicyConfiguration do
end
let(:default_branch) { security_policy_management_project.default_branch }
let(:repository) { instance_double(Repository, root_ref: 'master') }
let(:repository) { instance_double(Repository, root_ref: 'master', empty?: false) }
let(:policy_yaml) { build(:scan_execution_policy_yaml, policies: [build(:scan_execution_policy, name: 'Run DAST in every pipeline')]) }
before do
......
......@@ -69,7 +69,7 @@ module Gitlab
self.sha = commit.sha
self.status = commit.status
self.ref = project.default_branch
self.ref = project.repository.root_ref
end
# We only cache the status for the HEAD commit of a project
......@@ -79,7 +79,7 @@ module Gitlab
return unless sha
return unless ref
if commit.sha == sha && project.default_branch == ref
if commit.sha == sha && project.repository.root_ref == ref
store_in_cache
end
end
......
......@@ -29,6 +29,9 @@ RSpec.describe Gitlab::ImportExport::SnippetRepoRestorer do
expect(restorer.restore).to be_truthy
end.to change { SnippetRepository.count }.by(1)
snippet.repository.expire_method_caches(%i(exists?))
expect(snippet.repository_exists?).to be_truthy
blob = snippet.repository.blob_at(snippet.default_branch, snippet.file_name)
expect(blob).not_to be_nil
expect(blob.data).to eq(snippet.content)
......
......@@ -115,6 +115,7 @@ RSpec.describe SnippetRepository do
allow(snippet).to receive(:repository).and_return(repo)
allow(repo).to receive(:ls_files).and_return([])
allow(repo).to receive(:root_ref).and_return('master')
allow(repo).to receive(:empty?).and_return(false)
end
it 'infers the commit action based on the parameters if not present' do
......
......@@ -428,7 +428,7 @@ RSpec.describe PostReceive do
end
it 'expires the status cache' do
expect(snippet.repository).to receive(:empty?).and_return(true)
expect(snippet.repository).to receive(:empty?).at_least(:once).and_return(true)
expect(snippet.repository).to receive(:expire_status_cache)
perform
......
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