Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion cmd/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,9 +603,14 @@ func runSync(gitClient git.GitClient, githubClient github.GitHubClient) error {

if syncCherryPick {
// Automated cherry-pick rebuild with backup
backupBranch := branch.Name + "-backup"
tempBranch := branch.Name + "-rebuild"

// Find available backup branch name
backupBranch := branch.Name + "-backup"
for i := 2; gitClient.BranchExists(backupBranch); i++ {
backupBranch = fmt.Sprintf("%s-backup-%d", branch.Name, i)
}

fmt.Printf("\n")
fmt.Printf("⚠ Detected polluted branch history (%d commits, %d unique patches)\n", len(allCommits), len(uniqueCommits))
fmt.Printf(" Creating backup: %s\n", backupBranch)
Expand Down Expand Up @@ -657,6 +662,12 @@ func runSync(gitClient git.GitClient, githubClient github.GitHubClient) error {
return fmt.Errorf("failed to rename temp branch: %w", err)
}

// Restore stackparent config (git branch -D deletes the branch's config section)
configKey := fmt.Sprintf("branch.%s.stackparent", branch.Name)
if err := gitClient.SetConfig(configKey, branch.Parent); err != nil {
return fmt.Errorf("failed to restore stackparent config: %w", err)
}

fmt.Printf("✓ Rebuilt %s (backup saved as %s)\n", branch.Name, backupBranch)
fmt.Printf(" To delete backup later: git branch -D %s\n", backupBranch)

Expand Down