Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

SourceControlRepositoryService.test.ts

659 lines24.0 KB

1import { SourceControlProviderKind } from "@t3tools/contracts";
2import * as NodePath from "@effect/platform-node/NodePath";
3import * as NodeServices from "@effect/platform-node/NodeServices";
4import { assert, it } from "@effect/vitest";
5import * as Clock from "effect/Clock";
6import * as Effect from "effect/Effect";
7import * as FileSystem from "effect/FileSystem";
8import * as Path from "effect/Path";
9import * as Layer from "effect/Layer";
10import * as PlatformError from "effect/PlatformError";
11import { ChildProcessSpawner } from "effect/process";
12​
13import {
14 GitCommandError,
15 SourceControlProviderError,
16 type SourceControlCloneRepositoryInput,
17} from "@t3tools/contracts";
18​
19import * as ServerConfig from "../config.ts";
20import * as GitVcsDriver from "../vcs/GitVcsDriver.ts";
21import type * as SourceControlProvider from "@t3tools/source-control-core/server/SourceControlProvider";
22import * as SourceControlRateLimit from "@t3tools/source-control-core/server/SourceControlRateLimit";
23import * as SourceControlProviderRegistry from "./SourceControlProviderRegistry.ts";
24import * as SourceControlRepositoryService from "./SourceControlRepositoryService.ts";
25​
26const CLONE_URLS = {
27 nameWithOwner: "octocat/t3code",
28 url: "https://github.com/octocat/t3code",
29 sshUrl: "git@github.com:octocat/t3code.git",
30};
31​
32function makeProvider(
33 overrides: Partial<SourceControlProvider.SourceControlProvider["Service"]> = {},
34): SourceControlProvider.SourceControlProvider["Service"] {
35 const unsupported = (operation: string) =>
36 Effect.die(`unexpected provider operation ${operation}`) as Effect.Effect<
37 never,
38 SourceControlProviderError
39 >;
40​
41 return {
42 kind: SourceControlProviderKind.make("github"),
43 listChangeRequests: () => unsupported("listChangeRequests"),
44 getChangeRequest: () => unsupported("getChangeRequest"),
45 createChangeRequest: () => unsupported("createChangeRequest"),
46 getRepositoryCloneUrls: () => Effect.succeed(CLONE_URLS),
47 createRepository: () => Effect.succeed(CLONE_URLS),
48 getDefaultBranch: () => Effect.succeed(null),
49 checkoutChangeRequest: () => unsupported("checkoutChangeRequest"),
50 ...overrides,
51 };
53​
54function processOutput(): GitVcsDriver.ExecuteGitResult {
55 return {
56 exitCode: ChildProcessSpawner.ExitCode(0),
57 stdout: "",
58 stderr: "",
59 stdoutTruncated: false,
60 stderrTruncated: false,
61 };
63​
64function layer(input: {
65 readonly provider?: SourceControlProvider.SourceControlProvider["Service"];
66 readonly git?: Partial<GitVcsDriver.GitVcsDriver["Service"]>;
67 readonly fileSystem?: FileSystem.FileSystem;
68}) {
69 const layerService = SourceControlRepositoryService.layer.pipe(
70 Layer.provide(
71 Layer.mock(SourceControlProviderRegistry.SourceControlProviderRegistry)({
72 resolveLink: () => undefined,
73 get: () => Effect.succeed(input.provider ?? makeProvider()),
74 }),
75 ),
76 Layer.provide(
77 Layer.mock(GitVcsDriver.GitVcsDriver)({
78 execute: () => Effect.succeed(processOutput()),
79 ensureRemote: () => Effect.succeed("origin"),
80 pushCurrentBranch: () =>
81 Effect.succeed({
82 status: "pushed" as const,
83 branch: "feature/remote-v1",
84 upstreamBranch: "origin/feature/remote-v1",
85 setUpstream: true,
86 }),
87 ...input.git,
88 }),
89 ),
90 Layer.provide(
91 ServerConfig.layerTest(
92 process.cwd(),
93 input.fileSystem ? "/tmp/t3-source-control-repos" : { prefix: "t3-source-control-repos-" },
94 ),
95 ),
96 );
97​
98 return input.fileSystem
99 ? layerService.pipe(
100 Layer.provide(Layer.succeed(FileSystem.FileSystem, input.fileSystem)),
101 Layer.provideMerge(NodePath.layer),
102 )
103 : layerService.pipe(Layer.provideMerge(NodeServices.layer));
105​
106it.effect("looks up a repository while background reads to its host are paused", () =>
107 Effect.gen(function* () {
108 const limits = yield* SourceControlRateLimit.make;
109 const key = { provider: SourceControlProviderKind.make("github"), host: "github.com" };
110 yield* limits.recordRateLimit({
111 ...key,
112 lease: 0,
113 retryAt: (yield* Clock.currentTimeMillis) + 60_000,
114 });
115 // Gated like BitbucketApi's reads: refused during a pause unless a user is waiting.
116 const getRepositoryCloneUrls = () =>
117 SourceControlRateLimit.Interactive.pipe(
118 Effect.flatMap((interactive) =>
119 limits.check(key, interactive ? { allowPaused: true } : undefined),
120 ),
121 Effect.mapError(
122 (cause) =>
123 new SourceControlProviderError({
124 provider: key.provider,
125 operation: "getRepositoryCloneUrls",
126 cwd: process.cwd(),
127 detail: cause.detail,
128 cause,
129 }),
130 ),
131 Effect.as(CLONE_URLS),
132 );
133 const background = yield* Effect.flip(getRepositoryCloneUrls());
134 assert.instanceOf(background.cause, SourceControlRateLimit.SourceControlRateLimitPausedError);
135​
136 const repository = yield* Effect.gen(function* () {
137 const service = yield* SourceControlRepositoryService.SourceControlRepositoryService;
138 return yield* service.lookupRepository({
139 provider: key.provider,
140 repository: "octocat/t3code",
141 });
142 }).pipe(Effect.provide(layer({ provider: makeProvider({ getRepositoryCloneUrls }) })));
143​
144 assert.strictEqual(repository.nameWithOwner, "octocat/t3code");
145 }),
146);
147​
148it.effect("clones a looked-up repository after creating missing parent directories", () =>
149 Effect.gen(function* () {
150 const fs = yield* FileSystem.FileSystem;
151 const path = yield* Path.Path;
152 const temporaryDirectory = yield* fs.makeTempDirectoryScoped({
153 prefix: "t3-source-control-clone-parent-",
154 });
155 const parent = path.join(temporaryDirectory, "missing", "nested");
156 const destinationPath = path.join(parent, "t3code");
157 const cloneCalls: Array<{ cwd: string; args: ReadonlyArray<string> }> = [];
158​
159 yield* Effect.gen(function* () {
160 const service = yield* SourceControlRepositoryService.SourceControlRepositoryService;
161 const result = yield* service.cloneRepository({
162 provider: SourceControlProviderKind.make("github"),
163 repository: "octocat/t3code",
164 destinationPath,
165 protocol: "https",
166 });
167​
168 assert.deepStrictEqual(result, {
169 cwd: destinationPath,
170 remoteUrl: CLONE_URLS.url,
171 repository: { provider: SourceControlProviderKind.make("github"), ...CLONE_URLS },
172 });
173 assert.deepStrictEqual(cloneCalls, [
174 {
175 cwd: parent,
176 args: ["clone", "--progress", "--", CLONE_URLS.url, "t3code"],
177 },
178 ]);
179 }).pipe(
180 Effect.provide(
181 layer({
182 git: {
183 execute: (input) =>
184 Effect.gen(function* () {
185 assert.isTrue(yield* fs.exists(parent).pipe(Effect.orDie));
186 cloneCalls.push({ cwd: input.cwd, args: input.args });
187 return processOutput();
188 }),
189 },
190 }),
191 ),
192 );
193 }).pipe(Effect.provide(NodeServices.layer)),
194);
195​
196it.effect.each(["--bare", "source.git"])(
197 "clones a local repository named %s as a working tree",
198 (repositoryName) =>
199 Effect.gen(function* () {
200 const fs = yield* FileSystem.FileSystem;
201 const path = yield* Path.Path;
202 const git = yield* GitVcsDriver.GitVcsDriver;
203 const parent = yield* fs.makeTempDirectoryScoped({ prefix: "t3-clone-options-" });
204 yield* git.execute({
205 operation: "test.init",
206 cwd: parent,
207 args: ["init", "--bare", path.join(parent, repositoryName)],
208 });
209 const destinationPath = path.join(parent, "checkout");
210 yield* Effect.gen(function* () {
211 const service = yield* SourceControlRepositoryService.SourceControlRepositoryService;
212 const result = yield* service.cloneRepository({
213 remoteUrl: repositoryName,
214 destinationPath,
215 });
216 assert.strictEqual(result.cwd, destinationPath);
217 assert.isTrue(yield* fs.exists(path.join(destinationPath, ".git")));
218 }).pipe(Effect.provide(layer({ git: { execute: git.execute } })));
219 }).pipe(
220 Effect.provide(
221 GitVcsDriver.layer.pipe(
222 Layer.provide(
223 ServerConfig.layerTest(process.cwd(), {
224 prefix: "t3-clone-options-config-",
225 }),
226 ),
227 Layer.provideMerge(NodeServices.layer),
228 ),
229 ),
230 ),
231);
232​
233it.effect("reports clone progress from git's stderr and keeps its error text on failure", () =>
234 Effect.gen(function* () {
235 const fs = yield* FileSystem.FileSystem;
236 const path = yield* Path.Path;
237 const parent = yield* fs.makeTempDirectoryScoped({
238 prefix: "t3-source-control-clone-progress-",
239 });
240 const destinationPath = path.join(parent, "t3code");
241 const progress: Array<{ stage: string; percent: number | null; detail: string | null }> = [];
242​
243 const stderrLines = [
244 "Cloning into 't3code'...",
245 "remote: Enumerating objects: 10, done.",
246 "Receiving objects: 40% (4/10), 1.00 MiB | 2.00 MiB/s",
247 "Receiving objects: 100% (10/10), 2.50 MiB | 2.00 MiB/s, done.",
248 "fatal: early EOF",
249 "fatal: unable to access 'https://user:s3c@ret@github.com/octocat/t3code.git/': could not resolve host",
250 ];
251 const error = yield* Effect.gen(function* () {
252 const service = yield* SourceControlRepositoryService.SourceControlRepositoryService;
253 return yield* Effect.flip(
254 service.cloneRepository(
255 { remoteUrl: CLONE_URLS.sshUrl, destinationPath },
256 { onProgress: (line) => Effect.sync(() => void progress.push(line)) },
257 ),
258 );
259 }).pipe(
260 Effect.provide(
261 layer({
262 git: {
263 execute: (input) =>
264 Effect.gen(function* () {
265 for (const line of stderrLines) {
266 yield* input.progress?.onStderrLine?.(line) ?? Effect.void;
267 }
268 return yield* new GitCommandError({
269 operation: input.operation,
270 command: "git",
271 cwd: input.cwd,
272 detail: "Git command exited with a non-zero status.",
273 exitCode: 128,
274 });
275 }),
276 },
277 }),
278 ),
279 );
280​
281 assert.deepStrictEqual(progress, [
282 { stage: "counting", percent: null, detail: null },
283 { stage: "receiving", percent: 40, detail: "1.00 MiB | 2.00 MiB/s" },
284 { stage: "receiving", percent: 100, detail: "2.50 MiB | 2.00 MiB/s" },
285 ]);
286 assert.strictEqual(
287 error.detail,
288 "fatal: early EOF fatal: unable to access 'https://github.com/octocat/t3code.git/': could not resolve host",
289 );
290 }).pipe(Effect.provide(NodeServices.layer)),
291);
292​
293function rejectingSsh(
294 urls: Array<string>,
295 httpsFails: boolean,
296 reason: GitCommandError["reason"] = "authentication_failed",
297) {
298 return {
299 execute: (input: GitVcsDriver.ExecuteGitInput) =>
300 Effect.gen(function* () {
301 const url = input.args.at(-2)!;
302 urls.push(url);
303 if (url.startsWith("https://") && !httpsFails) return processOutput();
304 yield* (
305 input.progress?.onStderrLine?.(
306 url.startsWith("https://")
307 ? "fatal: could not read Username for 'https://github.com': terminal prompts disabled"
308 : "git@github.com: Permission denied (publickey).",
309 ) ?? Effect.void
310 );
311 return yield* new GitCommandError({
312 operation: input.operation,
313 command: "git",
314 cwd: input.cwd,
315 reason,
316 detail: "Git command exited with a non-zero status.",
317 });
318 }),
319 } satisfies Partial<GitVcsDriver.GitVcsDriver["Service"]>;
321​
322const cloneInTemporaryDirectory = (
323 git: Partial<GitVcsDriver.GitVcsDriver["Service"]>,
324 input: Omit<SourceControlCloneRepositoryInput, "destinationPath">,
325) =>
326 Effect.gen(function* () {
327 const fs = yield* FileSystem.FileSystem;
328 const path = yield* Path.Path;
329 const parent = yield* fs
330 .makeTempDirectoryScoped({ prefix: "t3-clone-fallback-" })
331 .pipe(Effect.orDie);
332 return yield* Effect.gen(function* () {
333 const service = yield* SourceControlRepositoryService.SourceControlRepositoryService;
334 return yield* service.cloneRepository({
335 ...input,
336 destinationPath: path.join(parent, "t3code"),
337 });
338 }).pipe(Effect.provide(layer({ git }).pipe(Layer.orDie)));
339 }).pipe(Effect.provide(NodeServices.layer));
340​
341it.effect("retries a clone over HTTPS when the SSH login is refused", () =>
342 Effect.gen(function* () {
343 const urls: Array<string> = [];
344 const result = yield* cloneInTemporaryDirectory(rejectingSsh(urls, false), {
345 remoteUrl: CLONE_URLS.sshUrl,
346 });
347​
348 assert.deepStrictEqual(urls, [CLONE_URLS.sshUrl, "https://github.com/octocat/t3code.git"]);
349 assert.strictEqual(result.remoteUrl, "https://github.com/octocat/t3code.git");
350 }),
351);
352​
353it.effect("reports both failures when the HTTPS retry fails too", () =>
354 Effect.gen(function* () {
355 const urls: Array<string> = [];
356 const error = yield* Effect.flip(
357 cloneInTemporaryDirectory(rejectingSsh(urls, true), { remoteUrl: CLONE_URLS.sshUrl }),
358 );
359​
360 assert.strictEqual(urls.length, 2);
361 assert.strictEqual(
362 error.detail,
363 "git@github.com: Permission denied (publickey). Cloning over HTTPS instead also failed: fatal: could not read Username for 'https://github.com': terminal prompts disabled",
364 );
365 }),
366);
367​
368it.effect.each([
369 ["the caller asked for SSH", "ssh", "authentication_failed"],
370 ["git failed for another reason", undefined, "remote_unreachable"],
371] as const)("does not retry over HTTPS when %s", ([, protocol, reason]) =>
372 Effect.gen(function* () {
373 const urls: Array<string> = [];
374 yield* Effect.flip(
375 cloneInTemporaryDirectory(rejectingSsh(urls, false, reason), {
376 remoteUrl: CLONE_URLS.sshUrl,
377 ...(protocol === undefined ? {} : { protocol }),
378 }),
379 );
380​
381 assert.deepStrictEqual(urls, [CLONE_URLS.sshUrl]);
382 }),
383);
384​
385it.effect("strips embedded credentials from the remote URL it reports", () =>
386 Effect.gen(function* () {
387 const fs = yield* FileSystem.FileSystem;
388 const path = yield* Path.Path;
389 const parent = yield* fs.makeTempDirectoryScoped({ prefix: "t3-source-control-redact-" });
390 const destinationPath = path.join(parent, "t3code");
391 const cloneArgs: Array<ReadonlyArray<string>> = [];
392 const result = yield* Effect.gen(function* () {
393 const service = yield* SourceControlRepositoryService.SourceControlRepositoryService;
394 return yield* service.prepareClone({
395 remoteUrl: "https://user:s3cret@github.com/octocat/t3code.git",
396 destinationPath,
397 });
398 }).pipe(
399 Effect.provide(
400 layer({
401 git: {
402 execute: (input) =>
403 Effect.sync(() => {
404 cloneArgs.push(input.args);
405 return processOutput();
406 }),
407 },
408 }),
409 ),
410 );
411 assert.equal(result.remoteUrl, "https://github.com/octocat/t3code.git");
412 assert.equal(result.cloneUrl, "https://user:s3cret@github.com/octocat/t3code.git");
413 }).pipe(Effect.provide(NodeServices.layer)),
414);
415​
416it.effect("discards only a directory git wrote to", () =>
417 Effect.gen(function* () {
418 const fs = yield* FileSystem.FileSystem;
419 const path = yield* Path.Path;
420 const parent = yield* fs.makeTempDirectoryScoped({ prefix: "t3-source-control-discard-" });
421 const partial = path.join(parent, "partial");
422 yield* fs.makeDirectory(path.join(partial, ".git"), { recursive: true });
423 yield* fs.writeFileString(path.join(partial, "README.md"), "half");
424 const foreign = path.join(parent, "foreign");
425 yield* fs.makeDirectory(foreign);
426 yield* fs.writeFileString(path.join(foreign, "notes.txt"), "mine");
427​
428 const replaced = path.join(parent, "replaced");
429 yield* fs.writeFileString(replaced, "not a directory");
430​
431 yield* Effect.gen(function* () {
432 const service = yield* SourceControlRepositoryService.SourceControlRepositoryService;
433 yield* service.discardClone(partial);
434 const error = yield* Effect.flip(service.discardClone(foreign));
435 assert.include(error.detail, "not from the clone");
436 const replacedError = yield* Effect.flip(service.discardClone(replaced));
437 assert.include(replacedError.detail, "could not be inspected");
438 yield* service.discardClone(path.join(parent, "missing"));
439 }).pipe(Effect.provide(layer({})));
440​
441 assert.deepStrictEqual(yield* fs.readDirectory(partial), []);
442 assert.deepStrictEqual(yield* fs.readDirectory(foreign), ["notes.txt"]);
443 assert.strictEqual(yield* fs.readFileString(replaced), "not a directory");
444 }).pipe(Effect.provide(NodeServices.layer)),
445);
446​
447it.effect("redacts query tokens and userinfo containing '@' from reported URLs", () =>
448 Effect.gen(function* () {
449 const fs = yield* FileSystem.FileSystem;
450 const path = yield* Path.Path;
451 const parent = yield* fs.makeTempDirectoryScoped({ prefix: "t3-source-control-redact2-" });
452 yield* Effect.gen(function* () {
453 const service = yield* SourceControlRepositoryService.SourceControlRepositoryService;
454 const query = yield* service.prepareClone({
455 remoteUrl: "https://github.com/octocat/t3code.git?access_token=s3cret",
456 destinationPath: path.join(parent, "a"),
457 });
458 assert.equal(query.remoteUrl, "https://github.com/octocat/t3code.git");
459 const nested = yield* service.prepareClone({
460 remoteUrl: "https://user:pa@rt@github.com/octocat/t3code.git",
461 destinationPath: path.join(parent, "b"),
462 });
463 assert.equal(nested.remoteUrl, "https://github.com/octocat/t3code.git");
464 }).pipe(Effect.provide(layer({})));
465 }).pipe(Effect.provide(NodeServices.layer)),
466);
467​
468it.effect("preserves destination probe failures instead of treating them as missing paths", () => {
469 const fileSystemCause = PlatformError.systemError({
470 _tag: "PermissionDenied",
471 module: "FileSystem",
472 method: "exists",
473 pathOrDescriptor: "/restricted/t3code",
474 });
475​
476 return Effect.gen(function* () {
477 const service = yield* SourceControlRepositoryService.SourceControlRepositoryService;
478 const error = yield* Effect.flip(
479 service.cloneRepository({
480 remoteUrl: CLONE_URLS.sshUrl,
481 destinationPath: "/restricted/t3code",
482 }),
483 );
484​
485 assert.strictEqual(error.provider, "unknown");
486 assert.strictEqual(error.operation, "cloneRepository");
487 assert.strictEqual(error.cause, fileSystemCause);
488 }).pipe(
489 Effect.provide(
490 layer({
491 fileSystem: FileSystem.makeNoop({
492 exists: () => Effect.fail(fileSystemCause),
493 makeDirectory: () => Effect.void,
494 }),
495 }),
496 ),
497 );
498});
499​
500it.effect("publishes to the remote name returned by ensureRemote", () => {
501 const pushCalls: Array<{ cwd: string; remoteName: string | null | undefined }> = [];
502​
503 return Effect.gen(function* () {
504 const service = yield* SourceControlRepositoryService.SourceControlRepositoryService;
505 const result = yield* service.publishRepository({
506 cwd: "/workspace",
507 provider: SourceControlProviderKind.make("github"),
508 repository: "octocat/t3code",
509 visibility: "private",
510 remoteName: "origin",
511 protocol: "ssh",
512 });
513​
514 assert.equal(result.remoteName, "origin-1");
515 assert.deepStrictEqual(pushCalls, [{ cwd: "/workspace", remoteName: "origin-1" }]);
516 }).pipe(
517 Effect.provide(
518 layer({
519 git: {
520 ensureRemote: () => Effect.succeed("origin-1"),
521 pushCurrentBranch: (cwd, _fallbackBranch, options) =>
522 Effect.sync(() => {
523 pushCalls.push({ cwd, remoteName: options?.remoteName });
524 return {
525 status: "pushed" as const,
526 branch: "feature/remote-v1",
527 upstreamBranch: `${options?.remoteName ?? "missing"}/feature/remote-v1`,
528 setUpstream: true,
529 };
530 }),
531 },
532 }),
533 ),
534 );
535});
536​
537function failingPush(reason?: GitCommandError["reason"]) {
538 return {
539 pushCurrentBranch: (cwd: string) =>
540 Effect.fail(
541 new GitCommandError({
542 operation: "GitVcsDriver.pushCurrentBranch.pushWithRequestedRemote",
543 command: "git",
544 cwd,
545 ...(reason === undefined ? {} : { reason }),
546 detail: "Git command exited with a non-zero status.",
547 }),
548 ),
549 } satisfies Partial<GitVcsDriver.GitVcsDriver["Service"]>;
551​
552it.effect("explains a rejected SSH push after creating the repository", () =>
553 Effect.gen(function* () {
554 const service = yield* SourceControlRepositoryService.SourceControlRepositoryService;
555 const error = yield* Effect.flip(
556 service.publishRepository({
557 cwd: "/workspace",
558 provider: SourceControlProviderKind.make("github"),
559 repository: "octocat/t3code",
560 visibility: "private",
561 protocol: "ssh",
562 }),
563 );
564​
565 assert.strictEqual(error.operation, "publishRepository");
566 assert.strictEqual(
567 error.detail,
568 'Created octocat/t3code and added it as remote "origin", but the push failed because SSH authentication was rejected. Add an SSH key to your account, or switch the remote to HTTPS with "git remote set-url origin https://github.com/octocat/t3code", then push again.',
569 );
570 assert.instanceOf(error.cause, GitCommandError);
571 }).pipe(Effect.provide(layer({ git: failingPush("authentication_failed") }))),
572);
573​
574// regression: #19219 publishing did not explain why the first push failed
575it.effect("says the repository exists when an unclassified publish push fails", () =>
576 Effect.gen(function* () {
577 const service = yield* SourceControlRepositoryService.SourceControlRepositoryService;
578 const error = yield* Effect.flip(
579 service.publishRepository({
580 cwd: "/workspace",
581 provider: SourceControlProviderKind.make("github"),
582 repository: "octocat/t3code",
583 visibility: "private",
584 protocol: "https",
585 }),
586 );
587​
588 assert.strictEqual(
589 error.detail,
590 'Created octocat/t3code and added it as remote "origin", but the push failed. Fix the problem, then push again.',
591 );
592 }).pipe(Effect.provide(layer({ git: failingPush() }))),
593);
594​
595it.effect("publish succeeds with status remote_added when the local repo has no commits", () => {
596 let pushCalls = 0;
597 return Effect.gen(function* () {
598 const service = yield* SourceControlRepositoryService.SourceControlRepositoryService;
599 const result = yield* service.publishRepository({
600 cwd: "/workspace",
601 provider: SourceControlProviderKind.make("github"),
602 repository: "octocat/t3code",
603 visibility: "private",
604 remoteName: "origin",
605 protocol: "ssh",
606 });
607​
608 assert.deepStrictEqual(result, {
609 repository: { provider: SourceControlProviderKind.make("github"), ...CLONE_URLS },
610 remoteName: "origin",
611 remoteUrl: CLONE_URLS.sshUrl,
612 branch: "main",
613 status: "remote_added",
614 });
615 assert.strictEqual(pushCalls, 0);
616 }).pipe(
617 Effect.provide(
618 layer({
619 git: {
620 execute: (input) =>
621 input.args[0] === "rev-parse"
622 ? Effect.fail(
623 new GitCommandError({
624 operation: input.operation,
625 command: "git rev-parse --verify HEAD",
626 cwd: input.cwd,
627 detail: "fatal: Needed a single revision",
628 }),
629 )
630 : Effect.succeed(processOutput()),
631 statusDetails: () =>
632 Effect.succeed({
633 isRepo: true,
634 hasOriginRemote: true,
635 isDefaultBranch: true,
636 branch: "main",
637 upstreamRef: null,
638 hasWorkingTreeChanges: false,
639 workingTree: { files: [], insertions: 0, deletions: 0 },
640 hasUpstream: false,
641 aheadCount: 0,
642 behindCount: 0,
643 aheadOfDefaultCount: 0,
644 }),
645 pushCurrentBranch: () =>
646 Effect.sync(() => {
647 pushCalls += 1;
648 return {
649 status: "pushed" as const,
650 branch: "main",
651 upstreamBranch: "origin/main",
652 setUpstream: true,
653 };
654 }),
655 },
656 }),
657 ),
658 );
659});