mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
pre-push: fix stdin line splitting when <local ref> has whitespace
From the `pre-push.sample` file: > Information about the commits which are being pushed is supplied as > lines to the standard input in the form: > > <local ref> <local sha1> <remote ref> <remote sha1> When `<local ref>` is not simply a branch name, but a more general ref (see git-rev-parse(1)), it could contain whitespace, and that breaks the split() call that expected only 3 spaces in the line. Changed to use `rsplit(maxsplit=3)` since only the <local ref> is likely to have embedded whitespace. Added a new test case for the same.
This commit is contained in:
parent
f9473e756d
commit
feb0d34213
2 changed files with 14 additions and 1 deletions
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue