[PATCH] D130108: git-clang-format: format index not worktree when using --staged

Mészáros Gergely via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 19 11:59:52 PDT 2022


Maetveis created this revision.
Maetveis added a project: clang-format.
Herald added a subscriber: arphaman.
Herald added a project: All.
Maetveis requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

When --staged (or --cached) use the index for formatting as well, not just for the line numbers
to format.
Without this change git-clang-format gets the changed line numbers based on the index, but then
formats these lines on the working tree version of the file.
This is a problem when the working tree and index differ. One common case would be 
(and is the motivation behind this patch) when applying the suggested changes `git-clang-format --staged`,
then forgetting to add the applied changes. When `git-clang-format --staged --diff` is used in a
pre-commit hook in this scenario, then the hook would allow committing the improperly formatted changes,
as the file is correctly formatted in the work tree.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130108

Files:
  clang/tools/clang-format/git-clang-format

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130108.445897.patch
Type: text/x-patch
Size: 4936 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220719/c42568e7/attachment.bin>


More information about the cfe-commits mailing list