fix: fixed pre and post commit hook behavior
This commit is contained in:
parent
290c0692bb
commit
f21777b1fb
4 changed files with 48 additions and 16 deletions
|
|
@ -3,4 +3,12 @@
|
|||
|
||||
echo "restoring stashed changes"
|
||||
|
||||
git stash pop -q
|
||||
# Find the most recent pre-commit stash and restore it
|
||||
recent_stash=$(git stash list | grep "pre-commit-stash-" | head -n 1 | cut -d: -f1)
|
||||
|
||||
if [ -n "$recent_stash" ]; then
|
||||
echo "Found recent pre-commit stash: $recent_stash"
|
||||
git stash pop -q "$recent_stash"
|
||||
else
|
||||
echo "No pre-commit stash found to restore"
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -4,14 +4,28 @@
|
|||
# Get current branch name
|
||||
current_branch=$(git branch --show-current)
|
||||
|
||||
# Only restore stash if we're on main branch and a merge just completed
|
||||
# Only perform actions if we're on main branch and a merge just completed
|
||||
if [ "$current_branch" = "main" ]; then
|
||||
# Check if there are any stashes to restore
|
||||
if git stash list | grep -q "stash@"; then
|
||||
echo "Post-merge: restoring stashed changes on main branch"
|
||||
git stash pop -q
|
||||
echo "Post-merge on main branch - running nix flake check"
|
||||
|
||||
# Run nix flake check after merge into main
|
||||
nix flake check
|
||||
|
||||
if [ ! $? -eq 0 ]; then
|
||||
echo "Warning: nix flake check failed after merge into main"
|
||||
echo "Please fix the issues as soon as possible"
|
||||
else
|
||||
echo "Post-merge: no stash to restore on main branch"
|
||||
echo "nix flake check passed after merge"
|
||||
fi
|
||||
|
||||
# Check if there are any pre-commit stashes to restore
|
||||
recent_stash=$(git stash list | grep "pre-commit-stash-" | head -n 1 | cut -d: -f1)
|
||||
|
||||
if [ -n "$recent_stash" ]; then
|
||||
echo "Post-merge: restoring pre-commit stash on main branch"
|
||||
git stash pop -q "$recent_stash"
|
||||
else
|
||||
echo "Post-merge: no pre-commit stash to restore on main branch"
|
||||
fi
|
||||
else
|
||||
echo "Post-merge: no action needed on branch '$current_branch'"
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@ fi
|
|||
if [ "$target_branch" = "main" ]; then
|
||||
echo "Merging into main branch - running nix flake check..."
|
||||
|
||||
echo "stashing all uncommitted changes"
|
||||
git stash -q --keep-index
|
||||
echo "stashing all uncommitted changes with named stash (excluding hooks)"
|
||||
git stash push -q --keep-index -m "pre-merge-stash-$(date +%s)" -- ':!.hooks/'
|
||||
|
||||
echo "checking flakes all compile"
|
||||
nix flake check
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue