This is an archive of the discontinued LLVM Phabricator instance.

git-clang-format: Add --cached option to format index
AbandonedPublic

Authored by owenpan on Jun 6 2017, 8:54 AM.

Details

Summary

Add --cached option to git-clang-format which behaves analogously to the use of --cached for other git subcommands, by causing the operation to work against the index state rather than the working directory state.

This can be particularly useful for hook scripts which need to check or change the formatting of the index state before commit.

Event Timeline

kevinoid created this revision.Jun 6 2017, 8:54 AM
kevinoid updated this revision to Diff 101799.Jun 7 2017, 12:59 PM

Fixed handling of case when no formatting changes are made but old_tree != new_tree in apply_changes.

MyDeveloperDay set the repository for this revision to rC Clang.Oct 31 2019, 3:32 AM
MyDeveloperDay added a project: Restricted Project.
Herald added a project: Restricted Project. · View Herald TranscriptOct 31 2019, 3:32 AM
Herald added a subscriber: arphaman. · View Herald Transcript

Is this revision still relavant, I find it annoying that I have to run git add again on any files that are already added but have been formatted.

If you think this is useful and can rebase it perhaps we can go around the review cycle again with a fresh set of eyes

owenpan commandeered this revision.Oct 25 2023, 4:46 AM
owenpan edited reviewers, added: kevinoid; removed: owenpan.

We have --cached now.

Herald added a project: Restricted Project. · View Herald TranscriptOct 25 2023, 4:46 AM
NOTE: Clang-Format Team Automated Review Comment

It looks like your clang-format review does not contain any unit tests, please try to ensure all code changes have a unit test (unless this is an NFC or refactoring, adding documentation etc..)

Add your unit tests in clang/unittests/Format and you can build with ninja FormatTests. We recommend using the verifyFormat(xxx) format of unit tests rather than EXPECT_EQ as this will ensure you change is tolerant to random whitespace changes (see FormatTest.cpp as an example)

For situations where your change is altering the TokenAnnotator.cpp which can happen if you are trying to improve the annotation phase to ensure we are correctly identifying the type of a token, please add a token annotator test in TokenAnnotatorTest.cpp

owenpan abandoned this revision.Oct 25 2023, 4:46 AM