@@ -6275,13 +6275,27 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => { |
6275 | 6275 | yield* git(updater, ["push", "origin", initialBranch]); |
6276 | 6276 |
|
6277 | 6277 | 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); |
6278 | 6288 | const cachedStatus = yield* driver.statusDetailsRemote(cwd, { |
6279 | 6289 | refreshUpstream: false, |
6280 | 6290 | }); |
6281 | 6291 | const refreshedStatus = yield* driver.statusDetailsRemote(cwd); |
6282 | 6292 |
|
6283 | 6293 | assert.equal(cachedStatus.behindCount, 0); |
6284 | 6294 | 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); |
6285 | 6299 | }), |
6286 | 6300 | ); |
6287 | 6301 |
|
@@ -6314,6 +6328,210 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => { |
6314 | 6328 | }), |
6315 | 6329 | ); |
6316 | 6330 |
|
| 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 | + |
6317 | 6535 | it.effect("a ref snapshot detects branch identity, ref and ancestry changes", () => |
6318 | 6536 | Effect.gen(function* () { |
6319 | 6537 | const cwd = yield* makeTmpDir(); |
@@ -6369,10 +6587,15 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => { |
6369 | 6587 | const shallowRefs = yield* git(shallow, ["show-ref", "--head"]); |
6370 | 6588 | const shallowSnapshot = yield* driver.readRefSnapshot(shallow); |
6371 | 6589 | 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); |
6372 | 6593 | const shallowWorktree = yield* makeTmpDir("git-vcs-driver-shallow-worktree-"); |
6373 | 6594 | yield* git(shallow, ["worktree", "add", "--detach", shallowWorktree]); |
6374 | 6595 | const worktreeSnapshot = yield* driver.readRefSnapshot(shallowWorktree); |
6375 | 6596 | assert.isNotNull(worktreeSnapshot); |
| 6597 | + const worktreeInputs = yield* driver.readStatusPoll(shallowWorktree, null, false); |
| 6598 | + assert.isNotNull(worktreeInputs); |
6376 | 6599 | yield* git(shallow, ["fetch", "--unshallow", "origin"]); |
6377 | 6600 | assert.equal(yield* git(shallow, ["show-ref", "--head"]), shallowRefs); |
6378 | 6601 | const unshallowSnapshot = yield* driver.readRefSnapshot(shallow); |
@@ -6381,6 +6604,12 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => { |
6381 | 6604 | assert.isNotNull(unshallowWorktreeSnapshot); |
6382 | 6605 | assert.notEqual(unshallowSnapshot, shallowSnapshot); |
6383 | 6606 | 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); |
6384 | 6613 |
|
6385 | 6614 | yield* git(cwd, ["checkout", "--detach"]); |
6386 | 6615 | yield* git(cwd, ["commit", "--allow-empty", "-m", "detached"]); |
|