Skip to content

Commit 70743bc

Browse files
steveyeggeclaude
andcommitted
feat: add best-effort push before --force nuke (gt-4vr)
Before deleting a polecat worktree and branch, attempt to push any unpushed commits to preserve work. Push failure is non-fatal since --force already implies acceptance of data loss. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 537c862 commit 70743bc

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

internal/cmd/polecat.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,6 +1239,34 @@ func nukePolecatFull(polecatName, rigName string, mgr *polecat.Manager, r *rig.R
12391239
nukeCleanupMolecules(polecatInfo.Issue, r)
12401240
}
12411241

1242+
// Step 2.75: Best-effort push before nuke (gt-4vr guardrail).
1243+
// Try to preserve any unpushed commits on the branch. If push fails,
1244+
// proceed — --force already means "I accept data loss".
1245+
if branchToDelete != "" {
1246+
var pushGit *git.Git
1247+
// Try worktree first (may still exist), then bare repo fallback
1248+
if polecatInfo != nil {
1249+
wtPath := filepath.Join(r.Path, "polecats", polecatName)
1250+
if _, statErr := os.Stat(wtPath); statErr == nil {
1251+
pushGit = git.NewGit(wtPath)
1252+
}
1253+
}
1254+
if pushGit == nil {
1255+
bareRepoPath := filepath.Join(r.Path, ".repo.git")
1256+
if info, statErr := os.Stat(bareRepoPath); statErr == nil && info.IsDir() {
1257+
pushGit = git.NewGitWithDir(bareRepoPath, "")
1258+
}
1259+
}
1260+
if pushGit != nil {
1261+
refspec := branchToDelete + ":" + branchToDelete
1262+
if err := pushGit.Push("origin", refspec, false); err != nil {
1263+
fmt.Printf(" %s best-effort push failed (proceeding): %v\n", style.Dim.Render("○"), err)
1264+
} else {
1265+
fmt.Printf(" %s pushed branch %s before nuke\n", style.Success.Render("✓"), branchToDelete)
1266+
}
1267+
}
1268+
}
1269+
12421270
// Step 3: Delete worktree (nuclear=true to bypass safety checks for stale polecats)
12431271
if err := mgr.RemoveWithOptions(polecatName, true, true, false); err != nil {
12441272
if errors.Is(err, polecat.ErrPolecatNotFound) {

0 commit comments

Comments
 (0)