Skip to content

Commit 0039a4d

Browse files
authored
Fix DOS pre-commit hook check. (#12718)
It turns out \r isn't recognized by -E (extended regex), using -P (perl) does recognize it. This also tightens up the .cmake suffix check by ensuring a literal '.' before cmake rather than any character.
1 parent e84ca70 commit 0039a4d

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

tools/git/pre-commit

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ deactivate
8585

8686
# Now repeat the above for CMakeLists.txt files.
8787
source ${CMAKE_FORMAT_VENV}/bin/activate
88-
git diff-index --cached --diff-filter=ACMR --name-only HEAD | grep -E 'CMakeLists.txt|.cmake$' | grep -vE "lib/(Catch2|fastlz|ls-hpack|swoc|yamlcpp)" | while read file; do
88+
git diff-index --cached --diff-filter=ACMR --name-only HEAD | grep -E 'CMakeLists.txt|\.cmake$' | grep -vE "lib/(Catch2|fastlz|ls-hpack|swoc|yamlcpp)" | while read file; do
8989
cmake-format "$file" | diff -u "$file" - >>"$cmake_format_patch_file"
9090
done
9191
deactivate
@@ -137,7 +137,8 @@ else
137137
fi
138138

139139
# Check for DOS carriage returns in staged files.
140-
DOS_CR=$(git diff-index --cached --diff-filter=ACMR --name-only HEAD | grep -vE "lib/(yamlcpp|Catch2|systemtap)" | grep -vE "\.test_input$" | xargs git diff --cached | grep -E '^\+.*\r$' || true)
140+
CR=$(printf '\r')
141+
DOS_CR=$(git diff-index --cached --diff-filter=ACMR --name-only HEAD | grep -vE "lib/(yamlcpp|Catch2|systemtap)" | grep -vE "\.test_input$" | xargs git diff --cached | grep "^+.*${CR}$" || true)
141142
if [ -n "$DOS_CR" ]; then
142143
echo "The commit is not accepted because it contains DOS carriage returns."
143144
echo "The easiest way to fix this is to run:"
@@ -149,6 +150,4 @@ else
149150
echo
150151
fi
151152

152-
# Cleanup before exit
153-
rm -f "$clang_patch_file" "$yapf_patch_file"
154153
exit 0

0 commit comments

Comments
 (0)