Skip to content

Commit 14831d5

Browse files
MarcoDotIOclaude
andcommitted
fix(server): a branch nested under a generated name no longer blocks the rename
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent c1b5aa3 commit 14831d5

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

‎apps/server/src/vcs/GitVcsDriverCore.test.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3662,6 +3662,26 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
36623662
}),
36633663
);
36643664

3665+
it.effect("skips a flattened name that a nested branch blocks", () =>
3666+
Effect.gen(function* () {
3667+
const cwd = yield* makeTmpDir();
3668+
yield* initRepoWithCommit(cwd);
3669+
const driver = yield* GitVcsDriver.GitVcsDriver;
3670+
yield* git(cwd, ["branch", "t3"]);
3671+
yield* git(cwd, ["checkout", "-b", "t3-abcd1234"]);
3672+
yield* git(cwd, ["branch", "t3-fix-login/child"]);
3673+
3674+
const renamed = yield* driver.renameBranch({
3675+
cwd,
3676+
oldBranch: "t3-abcd1234",
3677+
newBranch: "t3/fix-login",
3678+
});
3679+
3680+
assert.equal(renamed.branch, "t3-fix-login-1");
3681+
assert.equal(yield* git(cwd, ["branch", "--show-current"]), "t3-fix-login-1");
3682+
}),
3683+
);
3684+
36653685
it.effect("rejects a missing branch without restoring a matching dirty file", () =>
36663686
Effect.gen(function* () {
36673687
const cwd = yield* makeTmpDir();

‎apps/server/src/vcs/GitVcsDriverCore.ts‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,15 +1257,27 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
12571257
blockedByParent = yield* branchExists(cwd, segments.slice(0, index).join("/"));
12581258
}
12591259
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+
);
12601272

1261-
const isDesiredTaken = yield* branchExists(cwd, desiredBranch);
1273+
const isDesiredTaken = yield* isBranchNameTaken(desiredBranch);
12621274
if (!isDesiredTaken) {
12631275
return desiredBranch;
12641276
}
12651277

12661278
for (let suffix = 1; suffix <= 100; suffix += 1) {
12671279
const candidate = `${desiredBranch}-${suffix}`;
1268-
const isCandidateTaken = yield* branchExists(cwd, candidate);
1280+
const isCandidateTaken = yield* isBranchNameTaken(candidate);
12691281
if (!isCandidateTaken) {
12701282
return candidate;
12711283
}

0 commit comments

Comments
 (0)