Skip to content

Commit 2ed39c0

Browse files
committed
Add local pre-commit quality gates and installer
1 parent 4f9d2b3 commit 2ed39c0

4 files changed

Lines changed: 40 additions & 0 deletions

File tree

.githooks/checks.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env sh
2+
set -eu
3+
4+
echo "Running pre-commit checks..."
5+
echo "• cargo fmt --all -- --check"
6+
cargo fmt --all -- --check
7+
8+
echo "• cargo clippy --all-targets --all-features"
9+
cargo clippy --all-targets --all-features
10+
11+
echo "• cargo test --all-features"
12+
cargo test --all-features

.githooks/install.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env sh
2+
set -eu
3+
4+
repo_root="$(git rev-parse --show-toplevel)"
5+
cd "$repo_root"
6+
7+
git config --local core.hooksPath .githooks
8+
chmod +x .githooks/pre-commit .githooks/checks.sh
9+
10+
echo "Git hooks enabled from .githooks/"

.githooks/pre-commit

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env sh
2+
set -eu
3+
4+
script_dir="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
5+
sh "$script_dir/checks.sh"

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,19 @@ Supported terminals:
7474

7575
Contributions are welcome! Please open an issue or pull request on GitHub.
7676

77+
### Enable local pre-commit checks
78+
79+
To block commits when formatting, clippy, or tests fail, enable the repository hook once:
80+
81+
```bash
82+
./.githooks/install.sh
83+
```
84+
85+
The pre-commit hook runs:
86+
- `cargo fmt --all -- --check`
87+
- `cargo clippy --all-targets --all-features`
88+
- `cargo test --all-features`
89+
7790
## License
7891

7992
DistroShelf is licensed under the GPL-3.0-or-later license.

0 commit comments

Comments
 (0)