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 22, 13:15 UTC
fix(server): cap generated worktree folder names (#25212)
Co-authored-by: Dara Adedeji <76637177+SunkenInTime@users.noreply.github.com>
maria committed
Oct 29, 2026 at 17:50 UTC
0ed554001a9be58c2e2080592096f784f8c7a65b
2 files changed
+47
-2
apps/server/src/vcs/GitVcsDriverCore.test.ts
+36
@@ -3488,6 +3488,42 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
3488
}),
3489
);
3490
3491
+ it.effect("keeps generated worktree folders short without changing long branch names", () =>
3492
+ Effect.gen(function* () {
3493
+ const pathService = yield* Path.Path;
3494
+ const cwd = yield* makeTmpDir();
3495
+ const { initialBranch } = yield* initRepoWithCommit(cwd);
3496
+ const worktreesDirectory = yield* makeTmpDir("custom-worktrees-");
3497
+ const driver = yield* GitVcsDriver.GitVcsDriver;
3498
+ const folders = new Set<string>();
3499
+ const branches = [
3500
+ `feature/${"a".repeat(90)}/${"b".repeat(90)}/${"c".repeat(90)}`,
3501
+ `feature/${"a".repeat(90)}/${"b".repeat(90)}/${"d".repeat(90)}`,
3502
+ `feature/${"a".repeat(40)}/5fac`,
3503
+ `feature/${"a".repeat(40)}/18828`,
3504
+ `${"a".repeat(22)}😀/${"b".repeat(30)}`,
3505
+ "z".repeat(40),
3506
+ "z".repeat(41),
3507
+ ];
3508
+ for (const branch of branches) {
3509
+ const created = yield* driver.createWorktree(
3510
+ { cwd, path: null, refName: initialBranch, newRefName: branch },
3511
+ { worktreesDirectory },
3512
+ );
3513
+ const folder = pathService.basename(created.worktree.path);
3514
+ assert.isAtMost(folder.length, 40);
3515
+ if (branch.length <= 40) assert.equal(folder, branch);
3516
+ assert.equal(yield* git(created.worktree.path, ["branch", "--show-current"]), branch);
3517
+ assert.include(
3518
+ yield* git(cwd, ["-c", "core.quotePath=false", "worktree", "list", "--porcelain"]),
3519
+ `worktree ${created.worktree.path}`,
3520
+ );
3521
+ folders.add(folder);
3522
+ }
3523
+ assert.equal(folders.size, branches.length);
3524
+ }),
3525
+ );
3526
+
3527
it.effect("resolves the submodule mode from the option, then t3.json", () =>
3528
Effect.gen(function* () {
3529
const fileSystem = yield* FileSystem.FileSystem;
apps/server/src/vcs/GitVcsDriverCore.ts
+11
-2
@@ -3811,7 +3811,6 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
3811
yield* refuseOptionLikeRefName("GitVcsDriver.createWorktree", input.cwd, input.refName);
3812
yield* refuseOptionLikeRefName("GitVcsDriver.createWorktree", input.cwd, input.newRefName);
3813
const targetBranch = input.newRefName ?? input.refName;
3814
- const sanitizedBranch = targetBranch.replace(/\//g, "-");
3814
// Resolve sub/.. before taking the basename.
3815
const repoName = path.basename(path.resolve(input.cwd));
3816
let worktreePath = input.path;
@@ -3830,7 +3829,17 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
3829
detail: `The worktree location "${options?.worktreesDirectory}" must be an absolute folder on this machine, not a drive root. Change it in Settings → Worktrees.`,
3830
});
3831
}
3833
- worktreePath = path.join(parentDir, repoName, sanitizedBranch);
3832
+ let directoryName = targetBranch.replace(/\//g, "-");
3833
+ // Leave room for files beneath the worktree on Windows, regardless of branch length.
3834
+ if (directoryName.length > 40) {
3835
+ const digest = yield* crypto
3836
+ .digest("SHA-256", new TextEncoder().encode(targetBranch))
3837
+ .pipe(Effect.orDie);
3838
+ // Avoid splitting a surrogate pair, which Git would list back as a different path.
3839
+ const prefix = directoryName.slice(0, 23).replace(/[\uD800-\uDBFF]$/, "");
3840
+ directoryName = `${prefix}-${Hex.encode(digest).slice(0, 16)}`;
3841
+ }
3842
+ worktreePath = path.join(parentDir, repoName, directoryName);
3843
}
3844
if (input.newRefName) {
3845
// Kept apart from the checkout so the shared-config lock only covers the tracking write.