@devries-cameron20 / t3code Mirror · read-only / commits / e6a8b48389
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 19:45 UTC

fix(server): a new worktree no longer fails when its generated folder is left over from an earlier one (#35121)

Julius Marminge committed Nov 12, 2026 at 02:48 UTC e6a8b483890da0a42b46da626647456819b5267d
2 files changed +26 -2
apps/server/src/vcs/GitVcsDriverCore.test.ts
+16
@@ -5486,6 +5486,22 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
5486 );
5487 assert.equal(yield* fileSystem.exists(created.worktree.path), true);
5488
5489 + yield* git(cwd, ["worktree", "remove", "--force", created.worktree.path]);
5490 + yield* git(cwd, ["branch", "-D", "feature/custom-dir"]);
5491 + yield* fileSystem.makeDirectory(created.worktree.path);
5492 + const leftover = pathService.join(created.worktree.path, "notes.txt");
5493 + yield* fileSystem.writeFileString(leftover, "my notes");
5494 + const recreated = yield* driver.createWorktree(
5495 + { cwd, path: null, refName: initialBranch, newRefName: "feature/custom-dir" },
5496 + { worktreesDirectory },
5497 + );
5498 + assert.notEqual(recreated.worktree.path, created.worktree.path);
5499 + assert.equal(
5500 + yield* git(recreated.worktree.path, ["branch", "--show-current"]),
5501 + "feature/custom-dir",
5502 + );
5503 + assert.deepEqual(yield* fileSystem.readDirectory(created.worktree.path), ["notes.txt"]);
5504 +
5505 const error = yield* driver
5506 .createWorktree(
5507 { cwd, path: null, refName: initialBranch, newRefName: "feature/relative-dir" },
apps/server/src/vcs/GitVcsDriverCore.ts
+10 -2
@@ -4474,8 +4474,16 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
4474 if (Buffer.byteLength(prefix + character) > 23) break;
4475 prefix += character;
4476 }
4477 - const directoryName = `${prefix}-${Hex.encode(hash).slice(0, 16)}`;
4478 - worktreePath = path.join(parentDir, repoName, directoryName);
4477 + const basePath = path.join(parentDir, repoName, `${prefix}-${Hex.encode(hash).slice(0, 16)}`);
4478 + // The name is stable per branch, so a folder left by an earlier worktree must not block it.
4479 + worktreePath = basePath;
4480 + for (
4481 + let suffix = 2;
4482 + yield* fileSystem.exists(worktreePath).pipe(Effect.orElseSucceed(() => false));
4483 + suffix++
4484 + ) {
4485 + worktreePath = `${basePath}-${suffix}`;
4486 + }
4487 }
4488 const newRefName = input.newRefName;
4489 if (newRefName) {