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@76e4cb5

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
@@ -1527,6 +1527,50 @@ describe("VcsStatusBroadcaster", () => {
15271527
}).pipe(Effect.provide(NodeServices.layer), Effect.scoped),
15281528
);
15291529

1530+
it.effect("a HEAD watch ends when its git directory is removed", () =>
1531+
Effect.gen(function* () {
1532+
const gitDir = "/repo/.git/worktrees/feature";
1533+
const events = yield* Queue.unbounded<FileSystem.WatchEvent>();
1534+
const closed = yield* Deferred.make<void>();
1535+
let gitDirExists = true;
1536+
const state: Parameters<typeof layerTestFor>[0] = {
1537+
currentLocalStatus: { ...baseLocalStatus, refName: "main" },
1538+
currentRemoteStatus: null,
1539+
localStatusCalls: 0,
1540+
remoteStatusCalls: 0,
1541+
localInvalidationCalls: 0,
1542+
remoteInvalidationCalls: 0,
1543+
headPath: `${gitDir}/HEAD`,
1544+
fileSystem: FileSystem.makeNoop({
1545+
realPath: (target) => Effect.succeed(target),
1546+
exists: (target) => Effect.succeed(target !== gitDir || gitDirExists),
1547+
watch: (_target, options) =>
1548+
Stream.fromQueue(events).pipe(
1549+
Stream.onStart(Effect.sync(() => options?.onReady?.())),
1550+
Stream.ensuring(Deferred.succeed(closed, undefined)),
1551+
),
1552+
}),
1553+
};
1554+
1555+
yield* Effect.gen(function* () {
1556+
const broadcaster = yield* VcsStatusBroadcaster.VcsStatusBroadcaster;
1557+
const branches = yield* Stream.toPull(broadcaster.streamBranchStatus({ cwd: "/repo" }));
1558+
assert.deepEqual(yield* branches, [{ refName: "main" }]);
1559+
1560+
// Every checkout removes HEAD.lock, which leaves the watch running.
1561+
state.currentLocalStatus = { ...baseLocalStatus, refName: "other" };
1562+
yield* Queue.offer(events, { _tag: "Remove", path: "HEAD.lock" });
1563+
yield* Queue.offer(events, { _tag: "Update", path: "HEAD" });
1564+
assert.deepEqual(yield* branches, [{ refName: "other" }]);
1565+
1566+
// `git worktree remove` deletes the watched directory; Windows keeps reporting it.
1567+
gitDirExists = false;
1568+
yield* Queue.offer(events, { _tag: "Remove", path: gitDir });
1569+
yield* Deferred.await(closed);
1570+
}).pipe(Effect.provide(layerTestFor(state)), Effect.scoped);
1571+
}),
1572+
);
1573+
15301574
it.effect("releases remote demand while passive observers remain", () => {
15311575
const state = {
15321576
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
@@ -822,12 +822,19 @@ export const make = Effect.gen(function* () {
822822
const watchHead = Effect.fnUntraced(function* (cwd: string, ready: Deferred.Deferred<void>) {
823823
const headPath = yield* workflow.headPath(cwd);
824824
if (headPath === null) return;
825+
const headDirectory = path.dirname(headPath);
825826
// Git replaces HEAD by renaming HEAD.lock, which a watch on the file itself would lose.
826827
yield* fs
827-
.watch(path.dirname(headPath), {
828+
.watch(headDirectory, {
828829
onReady: () => Deferred.doneUnsafe(ready, Exit.void),
829830
})
830831
.pipe(
832+
// On Windows a watch outlives its deleted directory and reports it ~150k times a second.
833+
Stream.takeUntilEffect((event) =>
834+
event._tag === "Remove"
835+
? fs.exists(headDirectory).pipe(Effect.map((exists) => !exists))
836+
: Effect.succeed(false),
837+
),
831838
Stream.filter((event) => path.basename(event.path) === "HEAD"),
832839
// A rebase moves HEAD many times; refresh once for whatever arrived during a refresh.
833840
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.