forked from jan-leila/nix-config
		
	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" | 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 | # Get current branch name | ||||||
| current_branch=$(git branch --show-current) | 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 | if [ "$current_branch" = "main" ]; then | ||||||
|     # Check if there are any stashes to restore |     echo "Post-merge on main branch - running nix flake check" | ||||||
|     if git stash list | grep -q "stash@"; then |      | ||||||
|         echo "Post-merge: restoring stashed changes on main branch" |     # Run nix flake check after merge into main | ||||||
|         git stash pop -q |     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 |     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 |     fi | ||||||
| else | else | ||||||
|     echo "Post-merge: no action needed on branch '$current_branch'" |     echo "Post-merge: no action needed on branch '$current_branch'" | ||||||
|  |  | ||||||
|  | @ -1,15 +1,25 @@ | ||||||
| #!/usr/bin/env nix-shell | #!/usr/bin/env nix-shell | ||||||
| #! nix-shell -i bash ../shell.nix | #! nix-shell -i bash ../shell.nix | ||||||
| 
 | 
 | ||||||
| echo "stashing all uncommitted changes" | # Get current branch name | ||||||
| git stash -q --keep-index | current_branch=$(git branch --show-current) | ||||||
| 
 | 
 | ||||||
| echo "checking flakes all compile" | echo "stashing all uncommitted changes with named stash (excluding hooks)" | ||||||
|  | git stash push -q --keep-index -m "pre-commit-stash-$(date +%s)" -- ':!.hooks/' | ||||||
|  | 
 | ||||||
|  | # 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 |     nix flake check | ||||||
| 
 | 
 | ||||||
|     if [ ! $? -eq 0 ]; then |     if [ ! $? -eq 0 ]; then | ||||||
|  |         echo "Error: nix flake check failed on main branch" | ||||||
|         exit 1 |         exit 1 | ||||||
|     fi |     fi | ||||||
|  |     echo "nix flake check passed" | ||||||
|  | else | ||||||
|  |     echo "Not on main branch - skipping nix flake check" | ||||||
|  | fi | ||||||
| 
 | 
 | ||||||
| echo "running linter" | echo "running linter" | ||||||
| alejandra -q . | alejandra -q . | ||||||
|  |  | ||||||
|  | @ -17,8 +17,8 @@ fi | ||||||
| if [ "$target_branch" = "main" ]; then | if [ "$target_branch" = "main" ]; then | ||||||
|     echo "Merging into main branch - running nix flake check..." |     echo "Merging into main branch - running nix flake check..." | ||||||
|      |      | ||||||
|     echo "stashing all uncommitted changes" |     echo "stashing all uncommitted changes with named stash (excluding hooks)" | ||||||
|     git stash -q --keep-index |     git stash push -q --keep-index -m "pre-merge-stash-$(date +%s)" -- ':!.hooks/' | ||||||
| 
 | 
 | ||||||
|     echo "checking flakes all compile" |     echo "checking flakes all compile" | ||||||
|     nix flake check |     nix flake check | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue