@devries-cameron20 / t3code-1 / commits / adaaae60c6
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(server): publishing explains why the first push failed (#19219)

Salloxy committed Oct 18, 2026 at 15:34 UTC adaaae60c66b75eae84d0a464cd96c043f3a82aa
2 files changed +101 -1
apps/server/src/sourceControl/SourceControlRepositoryService.test.ts
+57
@@ -633,6 +633,63 @@ it.effect("publishes to the remote name returned by ensureRemote", () => {
633 );
634 });
635
636 +function failingPush(reason?: GitCommandError["reason"]) {
637 + return {
638 + pushCurrentBranch: (cwd: string) =>
639 + Effect.fail(
640 + new GitCommandError({
641 + operation: "GitVcsDriver.pushCurrentBranch.pushWithRequestedRemote",
642 + command: "git",
643 + cwd,
644 + ...(reason === undefined ? {} : { reason }),
645 + detail: "Git command exited with a non-zero status.",
646 + }),
647 + ),
648 + } satisfies Partial<GitVcsDriver.GitVcsDriver["Service"]>;
649 +}
650 +
651 +it.effect("explains a rejected SSH push after creating the repository", () =>
652 + Effect.gen(function* () {
653 + const service = yield* SourceControlRepositoryService.SourceControlRepositoryService;
654 + const error = yield* Effect.flip(
655 + service.publishRepository({
656 + cwd: "/workspace",
657 + provider: SourceControlProviderKind.make("github"),
658 + repository: "octocat/t3code",
659 + visibility: "private",
660 + protocol: "ssh",
661 + }),
662 + );
663 +
664 + assert.strictEqual(error.operation, "publishRepository");
665 + assert.strictEqual(
666 + error.detail,
667 + '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.',
668 + );
669 + assert.instanceOf(error.cause, GitCommandError);
670 + }).pipe(Effect.provide(layer({ git: failingPush("authentication_failed") }))),
671 +);
672 +
673 +it.effect("says the repository exists when an unclassified publish push fails", () =>
674 + Effect.gen(function* () {
675 + const service = yield* SourceControlRepositoryService.SourceControlRepositoryService;
676 + const error = yield* Effect.flip(
677 + service.publishRepository({
678 + cwd: "/workspace",
679 + provider: SourceControlProviderKind.make("github"),
680 + repository: "octocat/t3code",
681 + visibility: "private",
682 + protocol: "https",
683 + }),
684 + );
685 +
686 + assert.strictEqual(
687 + error.detail,
688 + 'Created octocat/t3code and added it as remote "origin", but the push failed. Fix the problem, then push again.',
689 + );
690 + }).pipe(Effect.provide(layer({ git: failingPush() }))),
691 +);
692 +
693 it.effect("publish succeeds with status remote_added when the local repo has no commits", () => {
694 let pushCalls = 0;
695 return Effect.gen(function* () {
apps/server/src/sourceControl/SourceControlRepositoryService.ts
+44 -1
@@ -9,6 +9,7 @@ import * as Schema from "effect/Schema";
9 import {
10 SourceControlProviderError,
11 SourceControlRepositoryError,
12 + type GitCommandFailureReason,
13 type SourceControlCloneRepositoryInput,
14 type SourceControlCloneRepositoryResult,
15 type SourceControlCloneProtocol,
@@ -141,6 +142,33 @@ function redactUrlCredentials(text: string): string {
142 return text.replace(URL_WITH_USERINFO, "$1");
143 }
144
145 +/**
146 + * Explains a failed first push of a published repository. The repository
147 + * already exists by then, so publishing again cannot help; the user has to
148 + * fix access and push. Built from fixed text and the provider's URLs only,
149 + * since git's stderr can carry credentials.
150 + */
151 +function publishPushFailureDetail(input: {
152 + readonly urls: SourceControlRepositoryCloneUrls;
153 + readonly remoteName: string;
154 + readonly remoteUrl: string;
155 + readonly reason: GitCommandFailureReason | undefined;
156 +}): string {
157 + const created = `Created ${input.urls.nameWithOwner} and added it as remote "${input.remoteName}", but the push failed`;
158 + const switchToHttps = `git remote set-url ${input.remoteName} ${input.urls.url}`;
159 + const usesSsh = input.remoteUrl === input.urls.sshUrl;
160 + switch (input.reason) {
161 + case "authentication_failed":
162 + return usesSsh
163 + ? `${created} because SSH authentication was rejected. Add an SSH key to your account, or switch the remote to HTTPS with "${switchToHttps}", then push again.`
164 + : `${created} because Git could not authenticate. Check your Git credentials, then push again.`;
165 + case "host_key_unverified":
166 + return `${created} because the host's SSH key is not trusted yet. Verify it by connecting once with ssh, or switch the remote to HTTPS with "${switchToHttps}", then push again.`;
167 + default:
168 + return `${created}. Fix the problem, then push again.`;
169 + }
170 +}
171 +
172 function selectRemoteUrl(
173 urls: SourceControlRepositoryCloneUrls,
174 protocol: SourceControlCloneProtocol | undefined,
@@ -437,7 +465,22 @@ export const make = Effect.gen(function* () {
465 };
466 }
467
440 - const pushResult = yield* git.pushCurrentBranch(input.cwd, null, { remoteName });
468 + const pushResult = yield* git.pushCurrentBranch(input.cwd, null, { remoteName }).pipe(
469 + Effect.mapError(
470 + (cause) =>
471 + new SourceControlRepositoryError({
472 + operation: "publishRepository",
473 + provider: providerKind,
474 + detail: publishPushFailureDetail({
475 + urls,
476 + remoteName,
477 + remoteUrl,
478 + reason: cause.reason,
479 + }),
480 + cause,
481 + }),
482 + ),
483 + );
484
485 return {
486 repository: toRepositoryInfo(providerKind, urls),