Skip to content

Commit c62e67f

Browse files
committed
pre-commit-hook.sh: Exit if shfmt modifies sth
- shfmt formatting should be committed together with the original change
1 parent 52b486a commit c62e67f

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

pre-commit-hook.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,16 @@
77
echo
88
echo -e "${GREEN} ###### RUNNING PRE-COMMIT HOOKS ###### ${NC}"
99

10-
find . -type f -name "*.sh" -execdir shfmt -w {} \;
10+
files=$(find . -type f -name "*.sh" -exec shfmt -l {} \;)
11+
if [ -n "$files" ]; then
12+
echo "Error: The following shell files need formatting:"
13+
echo "$files"
14+
echo ""
15+
echo "Running: find . -type f -name \"*.sh\" -exec shfmt -w {} \\;"
16+
find . -type f -name "*.sh" -execdir shfmt -w {} \;
17+
echo "git add the formatted files and commit again"
18+
exit 1
19+
fi
1120

1221
# NOTE: `find -execdir` cannot be used because it does not propagate errors
1322
# NOTE: I am passing the filename as a parameter to the bash subshell, see

0 commit comments

Comments
 (0)