Skip to content

Commit efd8938

Browse files
kakkokoowenca
andauthored
[clang-format] Fix working -assume-filename with .clang-format-ignore (#113100)
Fixes #113099. --------- Co-authored-by: Owen Pan <[email protected]>
1 parent a35ebcf commit efd8938

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

clang/test/Format/clang-format-ignore.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,15 @@
4646
// CHECK5-NEXT: {{Formatting \[4/5] .*foo\.c}}
4747
// CHECK5-NOT: foo.js
4848

49+
// RUN: echo "foo.*" > .clang-format-ignore
50+
// RUN: echo "int i ;" > foo.c
51+
// RUN: clang-format -assume-filename=foo.c < foo.c \
52+
// RUN: | FileCheck %s -check-prefix=CHECK6 -allow-empty
53+
// CHECK6-NOT: int
54+
55+
// RUN: clang-format -assume-filename=bar.c < foo.c \
56+
// RUN: | FileCheck %s -check-prefix=CHECK7 -match-full-lines
57+
// CHECK7: int i;
58+
4959
// RUN: cd ..
5060
// RUN: rm -r %t.dir

clang/tools/clang-format/ClangFormat.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,8 +707,11 @@ int main(int argc, const char **argv) {
707707
errs() << "Clang-formatting " << LineNo << " files\n";
708708
}
709709

710-
if (FileNames.empty())
710+
if (FileNames.empty()) {
711+
if (isIgnored(AssumeFileName))
712+
return 0;
711713
return clang::format::format("-", FailOnIncompleteFormat);
714+
}
712715

713716
if (FileNames.size() > 1 &&
714717
(!Offsets.empty() || !Lengths.empty() || !LineRanges.empty())) {

0 commit comments

Comments
 (0)