@@ -4,6 +4,9 @@ import * as Effect from "effect/Effect"; |
4 | 4 | import * as FileSystem from "effect/FileSystem"; |
5 | 5 | import * as Layer from "effect/Layer"; |
6 | 6 | 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"; |
7 | 10 |
|
8 | 11 | import * as ProcessRunner from "../processRunner.ts"; |
9 | 12 | import { makeIsWorktreeContainer } from "./worktreeContainer.ts"; |
@@ -90,5 +93,58 @@ it.layer(ProcessRunner.layer.pipe(Layer.provideMerge(NodeServices.layer)))( |
90 | 93 | assert.isFalse(yield* isWorktreeContainer(outside), "worktrees outside the folder"); |
91 | 94 | }), |
92 | 95 | ); |
| 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 | + ); |
93 | 149 | }, |
94 | 150 | ); |