Commit 166d6c1
Pivot out of agent worktree before prune in branch-finish (#423)
When `gx branch finish --cleanup` is invoked from inside the agent
worktree being cleaned up, the later `gx worktree prune` subprocess
inherits `cwd=repo_root` from the CLI, so its own active-cwd check
can't see that the calling shell is still sitting in the worktree
about to be deleted. The prune then removes the directory, the next
subprocess spawn fails with `ENOENT uv_cwd`, and `set -e` flips the
script exit code to 1 even though the merge and push already
succeeded.
Pivot the shell to `repo_root` right before prune when the caller's
cwd equals the source worktree, so the worktree can be removed
without invalidating the caller's cwd. Also guard the trailing
"still exists because it is the active shell cwd" message behind an
on-disk `-d "$source_worktree"` check so we only print the
leave-directory reminder when the worktree really is still there.
Co-authored-by: NagyVikt <nagy.viktordp@gmail.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 43aecbe commit 166d6c1
1 file changed
Lines changed: 12 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
830 | 830 | | |
831 | 831 | | |
832 | 832 | | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
833 | 844 | | |
834 | 845 | | |
835 | 846 | | |
836 | 847 | | |
837 | 848 | | |
838 | 849 | | |
839 | | - | |
| 850 | + | |
840 | 851 | | |
841 | 852 | | |
842 | 853 | | |
| |||
0 commit comments