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): removing a worktree on Windows no longer spins the serve… · incognitojam/styal@345de30

File tree

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

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

Copy file name to clipboardExpand all lines: apps/server/src/vcs/VcsStatusBroadcaster.test.ts
+44Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,6 +1538,50 @@ describe("VcsStatusBroadcaster", () => {
15381538
}).pipe(Effect.provide(NodeServices.layer), Effect.scoped),
15391539
);
15401540

1541+
it.effect("a HEAD watch ends when its git directory is removed", () =>
1542+
Effect.gen(function* () {
1543+
const gitDir = "/repo/.git/worktrees/feature";
1544+
const events = yield* Queue.unbounded<FileSystem.WatchEvent>();
1545+
const closed = yield* Deferred.make<void>();
1546+
let gitDirExists = true;
1547+
const state: Parameters<typeof layerTestFor>[0] = {
1548+
currentLocalStatus: { ...baseLocalStatus, refName: "main" },
1549+
currentRemoteStatus: null,
1550+
localStatusCalls: 0,
1551+
remoteStatusCalls: 0,
1552+
localInvalidationCalls: 0,
1553+
remoteInvalidationCalls: 0,
1554+
headPath: `${gitDir}/HEAD`,
1555+
fileSystem: FileSystem.makeNoop({
1556+
realPath: (target) => Effect.succeed(target),
1557+
exists: (target) => Effect.succeed(target !== gitDir || gitDirExists),
1558+
watch: (_target, options) =>
1559+
Stream.fromQueue(events).pipe(
1560+
Stream.onStart(Effect.sync(() => options?.onReady?.())),
1561+
Stream.ensuring(Deferred.succeed(closed, undefined)),
1562+
),
1563+
}),
1564+
};
1565+
1566+
yield* Effect.gen(function* () {
1567+
const broadcaster = yield* VcsStatusBroadcaster.VcsStatusBroadcaster;
1568+
const branches = yield* Stream.toPull(broadcaster.streamBranchStatus({ cwd: "/repo" }));
1569+
assert.deepEqual(yield* branches, [{ refName: "main" }]);
1570+
1571+
// Every checkout removes HEAD.lock, which leaves the watch running.
1572+
state.currentLocalStatus = { ...baseLocalStatus, refName: "other" };
1573+
yield* Queue.offer(events, { _tag: "Remove", path: "HEAD.lock" });
1574+
yield* Queue.offer(events, { _tag: "Update", path: "HEAD" });
1575+
assert.deepEqual(yield* branches, [{ refName: "other" }]);
1576+
1577+
// `git worktree remove` deletes the watched directory; Windows keeps reporting it.
1578+
gitDirExists = false;
1579+
yield* Queue.offer(events, { _tag: "Remove", path: gitDir });
1580+
yield* Deferred.await(closed);
1581+
}).pipe(Effect.provide(layerTestFor(state)), Effect.scoped);
1582+
}),
1583+
);
1584+
15411585
it.effect("releases remote demand while passive observers remain", () => {
15421586
const state = {
15431587
currentLocalStatus: baseLocalStatus,
Collapse file

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

Copy file name to clipboardExpand all lines: apps/server/src/vcs/VcsStatusBroadcaster.ts
+8-1Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,12 +870,19 @@ export const make = Effect.gen(function* () {
870870
const watchHead = Effect.fnUntraced(function* (cwd: string, ready: Deferred.Deferred<void>) {
871871
const headPath = yield* workflow.headPath(cwd);
872872
if (headPath === null) return;
873+
const headDirectory = path.dirname(headPath);
873874
// Git replaces HEAD by renaming HEAD.lock, which a watch on the file itself would lose.
874875
yield* fs
875-
.watch(path.dirname(headPath), {
876+
.watch(headDirectory, {
876877
onReady: () => Deferred.doneUnsafe(ready, Exit.void),
877878
})
878879
.pipe(
880+
// On Windows a watch outlives its deleted directory and reports it ~150k times a second.
881+
Stream.takeUntilEffect((event) =>
882+
event._tag === "Remove"
883+
? fs.exists(headDirectory).pipe(Effect.map((exists) => !exists))
884+
: Effect.succeed(false),
885+
),
879886
Stream.filter((event) => path.basename(event.path) === "HEAD"),
880887
// A rebase moves HEAD many times; refresh once for whatever arrived during a refresh.
881888
Stream.buffer({ capacity: 1, strategy: "sliding" }),

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.