Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pre-push: fix stdin line splitting when <local ref> has whitespace #2345

Merged
merged 1 commit into from Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion pre_commit/commands/hook_impl.py
Expand Up @@ -114,7 +114,8 @@ def _pre_push_ns(
remote_url = args[1]

for line in stdin.decode().splitlines():
local_branch, local_sha, remote_branch, remote_sha = line.split()
parts = line.rsplit(maxsplit=3)
local_branch, local_sha, remote_branch, remote_sha = parts
if local_sha == Z40:
continue
elif remote_sha != Z40 and _rev_exists(remote_sha):
Expand Down
12 changes: 12 additions & 0 deletions tests/commands/hook_impl_test.py
Expand Up @@ -242,6 +242,18 @@ def test_run_ns_pre_push_new_branch_existing_rev(push_example):
assert ns is None


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

with cwd(clone):
args = ('origin', src)
line = f'HEAD^{{/ }} {src_head} refs/heads/b2 {hook_impl.Z40}\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):
src, src_head, clone, _ = push_example

Expand Down