mirror-llvm-project/clang/tools
eoineoineoin e89830da7f
Add option to format a whole file using git-clang-format (#204336)
Today, git-clang-format will only format lines which have been modified.
However, in some cases, that's not sufficient to get a "clean" file
which would be unmodified by running `clang-format` manually.

I've got a minimal repro using the default clang-format rules. Setup a
new git repository and create a commit with an empty file:

```
mkdir /tmp/bla
cd /tmp/bla
git init
touch t.cpp
git add t.cpp
git commit -m "V1"
```

Add a line to that file containing a comment:
```
echo "int x = 0; // Comment describing x" > t.cpp
git add t.cpp
git clang-format --staged # Reports "clang-format did not modify any files"
git commit -m "V2"
```

There's nothing wrong with this file yet, and it's working as expected.
Problem arises when we add a new line with a comment which is not
aligned with the comment we've already added:

```
echo "int longerThanX = 0; // Should cause above to become aligned" >> t.cpp
git add t.cpp
git clang-format --staged # Reports "clang-format did not modify any files"
```

git-clang-format didn't change the staged file here as it's only
inspecting the modified lines, but according to the default formatting
rules, this new line actually has an effect on the preceding line. i.e.,
if you run `clang-format t.cpp`, you'll see that whitespace is added
before the "Comment describing x" to align with the "Should cause..."

It's not limited to _just_ the preceding line (e.g. in the case where we
have multiple lines like the first with comments which become
unaligned,) so can't just add more lines of context to the diff. This PR
just adds an option to format the whole file, instead of just the
modified sections.
2026-07-31 22:22:14 -07:00
..
apinotes-test
c-index-test [clang] Suppress glibc C11 extension warning in c-index-test (#193335) 2026-04-22 12:08:09 +01:00
cir-lsp-server [CIR] Centralize dialect registration across CIR tools (#200266) 2026-06-05 20:52:21 -04:00
cir-opt [CIR][OpenMP] Add host op filtering pass to CIR pipeline (#209592) 2026-07-21 20:41:03 -04:00
cir-translate [CIR] Pointer and vptr width from a CIR-native data-layout entry (#204185) 2026-07-30 16:50:13 -07:00
clang-check [Tooling][clang-tools-extra] Consume CommonOptionsParser errors in tools (#193675) 2026-04-24 13:25:26 +08:00
clang-diff
clang-extdef-mapping [NFC][clang] Fix typo and warnings in ClangExtDefMapGen.cpp (#175154) 2026-01-16 18:06:51 +01:00
clang-format Add option to format a whole file using git-clang-format (#204336) 2026-07-31 22:22:14 -07:00
clang-fuzzer [llc] Add -mtune option (#186998) 2026-03-20 10:20:40 +02:00
clang-import-test [Clang] Improve CodeGenerator API a bit (#175239) 2026-01-12 22:46:59 +01:00
clang-installapi Revert "[Support][JSON] Use std::unordered_map for object storage" (#193549) 2026-04-22 10:33:54 -07:00
clang-linker-wrapper [ClangLinkerWrapper][SPIRV] Fix embed bitcode option (#213137) 2026-07-31 14:49:09 +00:00
clang-nvlink-wrapper [NVPTX] Pass -Xcuda-ptxas to the nvlink wrapper for LTO (#213351) 2026-07-31 16:24:50 -05:00
clang-offload-bundler [clang-offload-bundler] Convert std::vector to llvm::SmallVector in OffloadBundlerConfig (#192259) 2026-06-10 08:09:05 +08:00
clang-refactor [Tooling][clang-tools-extra] Consume CommonOptionsParser errors in tools (#193675) 2026-04-24 13:25:26 +08:00
clang-repl [clang-repl] Rework layering of incremental executors. (#175448) 2026-01-12 11:46:26 +02:00
clang-scan-deps [clang][DependencyScanning] Implement the Streaming Style By-name Scanning API (#211406) 2026-07-31 08:54:13 -07:00
clang-shlib [clang-shlib] Fix linking libclang-cpp on Haiku (#156401) 2025-10-29 20:55:15 -04:00
clang-ssaf-analyzer [clang][ssaf] Shorten directory name to ScalableStaticAnalysis (#204697) 2026-06-24 16:44:57 -07:00
clang-ssaf-format [clang][ssaf] Add MultiArchSharedLibrary data structure (#206854) 2026-07-02 20:11:37 -07:00
clang-ssaf-linker [clang][ssaf] Add static-library create subcommand (#208799) 2026-07-17 00:41:48 +00:00
clang-sycl-linker [clang-sycl-linker] Forward all --ocloc-options occurrences to ocloc (#211075) 2026-07-21 22:59:12 +00:00
diag-build
diagtool [Clang][diagtool] Fix memory leak in ShowEnabledWarnings (#191711) 2026-04-12 14:34:36 -04:00
driver Reapply "[MC][NFC] Make FeatureKV/SubtargetKV pointers private" (#206234) (#206237) 2026-06-27 10:39:44 +00:00
include-mapping Fix tests of lookup table generator (#139463) 2025-05-27 13:45:11 +02:00
libclang [OpenMP] Split UPDATE clause into two: for ATOMIC and for DEPOBJ (#212270) 2026-07-29 07:30:31 -05:00
offload-arch [offload-arch] Fix amdgpu HIP DLL search path on Windows (#209898) 2026-07-22 08:31:14 -07:00
scan-build [clang][tools] Update Python2 code in set-xcode-analyzer to Python3 (#163737) 2025-11-03 13:16:10 +00:00
scan-build-py [clang][scan-build-py] Fix configure scripts when using Python 3.14 (#206792) 2026-07-10 11:38:53 +01:00
scan-view [clang][tools][scan-view] Remove Python2 compatibility code in ScanView.py (#163747) 2025-10-31 10:19:10 +00:00
CMakeLists.txt [clang][ssaf] Add clang-ssaf-analyzer (#196124) 2026-05-06 14:00:52 -07:00