-
Notifications
You must be signed in to change notification settings - Fork 19
Description
When adding a larger amount of files and directories to an existing (nearly empty)
git repository, "git commit -a" leads to githooks complaining about "Argument list
too long".
$ git add .
$ git commit -a -m "Import V7"
/home/mjk/.githooks/release/base-template.sh: 856: git: Argument list too long
/home/mjk/.githooks/release/base-template.sh: 250: git: Argument list too long
/home/mjk/.githooks/release/base-template.sh: 255: git: Argument list too long
/home/mjk/.githooks/release/base-template.sh: 856: git: Argument list too long
/home/mjk/.githooks/release/base-template.sh: 250: git: Argument list too long
/home/mjk/.githooks/release/base-template.sh: 255: git: Argument list too long
/home/mjk/.githooks/release/base-template.sh: 856: git: Argument list too long
/home/mjk/.githooks/release/base-template.sh: 250: git: Argument list too long
/home/mjk/.githooks/release/base-template.sh: 255: git: Argument list too long
[master 213c872] Import V7
4196 files changed, 3620500 insertions(+)
[...]
$ fd -t d -E .git | wc -l # number of directories (exclude ".git")
443
$ fd -t f -E .git | wc -l # number of files (exclude ".git")
4154
$ getconf ARG_MAX
2097152
$ git hooks version
Githooks - https://github.com/rycus86/githooks
----------------------------------------------
Version: 2303.282335-a988d0
Commit: a988d08 (Only print skipping disabled hooks once a day :sparkles:, 2023-03-28)
I am not sure if that error message comes from git or from the shell, but maybe
it would be possible to prevent it from happening by patching githooks: Either
by using something like xargs, or by storing the argument list in a temporary file,
or maybe this Stackoverflow answer points to the right direction:
------------ snip ------------
The "right answer", though, is probably to have the software itself be smarter. There's no need to invoke git add this particular way, with every file listed as one big argv vector. Indeed, instead of invoking git add directly, a program should probably be invoking git update-index instead. A Python program should probably be using update-index with the --stdin and -z flags (and any other flags as appropriate for this particular function's intended usage).
------------ snip ------------