fix: fixed pre and post commit hook behavior

This commit is contained in:
Leyla Becker 2025-10-20 20:55:35 -05:00
parent 290c0692bb
commit f21777b1fb
4 changed files with 48 additions and 16 deletions

View file

@ -1,14 +1,24 @@
#!/usr/bin/env nix-shell
#! nix-shell -i bash ../shell.nix
echo "stashing all uncommitted changes"
git stash -q --keep-index
# Get current branch name
current_branch=$(git branch --show-current)
echo "checking flakes all compile"
nix flake check
echo "stashing all uncommitted changes with named stash (excluding hooks)"
git stash push -q --keep-index -m "pre-commit-stash-$(date +%s)" -- ':!.hooks/'
if [ ! $? -eq 0 ]; then
exit 1
# Only run nix flake check if we're on main branch
if [ "$current_branch" = "main" ]; then
echo "On main branch - checking flakes all compile"
nix flake check
if [ ! $? -eq 0 ]; then
echo "Error: nix flake check failed on main branch"
exit 1
fi
echo "nix flake check passed"
else
echo "Not on main branch - skipping nix flake check"
fi
echo "running linter"
@ -19,4 +29,4 @@ RESULT=$?
echo "adding lint changes to commit"
git add -u
exit $RESULT
exit $RESULT