Skip to content

Commit 15fc51c

Browse files
fix(MORG-48): skip checkout when deleting a merged worktree branch (#38)
* fix(MORG-48): skip checkout when deleting a worktree branch When a branch with a worktree is being deleted during sync and the user is on that branch, git checkout main would fail because main is already checked out in the main worktree. The checkout is unnecessary anyway since removeWorktree handles cleanup — skip it and only checkout for regular (non-worktree) branches. * fix(MORG-48): use signalWorktreeCd when deleting current worktree branch When the user is in a worktree and its branch gets deleted during sync, use signalWorktreeCd to move the shell to the main worktree root — with the shell wrapper this is automatic; without it a cd hint is printed.
1 parent aabcae3 commit 15fc51c

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/commands/sync.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ import { theme, symbols } from '../ui/theme';
88
import { withSpinner } from '../ui/spinner';
99
import { confirm, select } from '../ui/prompts';
1010
import { promptTicketDone } from '../utils/providers';
11+
import { signalWorktreeCd } from '../utils/shell';
1112
import {
1213
getCurrentBranch,
1314
checkout,
1415
pullBranch,
1516
fetchAndUpdateBranch,
17+
getMainWorktreeRoot,
1618
rebaseBranch,
1719
mergeBranch,
1820
deleteBranch,
@@ -108,7 +110,14 @@ async function runSync(options: { all?: boolean }): Promise<void> {
108110
if (doDelete) {
109111
const currentBranch = await getCurrentBranch();
110112
if (currentBranch === branch.branchName) {
111-
await checkout(defaultBranch);
113+
if (branch.worktreePath) {
114+
// Can't checkout — defaultBranch is already used by the main worktree.
115+
// Signal the shell wrapper (or print a hint) to cd there instead.
116+
const mainRoot = await getMainWorktreeRoot();
117+
signalWorktreeCd(mainRoot);
118+
} else {
119+
await checkout(defaultBranch);
120+
}
112121
}
113122
// Remove worktree first so git allows the branch to be deleted
114123
if (branch.worktreePath) {

0 commit comments

Comments
 (0)