From d649d16d480a58689b470498838d38442962c3e3 Mon Sep 17 00:00:00 2001 From: Sawyer Date: Fri, 18 Sep 2026 02:15:31 -0700 Subject: [PATCH] fix(web): resolve the fetched branch from refs/remotes/origin/main (CL-8520) --- apps/web/src/git-fetch.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/web/src/git-fetch.ts b/apps/web/src/git-fetch.ts index 4db4ab797..7ecf6487f 100644 --- a/apps/web/src/git-fetch.ts +++ b/apps/web/src/git-fetch.ts @@ -12,6 +12,9 @@ globalThis.Buffer ??= Buffer; export class GitFetchError extends Error {} const MAIN_REF = "refs/heads/main"; +// Where a single-branch fetch through the `origin` remote lands; isomorphic-git +// does not write FETCH_HEAD on this filesystem. +const FETCHED_MAIN_REF = "refs/remotes/origin/main"; async function cloneAndFetchMain(args: { url: string; @@ -47,7 +50,7 @@ export async function fetchSourceFile(args: { }): Promise { try { const { fs, dir } = await cloneAndFetchMain(args); - const oid = await git.resolveRef({ fs, dir, ref: "FETCH_HEAD" }); + const oid = await git.resolveRef({ fs, dir, ref: FETCHED_MAIN_REF }); const { blob } = await git.readBlob({ fs, dir, oid, filepath: args.filepath }); return new TextDecoder().decode(blob); } catch (cause) { @@ -68,7 +71,7 @@ export async function fetchSourceFileOrEmpty(args: { const { fs, dir } = await cloneAndFetchMain(args); let oid: string; try { - oid = await git.resolveRef({ fs, dir, ref: "FETCH_HEAD" }); + oid = await git.resolveRef({ fs, dir, ref: FETCHED_MAIN_REF }); } catch (cause) { if (cause instanceof Errors.NotFoundError) return ""; throw cause;