diff --git a/heptapod/gitlab/change.py b/heptapod/gitlab/change.py index adb5d49653d610f2d40aa1e675bcc36b6216adc2_aGVwdGFwb2QvZ2l0bGFiL2NoYW5nZS5weQ==..85ac760749abcf3d64504ae5ba2fac5f24cdcc87_aGVwdGFwb2QvZ2l0bGFiL2NoYW5nZS5weQ== 100644 --- a/heptapod/gitlab/change.py +++ b/heptapod/gitlab/change.py @@ -39,6 +39,9 @@ def is_creation(self): return self.before == ZERO_SHA and self.after != ZERO_SHA + def is_deletion(self): + return self.after == ZERO_SHA and self.before != ZERO_SHA + def export_for_hook(self, handler, native=False): """Prepare for actual hook sending. diff --git a/hgext3rd/heptapod/state_maintainer.py b/hgext3rd/heptapod/state_maintainer.py index adb5d49653d610f2d40aa1e675bcc36b6216adc2_aGdleHQzcmQvaGVwdGFwb2Qvc3RhdGVfbWFpbnRhaW5lci5weQ==..85ac760749abcf3d64504ae5ba2fac5f24cdcc87_aGdleHQzcmQvaGVwdGFwb2Qvc3RhdGVfbWFpbnRhaW5lci5weQ== 100644 --- a/hgext3rd/heptapod/state_maintainer.py +++ b/hgext3rd/heptapod/state_maintainer.py @@ -119,6 +119,10 @@ # Methods relying on the expected implemented methods # + @property + def native(self): + return self.repo.ui.configbool(b'heptapod', b'native') + def is_wiki(self): """Tell whether self.repo is the storage for a GitLab wiki""" return (self.repo.ui.environ.get(b'GL_REPOSITORY', b'') @@ -815,7 +819,7 @@ prune_default_branch = to_prune.pop(default_git_branch, None) if ( prune_default_branch - and ui.configbool(b'heptapod', b'native') + and self.native and default_git_branch.startswith(b'branch/') ): msg = (b"These changes close or prune the Heptapod default " @@ -856,7 +860,7 @@ before=before_sha, after=after_sha) - if self.is_wiki(): + if self.is_wiki() and not self.native: # GitLab wikis are much hardwired onto 'master' in a Git repo on_default = changes.get(gitlab_branch_ref(b'branch/default')) if on_default is not None: @@ -936,7 +940,7 @@ return ui = self.repo.ui - native = ui.configbool(b'heptapod', b'native') + native = self.native ui.note(b"heptapod_notify_gitlab heptapod.native=%r" % native) if native and prune_reasons: @@ -1154,6 +1158,21 @@ if default_exists and not ref_is_topic(default_ref): return + # The default GitLab branch might not have been set on Wikis + # when they went native, see heptapod#1987. For Wikis, the choice + # is always 'branch/default'. + branch_default_ref = gitlab_branch_ref(b'branch/default') + if default_ref is None and self.is_wiki() and self.native: + change = changes.get(branch_default_ref) + exists = branch_default_ref in self.gitlab_refs + if change is not None: + # mutating boolean clearer than very long condition in `if` + exists &= not change.is_deletion() + exists |= change.is_creation() + if exists: + self.set_default_gitlab_ref(branch_default_ref) + return + new_named_branch_refs = set() fallback_new_refs = set() for ref, change in pycompat.iteritems(changes): @@ -1183,7 +1202,6 @@ ) return - branch_default_ref = gitlab_branch_ref(b'branch/default') if branch_default_ref in candidate_refs: new_default_ref = branch_default_ref else: diff --git a/hgext3rd/heptapod/tests/no_git/test_integration.py b/hgext3rd/heptapod/tests/no_git/test_integration.py index adb5d49653d610f2d40aa1e675bcc36b6216adc2_aGdleHQzcmQvaGVwdGFwb2QvdGVzdHMvbm9fZ2l0L3Rlc3RfaW50ZWdyYXRpb24ucHk=..85ac760749abcf3d64504ae5ba2fac5f24cdcc87_aGdleHQzcmQvaGVwdGFwb2QvdGVzdHMvbm9fZ2l0L3Rlc3RfaW50ZWdyYXRpb24ucHk= 100644 --- a/hgext3rd/heptapod/tests/no_git/test_integration.py +++ b/hgext3rd/heptapod/tests/no_git/test_integration.py @@ -211,9 +211,7 @@ sha = fixture.ctx1.hex() # for wikis, we duplicate `branch/default` as `master` - changes = {}, {b'refs/heads/branch/default': (ZERO_SHA, sha), - b'refs/heads/master': (ZERO_SHA, sha), - } + changes = {}, {b'refs/heads/branch/default': (ZERO_SHA, sha)} assert notifs == [ ('pre-receive', changes), ('post-receive', changes),