FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Handle SHA-256 zero OIDs in pre-push by AleksZyro · Pull Request #3738 · pre-commit/pre-commit · GitHub

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
8 changes: 6 additions & 2 deletions pre_commit/commands/hook_impl.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
Z40 = '0' * 40


def _is_zero_oid(s: str) -> bool:
return len(s) in {40, 64} and set(s) == {'0'}


def _run_legacy(
hook_type: str,
hook_dir: str | None,
Expand Down Expand Up @@ -128,9 +132,9 @@ def _pre_push_ns(
for line in stdin.decode().splitlines():
parts = line.rsplit(maxsplit=3)
local_branch, local_sha, remote_branch, remote_sha = parts
if local_sha == Z40:
if _is_zero_oid(local_sha):
continue
elif remote_sha != Z40 and _rev_exists(remote_sha):
elif not _is_zero_oid(remote_sha) and _rev_exists(remote_sha):
return _ns(
'pre-push', color,
from_ref=remote_sha, to_ref=local_sha,
Expand Down
11 changes: 11 additions & 0 deletions tests/commands/hook_impl_test.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,17 @@ def test_run_ns_pre_push_deleting_branch(push_example):
assert ns is None


def test_run_ns_pre_push_deleting_branch_sha256(push_example):
src, src_head, clone, _ = push_example

with cwd(clone):
args = ('origin', src)
stdin = f'(delete) {"0" * 64} refs/heads/b {src_head}'.encode()
ns = hook_impl._run_ns('pre-push', False, args, stdin)

assert ns is None


def test_hook_impl_main_noop_pre_push(cap_out, store, push_example):
src, src_head, clone, _ = push_example

Expand Down
Loading

Back | FazBrowse Home | New Git URL