Files
WSL/.gitignore
Ben Hillis b7735bba18 Replace pre-commit hook with CMake-generated clang-format check (#40136)
* Replace pre-commit hook with CMake-generated clang-format check

Replace the old pre-commit hook that shelled out to PowerShell and
never blocked commits (-NoFail) with a CMake-generated hook that
calls clang-format directly on staged C/C++ files.

- Add tools/hooks/pre-commit.in as a CMake template
- CMake resolves the clang-format path at configure time via
  LLVM_INSTALL_DIR, matching the existing FormatSource.ps1.in pattern
- Hook blocks commits on formatting errors, skips gracefully if
  clang-format is not available (cmake not yet run)
- ~5x faster than the old PowerShell approach (~0.5s vs ~2.6s)

* Make pre-commit hook behavior configurable via WSL_PRE_COMMIT_MODE

Add WSL_PRE_COMMIT_MODE CMake cache variable with three modes:
- warn (default): report formatting issues without blocking commit
- error: block commit when formatting issues are found
- fix: auto-format files and re-stage them

Also addresses PR feedback:
- Generate hook into build tree, copy to source tree for out-of-source builds
- Use repo-local tools/clang-format.exe instead of LLVM_INSTALL_DIR path
- Use @ONLY in configure_file to avoid shell variable substitution issues
- Document modes in dev-loop.md and UserConfig.cmake.sample

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-09 13:31:21 -07:00

71 lines
828 B
Plaintext

.vscode/*
.vs/
!vendor/.preserve
out
tmp
/.vs/
/.vscode/
*.sln
*.slnx
*.user
*.csproj
*.vcxproj
*.filters
*.pdb
*.lib
*.dll
obj/
Debug/
Release/
Properties/
/_deps/
/package/Strings/en-US/
/packages/
CMakeFiles/
CMakeCache.txt
*.msix
cmake_install.cmake
build_tools/
*_i.c
*_p.c
*_p.c
wslsupport/wslsupport.h
dlldata.c
.gdbinit
llvm/
*.a
*.so
*.o
linux/init/init
linux/init
initrd/init
bin/
*.nupkg
generated/
*.nuspec
test/linux/unit_tests/wsl_unit_tests
*.dir/
UserConfig.cmake
*.wix
*.wixobj
*.wixpdb
test.bat
AppxManifest.xml
package_layout/
priconf.xml
resources.map.txt
resources.pri
msi-install-*.txt
kernellogs.txt
FormatSource.ps1
msixinstaller/x64
package/x64
/appx-logs.txt
tools/clang-format.exe
tools/hooks/pre-commit
!/tools/hooks/pre-commit.in
/linux-crashes
doc/site/
directory.build.targets
test-storage/
*.vhdx