Skip to content

Commit 8af5eff

Browse files
committed
[#37] Show the proposed clang-format fix in all cases.
If the `hooks.clangFormatDiffInteractive` setting is false, the user is unable or unwilling to interact with the hook, but they still need to see the location of the proposed fix, in order to update the code so that the hook passes next time.
1 parent ac35e70 commit 8af5eff

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

git-pre-commit-format

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,15 @@ fi
287287

288288
# The code is not formatted correctly.
289289

290+
if hash colordiff 2> /dev/null; then
291+
colordiff < "$patch"
292+
else
293+
echo "${b}(Install colordiff to see this diff in color!)${n}"
294+
echo
295+
cat "$patch"
296+
fi
297+
echo
298+
290299
interactive=$(cd "$top_dir" && git config --bool hooks.clangFormatDiffInteractive)
291300
if [ "$interactive" != false ]; then
292301
# Interactive is the default, so anything that is not false is converted to
@@ -305,22 +314,13 @@ if [ "$interactive" = false ]; then
305314
exit 1
306315
fi
307316

308-
if hash colordiff 2> /dev/null; then
309-
colordiff < "$patch"
310-
else
311-
echo "${b}(Install colordiff to see this diff in color!)${n}"
312-
echo
313-
cat "$patch"
314-
fi
315-
316317
# We don't want to suggest applying clang-format after merge resolution
317318
if git rev-parse MERGE_HEAD >/dev/null 2>&1; then
318319
readonly this_is_a_merge=true
319320
else
320321
readonly this_is_a_merge=false
321322
fi
322323

323-
echo
324324
echo "${b}The staged content is not formatted correctly.${n}"
325325
echo "The fix shown above can be applied automatically to the commit."
326326
echo

0 commit comments

Comments
 (0)