diff options
| -rw-r--r-- | internal/sync/branch_analyzer.go | 36 | ||||
| -rw-r--r-- | internal/version/version.go | 2 |
2 files changed, 37 insertions, 1 deletions
diff --git a/internal/sync/branch_analyzer.go b/internal/sync/branch_analyzer.go index 95827db..3038fcc 100644 --- a/internal/sync/branch_analyzer.go +++ b/internal/sync/branch_analyzer.go @@ -541,6 +541,24 @@ func (s *Syncer) GenerateDeleteScript() (string, error) { fmt.Fprintf(file, "else\n") fmt.Fprintf(file, " echo \" 🔸 Deleting branch: %s (last commit: %s)\"\n", branch.Name, branch.LastCommit.Format("2006-01-02")) + // Check if we're on the branch to be deleted, and switch to main/master if so + fmt.Fprintf(file, " # Check if we're on the branch to be deleted\n") + fmt.Fprintf(file, " current_branch=$(git branch --show-current)\n") + fmt.Fprintf(file, " if [[ \"$current_branch\" == \"%s\" ]]; then\n", branch.Name) + fmt.Fprintf(file, " echo \" Switching from %s to main/master branch before deletion...\"\n", branch.Name) + fmt.Fprintf(file, " main_branch=$(find_main_branch)\n") + fmt.Fprintf(file, " if [[ -n \"$main_branch\" ]]; then\n") + fmt.Fprintf(file, " execute_cmd git checkout \"$main_branch\"\n") + fmt.Fprintf(file, " else\n") + fmt.Fprintf(file, " echo \" ⚠️ No main/master branch found to switch to!\"\n") + fmt.Fprintf(file, " echo \" Skipping deletion of %s\"\n", branch.Name) + fmt.Fprintf(file, " fi\n") + fmt.Fprintf(file, " fi\n") + fmt.Fprintf(file, " # Skip to next branch if we couldn't switch\n") + fmt.Fprintf(file, " if [[ \"$current_branch\" == \"%s\" ]] && [[ -z \"$main_branch\" ]]; then\n", branch.Name) + fmt.Fprintf(file, " continue\n") + fmt.Fprintf(file, " fi\n") + // Delete from remotes for _, remote := range branch.RemotesWithBranch { fmt.Fprintf(file, " execute_cmd git push %s --delete \"%s\"\n", remote, branch.Name) @@ -563,6 +581,24 @@ func (s *Syncer) GenerateDeleteScript() (string, error) { fmt.Fprintf(file, "else\n") fmt.Fprintf(file, " echo \" 🔹 Deleting ignored branch: %s (last commit: %s)\"\n", branch.Name, branch.LastCommit.Format("2006-01-02")) + // Check if we're on the branch to be deleted, and switch to main/master if so + fmt.Fprintf(file, " # Check if we're on the branch to be deleted\n") + fmt.Fprintf(file, " current_branch=$(git branch --show-current)\n") + fmt.Fprintf(file, " if [[ \"$current_branch\" == \"%s\" ]]; then\n", branch.Name) + fmt.Fprintf(file, " echo \" Switching from %s to main/master branch before deletion...\"\n", branch.Name) + fmt.Fprintf(file, " main_branch=$(find_main_branch)\n") + fmt.Fprintf(file, " if [[ -n \"$main_branch\" ]]; then\n") + fmt.Fprintf(file, " execute_cmd git checkout \"$main_branch\"\n") + fmt.Fprintf(file, " else\n") + fmt.Fprintf(file, " echo \" ⚠️ No main/master branch found to switch to!\"\n") + fmt.Fprintf(file, " echo \" Skipping deletion of %s\"\n", branch.Name) + fmt.Fprintf(file, " fi\n") + fmt.Fprintf(file, " fi\n") + fmt.Fprintf(file, " # Skip to next branch if we couldn't switch\n") + fmt.Fprintf(file, " if [[ \"$current_branch\" == \"%s\" ]] && [[ -z \"$main_branch\" ]]; then\n", branch.Name) + fmt.Fprintf(file, " continue\n") + fmt.Fprintf(file, " fi\n") + // Delete from remotes for _, remote := range branch.RemotesWithBranch { fmt.Fprintf(file, " execute_cmd git push %s --delete \"%s\"\n", remote, branch.Name) diff --git a/internal/version/version.go b/internal/version/version.go index b31f9ec..a136261 100644 --- a/internal/version/version.go +++ b/internal/version/version.go @@ -7,7 +7,7 @@ import ( var ( // Version is the current version of gitsyncer - Version = "0.8.1" + Version = "0.8.2" // GitCommit is the git commit hash at build time GitCommit = "unknown" |
