Skip to content

Commit 2a77ea5

Browse files
committed
Add git hooks
1 parent 697e1e6 commit 2a77ea5

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

git/hooks/pre-commit

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
set -eu
4+
5+
function timed_run() {
6+
description=$1
7+
command=$2
8+
timer=$(date +%s)
9+
10+
$command
11+
exit_code=$?
12+
timer=$(($(date +%s) - timer))
13+
14+
verbose=${MM_VERBOSE_HOOKS:-0}
15+
16+
if [ "$verbose" == "1" ]; then
17+
echo "ℹ️ $description - $timer seconds"
18+
echo "exit code: $exit_code"
19+
fi
20+
21+
if [ $exit_code -ne 0 ]; then
22+
echo "ℹ️ $description - failed"
23+
exit $exit_code
24+
fi
25+
}
26+
27+
timed_run "local/precious lint" "local/precious lint --staged"

git/setup.sh

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
chmod +x git/hooks/*
4+
cd .git/hooks || exit
5+
rm -f pre-commit.sample
6+
ln -s ../../git/hooks/pre-commit .
7+
git config --local core.hooksPath .git/hooks

0 commit comments

Comments
 (0)