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

git: split out methods to read default Git ref and branch

This is a simple refactor, but we take the opportunity to explain
the difference with the "default GitLab branch" of native
repositories: they're stored differently, should be equal wherever
it makes sense (it won't when native repositories won't use
hg-git except for mirroring).
parent 158b7fe2174c
No related branches found
No related tags found
1 merge request!35Native mode: Merge Request IID payloads and make sure we never prune the default GitLab branch
......@@ -109,6 +109,17 @@
self.gitdir = re.sub(br'\.hg$', b'', main_repo.root) + b'.git'
self.unfiltered_repo = self.repo.unfiltered()
def get_default_git_ref(self):
# HEAD is the source of truth for GitLab default branch
# For native projects, it's going to be the one stored
# in Mercurial, returned by get_default_gitlab_branch(), and we are
# maintaining consistency until we reach the HGitaly2 milestone
# (i.e., as long as hg-git is used even for native projects)
return self.git.refs.get_symrefs().get(b'HEAD')
def get_default_git_branch(self):
return git_branch_from_ref(self.get_default_git_ref())
def heptapod_gate_bookmarks(self, repo, allow, changes):
"""First handling of bookmark changes (refuse or not), return deleted.
......@@ -515,9 +526,7 @@
to Git SHAs
:returns: a mapping from Git refs to :class:`GitRefChange` objects
"""
# HEAD is the source of truth for GitLab default branch
default_git_branch = git_branch_from_ref(
self.git.refs.get_symrefs().get(b'HEAD'))
default_git_branch = self.get_default_git_branch()
to_prune = exportable.pop(ZERO_SHA, {})
to_prune.update(self.analyze_vanished_refs(existing, exportable))
to_prune.pop(default_git_branch, None)
......@@ -613,7 +622,7 @@
and if it previously has, we want that to change.
"""
git_refs = self.git.refs
default_ref = git_refs.get_symrefs().get(b'HEAD')
default_ref = self.get_default_git_ref()
default_exists = default_ref in git_refs
if default_exists and not ref_is_topic(default_ref):
return
......
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