Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env bash

# PRE-COMMIT HOOK
#
# checks for:
# - formatting
# - clippy

SCRIPT_DIR="$(git rev-parse --show-toplevel)"
CI_SCRIPT="$SCRIPT_DIR/ci-rust.sh"

if [ ! -f "$CI_SCRIPT" ]; then
echo "Error: ci-rust.sh not found at $CI_SCRIPT"
exit 1
fi

if [ ! -x "$CI_SCRIPT" ]; then
chmod u+x "$CI_SCRIPT"
fi

echo "Running pre-commit checks..."
echo ""

# Run fmt check
"$CI_SCRIPT" fmt
FMT_EXIT=$?

if [ $FMT_EXIT -ne 0 ]; then
echo ""
echo ""
echo "Commit aborted."
echo "Run './ci-rust.sh fmt-fix' to auto-fix issues."
exit 1
fi

# Run clippy check
"$CI_SCRIPT" clippy
CLIPPY_EXIT=$?

if [ $CLIPPY_EXIT -ne 0 ]; then
echo ""
echo ""
echo "Commit aborted."
echo "Run './ci-rust.sh clippy-fix' to auto-fix issues."
exit 1
fi

echo ""
echo "All pre-commit checks passed."
exit 0
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ The repository includes a CI script (`ci-rust.sh`) that runs all quality checks
```
You can fix formatting or linter issues by adding the -fix suffix to the command. e.g: `./ci-rust.sh clippy-fix`

### Running `fmt` and `clippy` as a pre-commit hook

A pre-commit hook script is available in `.githooks`, which executes the CI script with `fmt` and `clippy` only and without the `fix` option. To setup the hook, configure git to use the `.githooks` directory and make the `pre-commit` file executable.
```bash
git config core.hooksPath .githooks
chmod u+x .githooks/pre-commit
```

### Database & Diesel

**Timescale**
Expand Down
Loading