Issue 123921
Summary [ClangFormat] Print paths with null (git)
Labels
Assignees
Reporter createyourpersonalaccount
    I use `clang-format` in my git pre-commit hook to format my diffs:

```sh
git clang-format --staged \
  | tail -n +2 \
  | xargs git add
```

*This is not a secure git hook due to tricky filenames.*

The issue with `git clang-format --staged` is that it lacks an option to print the affected paths with nulls, hence it is non-composable in the shell, see e.g. <https://dwheeler.com/essays/filenames-in-shell.html>.

The way to fix this is to provide an option like `-z` (xargs has `-0`, find has `-z`, etc) that will make the affected paths be printed with null bytes at their end. Then the above command could be changed to:

```sh
git clang-format --staged -z \
  | xargs -0 git add
```

and there would not be any issues with the parsing of the filenames by xargs.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to