Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2021-06-29 08:45:21 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2021-06-29 08:45:21 +0300
commit39a79b3bde65993fd219faf35f24c77d85b357aa (patch)
tree5f13fb5709133a8d6534aa4b4d739d3e8ffc6609
parent28e6eebf54f40a2ff820c996698c720b1a898266 (diff)
parenta1395884165c14f0dbaa21bb59209b026d60edf6 (diff)
Merge branch '221159-fj-retrieve-head-ref-for-wiki-repo' into 'master'
Retrieve ref from unborn HEAD for wikis See merge request gitlab-org/gitaly!3610
-rw-r--r--ruby/lib/gitlab/git/repository.rb8
-rw-r--r--ruby/lib/gitlab/git/wiki.rb9
-rw-r--r--ruby/spec/lib/gitlab/git/repository_spec.rb18
-rw-r--r--ruby/spec/lib/gitlab/git/wiki_spec.rb32
4 files changed, 66 insertions, 1 deletions
diff --git a/ruby/lib/gitlab/git/repository.rb b/ruby/lib/gitlab/git/repository.rb
index a4d21f5e2..fad18e5b2 100644
--- a/ruby/lib/gitlab/git/repository.rb
+++ b/ruby/lib/gitlab/git/repository.rb
@@ -436,6 +436,14 @@ module Gitlab
rugged&.close if defined?(@rugged)
end
+ def head_symbolic_ref
+ message, status = run_git(%w[symbolic-ref HEAD])
+
+ return 'main' if status.nonzero?
+
+ Ref.extract_branch_name(message.squish)
+ end
+
private
def sparse_checkout_empty?(output)
diff --git a/ruby/lib/gitlab/git/wiki.rb b/ruby/lib/gitlab/git/wiki.rb
index 452351afd..506b4489f 100644
--- a/ruby/lib/gitlab/git/wiki.rb
+++ b/ruby/lib/gitlab/git/wiki.rb
@@ -60,11 +60,18 @@ module Gitlab
end
def gollum_wiki
- @gollum_wiki ||= Gollum::Wiki.new(@repository.path)
+ options = {}
+ options[:ref] = gollum_default_ref if gollum_default_ref
+
+ @gollum_wiki ||= Gollum::Wiki.new(@repository.path, options)
end
private
+ def gollum_default_ref
+ @gollum_default_ref ||= @repository.root_ref || @repository.head_symbolic_ref
+ end
+
def new_page(gollum_page)
Gitlab::Git::WikiPage.new(gollum_page, new_version(gollum_page, gollum_page.version.id))
end
diff --git a/ruby/spec/lib/gitlab/git/repository_spec.rb b/ruby/spec/lib/gitlab/git/repository_spec.rb
index 70899d4c7..6bbf4bcff 100644
--- a/ruby/spec/lib/gitlab/git/repository_spec.rb
+++ b/ruby/spec/lib/gitlab/git/repository_spec.rb
@@ -470,6 +470,24 @@ describe Gitlab::Git::Repository do # rubocop:disable Metrics/BlockLength
end
end
+ describe '#head_symbolic_ref' do
+ subject { repository.head_symbolic_ref }
+
+ it 'returns the symbolic ref in HEAD' do
+ expect(subject).to eq('master')
+ end
+
+ context 'when repo is empty' do
+ let(:repository) { gitlab_git_from_gitaly(new_empty_test_repo) }
+
+ it 'returns the symbolic ref in HEAD' do
+ repository.rugged.head = 'refs/heads/foo'
+
+ expect(subject).to eq('foo')
+ end
+ end
+ end
+
def create_remote_branch(remote_name, branch_name, source_branch_name)
source_branch = repository.branches.find { |branch| branch.name == source_branch_name }
repository_rugged.references.create("refs/remotes/#{remote_name}/#{branch_name}", source_branch.dereferenced_target.sha)
diff --git a/ruby/spec/lib/gitlab/git/wiki_spec.rb b/ruby/spec/lib/gitlab/git/wiki_spec.rb
index aca0f0dee..9240ed62c 100644
--- a/ruby/spec/lib/gitlab/git/wiki_spec.rb
+++ b/ruby/spec/lib/gitlab/git/wiki_spec.rb
@@ -132,6 +132,38 @@ describe Gitlab::Git::Wiki do
end
end
+ describe '#gollum_wiki' do
+ context 'when repository is empty' do
+ it 'instantiates the gollum wiki with the repo symbolic ref' do
+ repository.rugged.head = 'refs/heads/foo'
+
+ expect(Gollum::Wiki).to receive(:new).with(repository.path, hash_including(ref: 'foo'))
+
+ subject.gollum_wiki
+ end
+ end
+
+ context 'when repository is not empty' do
+ let(:repository) { gitlab_git_from_gitaly(new_mutable_git_test_repo) }
+
+ it 'instantiates the gollum wiki with the repo root_ref' do
+ expect(Gollum::Wiki).to receive(:new).with(repository.path, hash_including(ref: repository.root_ref))
+
+ subject.gollum_wiki
+ end
+ end
+
+ context 'when symbolic ref and root ref cannot be found' do
+ it 'instantiates the gollum wiki without any ref' do
+ allow(subject).to receive(:gollum_default_ref).and_return(nil)
+
+ expect(Gollum::Wiki).to receive(:new).with(repository.path, {})
+
+ subject.gollum_wiki
+ end
+ end
+ end
+
def create_page(name, content)
subject.write_page(name, :markdown, content, commit_details(name))
end