From 7f9b29dfd4d140ebd361a595a2bfe8b2a5d9f4b2 Mon Sep 17 00:00:00 2001 From: "Andrew S. Brown" Date: Wed, 6 Feb 2019 11:58:03 -0800 Subject: [PATCH] Add osx specific limit for command-line length Limit on OSX is 262144 --- pre_commit/xargs.py | 2 ++ tests/xargs_test.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/pre_commit/xargs.py b/pre_commit/xargs.py index e2686f0f..d6721a36 100644 --- a/pre_commit/xargs.py +++ b/pre_commit/xargs.py @@ -15,6 +15,8 @@ from pre_commit.util import cmd_output # TODO: properly compute max_length value def _get_platform_max_length(): + if sys.platform == "darwin": + return 262144 # posix minimum return 4 * 1024 diff --git a/tests/xargs_test.py b/tests/xargs_test.py index 0e91f9be..9036eae0 100644 --- a/tests/xargs_test.py +++ b/tests/xargs_test.py @@ -36,6 +36,13 @@ def linux_mock(): yield +@pytest.fixture +def osx_mock(): + with mock.patch.object(sys, 'getfilesystemencoding', return_value='utf-8'): + with mock.patch.object(sys, 'platform', 'darwin'): + yield + + def test_partition_trivial(): assert xargs.partition(('cmd',), (), 1) == (('cmd',),) @@ -88,6 +95,13 @@ def test_partition_limit_linux(linux_mock): assert ret == (cmd + varargs,) +def test_partition_limit_osx(osx_mock): + cmd = ('ninechars',) + varargs = (('x' * 9,) * 26214) + ret = xargs.partition(cmd, varargs, 1) + assert ret == (cmd + varargs[0:26213], (cmd + varargs[26213:])) + + def test_argument_too_long_with_large_unicode(linux_mock): cmd = ('ninechars',) varargs = ('😑' * 10,) # 4 bytes * 10