Open source AI coding agent. Designed for large projects and real world tasks.
Go aiai-agentsai-developer-toolsai-toolsclicommand-linedeveloper-toolsgitgolanggpt-4llmopenaipolyglot-programmingterminalterminal-basedterminal-ui
fixes for stash pop issues after apply
Dane Schneider3381013fb091
diff --git a/app/cli/lib/apply.go b/app/cli/lib/apply.goindex 3fb2c5e0..4f0e3706 100644--- a/app/cli/lib/apply.go+++ b/app/cli/lib/apply.go@@ -120,7 +120,18 @@ func MustApplyPlan(planId, branch string, autoConfirm bool) {}if isRepo && hasUncommittedChanges {- // If there are uncommitted changes, stash them+ // If there are uncommitted changes, first checkout any files that will be applied, then stash the changes++ // Checkout the files that will be applied+ // It's safe to do this with the confidence that no work will be lost because we just ensured the plan is using the latest state of all these files+ for path := range toApply {+ err := GitCheckoutFile(path)+ if err != nil {+ term.OutputSimpleError("Failed to reset file %s: %v", path, err)+ term.OutputUnformattedErrorAndExit(err.Error())+ }+ }+err := GitStashCreate("Plandex auto-stash")if err != nil {term.OutputSimpleError("Failed to create git stash:")diff --git a/app/cli/lib/git.go b/app/cli/lib/git.goindex 6d2ae9a6..6a9ec1a7 100644--- a/app/cli/lib/git.go+++ b/app/cli/lib/git.go@@ -95,6 +95,10 @@ func GitStashPop(forceOverwrite bool) error {res, err := exec.Command("git", "stash", "pop").CombinedOutput()+ // we should no longer have conflicts since we are forcing an update before+ // running the 'apply' command as well as resetting any files with uncommitted change+ // still leaving this though in case something goes wrong+if err != nil {log.Println("Error popping git stash:", string(res))@@ -151,6 +155,18 @@ func GitClearUncommittedChanges() error {return nil}+func GitCheckoutFile(path string) error {+ gitMutex.Lock()+ defer gitMutex.Unlock()++ res, err := exec.Command("git", "checkout", path).CombinedOutput()+ if err != nil {+ return fmt.Errorf("error checking out file %s | err: %v, output: %s", path, err, string(res))+ }++ return nil+}+func parseConflictFiles(gitOutput string) []string {var conflictFiles []stringlines := strings.Split(gitOutput, "\n")