Skip to content

Commit 8160044

Browse files
committed
Lint the Git hooks
- Bash “strict mode” - address ShellCheck complaints - replace backticks with `$()` - don’t compare against `$?`
1 parent 1a8d10d commit 8160044

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

scripts/pre-commit.bash

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
#!/usr/bin/env bash
2+
set -euo pipefail
23

3-
echo "Running pre-commit hook from "`pwd`
4-
./scripts/test.sh
4+
echo "Running pre-commit hook from $(pwd)"
55

6-
# $? stores exit value of the last command
7-
if [ $? -ne 0 ]; then
6+
if ! ./scripts/test.sh; then
87
echo "Tests must pass before commit!"
98
exit 1
109
fi

scripts/pre-push.bash

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
#!/bin/bash
2-
# Run the following command in the root of your project to install this pre-push hook:
3-
# cp git-hooks/pre-push .git/hooks/pre-push; chmod 700 .git/hooks/pre-push
2+
set -euo pipefail
3+
4+
# Run `./install-hooks.bash` to install this pre-push hook.
45

56
# Check if we actually have commits to push
6-
commits=`git log @{u}..`
7+
commits=$(git log "@{u}..")
78
if [ -z "$commits" ]; then
89
exit 0
910
fi
1011

1112
CMD="./scripts/test.sh"
12-
eval $CMD
13-
RESULT=$?
14-
if [ $RESULT -ne 0 ]; then
13+
if ! "$CMD"; then
1514
echo "The git push operation was canceled because \`$CMD\` did not complete successfully."
1615
exit 1
1716
fi

0 commit comments

Comments
 (0)