Skip to content
Snippets Groups Projects
Commit f425f770 authored by Georges Racinet's avatar Georges Racinet
Browse files

Wiki: made `master` Git branch always identical to `branch/default`

GitLab wikis only read from `master`, and that's
pretty hardcoded, down the way to Gitaly, which itself embeds the
Gollum library, instead of just providing raw repo content.

Since we don't want to fork Gitaly, as long as we are using a Git mirror,
it's simpler to tie the `master` and `branch/default` Git branches
together in the case of wikis.
parent dfa26734
No related branches found
No related tags found
No related merge requests found
Pipeline #6027 passed
...@@ -468,5 +468,14 @@ ...@@ -468,5 +468,14 @@
before_sha = existing.get(ref, ZERO_SHA) before_sha = existing.get(ref, ZERO_SHA)
if after_sha and after_sha != before_sha: if after_sha and after_sha != before_sha:
changes[ref] = GitRefChange(ref, before_sha, after_sha) changes[ref] = GitRefChange(ref, before_sha, after_sha)
if self.is_wiki():
# GitLab wikis are much hardwired onto 'master' in a Git repo
on_default = changes.get(git_branch_ref('branch/default'))
if on_default is not None:
master = git_branch_ref('master')
changes[master] = GitRefChange(
master, on_default.before, on_default.after)
return changes return changes
...@@ -471,5 +480,10 @@ ...@@ -471,5 +480,10 @@
return changes return changes
def is_wiki(self):
"""Tell whether self.repo is the storage for a GitLab wiki"""
return (self.repo.ui.environ.get('GL_REPOSITORY', '')
.startswith('wiki-'))
def gitlab_get_hook(self, name): def gitlab_get_hook(self, name):
hook = self._gl_hooks.get(name) hook = self._gl_hooks.get(name)
if hook is None and gitlab is not None: if hook is None and gitlab is not None:
......
...@@ -146,6 +146,29 @@ ...@@ -146,6 +146,29 @@
] ]
def test_wiki(tmpdir, monkeypatch):
notifs = []
monkeypatch.setattr(gitlab, 'Hook', recording_hook(notifs))
repo_path = tmpdir.join('repo.hg')
wrapper, base_ctx = make_main_repo(repo_path)
wrapper.repo.ui.environ['GL_REPOSITORY'] = 'wiki-251'
git_repo = GitRepo.init(tmpdir.join('repo.git'))
wrapper.command('gitlab-mirror')
# for wikis, we duplicate `branch/default` as `master`
assert git_repo.branch_titles() == {'branch/default': 'default1',
'master': 'default1',
}
sha = git_repo.branches()['branch/default']['sha']
changes = {'refs/heads/branch/default': (ZERO_SHA, sha),
'refs/heads/master': (ZERO_SHA, sha),
}
assert notifs == [
('pre-receive', changes),
('post-receive', changes),
]
def test_tags(tmpdir, monkeypatch): def test_tags(tmpdir, monkeypatch):
notifs = [] notifs = []
monkeypatch.setattr(gitlab, 'Hook', recording_hook(notifs)) monkeypatch.setattr(gitlab, 'Hook', recording_hook(notifs))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment