Skip to content

Commit fc7431a

Browse files
committed
fix(server): keep worktree creation working when git config is locked
1 parent f328db3 commit fc7431a

2 files changed

Lines changed: 46 additions & 1 deletion

File tree

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,6 +1686,44 @@ it.layer(TestLayer)("GitVcsDriver core integration", (it) => {
16861686
}),
16871687
);
16881688

1689+
it.effect("still creates the worktree when the base-ref config is locked", () =>
1690+
Effect.gen(function* () {
1691+
const cwd = yield* makeTmpDir();
1692+
const { initialBranch } = yield* initRepoWithCommit(cwd);
1693+
const pathService = yield* Path.Path;
1694+
const fileSystem = yield* FileSystem.FileSystem;
1695+
const worktreePath = pathService.join(yield* makeTmpDir("git-worktrees-"), "locked-config");
1696+
yield* writeTextFile(cwd, ".git/config.lock", "");
1697+
const driver = yield* GitVcsDriver.GitVcsDriver;
1698+
1699+
const created = yield* driver.createWorktree({
1700+
cwd,
1701+
path: worktreePath,
1702+
refName: initialBranch,
1703+
newRefName: "feature/locked-config",
1704+
baseRefName: initialBranch,
1705+
});
1706+
1707+
assert.deepEqual(created.worktree, {
1708+
path: worktreePath,
1709+
refName: "feature/locked-config",
1710+
});
1711+
assert.equal(
1712+
yield* git(worktreePath, ["branch", "--show-current"]),
1713+
"feature/locked-config",
1714+
);
1715+
assert.equal(
1716+
yield* fileSystem.readFileString(pathService.join(worktreePath, "README.md")),
1717+
"# test\n",
1718+
);
1719+
assert.equal(
1720+
yield* driver.readConfigValue(worktreePath, "branch.feature/locked-config.gh-merge-base"),
1721+
null,
1722+
);
1723+
assert.equal(yield* fileSystem.exists(pathService.join(cwd, ".git/config.lock")), true);
1724+
}),
1725+
);
1726+
16891727
it.effect("reports checkout progress while creating a worktree", () =>
16901728
Effect.gen(function* () {
16911729
const cwd = yield* makeTmpDir();

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3119,7 +3119,14 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
31193119
"config",
31203120
`branch.${input.newRefName}.gh-merge-base`,
31213121
baseBranch,
3122-
]);
3122+
]).pipe(
3123+
Effect.catch((cause) =>
3124+
Effect.logWarning("worktree base-ref configuration failed; using base-branch fallback", {
3125+
worktreePath,
3126+
cause,
3127+
}),
3128+
),
3129+
);
31233130
}
31243131

31253132
return {

0 commit comments

Comments
 (0)