-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[clang-format] Fix a serious bug in
git clang-format -f
(#102629)
With the --force (or -f) option, git-clang-format wipes out input files excluded by a .clang-format-ignore file if they have unstaged changes. This patch adds a hidden clang-format option --list-ignored that lists such excluded files for git-clang-format to filter out. Fixes #102459.
- Loading branch information
Showing
3 changed files
with
84 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// RUN: rm -rf %t.dir | ||
// RUN: mkdir -p %t.dir/level1/level2 | ||
|
||
// RUN: cd %t.dir | ||
// RUN: echo "*" > .clang-format-ignore | ||
// RUN: echo "level*/*.c*" >> .clang-format-ignore | ||
// RUN: echo "*/*2/foo.*" >> .clang-format-ignore | ||
|
||
// RUN: touch foo.cc | ||
// RUN: clang-format -list-ignored .clang-format-ignore foo.cc \ | ||
// RUN: | FileCheck %s | ||
// CHECK: .clang-format-ignore | ||
// CHECK-NEXT: foo.cc | ||
|
||
// RUN: cd level1 | ||
// RUN: touch bar.cc baz.c | ||
// RUN: clang-format -list-ignored bar.cc baz.c \ | ||
// RUN: | FileCheck %s -check-prefix=CHECK2 | ||
// CHECK2: bar.cc | ||
// CHECK2-NEXT: baz.c | ||
|
||
// RUN: cd level2 | ||
// RUN: touch foo.c foo.js | ||
// RUN: clang-format -list-ignored foo.c foo.js \ | ||
// RUN: | FileCheck %s -check-prefix=CHECK3 | ||
// CHECK3: foo.c | ||
// CHECK3-NEXT: foo.js | ||
|
||
// RUN: touch .clang-format-ignore | ||
// RUN: clang-format -list-ignored foo.c foo.js \ | ||
// RUN: | FileCheck %s -allow-empty -check-prefix=CHECK4 | ||
// CHECK4-NOT: foo.c | ||
// CHECK4-NOT: foo.js | ||
|
||
// RUN: echo "*.js" > .clang-format-ignore | ||
// RUN: clang-format -list-ignored foo.c foo.js \ | ||
// RUN: | FileCheck %s -check-prefix=CHECK5 | ||
// CHECK5-NOT: foo.c | ||
// CHECK5: foo.js | ||
|
||
// RUN: cd ../.. | ||
// RUN: clang-format -list-ignored *.cc level1/*.c* level1/level2/foo.* \ | ||
// RUN: | FileCheck %s -check-prefix=CHECK6 | ||
// CHECK6: foo.cc | ||
// CHECK6-NEXT: bar.cc | ||
// CHECK6-NEXT: baz.c | ||
// CHECK6-NOT: foo.c | ||
// CHECK6-NEXT: foo.js | ||
|
||
// RUN: rm .clang-format-ignore | ||
// RUN: clang-format -list-ignored *.cc level1/*.c* level1/level2/foo.* \ | ||
// RUN: | FileCheck %s -check-prefix=CHECK7 | ||
// CHECK7-NOT: foo.cc | ||
// CHECK7-NOT: bar.cc | ||
// CHECK7-NOT: baz.c | ||
// CHECK7-NOT: foo.c | ||
// CHECK7: foo.js | ||
|
||
// RUN: cd .. | ||
// RUN: rm -r %t.dir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters