Skip to content

Commit 6cb55dd

Browse files
fix(server): lock worktree branch configuration before checkout
1 parent 2a788aa commit 6cb55dd

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

‎apps/server/src/orchestration-v2/ThreadLaunchService.test.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,7 @@ it.effect(
14441444
"-m",
14451445
"initial",
14461446
]);
1447+
yield* git(["config", "branch.autoSetupMerge", "always"]);
14471448
const existingPath = path.join(worktreesDirectory, "existing");
14481449
yield* driver.createWorktree({
14491450
cwd,
@@ -1502,6 +1503,12 @@ it.effect(
15021503
assert.isTrue(yield* fs.exists(projection.thread.worktreePath!));
15031504
const base = yield* git(["config", `branch.${projection.thread.branch}.gh-merge-base`]);
15041505
assert.equal(base.stdout.trim(), "main");
1506+
const upstream = yield* git([
1507+
"rev-parse",
1508+
"--abbrev-ref",
1509+
`${projection.thread.branch}@{upstream}`,
1510+
]);
1511+
assert.equal(upstream.stdout.trim(), "main");
15051512
}
15061513
assert.deepEqual(
15071514
launched.map((projection) => projection.thread.branch).toSorted(),

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3509,9 +3509,20 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
35093509
}
35103510
worktreePath = path.join(parentDir, repoName, sanitizedBranch);
35113511
}
3512-
const args = input.newRefName
3513-
? ["worktree", "add", "-b", input.newRefName, "--", worktreePath, input.refName]
3514-
: ["worktree", "add", "--", worktreePath, input.refName];
3512+
if (input.newRefName) {
3513+
// Branch creation may write upstream config. Keep it under the same lock
3514+
// as renames, but leave the expensive checkout outside the lock.
3515+
yield* configLocks.withLock(
3516+
yield* resolveGitCommonDir(input.cwd),
3517+
runGit("GitVcsDriver.createWorktree.createBranch", input.cwd, [
3518+
"branch",
3519+
"--",
3520+
input.newRefName,
3521+
input.refName === "-" ? "@{-1}" : input.refName,
3522+
]),
3523+
);
3524+
}
3525+
const args = ["worktree", "add", "--", worktreePath, targetBranch];
35153526
const progress = options?.progress;
35163527
const onCheckoutProgress = progress?.onCheckoutProgress;
35173528

0 commit comments

Comments
 (0)