Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Update hook_impl.py
Attempt to fix #2424, which has incorrectly been marked as a duplicate of #860
  • Loading branch information
taliastocks authored Mar 14, 2025
commit e7959ecc5d9f72485d98827e6aaa7e1db9d907a3
6 changes: 5 additions & 1 deletion pre_commit/commands/hook_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ def _rev_exists(rev: str) -> bool:
return not subprocess.call(('git', 'rev-list', '--quiet', rev))


def _is_ancestor(ancestor: str, rev: str):
Comment thread
taliastocks marked this conversation as resolved.
Outdated
return not subprocess.call(('git', 'merge-base', '--is-ancestor', ancestor, rev))
Comment thread
taliastocks marked this conversation as resolved.
Outdated


def _pre_push_ns(
color: bool,
args: Sequence[str],
Expand All @@ -126,7 +130,7 @@ def _pre_push_ns(
local_branch, local_sha, remote_branch, remote_sha = parts
if local_sha == Z40:
continue
elif remote_sha != Z40 and _rev_exists(remote_sha):
elif remote_sha != Z40 and _rev_exists(remote_sha) and _is_ancestor(remote_sha, local_sha):
Comment thread
taliastocks marked this conversation as resolved.
Outdated
return _ns(
'pre-push', color,
from_ref=remote_sha, to_ref=local_sha,
Expand Down