Skip to content

Commit 5ebe1c1

Browse files
committed
Add pre-commit hook
1 parent a038fc1 commit 5ebe1c1

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

Makefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,22 @@
55
# Variables
66
SHELL := /usr/bin/env bash
77
REPO_ROOT := $(shell git rev-parse --show-toplevel)
8-
TEST_SCRIPT := $(REPO_ROOT)/scripts/run.sh
8+
TEST_SCRIPT := $(REPO_ROOT)/script/run.sh
99

1010
help:
1111
@echo "Makefile targets:"
1212
@echo " test Run all tests using the run_tests.sh script"
1313
@echo " help Show this help message"
1414

15+
install-git-hooks:
16+
@ls -R ./.git/hooks > before.txt
17+
@cp -r ./script/hooks/ ./.git/
18+
@chmod +x ./.git/hooks/pre-commit
19+
@ls -R ./.git/hooks > after.txt
20+
@diff before.txt after.txt || true
21+
@rm before.txt after.txt
22+
@echo "Hooks installed successfully."
23+
1524
test:
1625
@if [ ! -f "$(TEST_SCRIPT)" ]; then \
1726
echo "Error: run_tests.sh not found in repository root."; \

readme.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,7 @@ Shows that certain participants provided an invalid final share, though the algo
4949

5050
Reveals that some participants have sent improperly encrypted data that is either incorrect or malicious, violating the algorithm's invariants.
5151

52+
### GIT hooks
53+
54+
```make install-git-hooks```
5255

script/hooks/pre-commit

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/sh
2+
echo "Local Pre-commit Hook...\n"
3+
4+
set -eu
5+
6+
if ! cargo fmt -- --check
7+
then
8+
echo "There are some code style issues."
9+
echo "Run cargo fmt first."
10+
exit 1
11+
fi
12+
13+
if ! cargo clippy --all-targets -- -D warnings
14+
then
15+
echo "There are some clippy issues."
16+
exit 1
17+
fi
18+
19+
if ! cargo test
20+
then
21+
echo "There are some test issues."
22+
exit 1
23+
fi
24+
25+
exit 0
File renamed without changes.

0 commit comments

Comments
 (0)