AI Agents SDE Task Viewer
      • Pr description
  1. Home
  2. AgentSDE
  3. agent-core
  4. gh-266
  5. changes
  6. pr_description.md
pr_description.md(1.1 KB)· Apr 3, 2026· 1 min read
  • Problem
  • Task / Link
  • Changes
  • Notes
  • Testing

Guard against main repo on target branch before worktree creation#

Problem#

When the main repo is checked out on the target feature branch, git branch -D silently fails, causing git worktree add -b to fatal with "branch already exists". This was the root cause of issue #246 being stuck for 12+ hours.

Task / Link#

Closes #266

Changes#

  • Added a branch guard in WorktreeService.createWorktree() after git fetch origin
  • Detects current branch via git rev-parse --abbrev-ref HEAD
  • If the main repo is on the target branch, auto-switches to master with a warning log
  • If git checkout master fails, throws a descriptive error (does not swallow)
  • Detached HEAD state is treated as safe — no switch attempted
  • Added two new unit tests: auto-switch success and checkout failure scenarios

Notes#

If the main repo has uncommitted changes when the conflict is detected, git checkout master will fail and a typed error is thrown — by design per issue scope (surface the error, do not stash).

Testing#

  • 13 unit tests pass (11 existing + 2 new)
  • New tests cover: auto-switch to master succeeds, and checkout failure throws descriptive error
PrdAgent-runner