Skip to content

Commit

Permalink
Fix review request for already known commitID
Browse files Browse the repository at this point in the history
If someone pushed a commit to a tag only instead to a branch
it was not recognized as "already known commit" it the hooks
tried to create another review request for the same commit.

So let's check tag for already known commits, too.
  • Loading branch information
misery committed Jan 31, 2025
1 parent c1c0103 commit 653e975
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions contrib/mercurial_git_push.py
Original file line number Diff line number Diff line change
Expand Up @@ -1433,12 +1433,17 @@ class GitRevision(BaseRevision):
"""Class to represent information of changeset."""

@staticmethod
def fetch_known_branches(rev):
output = execute(['git', 'branch', '--contains', rev])
branches = []
for branch in output.splitlines():
branches.append(branch.replace('*', '').strip())
return branches
def fetch_known_refs(rev):
output = execute(['git', 'for-each-ref', '--contains', rev])
refs = []
for line in output.splitlines():
values = line.split()
if values[1] in ('commit', 'tag') and (
'refs/heads/' in values[2] or
'refs/tags/' in values[2]
):
refs.append(values[2])
return refs

@staticmethod
def fetch_raw(node, base, skipKnown=True):
Expand All @@ -1454,7 +1459,7 @@ def fetch_raw(node, base, skipKnown=True):

if skipKnown:
def isKnown(rev):
return len(GitRevision.fetch_known_branches(rev)) > 0
return len(GitRevision.fetch_known_refs(rev)) > 0
changes[:] = [x for x in changes if not isKnown(x)]
return changes

Expand Down Expand Up @@ -1545,7 +1550,7 @@ def hasDangling(self):
if self._has_dangling is None:
self._has_dangling = (
self.isMerge() and
len(GitRevision.fetch_known_branches(self.parent(1))) == 0
len(GitRevision.fetch_known_refs(self.parent(1))) == 0
)
return self._has_dangling

Expand Down

0 comments on commit 653e975

Please sign in to comment.