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

Skip to content

Commit 3bf852f

Browse files
committed
Limit xargs line length. Resolves pre-commit#205.
1 parent 52c2d9c commit 3bf852f

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

pre_commit/languages/helpers.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ def file_args_to_stdin(file_args):
1010
def run_hook(env, hook, file_args):
1111
quoted_args = [pipes.quote(arg) for arg in hook['args']]
1212
return env.run(
13-
' '.join(['xargs', '-0', hook['entry']] + quoted_args),
13+
# Use -s 4000 (slightly less than posix mandated minimum)
14+
# This is to prevent "xargs: ... Bad file number" on windows
15+
' '.join(['xargs', '-0', '-s4000', hook['entry']] + quoted_args),
1416
stdin=file_args_to_stdin(file_args),
1517
retcode=None,
1618
)

tests/commands/run_test.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,3 +305,32 @@ def test_get_changed_files():
305305
'3387edbb1288a580b37fe25225aa0b856b18ad1a',
306306
)
307307
assert files == ['CHANGELOG.md', 'setup.py']
308+
309+
310+
def test_lots_of_files(mock_out_store_directory, tmpdir_factory):
311+
# windows xargs seems to have a bug, here's a regression test for
312+
# our workaround
313+
git_path = make_consuming_repo(tmpdir_factory, 'python_hooks_repo')
314+
with cwd(git_path):
315+
# Override files so we run against them
316+
with io.open(
317+
'.pre-commit-config.yaml', 'a+',
318+
) as config_file:
319+
config_file.write(' files: ""\n')
320+
321+
# Write a crap ton of files
322+
for i in range(400):
323+
filename = '{0}{1}'.format('a' * 100, i)
324+
open(filename, 'w').close()
325+
326+
cmd_output('bash', '-c', 'git add .')
327+
install(Runner(git_path))
328+
329+
# Don't want to write to home directory
330+
env = dict(os.environ, **{'PRE_COMMIT_HOME': tmpdir_factory.get()})
331+
cmd_output(
332+
'git', 'commit', '-m', 'Commit!',
333+
# git commit puts pre-commit to stderr
334+
stderr=subprocess.STDOUT,
335+
env=env,
336+
)

0 commit comments

Comments
 (0)