Skip to content

Commit

Permalink
Git pre-push hook with install script that checks fmt and clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
lucksus committed Aug 8, 2024
1 parent 73976f3 commit 6643c4d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ pnpm run package-ad4m

(Note that the last step of this might/will fail if you don't have the code signing keys. You can ignore that last error and find bundles in `target/release`.)

## Development
### Setup Git Hooks

After cloning the repository, run the following script to set up Git hooks:

```sh
./setup-hooks.sh
```

## Testing

Full test run of all packages:
Expand Down
19 changes: 19 additions & 0 deletions hooks/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh

echo "Running pre-push hook..."

# Run cargo fmt to format the code
if ! cargo fmt -- --check; then
echo "Code is not formatted. Please run 'cargo fmt' to format the code."
exit 1
fi

# Run cargo clippy to check for linting issues
if ! cargo clippy -- -D warnings; then
echo "Clippy found warnings. Please fix them before pushing."
exit 1
fi

# If both checks pass, allow the push to proceed
exit 0

13 changes: 13 additions & 0 deletions setup-hooks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh

# Create the hooks directory if it doesn't exist
mkdir -p .git/hooks

# Copy the pre-push hook to the Git hooks directory
cp hooks/pre-push .git/hooks/pre-push
chmod +x .git/hooks/pre-push

# Configure Git to use the custom hooks directory
git config core.hooksPath .git/hooks

echo "Git Hooks installed and configured."

0 comments on commit 6643c4d

Please sign in to comment.