feat: supported branching for commit checking
This commit is contained in:
parent
0c88746da1
commit
260e37e016
3 changed files with 100 additions and 9 deletions
18
.hooks/post-merge
Executable file
18
.hooks/post-merge
Executable file
|
|
@ -0,0 +1,18 @@
|
|||
#!/usr/bin/env nix-shell
|
||||
#! nix-shell -i bash ../shell.nix
|
||||
|
||||
# Get current branch name
|
||||
current_branch=$(git branch --show-current)
|
||||
|
||||
# Only restore stash 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
|
||||
else
|
||||
echo "Post-merge: no stash to restore on main branch"
|
||||
fi
|
||||
else
|
||||
echo "Post-merge: no action needed on branch '$current_branch'"
|
||||
fi
|
||||
37
.hooks/pre-merge-commit
Executable file
37
.hooks/pre-merge-commit
Executable file
|
|
@ -0,0 +1,37 @@
|
|||
#!/usr/bin/env nix-shell
|
||||
#! nix-shell -i bash ../shell.nix
|
||||
|
||||
# Get the target branch (the branch being merged into)
|
||||
target_branch=""
|
||||
|
||||
# Check if we're in the middle of a merge
|
||||
if [ -f .git/MERGE_HEAD ]; then
|
||||
# We're in a merge, check if the current branch is main
|
||||
current_branch=$(git branch --show-current)
|
||||
if [ "$current_branch" = "main" ]; then
|
||||
target_branch="main"
|
||||
fi
|
||||
fi
|
||||
|
||||
# If we're merging into main, run nix flake check
|
||||
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 "checking flakes all compile"
|
||||
nix flake check
|
||||
|
||||
if [ ! $? -eq 0 ]; then
|
||||
echo "Error: nix flake check failed. Merge aborted."
|
||||
echo "Please fix the issues and try merging again."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "nix flake check passed. Merge can proceed."
|
||||
else
|
||||
echo "Not merging into main branch, skipping nix flake check."
|
||||
fi
|
||||
|
||||
exit 0
|
||||
Loading…
Add table
Add a link
Reference in a new issue