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
5 changes: 3 additions & 2 deletions pre_commit/commands/hook_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from pre_commit.store import Store

Z40 = '0' * 40
Z64 = '0' * 64


def _run_legacy(
Expand Down Expand Up @@ -128,9 +129,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 local_sha in {Z40, Z64}:
continue
elif remote_sha != Z40 and _rev_exists(remote_sha):
elif remote_sha not in {Z40, Z64} and _rev_exists(remote_sha):
return _ns(
'pre-push', color,
from_ref=remote_sha, to_ref=local_sha,
Expand Down
30 changes: 18 additions & 12 deletions tests/commands/hook_impl_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,43 +284,47 @@ def test_run_ns_pre_push_updating_branch(push_example):
assert ns.all_files is False


def test_run_ns_pre_push_new_branch(push_example):
@pytest.mark.parametrize('zero', (hook_impl.Z40, hook_impl.Z64))
def test_run_ns_pre_push_new_branch(push_example, zero):
src, src_head, clone, clone_head = push_example

with cwd(clone):
args = ('origin', src)
stdin = f'HEAD {clone_head} refs/heads/b {hook_impl.Z40}\n'.encode()
stdin = f'HEAD {clone_head} refs/heads/b {zero}\n'.encode()
ns = hook_impl._run_ns('pre-push', False, args, stdin)

assert ns is not None
assert ns.from_ref == src_head
assert ns.to_ref == clone_head


def test_run_ns_pre_push_new_branch_existing_rev(push_example):
@pytest.mark.parametrize('zero', (hook_impl.Z40, hook_impl.Z64))
def test_run_ns_pre_push_new_branch_existing_rev(push_example, zero):
src, src_head, clone, _ = push_example

with cwd(clone):
args = ('origin', src)
stdin = f'HEAD {src_head} refs/heads/b2 {hook_impl.Z40}\n'.encode()
stdin = f'HEAD {src_head} refs/heads/b2 {zero}\n'.encode()
ns = hook_impl._run_ns('pre-push', False, args, stdin)

assert ns is None


def test_run_ns_pre_push_ref_with_whitespace(push_example):
@pytest.mark.parametrize('zero', (hook_impl.Z40, hook_impl.Z64))
def test_run_ns_pre_push_ref_with_whitespace(push_example, zero):
src, src_head, clone, _ = push_example

with cwd(clone):
args = ('origin', src)
line = f'HEAD^{{/ }} {src_head} refs/heads/b2 {hook_impl.Z40}\n'
line = f'HEAD^{{/ }} {src_head} refs/heads/b2 {zero}\n'
stdin = line.encode()
ns = hook_impl._run_ns('pre-push', False, args, stdin)

assert ns is None


def test_pushing_orphan_branch(push_example):
@pytest.mark.parametrize('zero', (hook_impl.Z40, hook_impl.Z64))
def test_pushing_orphan_branch(push_example, zero):
src, src_head, clone, _ = push_example

cmd_output('git', 'checkout', '--orphan', 'b2', cwd=clone)
Expand All @@ -329,28 +333,30 @@ def test_pushing_orphan_branch(push_example):

with cwd(clone):
args = ('origin', src)
stdin = f'HEAD {clone_rev} refs/heads/b2 {hook_impl.Z40}\n'.encode()
stdin = f'HEAD {clone_rev} refs/heads/b2 {zero}\n'.encode()
ns = hook_impl._run_ns('pre-push', False, args, stdin)

assert ns is not None
assert ns.all_files is True


def test_run_ns_pre_push_deleting_branch(push_example):
@pytest.mark.parametrize('zero', (hook_impl.Z40, hook_impl.Z64))
def test_run_ns_pre_push_deleting_branch(push_example, zero):
src, src_head, clone, _ = push_example

with cwd(clone):
args = ('origin', src)
stdin = f'(delete) {hook_impl.Z40} refs/heads/b {src_head}'.encode()
stdin = f'(delete) {zero} 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):
@pytest.mark.parametrize('zero', (hook_impl.Z40, hook_impl.Z64))
def test_hook_impl_main_noop_pre_push(cap_out, store, push_example, zero):
src, src_head, clone, _ = push_example

stdin = f'(delete) {hook_impl.Z40} refs/heads/b {src_head}'.encode()
stdin = f'(delete) {zero} refs/heads/b {src_head}'.encode()
with mock.patch.object(sys.stdin.buffer, 'read', return_value=stdin):
with cwd(clone):
write_config('.', sample_local_config())
Expand Down
Loading