Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2562c7f

Browse files
authored
Merge pull request #2345 from wwade/main
pre-push: fix stdin line splitting when <local ref> has whitespace
2 parents f9473e7 + feb0d34 commit 2562c7f

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

pre_commit/commands/hook_impl.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ def _pre_push_ns(
114114
remote_url = args[1]
115115

116116
for line in stdin.decode().splitlines():
117-
local_branch, local_sha, remote_branch, remote_sha = line.split()
117+
parts = line.rsplit(maxsplit=3)
118+
local_branch, local_sha, remote_branch, remote_sha = parts
118119
if local_sha == Z40:
119120
continue
120121
elif remote_sha != Z40 and _rev_exists(remote_sha):

tests/commands/hook_impl_test.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,18 @@ def test_run_ns_pre_push_new_branch_existing_rev(push_example):
242242
assert ns is None
243243

244244

245+
def test_run_ns_pre_push_ref_with_whitespace(push_example):
246+
src, src_head, clone, _ = push_example
247+
248+
with cwd(clone):
249+
args = ('origin', src)
250+
line = f'HEAD^{{/ }} {src_head} refs/heads/b2 {hook_impl.Z40}\n'
251+
stdin = line.encode()
252+
ns = hook_impl._run_ns('pre-push', False, args, stdin)
253+
254+
assert ns is None
255+
256+
245257
def test_pushing_orphan_branch(push_example):
246258
src, src_head, clone, _ = push_example
247259

0 commit comments

Comments
 (0)