Skip to content

Commit 2cc7f95

Browse files
committed
fix(server): detect same-commit branch switches in refresh snapshots
Made with GPT-6.1 Sol via Codex in T3 Code.
1 parent 42bfcff commit 2cc7f95

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3477,7 +3477,7 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
34773477
}),
34783478
);
34793479

3480-
it.effect("a ref snapshot changes when a fetch or commit changes refs or ancestry", () =>
3480+
it.effect("a ref snapshot detects branch identity, ref and ancestry changes", () =>
34813481
Effect.gen(function* () {
34823482
const cwd = yield* makeTmpDir();
34833483
const remote = yield* makeTmpDir("git-vcs-driver-remote-");
@@ -3499,6 +3499,25 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
34993499
yield* git(cwd, ["fetch", "origin"]);
35003500
assert.equal(yield* snapshot, initial);
35013501

3502+
yield* git(cwd, ["branch", "same-commit"]);
3503+
const beforeCheckout = yield* snapshot;
3504+
const refsBeforeCheckout = yield* git(cwd, ["show-ref", "--head"]);
3505+
yield* git(cwd, ["checkout", "same-commit"]);
3506+
assert.equal(yield* git(cwd, ["show-ref", "--head"]), refsBeforeCheckout);
3507+
const afterCheckout = yield* snapshot;
3508+
assert.isNotNull(afterCheckout);
3509+
assert.notEqual(afterCheckout, beforeCheckout);
3510+
yield* git(cwd, ["checkout", "--detach"]);
3511+
assert.equal(yield* git(cwd, ["show-ref", "--head"]), refsBeforeCheckout);
3512+
const detached = yield* snapshot;
3513+
assert.isNotNull(detached);
3514+
assert.notEqual(detached, beforeCheckout);
3515+
assert.notEqual(detached, afterCheckout);
3516+
assert.equal(yield* snapshot, detached);
3517+
yield* git(cwd, ["checkout", initialBranch]);
3518+
assert.equal(yield* snapshot, beforeCheckout);
3519+
yield* git(cwd, ["branch", "-d", "same-commit"]);
3520+
35023521
yield* writeTextFile(updater, "remote.txt", "remote\n");
35033522
yield* git(updater, ["add", "remote.txt"]);
35043523
yield* git(updater, ["commit", "-m", "remote commit"]);

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1655,12 +1655,20 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
16551655
},
16561656
);
16571657
if (result.exitCode !== 0) return null;
1658+
const symbolicHead = yield* executeGit(
1659+
"GitVcsDriver.readRefSnapshot",
1660+
cwd,
1661+
["symbolic-ref", "--quiet", "HEAD"],
1662+
{ allowNonZeroExit: true },
1663+
);
1664+
// Exit 1 means detached HEAD; other failures require a full status read.
1665+
if (symbolicHead.exitCode !== 0 && symbolicHead.exitCode !== 1) return null;
16581666
// Deepening a shallow clone changes ancestry without moving refs.
16591667
const shallowPath = path.join(yield* resolveGitCommonDir(cwd), "shallow");
16601668
const shallow = (yield* fileSystem.exists(shallowPath))
16611669
? yield* fileSystem.readFileString(shallowPath)
16621670
: "";
1663-
return `${result.stdout}\0${shallow}`;
1671+
return `${result.stdout}\0${symbolicHead.stdout}\0${shallow}`;
16641672
},
16651673
Effect.orElseSucceed(() => null),
16661674
);

0 commit comments

Comments
 (0)