Skip to content

Commit 277ec2e

Browse files
committed
Make git hooks more robust
1 parent b2b1c54 commit 277ec2e

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

developer-scripts/git-hooks/commit-msg

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/bin/bash
22
#
33
# An example hook script to check the commit log message.
44
# Called by "git commit" with one argument, the name of the file
@@ -77,7 +77,8 @@ test "" = "$(grep '^Signed-off-by: ' "$1" |
7777
# Check that the first line of the commit starts with a
7878
# capitalized letter.
7979
if ! (head -n 1 $1 | grep '^[A-Z]' &>/dev/null ); then
80-
echo >&2 "First word of commit message must be a capitalized imperative verb.\n"
80+
echo >&2 "First word of commit message must be a capitalized imperative verb."
81+
echo ""
8182
let status=1
8283
fi
8384

@@ -89,23 +90,28 @@ cat $1 | \
8990
nchars=$(wc -c <<<$line)
9091
if [[ "$ln" -eq "1" ]]; then
9192
if [[ "$nchars" -gt "51" ]]; then
92-
echo >&2 "First line of commit message too long ($nchars > 50 chars)\n"
93+
echo >&2 "First line of commit message too long ($nchars > 50 chars)"
94+
echo ""
9395
let status=1
9496
fi
9597
elif [[ "$ln" -eq "2" ]]; then
9698
if [[ "$nchars" -gt "1" ]] && ! grep '^#' <<<"$line" >/dev/null; then
97-
echo >&2 "Second line of commit message not blank\n"
99+
echo >&2 "Second line of commit message not blank"
100+
echo ""
98101
let status=1
99102
fi
100103
else
101104
if [[ "$nchars" -gt "72" ]]; then
102-
echo >&2 "Line $ln of commit message too long ($nchars > 72 chars)\n"
105+
echo >&2 "Line $ln of commit message too long ($nchars > 72 chars)"
106+
echo ""
103107
let status=1
104108
fi
105109
fi
106110
done
107111

108-
if [[ $status != 0 ]]; then
109-
error_message
110-
exit 1
112+
if [[ $status = 0 ]]; then
113+
exit 0
111114
fi
115+
116+
error_message
117+
exit 1

developer-scripts/git-hooks/pre-commit

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/bin/bash
22
#
33
# An example hook script to verify what is about to be committed.
44
# Called by "git commit" with no arguments. The hook should
@@ -71,15 +71,18 @@ for f in $(git diff-index --name-status --cached $against | grep -v ^D | cut -c3
7171
if [[ "$f" =~ ([.](h|m|c|rb|sh|py|txt|md|f90|F90|cmake|x64|csh)|makefile|Makefile)$ ]] ||
7272
head -n 1 | grep '^#!/'; then
7373
if ! ends_with_newline "$f"; then
74-
echo &>2 "No newline at end of file: $f\n"
74+
echo &>2 "No newline at end of file: $f"
75+
echo ""
7576
let status=1
7677
fi
7778
fi
7879
done
7980

8081
# If there are whitespace errors, print the offending file names and fail.
81-
git diff-index --check --cached $against -- || let status=1
82+
git diff-index --check --cached $against -- || (let status=1 echo 'white space violations found')
8283

83-
if [[ $status != 0 ]]; then
84-
exit 1
84+
if [[ $status = 0 ]]; then
85+
exit 0
8586
fi
87+
88+
exit 1

developer-scripts/setup-git.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ if [[ "$1" ]]; then
88
echo "WARNING: Settings will be applied globally. This may over-write some of your global git settings."
99
read -p "Press Ctrl-C to abort, and try again without \`--global\` or press any key to contibue" foo
1010
else
11-
echo -e "Usage: $0 [--global] [--help]\n"
11+
echo "Usage: $0 [--global] [--help]"
12+
echo ""
1213
echo "This script is to configure your git environment"
1314
echo "For contributing to OpenCoarrays. The \`--help\`"
1415
echo "flag will print this message. The \`--global\`"

0 commit comments

Comments
 (0)