Skip to content

Commit 8fef39a

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

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

scripts/pre-commit.bash

Lines changed: 5 additions & 6 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
8-
echo "Tests must pass before commit!"
9-
exit 1
6+
if ! ./scripts/test.sh; then
7+
echo "Tests must pass before commit!"
8+
exit 1
109
fi

scripts/pre-push.bash

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +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
15-
echo "The git push operation was canceled because \`$CMD\` did not complete successfully."
13+
if ! "$CMD"; then
14+
echo "The git push operation was canceled because ‘$CMD’ did not complete successfully."
1615
exit 1
1716
fi
18-
exit 0

0 commit comments

Comments
 (0)