Skip to content

Commit b7d9c1c

Browse files
fix(server): detect a merge by its MERGE_HEAD file, not a ref of that name
rev-parse --verify MERGE_HEAD also resolves a branch named MERGE_HEAD, so a clean repository with that branch attempted an empty commit. Check the merge state file, like the selected-file guard does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 0258f6c commit b7d9c1c

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6813,6 +6813,10 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
68136813
const cwd = yield* makeTmpDir();
68146814
const { initialBranch } = yield* initRepoWithCommit(cwd);
68156815
const driver = yield* GitVcsDriver.GitVcsDriver;
6816+
// A branch named MERGE_HEAD is not a merge in progress.
6817+
yield* git(cwd, ["branch", "MERGE_HEAD"]);
6818+
assert.isNull(yield* driver.prepareCommitContext(cwd, undefined, { includePatch: false }));
6819+
yield* git(cwd, ["branch", "-D", "MERGE_HEAD"]);
68166820
yield* git(cwd, ["checkout", "-b", "feature"]);
68176821
yield* writeTextFile(cwd, "README.md", "feature version\n");
68186822
yield* git(cwd, ["commit", "-am", "Feature"]);

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2715,13 +2715,14 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
27152715
).pipe(Effect.map((stdout) => stdout.trim()));
27162716
if (stagedSummary.length === 0) {
27172717
// Like git commit, a merge resolved to HEAD's tree still records its merge commit.
2718-
const mergeHead = yield* executeGit(
2718+
const mergeHeadPath = yield* runGitStdout(
27192719
"GitVcsDriver.prepareCommitContext.mergeHead",
27202720
cwd,
2721-
["rev-parse", "--verify", "--quiet", "MERGE_HEAD"],
2722-
{ allowNonZeroExit: true },
2721+
["rev-parse", "--git-path", "MERGE_HEAD"],
27232722
);
2724-
if (mergeHead.exitCode !== 0) return null;
2723+
if (!(yield* fileSystem.exists(path.resolve(physicalCwd, mergeHeadPath.trim())))) {
2724+
return null;
2725+
}
27252726
}
27262727

27272728
// A user-supplied message needs change detection, but no patch for generation.

0 commit comments

Comments
 (0)