Skip to content

Commit 5e862e7

Browse files
authored
Merge pull request #131 from veridatum-labs/chore/pre-commit-guardrails
Add lightweight pre-commit guardrails
2 parents cf406f7 + aec5e1b commit 5e862e7

4 files changed

Lines changed: 53 additions & 1 deletion

File tree

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
# mutation self-test (scripts/mutation-test.ps1 -SelfTest) can apply them with
33
# `git apply` regardless of the checkout's autocrlf setting.
44
tests/mutation/seeds/*.patch -text
5+
6+
.githooks/* text eol=lf

.githooks/commit-msg

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/sh
2+
set -eu
3+
4+
message_file="$1"
5+
subject="$(sed -n '1p' "$message_file" | tr -d '\r')"
6+
7+
case "$subject" in
8+
Merge\ *|Revert\ \"*|fixup!\ *|squash!\ *)
9+
exit 0
10+
;;
11+
esac
12+
13+
pattern='^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\([[:alnum:]./_-]+\))?!?: .+'
14+
15+
if printf '%s\n' "$subject" | grep -Eq "$pattern"; then
16+
exit 0
17+
fi
18+
19+
cat <<'EOF'
20+
Commit message must use a conventional subject, for example:
21+
feat: add proof search
22+
fix(registry): reject inactive issuers
23+
chore!: update supported Rust version
24+
25+
Allowed types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert.
26+
Scopes, breaking-change markers, issue IDs, and subject punctuation are optional.
27+
EOF
28+
exit 1

.githooks/pre-commit

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/sh
2+
set -eu
3+
4+
staged_files="$(git diff --cached --name-only --diff-filter=ACMRD)"
5+
6+
if [ -z "$staged_files" ]; then
7+
exit 0
8+
fi
9+
10+
if ! printf '%s\n' "$staged_files" | grep -Eq '(Cargo\.lock|Cargo\.toml|\.rs)$'; then
11+
echo "pre-commit: no Rust code or Cargo configuration changes; skipping tests."
12+
exit 0
13+
fi
14+
15+
echo "pre-commit: running contracts workspace tests..."
16+
cargo test --workspace

CONTRIBUTING.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,15 @@ This repository contains Soroban contracts for EarnProof issuer status, proof co
77
```bash
88
cargo build --workspace
99
cargo test --workspace
10+
git config core.hooksPath .githooks
1011
```
1112

13+
Run the Git command once per checkout to enable the tracked hooks. The
14+
pre-commit hook runs workspace tests when staged Rust or Cargo files change.
15+
The commit-message hook accepts conventional subjects such as `feat: add proof
16+
search` and `fix(registry): reject inactive issuers`; scopes and issue IDs are
17+
optional.
18+
1219
## Validation
1320

1421
Run these before opening a pull request:
@@ -36,4 +43,3 @@ cargo build --workspace
3643
- Contract storage, authorization, and event behavior are covered by tests.
3744
- Documentation matches actual on-chain behavior.
3845
- Testnet deployment evidence is updated when deployment behavior changes.
39-

0 commit comments

Comments
 (0)