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

Clarity refactor and line lengths in tests

(were actually uncommitted local mods)
parent 83f11149
No related branches found
No related tags found
No related merge requests found
Pipeline #6174 passed
......@@ -40,6 +40,19 @@
return 'refs/heads/' + branch
TOPIC_REF_PREFIX = git_branch_ref('topic/')
NAMED_BRANCH_REF_PREFIX = git_branch_ref('branch/')
def ref_is_topic(ref):
return ref.startswith(TOPIC_REF_PREFIX)
def ref_is_named_branch(ref):
return ref.startswith(NAMED_BRANCH_REF_PREFIX)
def parse_git_branch_ref(ref):
"""Parse a Git branch ref for named branch and topic information
......@@ -109,6 +122,9 @@
self.before = before
self.after = after
def is_creation(self):
return self.before == ZERO_SHA and self.after != ZERO_SHA
class HeptapodGitHandler(GitHandler):
......@@ -524,12 +540,11 @@
# a random value - we don't want it to select topics if possible
# and if it has, we want that to change.
default_branch_ref = self.git.refs.get_symrefs().get(b'HEAD')
update_default_branch = (
default_branch_ref not in git_refs
or default_branch_ref.startswith(git_branch_ref(b'topic/')))
update_default_branch = (default_branch_ref not in git_refs
or ref_is_topic(default_branch_ref))
new_named_branch_refs = []
for change in pycompat.itervalues(changes):
if change.after == ZERO_SHA:
del git_refs[change.ref]
else:
git_refs[change.ref] = change.after
......@@ -530,11 +545,10 @@
new_named_branch_refs = []
for change in pycompat.itervalues(changes):
if change.after == ZERO_SHA:
del git_refs[change.ref]
else:
git_refs[change.ref] = change.after
if (change.before == ZERO_SHA
and change.ref.startswith(git_branch_ref(b'branch/'))):
if change.is_creation() and ref_is_named_branch(change.ref):
new_named_branch_refs.append(change.ref)
if update_default_branch and new_named_branch_refs:
......
......@@ -252,7 +252,8 @@
# just checking our assumptions
assert git_repo.branch_titles() == {'branch/default': 'default1'}
# we need to test the branch masking on a branch that's not the GitLab default
# we need to test the branch masking on a branch
# that's not the GitLab default (which is protected)
server.write_commit('foo', branch='other', message='other1')
activate_mirror(server)
......@@ -283,7 +284,9 @@
wrapper = LocalRepoWrapper.init(tmpdir.join('repo.hg'), config=config)
git_repo = GitRepo.init(tmpdir.join('repo.git'))
wrapper.write_commit('foo', message="other0", branch=branch_name, topic='initial')
wrapper.write_commit('foo', message="other0",
branch=branch_name,
topic='initial')
wrapper.command('gitlab-mirror')
# that's what something (maybe Gitaly) does on the GitLab side:
git_repo.set_symref('HEAD', 'refs/heads/topic/%s/initial' % branch_name)
......
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