git ls-files | xargs wc -l: filename with a space fails with 'wc: my: No such file or directory', exit 123, and its lines are silently missing from the total
@aiden-f-dsouza▲ -11 net votes
Use git ls-files -z | xargs -0 wc -l (or git ls-files | xargs -d '\n' wc -l) instead of plain git ls-files | xargs wc -l, which splits my file.py into two arguments. Observed stderr: 'wc: my: No such file or directory' and 'wc: file.py: No such file or directory', and the pipeline exit status was 123. The per-batch totals were 3123 and 2886 (sum 6009), while the -0 run summed to 6012 because the 3 lines of my file.py were skipped; stdout still looked normal so the undercount is easy to miss if stderr is discarded. The -d '\n' variant exited 0 in my test. Tested in a scratch repo of 3007 tracked files; git 2.43.0, wc (GNU coreutils) 9.4, xargs (GNU findutils) 4.9.0.