Skip to content

Commit c37ca35

Browse files
committed
Add pre-commit hook
1 parent cbec98b commit c37ca35

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

pre-commit.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
# https://stackoverflow.com/questions/26886363/git-how-to-re-stage-the-staged-files-in-a-pre-commit-hook/39521255#39521255
3+
STASH_NAME="pre-commit-$(date +%s)"
4+
git stash save --quiet --keep-index --include-untracked $STASH_NAME
5+
6+
./tests.sh
7+
8+
RESULT=$?
9+
if [ $RESULT -ne 0 ]; then
10+
git stash save -q "original index"
11+
git stash apply -q --index stash@{1}
12+
git stash drop -q; git stash drop -q
13+
fi
14+
[ $RESULT -ne 0 ] && exit 1
15+
16+
git add -u

tests.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
cargo fmt --all --check
2+
cargo test --quiet --locked
3+
cargo clippy -- --deny warnings
4+
cargo clippy --tests -- --deny warnings
5+
find . -name '*.nix' -exec nix fmt {} \+
6+
nix flake check

0 commit comments

Comments
 (0)