Skip to content

Improve apply conflict handling: show conflicted files and guide user to resolution #80

Description

@that-github-user

Problem

When thinktank apply hits a merge conflict, the error message is:

Failed to apply diff. There may be conflicts.
The worktree is preserved at: /tmp/thinktank-2-abc123
You can manually apply changes from there.

This leaves the user:

  1. Not knowing which files conflicted
  2. Not knowing how to proceed (should they git merge? copy files? discard?)
  3. With a dangling worktree they have to clean up manually

Proposed improvement

After a failed git apply --3way, parse the conflict output and show:

✗ Apply failed: 2 files have conflicts

  Conflicted files:
    src/auth/middleware.ts
    tests/auth.test.ts

  Options:
    1. Open worktree and resolve manually: /tmp/thinktank-2-abc123
    2. Try a different agent:              thinktank apply --agent 3
    3. Discard this attempt:               thinktank apply --cleanup

  The worktree at /tmp/thinktank-2-abc123 is preserved until you resolve or discard.

Implementation notes

  • Parse git apply stderr for error: ... already exists in index and CONFLICT markers
  • --cleanup flag removes the preserved worktree without applying anything
  • Consider adding thinktank apply --open to open the worktree in the user's editor

Acceptance criteria

  • Conflicted filenames are shown after a failed apply
  • Three resolution options are printed with exact commands
  • thinktank apply --cleanup removes the preserved worktree and exits cleanly
  • thinktank apply --agent N works as a retry with a different agent
  • The worktree path printed is always valid (not a temp path that was cleaned up)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions