Skip to content

Commit d55594d

Browse files
fix: process.chdir to main worktree before removing current worktree on sync (#39)
fix: process.chdir to main worktree before removing current worktree When morg sync deletes the current branch's worktree, the process cwd becomes a deleted directory. All subsequent git calls (deleteBranch, getCurrentBranch in Step 4) then fail because git can't find the repo. Fix: call process.chdir(mainRoot) before removeWorktree so the process stays in a valid git directory for the rest of the sync run.
1 parent ad75e59 commit d55594d

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

src/commands/sync.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,10 @@ async function runSync(options: { all?: boolean }): Promise<void> {
112112
if (currentBranch === branch.branchName) {
113113
if (branch.worktreePath) {
114114
// Can't checkout — defaultBranch is already used by the main worktree.
115-
// Signal the shell wrapper (or print a hint) to cd there instead.
115+
// Move the process out of the worktree directory before it's removed so
116+
// subsequent git commands keep working, then signal the shell to cd there.
116117
const mainRoot = await getMainWorktreeRoot();
118+
process.chdir(mainRoot);
117119
signalWorktreeCd(mainRoot);
118120
} else {
119121
await checkout(defaultBranch);

0 commit comments

Comments
 (0)