mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Merge pull request #2345 from wwade/main
pre-push: fix stdin line splitting when <local ref> has whitespace
This commit is contained in:
commit
2562c7f796
2 changed files with 14 additions and 1 deletions
|
|
@ -114,7 +114,8 @@ def _pre_push_ns(
|
||||||
remote_url = args[1]
|
remote_url = args[1]
|
||||||
|
|
||||||
for line in stdin.decode().splitlines():
|
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:
|
if local_sha == Z40:
|
||||||
continue
|
continue
|
||||||
elif remote_sha != Z40 and _rev_exists(remote_sha):
|
elif remote_sha != Z40 and _rev_exists(remote_sha):
|
||||||
|
|
|
||||||
|
|
@ -242,6 +242,18 @@ def test_run_ns_pre_push_new_branch_existing_rev(push_example):
|
||||||
assert ns is None
|
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):
|
def test_pushing_orphan_branch(push_example):
|
||||||
src, src_head, clone, _ = push_example
|
src, src_head, clone, _ = push_example
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue