Skip to content

Commit 86c476e

Browse files
refactor(server): parse gh-resolved marks with one pattern
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 5188c1b commit 86c476e

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

‎apps/server/src/project/RepositoryIdentityResolver.ts‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,17 @@ function pickMarkedRemote(
7878
remotes: ReadonlyMap<string, string>,
7979
resolved: string,
8080
): { readonly remoteName: string; readonly remoteUrl: string } | null {
81-
const marks: Array<{ readonly remoteName: string; readonly value: string }> = [];
82-
for (const line of resolved.split("\n")) {
83-
const separator = line.indexOf(" ");
84-
const key = line.slice(0, separator);
85-
const value = line.slice(separator + 1).trim();
86-
if (separator === -1 || !key.startsWith("remote.") || !key.endsWith(".gh-resolved")) continue;
87-
const remoteName = key.slice("remote.".length, -".gh-resolved".length);
88-
if (remotes.has(remoteName) && value.length > 0) marks.push({ remoteName, value });
89-
}
81+
const marks = resolved.split("\n").flatMap((line) => {
82+
const match = /^remote\.(.+)\.gh-resolved\s+(\S+)$/u.exec(line.trim());
83+
const remoteUrl = match?.[1] === undefined ? undefined : remotes.get(match[1]);
84+
return match?.[1] && match[2] && remoteUrl
85+
? [{ remoteName: match[1], remoteUrl, value: match[2] }]
86+
: [];
87+
});
9088
// gh's choice is ambiguous with several marks; GitHubSourceControlProvider ignores them too.
9189
const [mark, ...others] = marks;
9290
if (!mark || others.length > 0) return null;
93-
const markedUrl = remotes.get(mark.remoteName)!;
91+
const markedUrl = mark.remoteUrl;
9492
if (mark.value === "base") return { remoteName: mark.remoteName, remoteUrl: markedUrl };
9593
const host = normalizeGitRemoteUrl(markedUrl).split("/")[0];
9694
const markedKey = `${host}/${mark.value.toLowerCase()}`;

0 commit comments

Comments
 (0)