From e7959ecc5d9f72485d98827e6aaa7e1db9d907a3 Mon Sep 17 00:00:00 2001 From: Talia Stocks <928827+taliastocks@users.noreply.github.com> Date: Fri, 14 Mar 2025 12:03:45 -0400 Subject: [PATCH 1/4] Update hook_impl.py Attempt to fix https://github.com/pre-commit/pre-commit/issues/2424, which has incorrectly been marked as a duplicate of https://github.com/pre-commit/pre-commit/issues/860 --- pre_commit/commands/hook_impl.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pre_commit/commands/hook_impl.py b/pre_commit/commands/hook_impl.py index 49a80b7b..c5d20169 100644 --- a/pre_commit/commands/hook_impl.py +++ b/pre_commit/commands/hook_impl.py @@ -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): + return not subprocess.call(('git', 'merge-base', '--is-ancestor', ancestor, rev)) + + def _pre_push_ns( color: bool, args: Sequence[str], @@ -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): return _ns( 'pre-push', color, from_ref=remote_sha, to_ref=local_sha, From 6c87f31a796d5b79223a9bde532db496dddab200 Mon Sep 17 00:00:00 2001 From: Talia Stocks <928827+taliastocks@users.noreply.github.com> Date: Fri, 14 Mar 2025 12:26:25 -0400 Subject: [PATCH 2/4] Apply suggestions from code review --- pre_commit/commands/hook_impl.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pre_commit/commands/hook_impl.py b/pre_commit/commands/hook_impl.py index c5d20169..ba6491b4 100644 --- a/pre_commit/commands/hook_impl.py +++ b/pre_commit/commands/hook_impl.py @@ -114,7 +114,9 @@ def _rev_exists(rev: str) -> bool: def _is_ancestor(ancestor: str, rev: str): - return not subprocess.call(('git', 'merge-base', '--is-ancestor', ancestor, rev)) + return not subprocess.call( + ('git', 'merge-base', '--is-ancestor', ancestor, rev) + ) def _pre_push_ns( @@ -130,7 +132,8 @@ 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) and _is_ancestor(remote_sha, local_sha): + elif remote_sha != Z40 and _rev_exists(remote_sha) \ + and _is_ancestor(remote_sha, local_sha): return _ns( 'pre-push', color, from_ref=remote_sha, to_ref=local_sha, From 311eeac59205ce9f6bd1cdea84404272943d58c7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 14 Mar 2025 16:26:39 +0000 Subject: [PATCH 3/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- pre_commit/commands/hook_impl.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pre_commit/commands/hook_impl.py b/pre_commit/commands/hook_impl.py index ba6491b4..bd936133 100644 --- a/pre_commit/commands/hook_impl.py +++ b/pre_commit/commands/hook_impl.py @@ -115,7 +115,7 @@ def _rev_exists(rev: str) -> bool: def _is_ancestor(ancestor: str, rev: str): return not subprocess.call( - ('git', 'merge-base', '--is-ancestor', ancestor, rev) + ('git', 'merge-base', '--is-ancestor', ancestor, rev), ) @@ -133,7 +133,7 @@ def _pre_push_ns( if local_sha == Z40: continue elif remote_sha != Z40 and _rev_exists(remote_sha) \ - and _is_ancestor(remote_sha, local_sha): + and _is_ancestor(remote_sha, local_sha): return _ns( 'pre-push', color, from_ref=remote_sha, to_ref=local_sha, From aadf7169021fbcf4a61636eecb64a5affc7fc286 Mon Sep 17 00:00:00 2001 From: Talia Stocks <928827+taliastocks@users.noreply.github.com> Date: Fri, 14 Mar 2025 12:27:41 -0400 Subject: [PATCH 4/4] Update pre_commit/commands/hook_impl.py --- pre_commit/commands/hook_impl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pre_commit/commands/hook_impl.py b/pre_commit/commands/hook_impl.py index bd936133..d77b7627 100644 --- a/pre_commit/commands/hook_impl.py +++ b/pre_commit/commands/hook_impl.py @@ -113,7 +113,7 @@ def _rev_exists(rev: str) -> bool: return not subprocess.call(('git', 'rev-list', '--quiet', rev)) -def _is_ancestor(ancestor: str, rev: str): +def _is_ancestor(ancestor: str, rev: str) -> bool: return not subprocess.call( ('git', 'merge-base', '--is-ancestor', ancestor, rev), )