Skip to content

Commit 3882f60

Browse files
authored
Merge pull request #207 from sysprog21/improve-shasum
Improve the detection of checksum program
2 parents c621c4b + 8d08946 commit 3882f60

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

scripts/pre-commit.hook

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,13 @@ if [ $? -ne 0 ]; then
7979
DIFF=diff
8080
fi
8181

82-
SHA1SUM=$(which sha1sum)
83-
if [ $? -ne 0 ]; then
84-
SHA1SUM=shasum
82+
if command -v sha1sum >/dev/null 2>&1; then
83+
SHA1SUM="sha1sum"
84+
elif command -v shasum >/dev/null 2>&1; then
85+
SHA1SUM="shasum"
86+
else
87+
echo "[!] sha1sum or shasum not installed." >&2
88+
exit 1
8589
fi
8690

8791
FILES=$(git diff --cached --name-only --diff-filter=ACMR | grep -E "\.(c|cpp|h)$")
@@ -116,7 +120,7 @@ if [ ! -z "${FILES[*]}" ]; then
116120
echo "${FILES[*]}"
117121
fi
118122

119-
$SHA1SUM -c scripts/checksums >/dev/null
123+
$SHA1SUM -c scripts/checksums 2>/dev/null >/dev/null
120124
if [ $? -ne 0 ]; then
121125
echo "[!] You are not allowed to change the header file queue.h or list.h" >&2
122126
exit 1

0 commit comments

Comments
 (0)