The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 04:30 UTC
fix(server): published repos fall back to HTTPS when SSH is refused (#30142)
Co-authored-by: SAPHID <saphid@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Alex Southwell committed
Nov 3, 2026 at 23:47 UTC
6ea23bd4264e77442d2e29ffeab4d9c550559c7a
2 files changed
+83
-15
apps/server/src/sourceControl/SourceControlRepositoryService.test.ts
+46
@@ -648,6 +648,52 @@ it.effect("explains a rejected SSH push after creating the repository", () =>
648
}).pipe(Effect.provide(layer({ git: failingPush("authentication_failed") }))),
649
);
650
651
+// regression: an auto-selected SSH remote kept failing every later fetch after a refused push
652
+it.effect("switches an auto-selected remote to HTTPS when the SSH push is refused", () => {
653
+ const gitArgs: Array<ReadonlyArray<string>> = [];
654
+ let pushAttempts = 0;
655
+ return Effect.gen(function* () {
656
+ const service = yield* SourceControlRepositoryService.SourceControlRepositoryService;
657
+ const result = yield* service.publishRepository({
658
+ cwd: "/workspace",
659
+ provider: SourceControlProviderKind.make("github"),
660
+ repository: "octocat/t3code",
661
+ visibility: "private",
662
+ });
663
+
664
+ assert.strictEqual(result.status, "pushed");
665
+ assert.strictEqual(result.remoteUrl, CLONE_URLS.url);
666
+ assert.strictEqual(pushAttempts, 2);
667
+ assert.deepStrictEqual(gitArgs, [
668
+ ["rev-parse", "--verify", "HEAD"],
669
+ ["remote", "set-url", "origin", CLONE_URLS.url],
670
+ ]);
671
+ }).pipe(
672
+ Effect.provide(
673
+ layer({
674
+ git: {
675
+ execute: (input) =>
676
+ Effect.sync(() => {
677
+ gitArgs.push(input.args);
678
+ return processOutput();
679
+ }),
680
+ pushCurrentBranch: (cwd) => {
681
+ pushAttempts += 1;
682
+ return pushAttempts === 1
683
+ ? failingPush("authentication_failed").pushCurrentBranch(cwd)
684
+ : Effect.succeed({
685
+ status: "pushed" as const,
686
+ branch: "main",
687
+ upstreamBranch: "origin/main",
688
+ setUpstream: true,
689
+ });
690
+ },
691
+ },
692
+ }),
693
+ ),
694
+ );
695
+});
696
+
697
// regression: #19219 publishing did not explain why the first push failed
698
it.effect("says the repository exists when an unclassified publish push fails", () =>
699
Effect.gen(function* () {
apps/server/src/sourceControl/SourceControlRepositoryService.ts
+37
-15
@@ -502,28 +502,50 @@ export const make = Effect.gen(function* () {
502
};
503
}
504
505
- const pushResult = yield* git.pushCurrentBranch(input.cwd, null, { remoteName }).pipe(
506
- Effect.mapError(
507
- (cause) =>
508
- new SourceControlRepositoryError({
509
- operation: "publishRepository",
510
- provider: providerKind,
511
- detail: publishPushFailureDetail({
512
- urls,
513
- remoteName,
514
- remoteUrl,
515
- reason: cause.reason,
505
+ const push = (pushUrl: string) =>
506
+ git.pushCurrentBranch(input.cwd, null, { remoteName }).pipe(
507
+ Effect.map((result) => ({ branch: result.branch, remoteUrl: pushUrl })),
508
+ Effect.mapError(
509
+ (cause) =>
510
+ new SourceControlRepositoryError({
511
+ operation: "publishRepository",
512
+ provider: providerKind,
513
+ detail: publishPushFailureDetail({
514
+ urls,
515
+ remoteName,
516
+ remoteUrl: pushUrl,
517
+ reason: cause.reason,
518
+ }),
519
+ cause,
520
}),
517
- cause,
518
- }),
521
+ ),
522
+ );
523
+
524
+ // Like clone, an auto-selected SSH remote switches to HTTPS when SSH is refused;
525
+ // otherwise the remote keeps failing every later fetch and push.
526
+ const canSwitchToHttps = input.protocol !== "ssh" && remoteUrl === urls.sshUrl;
527
+ const pushed = yield* push(remoteUrl).pipe(
528
+ Effect.catchIf(
529
+ (error) => canSwitchToHttps && isSshRejection(error),
530
+ (sshError) =>
531
+ git
532
+ .execute({
533
+ operation: "SourceControlRepositoryService.publishRepository.switchToHttps",
534
+ cwd: input.cwd,
535
+ args: ["remote", "set-url", remoteName, urls.url],
536
+ })
537
+ .pipe(
538
+ Effect.mapError(() => sshError),
539
+ Effect.andThen(push(urls.url)),
540
+ ),
541
),
542
);
543
544
return {
545
repository: toRepositoryInfo(providerKind, urls),
546
remoteName,
525
- remoteUrl,
526
- branch: pushResult.branch,
547
+ remoteUrl: pushed.remoteUrl,
548
+ branch: pushed.branch,
549
status: "pushed" as const,
550
};
551
},