Skip to content

Commit b362d18

Browse files
committed
Revert "use 3-way merge when applying user changes"
this is still not robust enough to cover the scenario where the user deleted a file. we should just do a hard reset to the environment's changes instead, and not attempt to restore their changes, since we just synced them over. This reverts commit 856d418.
1 parent 856d418 commit b362d18

1 file changed

Lines changed: 4 additions & 21 deletions

File tree

repository/repository.go

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -471,30 +471,13 @@ func (r *Repository) Apply(ctx context.Context, id string, w io.Writer) (rerr er
471471
if hasUnstagedChanges {
472472
fmt.Fprintf(w, "Restoring user changes...\n")
473473

474-
// 1. Temporarily commit the agent's changes (if any)
475-
if err := RunInteractiveGitCommand(ctx, r.userRepoPath, w,
476-
"commit",
477-
// it's simpler/safer to just keep this path unconditional than check if there
478-
// were staged stuff before, so just allow an empty commit; we'll be
479-
// getting rid of it immediately anyway
480-
"--allow-empty",
481-
"-m", "temp: agent changes (you should not see this)",
482-
); err != nil {
474+
// 1. Temporarily commit the agent's changes
475+
if err := RunInteractiveGitCommand(ctx, r.userRepoPath, w, "commit", "-m", "temp: agent changes"); err != nil {
483476
return fmt.Errorf("failed to commit agent changes: %w", err)
484477
}
485478

486-
// 2. Apply the user's patch, using 3-way merge with --check beforehand to
487-
// avoid leaving conflict markers
488-
var checkOut strings.Builder
489-
checkCmd := exec.CommandContext(ctx, "git", "apply", "--3way", "--check", "-")
490-
checkCmd.Dir = r.userRepoPath
491-
checkCmd.Stdin = strings.NewReader(diffOutput)
492-
checkCmd.Stdout = &checkOut
493-
checkCmd.Stderr = &checkOut
494-
if err := checkCmd.Run(); err != nil {
495-
return fmt.Errorf("conflict detected when re-applying user changes:\n%s", checkOut.String())
496-
}
497-
applyCmd := exec.CommandContext(ctx, "git", "apply", "--3way", "-")
479+
// 2. Apply the user's patch
480+
applyCmd := exec.CommandContext(ctx, "git", "apply", "-")
498481
applyCmd.Dir = r.userRepoPath
499482
applyCmd.Stdin = strings.NewReader(diffOutput)
500483
applyCmd.Stdout = w

0 commit comments

Comments
 (0)