GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(server): skip local status refreshes for unrelated Git ref change… · patroza/t3code@0d37144

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/server/src
    • git
      • GitWorkflowService.ts
    • vcs
      • GitVcsDriver.ts
      • GitVcsDriverCore.test.ts
      • GitVcsDriverCore.ts
      • VcsStatusBroadcaster.test.ts
      • VcsStatusBroadcaster.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/server/src/git/GitWorkflowService.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/git/GitWorkflowService.ts
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ export class GitWorkflowService extends Context.Service<
7070
) => Effect.Effect<VcsStatusRemoteResult | null, GitManagerServiceError>;
7171
readonly invalidateLocalStatus: (cwd: string) => Effect.Effect<void, never>;
7272
readonly invalidateRemoteStatus: (cwd: string) => Effect.Effect<void, never>;
73-
readonly readLocalStatusRefSnapshot: GitVcsDriver.GitVcsDriver["Service"]["readLocalStatusRefSnapshot"];
73+
readonly readStatusRefreshRefs: GitVcsDriver.GitVcsDriver["Service"]["readStatusRefreshRefs"];
74+
readonly readStatusPoll: GitVcsDriver.GitVcsDriver["Service"]["readStatusPoll"];
7475
readonly readRefSnapshot: GitVcsDriver.GitVcsDriver["Service"]["readRefSnapshot"];
7576
readonly invalidateStatus: (cwd: string) => Effect.Effect<void, never>;
7677
/** The checkout's own HEAD file, inside a linked worktree's admin directory when there is one. */
@@ -400,7 +401,8 @@ export const make = Effect.gen(function* () {
400401
}),
401402
invalidateLocalStatus: gitManager.invalidateLocalStatus,
402403
invalidateRemoteStatus: gitManager.invalidateRemoteStatus,
403-
readLocalStatusRefSnapshot: git.readLocalStatusRefSnapshot,
404+
readStatusRefreshRefs: git.readStatusRefreshRefs,
405+
readStatusPoll: git.readStatusPoll,
404406
readRefSnapshot: git.readRefSnapshot,
405407
invalidateStatus: gitManager.invalidateStatus,
406408
headPath: Effect.fn("GitWorkflowService.headPath")(function* (cwd) {
Collapse file

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

Copy file name to clipboardExpand all lines: apps/server/src/vcs/GitVcsDriver.ts
+12-3Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,9 +420,18 @@ export class GitVcsDriver extends Context.Service<
420420
cwd: string,
421421
options?: GitRemoteStatusOptions,
422422
) => Effect.Effect<GitRemoteStatusDetails, GitCommandError>;
423-
/** Refs, HEAD and shallow boundaries. Null on read failure. */
424-
readonly readLocalStatusRefSnapshot: (cwd: string) => Effect.Effect<string | null>;
425-
/** Includes worktree paths. Accepts an existing local status ref snapshot to avoid re-reading refs. */
423+
/** Refs used by an explicit refresh and its branch-picker digest. */
424+
readonly readStatusRefreshRefs: (cwd: string) => Effect.Effect<string | null>;
425+
readonly readStatusPoll: (
426+
cwd: string,
427+
branch: string | null,
428+
refreshUpstream: boolean,
429+
) => Effect.Effect<{
430+
readonly inputStamp: string;
431+
readonly inputStampAfterLookup: Effect.Effect<string | null>;
432+
readonly details: GitRemoteStatusDetails;
433+
} | null>;
434+
/** Branch-picker digest input, including worktree paths. */
426435
readonly readRefSnapshot: (cwd: string, refs?: string) => Effect.Effect<string | null>;
427436
readonly prepareCommitContext: (
428437
cwd: string,
Collapse file

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

Copy file name to clipboardExpand all lines: apps/server/src/vcs/GitVcsDriverCore.test.ts
+229Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6275,13 +6275,27 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
62756275
yield* git(updater, ["push", "origin", initialBranch]);
62766276

62776277
const driver = yield* GitVcsDriver.GitVcsDriver;
6278+
yield* git(cwd, [
6279+
"symbolic-ref",
6280+
"refs/remotes/origin/HEAD",
6281+
`refs/remotes/origin/${initialBranch}`,
6282+
]);
6283+
const linked = yield* makeTmpDir();
6284+
yield* git(cwd, ["worktree", "add", "-b", "feature", linked]);
6285+
const observed = yield* driver.readStatusPoll(linked, "feature", false);
6286+
if (observed === null) return assert.fail("Expected poll inputs for the linked worktree");
6287+
assert.equal(yield* observed.inputStampAfterLookup, observed.inputStamp);
62786288
const cachedStatus = yield* driver.statusDetailsRemote(cwd, {
62796289
refreshUpstream: false,
62806290
});
62816291
const refreshedStatus = yield* driver.statusDetailsRemote(cwd);
62826292

62836293
assert.equal(cachedStatus.behindCount, 0);
62846294
assert.equal(refreshedStatus.behindCount, 1);
6295+
const fresh = yield* driver.readStatusPoll(linked, "feature", false);
6296+
if (fresh === null) return assert.fail("Expected poll inputs after the fetch");
6297+
assert.notEqual(fresh.inputStamp, observed.inputStamp);
6298+
assert.equal(yield* observed.inputStampAfterLookup, fresh.inputStamp);
62856299
}),
62866300
);
62876301

@@ -6314,6 +6328,210 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
63146328
}),
63156329
);
63166330

6331+
it.effect.each([{ reftable: false }, { reftable: gitHasReftable }])(
6332+
"scopes linked worktree poll inputs and matches Git after ref moves (reftable: $reftable)",
6333+
({ reftable }) =>
6334+
Effect.gen(function* () {
6335+
const cwd = yield* makeTmpDir();
6336+
const linked = yield* makeTmpDir();
6337+
const sibling = yield* makeTmpDir();
6338+
yield* commitInitialRepo(cwd, [
6339+
"--initial-branch=main",
6340+
...(reftable ? ["--ref-format=reftable"] : []),
6341+
]);
6342+
yield* git(cwd, ["remote", "add", "origin", cwd]);
6343+
const initial = yield* git(cwd, ["rev-parse", "HEAD"]);
6344+
yield* git(cwd, ["commit", "--allow-empty", "-m", "next"]);
6345+
const next = yield* git(cwd, ["rev-parse", "HEAD"]);
6346+
yield* git(cwd, ["update-ref", "refs/remotes/origin/main", initial]);
6347+
yield* git(cwd, ["update-ref", "refs/remotes/origin/trunk", next]);
6348+
yield* git(cwd, ["update-ref", "refs/remotes/origin/feature", initial]);
6349+
yield* git(cwd, ["symbolic-ref", "refs/remotes/origin/HEAD", "refs/remotes/origin/main"]);
6350+
yield* git(cwd, ["worktree", "add", "-b", "feature", linked, next]);
6351+
yield* git(cwd, ["worktree", "add", "-b", "sibling", sibling, initial]);
6352+
yield* git(linked, ["branch", "--set-upstream-to=origin/feature"]);
6353+
yield* git(cwd, ["config", "extensions.worktreeConfig", "true"]);
6354+
6355+
const driver = yield* GitVcsDriver.GitVcsDriver;
6356+
const readPoll = Effect.fnUntraced(function* () {
6357+
const head = yield* driver.execute({
6358+
operation: "GitVcsDriver.test.head",
6359+
cwd: linked,
6360+
args: ["symbolic-ref", "--quiet", "--short", "HEAD"],
6361+
allowNonZeroExit: true,
6362+
});
6363+
const branch = head.exitCode === 0 ? head.stdout.trim() : null;
6364+
const poll = yield* driver.readStatusPoll(linked, branch, false);
6365+
if (poll === null) return assert.fail("Expected a bounded poll read");
6366+
const defaultRef = yield* git(linked, [
6367+
"rev-parse",
6368+
"--verify",
6369+
"--symbolic-full-name",
6370+
"refs/remotes/origin/HEAD",
6371+
]);
6372+
const upstream = yield* driver.execute({
6373+
operation: "GitVcsDriver.test.upstream",
6374+
cwd: linked,
6375+
args: ["rev-parse", "--symbolic-full-name", "@{upstream}"],
6376+
allowNonZeroExit: true,
6377+
});
6378+
const hasUpstream = upstream.exitCode === 0;
6379+
const configured = yield* driver.execute({
6380+
operation: "GitVcsDriver.test.base",
6381+
cwd: linked,
6382+
args: ["config", "--get", "branch.feature.t3-merge-base-ref"],
6383+
allowNonZeroExit: true,
6384+
});
6385+
const base = configured.exitCode === 0 ? configured.stdout.trim() : defaultRef;
6386+
const aheadOfBase =
6387+
branch === null
6388+
? 0
6389+
: Number(yield* git(linked, ["rev-list", "--count", `${base}..HEAD`]));
6390+
const [ahead = 0, behind = 0] = hasUpstream
6391+
? (yield* git(linked, ["rev-list", "--left-right", "--count", "HEAD...@{upstream}"]))
6392+
.split(/\s+/)
6393+
.map(Number)
6394+
: [aheadOfBase, 0];
6395+
assert.deepStrictEqual(poll.details, {
6396+
isRepo: true,
6397+
branch,
6398+
defaultBranch: defaultRef.replace("refs/remotes/origin/", ""),
6399+
hasPrimaryRemote: true,
6400+
isDefaultBranch: false,
6401+
upstreamRef: hasUpstream
6402+
? upstream.stdout.trim().replace(/^refs\/remotes\//, "")
6403+
: null,
6404+
hasUpstream,
6405+
aheadCount: ahead,
6406+
behindCount: behind,
6407+
aheadOfDefaultCount: aheadOfBase,
6408+
});
6409+
return poll.inputStamp;
6410+
});
6411+
6412+
let snapshot = yield* readPoll();
6413+
const digest = yield* driver.readRefSnapshot(linked);
6414+
yield* git(cwd, ["update-ref", "refs/t3/checkpoints/thread/turn", next]);
6415+
assert.notEqual(yield* driver.readRefSnapshot(linked), digest);
6416+
assert.equal(yield* readPoll(), snapshot);
6417+
assert.notEqual(
6418+
(yield* driver.readStatusPoll(sibling, "sibling", false))?.inputStamp,
6419+
snapshot,
6420+
);
6421+
6422+
yield* git(sibling, ["update-ref", "refs/heads/sibling", next]);
6423+
yield* git(cwd, ["update-ref", "refs/remotes/origin/unrelated", next]);
6424+
yield* git(cwd, ["pack-refs", "--all"]);
6425+
assert.equal(yield* readPoll(), snapshot);
6426+
// Divergence comes from the poll itself; readPoll checks it against Git.
6427+
yield* git(cwd, ["update-ref", "refs/remotes/origin/feature", next]);
6428+
snapshot = yield* readPoll();
6429+
6430+
yield* git(cwd, [
6431+
"symbolic-ref",
6432+
"refs/remotes/origin/HEAD",
6433+
"refs/remotes/origin/trunk",
6434+
]);
6435+
const movedHead = yield* readPoll();
6436+
assert.notEqual(movedHead, snapshot);
6437+
yield* git(cwd, ["update-ref", "refs/remotes/origin/trunk", initial]);
6438+
const movedBase = yield* readPoll();
6439+
assert.notEqual(movedBase, movedHead);
6440+
yield* git(linked, [
6441+
"config",
6442+
"--worktree",
6443+
"branch.feature.t3-merge-base-ref",
6444+
"refs/remotes/origin/main",
6445+
]);
6446+
const configuredBase = yield* readPoll();
6447+
assert.notEqual(configuredBase, movedBase);
6448+
assert.equal(
6449+
(yield* driver.statusDetailsLocal(linked, { includeBranchChanges: true })).branchChanges
6450+
?.baseRef,
6451+
"origin/main",
6452+
);
6453+
yield* git(linked, ["branch", "--unset-upstream"]);
6454+
yield* readPoll();
6455+
yield* git(linked, ["checkout", "--detach", "HEAD"]);
6456+
const detached = yield* readPoll();
6457+
assert.notEqual(detached, configuredBase);
6458+
yield* git(linked, ["checkout", "feature"]);
6459+
assert.notEqual(yield* readPoll(), detached);
6460+
6461+
yield* git(cwd, ["branch", "local-base", initial]);
6462+
const localWorktree = yield* makeTmpDir();
6463+
yield* driver.createWorktree({
6464+
cwd,
6465+
path: localWorktree,
6466+
refName: "refs/heads/local-base",
6467+
baseRefName: "refs/heads/local-base",
6468+
newRefName: "local-feature",
6469+
});
6470+
assert.equal(
6471+
yield* git(localWorktree, ["config", "--get", "branch.local-feature.t3-merge-base"]),
6472+
"local-base",
6473+
);
6474+
yield* git(localWorktree, ["commit", "--allow-empty", "-m", "local feature"]);
6475+
const pollLocal = driver.readStatusPoll(localWorktree, "local-feature", false);
6476+
const local = yield* pollLocal;
6477+
assert.isNotNull(local);
6478+
assert.equal(local?.details.aheadCount, 1);
6479+
yield* git(cwd, ["update-ref", "refs/t3/checkpoints/thread/unrelated", initial]);
6480+
assert.equal((yield* pollLocal)?.inputStamp, local?.inputStamp);
6481+
const featureHead = yield* git(localWorktree, ["rev-parse", "HEAD"]);
6482+
yield* git(cwd, ["update-ref", "refs/heads/local-base", featureHead]);
6483+
const advanced = yield* pollLocal;
6484+
assert.isNotNull(advanced);
6485+
assert.notEqual(advanced?.inputStamp, local?.inputStamp);
6486+
assert.equal(advanced?.details.aheadCount, 0);
6487+
}),
6488+
);
6489+
6490+
it.effect("uses Git's exact fallback ref lookup for differently cased loose refs", () =>
6491+
Effect.gen(function* () {
6492+
const cwd = yield* makeTmpDir();
6493+
yield* commitInitialRepo(cwd, ["--initial-branch=Main"]);
6494+
yield* git(cwd, ["checkout", "-b", "feature"]);
6495+
yield* git(cwd, ["commit", "--allow-empty", "-m", "feature work"]);
6496+
const driver = yield* GitVcsDriver.GitVcsDriver;
6497+
const poll = driver.readStatusPoll(cwd, "feature", false);
6498+
const before = yield* poll;
6499+
assert.isNotNull(before);
6500+
const direct = yield* driver.statusDetailsRemote(cwd, { refreshUpstream: false });
6501+
assert.deepStrictEqual(before?.details, direct);
6502+
yield* git(cwd, ["update-ref", "refs/heads/Main", "HEAD"]);
6503+
const after = yield* poll;
6504+
assert.isNotNull(after);
6505+
assert.deepStrictEqual(
6506+
after?.details,
6507+
yield* driver.statusDetailsRemote(cwd, { refreshUpstream: false }),
6508+
);
6509+
// With loose refs, the filesystem decides whether Main also resolves as main.
6510+
if (direct.aheadCount > 0) assert.notEqual(after?.inputStamp, before?.inputStamp);
6511+
}),
6512+
);
6513+
6514+
it.effect("polls an unborn worktree and declines unproven ref dependencies", () =>
6515+
Effect.gen(function* () {
6516+
const cwd = yield* makeTmpDir();
6517+
yield* git(cwd, ["init", "--initial-branch=main"]);
6518+
const driver = yield* GitVcsDriver.GitVcsDriver;
6519+
const poll = driver.readStatusPoll(cwd, "main", false);
6520+
const unborn = yield* poll;
6521+
assert.isNotNull(unborn);
6522+
assert.equal((yield* poll)?.inputStamp, unborn?.inputStamp);
6523+
assert.equal(unborn?.details.branch, "main");
6524+
assert.isFalse(unborn?.details.hasUpstream);
6525+
yield* commitInitialRepo(cwd);
6526+
const born = yield* poll;
6527+
assert.isNotNull(born);
6528+
assert.notEqual(born?.inputStamp, unborn?.inputStamp);
6529+
yield* git(cwd, ["commit", "--allow-empty", "-m", "replacement"]);
6530+
yield* git(cwd, ["replace", "HEAD^", "HEAD"]);
6531+
assert.isNull(yield* poll);
6532+
}),
6533+
);
6534+
63176535
it.effect("a ref snapshot detects branch identity, ref and ancestry changes", () =>
63186536
Effect.gen(function* () {
63196537
const cwd = yield* makeTmpDir();
@@ -6369,10 +6587,15 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
63696587
const shallowRefs = yield* git(shallow, ["show-ref", "--head"]);
63706588
const shallowSnapshot = yield* driver.readRefSnapshot(shallow);
63716589
assert.isNotNull(shallowSnapshot);
6590+
const shallowBranch = yield* git(shallow, ["symbolic-ref", "--short", "HEAD"]);
6591+
const shallowInputs = yield* driver.readStatusPoll(shallow, shallowBranch, false);
6592+
assert.isNotNull(shallowInputs);
63726593
const shallowWorktree = yield* makeTmpDir("git-vcs-driver-shallow-worktree-");
63736594
yield* git(shallow, ["worktree", "add", "--detach", shallowWorktree]);
63746595
const worktreeSnapshot = yield* driver.readRefSnapshot(shallowWorktree);
63756596
assert.isNotNull(worktreeSnapshot);
6597+
const worktreeInputs = yield* driver.readStatusPoll(shallowWorktree, null, false);
6598+
assert.isNotNull(worktreeInputs);
63766599
yield* git(shallow, ["fetch", "--unshallow", "origin"]);
63776600
assert.equal(yield* git(shallow, ["show-ref", "--head"]), shallowRefs);
63786601
const unshallowSnapshot = yield* driver.readRefSnapshot(shallow);
@@ -6381,6 +6604,12 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
63816604
assert.isNotNull(unshallowWorktreeSnapshot);
63826605
assert.notEqual(unshallowSnapshot, shallowSnapshot);
63836606
assert.notEqual(unshallowWorktreeSnapshot, worktreeSnapshot);
6607+
const deepened = yield* driver.readStatusPoll(shallow, shallowBranch, false);
6608+
const deepenedWorktree = yield* driver.readStatusPoll(shallowWorktree, null, false);
6609+
assert.isNotNull(deepened);
6610+
assert.isNotNull(deepenedWorktree);
6611+
assert.notEqual(deepened?.inputStamp, shallowInputs?.inputStamp);
6612+
assert.notEqual(deepenedWorktree?.inputStamp, worktreeInputs?.inputStamp);
63846613

63856614
yield* git(cwd, ["checkout", "--detach"]);
63866615
yield* git(cwd, ["commit", "--allow-empty", "-m", "detached"]);

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.