pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/pre-commit/pre-commit/pull/3692/files

github.githubassets.com/assets/code-34e10031edc15af1.css" /> Handle SHA-256 zero OIDs in pre-push by Sean-Kenneth-Doherty · Pull Request #3692 · pre-commit/pre-commit · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 8 additions & 2 deletions pre_commit/commands/hook_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from pre_commit.store import Store

Z40 = '0' * 40
Z64 = '0' * 64
ZERO_OIDS = frozenset((Z40, Z64))


def _run_legacy(
Expand Down Expand Up @@ -117,6 +119,10 @@ def _rev_exists(rev: str) -> bool:
return not subprocess.call(('git', 'rev-list', '--quiet', rev))


def _is_zero_oid(oid: str) -> bool:
return oid in ZERO_OIDS


def _pre_push_ns(
color: bool,
args: Sequence[str],
Expand All @@ -128,9 +134,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
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 = ('origen', src)
stdin = f'(delete) {hook_impl.Z64} 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
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy