Skip to content

Commit d3f224e

Browse files
committed
fix(server): distinguish merge metadata from named refs
1 parent 996da60 commit d3f224e

2 files changed

Lines changed: 61 additions & 6 deletions

File tree

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3847,6 +3847,50 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
38473847
}),
38483848
);
38493849

3850+
it.effect.each([
3851+
{ location: "root", ref: "refs/heads/MERGE_HEAD" },
3852+
{ location: "nested", ref: "refs/heads/MERGE_HEAD" },
3853+
{ location: "worktree", ref: "refs/heads/MERGE_HEAD" },
3854+
{ location: "root", ref: "refs/tags/MERGE_HEAD" },
3855+
{ location: "nested", ref: "refs/tags/MERGE_HEAD" },
3856+
{ location: "worktree", ref: "refs/tags/MERGE_HEAD" },
3857+
])(
3858+
"commits selected files with a MERGE_HEAD ref and no merge ($location, $ref)",
3859+
({ location, ref }) =>
3860+
Effect.gen(function* () {
3861+
let cwd = yield* makeTmpDir();
3862+
yield* initRepoWithCommit(cwd);
3863+
const driver = yield* GitVcsDriver.GitVcsDriver;
3864+
const fs = yield* FileSystem.FileSystem;
3865+
const path = yield* Path.Path;
3866+
const originalHead = yield* git(cwd, ["rev-parse", "HEAD"]);
3867+
yield* git(cwd, ["update-ref", ref, originalHead]);
3868+
if (location === "worktree") {
3869+
const linked = path.join(yield* makeTmpDir(), "linked");
3870+
yield* git(cwd, ["worktree", "add", "-b", "linked", linked]);
3871+
cwd = linked;
3872+
}
3873+
const commitCwd = location === "nested" ? path.join(cwd, "nested") : cwd;
3874+
yield* fs.makeDirectory(commitCwd, { recursive: true });
3875+
yield* writeTextFile(cwd, "selected.txt", "selected\n");
3876+
yield* writeTextFile(cwd, "unrelated.txt", "unrelated\n");
3877+
const mergePath = yield* git(commitCwd, ["rev-parse", "--git-path", "MERGE_HEAD"]);
3878+
assert.isFalse(yield* fs.exists(path.resolve(commitCwd, mergePath)));
3879+
3880+
yield* driver.commit(commitCwd, "Selected without merge", "", {
3881+
stage: { filePaths: ["selected.txt"] },
3882+
});
3883+
3884+
assert.equal(yield* git(cwd, ["show", "-s", "--format=%P", "HEAD"]), originalHead);
3885+
assert.equal(
3886+
yield* git(cwd, ["show", "--pretty=", "--name-only", "HEAD"]),
3887+
"selected.txt",
3888+
);
3889+
assert.equal(yield* git(cwd, ["rev-parse", ref]), originalHead);
3890+
assert.include(yield* git(cwd, ["status", "--porcelain"]), "?? unrelated.txt");
3891+
}),
3892+
);
3893+
38503894
it.effect.each([
38513895
{ location: "root", conflict: false },
38523896
{ location: "nested", conflict: false },

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2332,14 +2332,25 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
23322332
{ env },
23332333
);
23342334
} else {
2335-
const mergeHead = yield* executeGit(
2336-
"GitVcsDriver.commit.mergeHead",
2337-
cwd,
2338-
["rev-parse", "--verify", "--quiet", "MERGE_HEAD"],
2339-
{ allowNonZeroExit: true },
2335+
const mergeHeadPath = yield* runGitStdout("GitVcsDriver.commit.mergeHead", cwd, [
2336+
"rev-parse",
2337+
"--git-path",
2338+
"MERGE_HEAD",
2339+
]);
2340+
const isMerging = yield* fileSystem.exists(path.resolve(cwd, mergeHeadPath.trim())).pipe(
2341+
Effect.mapError(
2342+
(cause) =>
2343+
new GitCommandError({
2344+
operation: "GitVcsDriver.commit.mergeHead",
2345+
command: "git commit",
2346+
cwd,
2347+
detail: "Could not check whether a merge is in progress.",
2348+
cause,
2349+
}),
2350+
),
23402351
);
23412352
// Like git commit --only, reject partial merges before reset can discard their ancestry.
2342-
if (mergeHead.exitCode === 0) {
2353+
if (isMerging) {
23432354
return yield* new GitCommandError({
23442355
operation: "GitVcsDriver.commit",
23452356
command: "git commit",

0 commit comments

Comments
 (0)