@devries-cameron20 / t3code-1 / commits / 6615615b12
Fork 0

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

fix(shared): preserve Git remote headers after comments (#31788)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Darsh Mahadevia committed Nov 14, 2026 at 22:21 UTC 6615615b1259c3ae6c1fdd0b2e8b70650289ce85
2 files changed +16 -3
packages/shared/src/git.test.ts
+15 -1
@@ -164,6 +164,20 @@ describe("parseOriginUrlFromGitConfig", () => {
164 expect(
165 parseOriginUrlFromGitConfig('[remote "origin"]\n\turl = "git@github.com:acme/repo.git"\n'),
166 ).toBe("git@github.com:acme/repo.git");
167 + for (const newline of ["\n", "\r\n"]) {
168 + for (const comment of ["#", ";"]) {
169 + const config = [
170 + '[remote "upstream"]',
171 + `url = https://github.com/other/repo.git ${comment} ignored backslash \\`,
172 + '[remote "origin"]',
173 + `url = https://github.com/acme/repo.git ${comment} ignored backslash \\`,
174 + `${comment} ignored backslash \\`,
175 + '[remote "fork"]',
176 + "url = https://github.com/me/repo.git",
177 + ].join(newline);
178 + expect(parseOriginUrlFromGitConfig(config)).toBe("https://github.com/acme/repo.git");
179 + }
180 + }
181 });
182
183 it("accepts legacy dotted headers, header comments, and line continuations", () => {
@@ -185,7 +199,7 @@ describe("parseOriginUrlFromGitConfig", () => {
199 parseOriginUrlFromGitConfig(
200 '[remote "origin"]\n\turl = https://github.com/acme/\\\n\t\trepo.git\n',
201 ),
188 - ).toBe("https://github.com/acme/repo.git");
202 + ).toBe("https://github.com/acme/\t\trepo.git");
203 });
204
205 it("reads settings on the remote header line", () => {
packages/shared/src/git.ts
+1 -2
@@ -283,8 +283,7 @@ export function parseOriginUrlFromGitConfig(configText: string): string | null {
283 let section: string | null = null;
284 let originUrl: string | null = null;
285 let firstRemoteUrl: string | null = null;
286 - const joined = configText.replace(/\\\r?\n[ \t]*/g, "");
287 - for (const rawLine of joined.split(/\r?\n/)) {
286 + for (const rawLine of gitConfigLines(configText)) {
287 let line = rawLine.trim();
288 if (line.length === 0 || line.startsWith("#") || line.startsWith(";")) continue;
289 // Git preserves case in quoted remote subsections but lowercases legacy dotted ones,