@devries-cameron20 / t3code-1 / commits / 10581521d2
Fork 0

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

fix(shared): preserve IPv6 hosts when switching clone protocols (#30798)

Co-authored-by: Simone <185146821+Lucenx9@users.noreply.github.com>

Simone committed Nov 6, 2026 at 05:40 UTC 10581521d27d14d8f0a15dfc24525efbd52ae057
2 files changed +26 -3
packages/shared/src/cloneUrl.test.ts
+23
@@ -117,6 +117,18 @@ describe("cloneUrlForProtocol", () => {
117 expect(cloneUrlForProtocol("ssh://git@gitlab.com/group/sub/repo.git", "https")).toBe(
118 "https://gitlab.com/group/sub/repo.git",
119 );
120 + expect(cloneUrlForProtocol("git@[2001:db8::1]:org/repo.git", "https")).toBe(
121 + "https://[2001:db8::1]/org/repo.git",
122 + );
123 + expect(cloneUrlForProtocol("[2001:db8::1]:org/repo.git", "https")).toBe(
124 + "https://[2001:db8::1]/org/repo.git",
125 + );
126 + expect(cloneUrlForProtocol("ssh://git@[2001:db8::1]/org/repo.git", "https")).toBe(
127 + "https://[2001:db8::1]/org/repo.git",
128 + );
129 + expect(cloneUrlForProtocol("https://[2001:db8::1]/org/repo.git", "ssh")).toBe(
130 + "git@[2001:db8::1]:org/repo.git",
131 + );
132 });
133
134 it("keeps the URL as is for its own protocol and drops HTTPS credentials on switch", () => {
@@ -134,6 +146,17 @@ describe("cloneUrlForProtocol", () => {
146 expect(cloneUrlForProtocol("https://host.example:8443/a/b.git", "https")).toBe(
147 "https://host.example:8443/a/b.git",
148 );
149 + expect(cloneUrlForProtocol("ssh://git@[2001:db8::1]:2222/a/b.git", "https")).toBeNull();
150 + expect(cloneUrlForProtocol("ssh://git@[2001:db8::1]:2222/a/b.git", "ssh")).toBe(
151 + "ssh://git@[2001:db8::1]:2222/a/b.git",
152 + );
153 + expect(cloneUrlForProtocol("https://[2001:db8::1]:8443/a/b.git", "ssh")).toBeNull();
154 + expect(cloneUrlForProtocol("https://[2001:db8::1]:8443/a/b.git", "https")).toBe(
155 + "https://[2001:db8::1]:8443/a/b.git",
156 + );
157 + expect(cloneUrlForProtocol("git@host.example:/srv/repo.git", "https")).toBeNull();
158 + expect(cloneUrlForProtocol("git@[2001:db8::1]:/srv/repo.git", "https")).toBeNull();
159 + expect(cloneUrlForProtocol("[2001:db8::1]:/srv/repo.git", "https")).toBeNull();
160 expect(cloneUrlForProtocol("/srv/git/repo.git", "https")).toBeNull();
161 expect(cloneUrlProtocol("file:///srv/git/repo.git")).toBeNull();
162 });
packages/shared/src/cloneUrl.ts
+3 -3
@@ -2,10 +2,10 @@ import { isWindowsDrivePath } from "./path.ts";
2
3 export type CloneProtocol = "ssh" | "https";
4
5 -const SCP_LIKE_URL = /^(?:[^@/\s]+@)?([^:/\s]+):(?!\/)(.+)$/;
5 +const SCP_LIKE_URL = /^(?:[^@/\s]+@)?(\[[^\]@/\s]+\]|[^:/\s[\]]+):(?!\/)(.+)$/;
6 // Userinfo may contain `@`; the last one before the first slash separates the host.
7 -const SSH_URL = /^ssh:\/\/(?:[^/\s]*@)?([^@:/\s]+)(:\d+)?\/(.+)$/;
8 -const HTTPS_URL = /^https?:\/\/(?:[^/\s]*@)?([^@:/\s]+)(:\d+)?\/(.+)$/;
7 +const SSH_URL = /^ssh:\/\/(?:[^/\s]*@)?(\[[^\]@/\s]+\]|[^@:/\s]+)(:\d+)?\/(.+)$/;
8 +const HTTPS_URL = /^https?:\/\/(?:[^/\s]*@)?(\[[^\]@/\s]+\]|[^@:/\s]+)(:\d+)?\/(.+)$/;
9
10 function parseCloneUrl(
11 url: string,