Skip to content

Commit 344792d

Browse files
only21milclaude
andcommitted
fix(server): detect operation refs that share a branch or tag name
With a same-named branch or tag, rev-parse warned about the ambiguity and printed nothing, so the guard missed a merge or pick in progress. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent b1c1c88 commit 344792d

2 files changed

Lines changed: 21 additions & 17 deletions

File tree

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

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4993,6 +4993,7 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
49934993
yield* git(cwd, ["add", "."]);
49944994
yield* git(cwd, ["commit", "-m", "Main"]);
49954995
const mainHead = yield* git(cwd, ["rev-parse", "HEAD"]);
4996+
yield* git(cwd, ["branch", "MERGE_HEAD"]);
49964997
if (location === "worktree") {
49974998
const worktree = path.join(yield* makeTmpDir(), "linked");
49984999
yield* git(cwd, ["worktree", "add", "-b", "linked", worktree]);
@@ -5062,6 +5063,7 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
50625063
const cwd = yield* makeTmpDir();
50635064
const { initialBranch } = yield* initRepoWithCommit(cwd);
50645065
const driver = yield* GitVcsDriver.GitVcsDriver;
5066+
const path = yield* Path.Path;
50655067
yield* git(cwd, ["checkout", "-b", "feature"]);
50665068
yield* writeTextFile(cwd, "README.md", "feature version\n");
50675069
yield* writeTextFile(cwd, "picked.txt", "picked\n");
@@ -5072,6 +5074,7 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
50725074
yield* writeTextFile(cwd, "README.md", "other version\n");
50735075
yield* git(cwd, ["commit", "-am", "Other"]);
50745076
const head = yield* git(cwd, ["rev-parse", "HEAD"]);
5077+
yield* git(cwd, ["branch", stateRef]);
50755078
const started = yield* driver.execute({
50765079
operation: "test.sequencer",
50775080
cwd,
@@ -5082,28 +5085,21 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
50825085
yield* writeTextFile(cwd, "README.md", "resolved version\n");
50835086
const gitDir = yield* git(cwd, ["rev-parse", "--absolute-git-dir"]);
50845087
const names = ["index", stateRef, "MERGE_MSG"];
5085-
const before = names.map((name) => NodeFS.readFileSync(`${gitDir}/${name}`));
5088+
const before = names.map((name) => NodeFS.readFileSync(path.join(gitDir, name)));
50865089

5087-
const result = yield* driver
5090+
const error = yield* driver
50885091
.commit(cwd, "Partial", "", { stage: { filePaths: ["picked.txt"] } })
5089-
.pipe(Effect.result);
5090-
if (Result.isSuccess(result)) {
5091-
assert.fail(`Selected ${operation} commit succeeded`);
5092-
} else {
5093-
assert.include(
5094-
result.failure.detail,
5095-
`Cannot commit selected files during a ${operation}`,
5096-
);
5097-
}
5092+
.pipe(Effect.flip);
5093+
assert.include(error.detail, `Cannot commit selected files during a ${operation}`);
50985094
assert.deepEqual(
5099-
names.map((name) => NodeFS.readFileSync(`${gitDir}/${name}`)),
5095+
names.map((name) => NodeFS.readFileSync(path.join(gitDir, name))),
51005096
before,
51015097
);
51025098
assert.equal(yield* git(cwd, ["rev-parse", "HEAD"]), head);
51035099

51045100
yield* driver.commit(cwd, "Finish", "", { stage: {} });
51055101
assert.equal(yield* git(cwd, ["show", "-s", "--format=%an", "HEAD"]), author);
5106-
assert.isFalse(NodeFS.existsSync(`${gitDir}/${stateRef}`));
5102+
assert.isFalse(NodeFS.existsSync(path.join(gitDir, stateRef)));
51075103
}),
51085104
);
51095105

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2415,18 +2415,26 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
24152415
{ env },
24162416
);
24172417
} else {
2418-
// Reset discards these, so reject partial commits that would lose their ancestry or author.
2418+
// Reset deletes these, so reject partial commits rather than lose the merge, pick or revert.
24192419
for (const [stateRef, action] of [
24202420
["MERGE_HEAD", "merge"],
24212421
["CHERRY_PICK_HEAD", "cherry-pick"],
24222422
["REVERT_HEAD", "revert"],
24232423
] as const) {
2424-
// Reftable stores CHERRY_PICK_HEAD and REVERT_HEAD as refs, not files. The full name
2425-
// skips branches and tags that reuse the name.
2424+
// Reftable stores CHERRY_PICK_HEAD and REVERT_HEAD as refs, not files. A same-named
2425+
// branch or tag resolves to its full name, and an ambiguity warning would blank stdout.
24262426
const state = yield* runGitStdout(
24272427
"GitVcsDriver.commit.operationState",
24282428
cwd,
2429-
["rev-parse", "--verify", "--quiet", "--symbolic-full-name", stateRef],
2429+
[
2430+
"-c",
2431+
"core.warnAmbiguousRefs=false",
2432+
"rev-parse",
2433+
"--verify",
2434+
"--quiet",
2435+
"--symbolic-full-name",
2436+
stateRef,
2437+
],
24302438
true,
24312439
);
24322440
if (state.trim() === stateRef) {

0 commit comments

Comments
 (0)