Skip to content

Commit 874fbd5

Browse files
StiensWoutcodexclaudeGrok 4.7
committed
fix(server): reserve case variants during branch allocation
Co-authored-by: GPT 6.1 Sol <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Grok 4.7 <[email protected]>
1 parent a46f47f commit 874fbd5

2 files changed

Lines changed: 42 additions & 23 deletions

File tree

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

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4319,13 +4319,13 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
43194319
}),
43204320
);
43214321

4322-
it.effect("flattens a generated name when a branch at its parent path blocks it", () =>
4322+
it.effect.each(["t3", "T3"])("flattens a generated name when parent %s blocks it", (parent) =>
43234323
Effect.gen(function* () {
43244324
const cwd = yield* makeTmpDir();
43254325
yield* initRepoWithCommit(cwd);
43264326
const driver = yield* GitVcsDriver.GitVcsDriver;
43274327
// A local `t3` branch is why launches start on the flat `t3-<hex>` temporary branch.
4328-
yield* git(cwd, ["branch", "t3"]);
4328+
yield* git(cwd, ["branch", parent]);
43294329
yield* git(cwd, ["checkout", "-b", "t3-abcd1234"]);
43304330
yield* git(cwd, ["branch", "t3-fix-login"]);
43314331

@@ -4340,24 +4340,26 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
43404340
}),
43414341
);
43424342

4343-
it.effect("skips a flattened name that a nested branch blocks", () =>
4344-
Effect.gen(function* () {
4345-
const cwd = yield* makeTmpDir();
4346-
yield* initRepoWithCommit(cwd);
4347-
const driver = yield* GitVcsDriver.GitVcsDriver;
4348-
yield* git(cwd, ["branch", "t3"]);
4349-
yield* git(cwd, ["checkout", "-b", "t3-abcd1234"]);
4350-
yield* git(cwd, ["branch", "t3-fix-login/child"]);
4343+
it.effect.each(["t3-fix-login/child", "T3-Fix-Login/child", "T3-FIX-LOGIN"])(
4344+
"skips a flattened name blocked by %s",
4345+
(occupied) =>
4346+
Effect.gen(function* () {
4347+
const cwd = yield* makeTmpDir();
4348+
yield* initRepoWithCommit(cwd);
4349+
const driver = yield* GitVcsDriver.GitVcsDriver;
4350+
yield* git(cwd, ["branch", "t3"]);
4351+
yield* git(cwd, ["checkout", "-b", "t3-abcd1234"]);
4352+
yield* git(cwd, ["branch", occupied]);
43514353

4352-
const renamed = yield* driver.renameBranch({
4353-
cwd,
4354-
oldBranch: "t3-abcd1234",
4355-
newBranch: "t3/fix-login",
4356-
});
4354+
const renamed = yield* driver.renameBranch({
4355+
cwd,
4356+
oldBranch: "t3-abcd1234",
4357+
newBranch: "t3/fix-login",
4358+
});
43574359

4358-
assert.equal(renamed.branch, "t3-fix-login-1");
4359-
assert.equal(yield* git(cwd, ["branch", "--show-current"]), "t3-fix-login-1");
4360-
}),
4360+
assert.equal(renamed.branch, "t3-fix-login-1");
4361+
assert.equal(yield* git(cwd, ["branch", "--show-current"]), "t3-fix-login-1");
4362+
}),
43614363
);
43624364

43634365
it.effect("refuses exhausted automatic suffixes without changing existing branches", () =>
@@ -4377,6 +4379,8 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
43774379
.renameBranch({ cwd, oldBranch: initialBranch, newBranch: "topic" })
43784380
.pipe(Effect.result);
43794381
assert.isTrue(Result.isFailure(result));
4382+
if (Result.isFailure(result))
4383+
assert.include(result.failure.detail, "Could not find an available branch name");
43804384
assert.equal(yield* git(cwd, ["branch", "--show-current"]), initialBranch);
43814385
assert.equal((yield* driver.listLocalBranchNames(cwd)).length, 102);
43824386
}),
@@ -4388,7 +4392,12 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
43884392
Effect.gen(function* () {
43894393
const cwd = yield* makeTmpDir();
43904394
const { initialBranch } = yield* initRepoWithCommit(cwd);
4391-
const expected = yield* git(cwd, ["rev-parse", "HEAD"]);
4395+
const expected = yield* git(cwd, [
4396+
"commit-tree",
4397+
"HEAD^{tree}",
4398+
"-m",
4399+
"concurrent winner",
4400+
]);
43924401
const original = yield* GitVcsDriver.GitVcsDriver;
43934402
const delegate = yield* ChildProcessSpawner.ChildProcessSpawner;
43944403
let claimed = false;
@@ -5037,6 +5046,10 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
50375046
pathService.dirname(created.worktree.path),
50385047
pathService.join(worktreesDirectory, pathService.basename(cwd)),
50395048
);
5049+
assert.match(
5050+
pathService.basename(created.worktree.path),
5051+
/^feature-custom-dir-[0-9a-f]{16}$/,
5052+
);
50405053
assert.equal(yield* fileSystem.exists(created.worktree.path), true);
50415054

50425055
const error = yield* driver

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,7 +1269,13 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
12691269
["for-each-ref", "--format=%(refname:strip=2)", "refs/heads/"],
12701270
{ maxOutputBytes: 16 * 1024 * 1024 },
12711271
);
1272-
const branches = new Set(stdout.split("\n").filter(Boolean));
1272+
// Reserve case variants too: loose refs can live on case-insensitive filesystems.
1273+
const branches = new Set(
1274+
stdout
1275+
.split("\n")
1276+
.filter(Boolean)
1277+
.map((name) => name.toLowerCase()),
1278+
);
12731279
// A branch nested under a name (`t3-fix/child`) blocks it as surely as one with the name.
12741280
const blockedNames = new Set(branches);
12751281
for (const branch of branches) {
@@ -1281,13 +1287,13 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
12811287
// An ancestor ref blocks every suffix beneath it, so flatten to a sibling.
12821288
const segments = requestedBranch.split("/");
12831289
const blockedByParent = segments.some(
1284-
(_, index) => index > 0 && branches.has(segments.slice(0, index).join("/")),
1290+
(_, index) => index > 0 && branches.has(segments.slice(0, index).join("/").toLowerCase()),
12851291
);
12861292
const desiredBranch = blockedByParent ? segments.join("-") : requestedBranch;
1287-
if (!blockedNames.has(desiredBranch)) return desiredBranch;
1293+
if (!blockedNames.has(desiredBranch.toLowerCase())) return desiredBranch;
12881294
for (let suffix = 1; suffix <= 100; suffix += 1) {
12891295
const candidate = `${desiredBranch}-${suffix}`;
1290-
if (!blockedNames.has(candidate)) return candidate;
1296+
if (!blockedNames.has(candidate.toLowerCase())) return candidate;
12911297
}
12921298

12931299
return yield* new GitCommandError({

0 commit comments

Comments
 (0)