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): worktree containers are refused on Git before 2.36 (#43224) · patroza/t3code@0ccd7a8

File tree

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

‎apps/server/src/project/worktreeContainer.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/project/worktreeContainer.test.ts
+56Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import * as Effect from "effect/Effect";
44
import * as FileSystem from "effect/FileSystem";
55
import * as Layer from "effect/Layer";
66
import * as Path from "effect/Path";
7+
import * as Sink from "effect/Sink";
8+
import * as Stream from "effect/Stream";
9+
import { ChildProcess, ChildProcessSpawner } from "effect/process";
710

811
import * as ProcessRunner from "../processRunner.ts";
912
import { makeIsWorktreeContainer } from "./worktreeContainer.ts";
@@ -90,5 +93,58 @@ it.layer(ProcessRunner.layer.pipe(Layer.provideMerge(NodeServices.layer)))(
9093
assert.isFalse(yield* isWorktreeContainer(outside), "worktrees outside the folder");
9194
}),
9295
);
96+
it.effect("finds a container with Git that rejects worktree list -z", () =>
97+
Effect.gen(function* () {
98+
const fileSystem = yield* FileSystem.FileSystem;
99+
const path = yield* Path.Path;
100+
const delegate = yield* ChildProcessSpawner.ChildProcessSpawner;
101+
// Git before 2.36 has no `worktree list -z` and exits with a usage error.
102+
const oldGitSpawner = ChildProcessSpawner.make((command) =>
103+
Effect.gen(function* () {
104+
if (!ChildProcess.isStandardCommand(command)) {
105+
return yield* Effect.die("expected a standard Git command");
106+
}
107+
if (command.args.includes("worktree") && command.args.includes("-z")) {
108+
return ChildProcessSpawner.makeHandle({
109+
pid: ChildProcessSpawner.ProcessId(1),
110+
exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(129)),
111+
isRunning: Effect.succeed(false),
112+
kill: () => Effect.void,
113+
unref: Effect.succeed(Effect.void),
114+
stdin: Sink.drain,
115+
stdout: Stream.empty,
116+
stderr: Stream.encodeText(Stream.make("error: unknown switch `z'")),
117+
all: Stream.empty,
118+
getInputFd: () => Sink.drain,
119+
getOutputFd: () => Stream.empty,
120+
});
121+
}
122+
return yield* delegate.spawn(command);
123+
}),
124+
);
125+
const isWorktreeContainer = yield* makeIsWorktreeContainer.pipe(
126+
Effect.provideServiceEffect(
127+
ProcessRunner.ProcessRunner,
128+
ProcessRunner.make().pipe(
129+
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, oldGitSpawner),
130+
),
131+
),
132+
);
133+
const fixture = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-container-test-" });
134+
const source = path.join(fixture, "source");
135+
yield* fileSystem.makeDirectory(source);
136+
yield* git(source, "init", "-b", "develop");
137+
yield* fileSystem.writeFileString(path.join(source, "README.md"), "readme\n");
138+
yield* git(source, "add", "README.md");
139+
yield* git(source, "commit", "-m", "init");
140+
const root = path.join(fixture, "container");
141+
yield* fileSystem.makeDirectory(root);
142+
yield* git(fixture, "clone", "--bare", source, path.join(root, ".bare"));
143+
yield* fileSystem.writeFileString(path.join(root, ".git"), "gitdir: ./.bare\n");
144+
yield* git(root, "worktree", "add", "develop", "develop");
145+
146+
assert.isTrue(yield* isWorktreeContainer(root));
147+
}),
148+
);
93149
},
94150
);
Collapse file

‎apps/server/src/project/worktreeContainer.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/project/worktreeContainer.ts
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ export const makeIsWorktreeContainer = Effect.gen(function* () {
7979
if (hasIndex) return false;
8080
}
8181

82-
const worktrees = yield* git(["worktree", "list", "--porcelain", "-z"]);
82+
// Pre-2.36 Git rejects worktree list -z; normalize its line output to NUL records.
83+
const worktrees =
84+
(yield* git(["worktree", "list", "--porcelain", "-z"])) ??
85+
(yield* git(["worktree", "list", "--porcelain"]))?.replaceAll("\n", "\0") ??
86+
null;
8387
if (worktrees === null) return false;
8488
// The first entry is the main worktree, which Git reports as the metadata directory here.
8589
const linkedWorktreePaths = splitNul(worktrees)

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.