@devries-cameron20 / t3code Mirror · read-only / commits / 1917c8a33a
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 22, 08:15 UTC

fix(server): worktree threads get their generated branch name when a branch named t3 exists (#27815)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

MarcoDotIO committed Oct 31, 2026 at 22:42 UTC 1917c8a33a7453556213dccca82d24735e0a0370
2 files changed +65 -3
apps/server/src/vcs/GitVcsDriverCore.test.ts
+41
@@ -3695,6 +3695,47 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
3695 }),
3696 );
3697
3698 + it.effect("flattens a generated name when a branch at its parent path blocks it", () =>
3699 + Effect.gen(function* () {
3700 + const cwd = yield* makeTmpDir();
3701 + yield* initRepoWithCommit(cwd);
3702 + const driver = yield* GitVcsDriver.GitVcsDriver;
3703 + // A local `t3` branch is why launches start on the flat `t3-<hex>` temporary branch.
3704 + yield* git(cwd, ["branch", "t3"]);
3705 + yield* git(cwd, ["checkout", "-b", "t3-abcd1234"]);
3706 + yield* git(cwd, ["branch", "t3-fix-login"]);
3707 +
3708 + const renamed = yield* driver.renameBranch({
3709 + cwd,
3710 + oldBranch: "t3-abcd1234",
3711 + newBranch: "t3/fix-login",
3712 + });
3713 +
3714 + assert.equal(renamed.branch, "t3-fix-login-1");
3715 + assert.equal(yield* git(cwd, ["branch", "--show-current"]), "t3-fix-login-1");
3716 + }),
3717 + );
3718 +
3719 + it.effect("skips a flattened name that a nested branch blocks", () =>
3720 + Effect.gen(function* () {
3721 + const cwd = yield* makeTmpDir();
3722 + yield* initRepoWithCommit(cwd);
3723 + const driver = yield* GitVcsDriver.GitVcsDriver;
3724 + yield* git(cwd, ["branch", "t3"]);
3725 + yield* git(cwd, ["checkout", "-b", "t3-abcd1234"]);
3726 + yield* git(cwd, ["branch", "t3-fix-login/child"]);
3727 +
3728 + const renamed = yield* driver.renameBranch({
3729 + cwd,
3730 + oldBranch: "t3-abcd1234",
3731 + newBranch: "t3/fix-login",
3732 + });
3733 +
3734 + assert.equal(renamed.branch, "t3-fix-login-1");
3735 + assert.equal(yield* git(cwd, ["branch", "--show-current"]), "t3-fix-login-1");
3736 + }),
3737 + );
3738 +
3739 it.effect("rejects a missing branch without restoring a matching dirty file", () =>
3740 Effect.gen(function* () {
3741 const cwd = yield* makeTmpDir();
apps/server/src/vcs/GitVcsDriverCore.ts
+24 -3
@@ -1247,16 +1247,37 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
1247
1248 const resolveAvailableBranchName = Effect.fn("resolveAvailableBranchName")(function* (
1249 cwd: string,
1250 - desiredBranch: string,
1250 + requestedBranch: string,
1251 ) {
1252 - const isDesiredTaken = yield* branchExists(cwd, desiredBranch);
1252 + // A branch at a parent path (such as `t3`) blocks every ref nested under it, so no suffix
1253 + // would help; flatten to a sibling the way temporary worktree branches already do.
1254 + const segments = requestedBranch.split("/");
1255 + let blockedByParent = false;
1256 + for (let index = 1; index < segments.length && !blockedByParent; index += 1) {
1257 + blockedByParent = yield* branchExists(cwd, segments.slice(0, index).join("/"));
1258 + }
1259 + const desiredBranch = blockedByParent ? segments.join("-") : requestedBranch;
1260 + // A branch nested under the name (`t3-fix/child`) blocks it as surely as one with the name.
1261 + const isBranchNameTaken = (name: string) =>
1262 + Effect.zipWith(
1263 + branchExists(cwd, name),
1264 + runGitStdout(
1265 + "GitVcsDriver.branchExists",
1266 + cwd,
1267 + ["for-each-ref", "--count=1", "--format=%(refname)", `refs/heads/${name}/`],
1268 + true,
1269 + ),
1270 + (exists, nested) => exists || nested.trim().length > 0,
1271 + );
1272 +
1273 + const isDesiredTaken = yield* isBranchNameTaken(desiredBranch);
1274 if (!isDesiredTaken) {
1275 return desiredBranch;
1276 }
1277
1278 for (let suffix = 1; suffix <= 100; suffix += 1) {
1279 const candidate = `${desiredBranch}-${suffix}`;
1259 - const isCandidateTaken = yield* branchExists(cwd, candidate);
1280 + const isCandidateTaken = yield* isBranchNameTaken(candidate);
1281 if (!isCandidateTaken) {
1282 return candidate;
1283 }