Commit 1e1c6717 authored by Matthias Käppler's avatar Matthias Käppler

Merge branch 'jc-wiki-dont-call-writeref' into 'master'

Wiki: do not set default branch

See merge request gitlab-org/gitlab!82828
parents 77d3ce8f 74227c9e
......@@ -87,8 +87,7 @@ class Wiki
end
def create_wiki_repository
repository.create_if_not_exists
change_head_to_default_branch
repository.create_if_not_exists(default_branch)
raise CouldNotCreateWikiError unless repository_exists?
rescue StandardError => err
......@@ -322,16 +321,6 @@ class Wiki
def default_message(action, title)
"#{user.username} #{action} page: #{title}"
end
def change_head_to_default_branch
# If the wiki has commits in the 'HEAD' branch means that the current
# HEAD is pointing to the right branch. If not, it could mean that either
# the repo has just been created or that 'HEAD' is pointing
# to the wrong branch and we need to rewrite it
return if repository.raw_repository.commit_count('HEAD') != 0
repository.raw_repository.write_ref('HEAD', "refs/heads/#{default_branch}")
end
end
Wiki.prepend_mod_with('Wiki')
......@@ -12,14 +12,15 @@ RSpec.describe GroupWiki do
end
describe '#create_wiki_repository' do
let(:shard) { 'foo' }
it 'tracks the repository storage in the database' do
shard = 'foo'
# Use a custom storage shard value, to make sure we're not falling back to the default.
allow(subject).to receive(:repository_storage).and_return(shard)
allow(subject).to receive(:default_branch).and_return('bar')
# Don't actually create the repository, because the storage shard doesn't exist.
expect(subject.repository).to receive(:create_if_not_exists)
expect(subject).to receive(:change_head_to_default_branch)
allow(subject).to receive(:repository_exists?).and_return(true)
expect(subject).to receive(:track_wiki_repository).with(shard)
......
......@@ -599,36 +599,13 @@ RSpec.shared_examples 'wiki model' do
context 'when repository is empty' do
let(:wiki_container) { wiki_container_without_repo }
it 'changes the HEAD reference to the default branch' do
wiki.repository.create_if_not_exists
wiki.repository.raw_repository.write_ref('HEAD', 'refs/heads/bar')
it 'creates the repository with the default branch' do
wiki.repository.create_if_not_exists(default_branch)
subject
expect(File.read(head_path).squish).to eq "ref: refs/heads/#{default_branch}"
end
end
context 'when repository is not empty' do
before do
wiki.create_page('index', 'test content')
end
it 'does nothing when HEAD points to the right branch' do
expect(wiki.repository.raw_repository).not_to receive(:write_ref)
subject
end
context 'when HEAD points to the wrong branch' do
it 'rewrites HEAD with the right branch' do
wiki.repository.raw_repository.write_ref('HEAD', 'refs/heads/bar')
subject
expect(File.read(head_path).squish).to eq "ref: refs/heads/#{default_branch}"
end
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