Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions apps/web/src/git-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -47,7 +50,7 @@ export async function fetchSourceFile(args: {
}): Promise<string> {
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) {
Expand All @@ -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;
Expand Down
Loading