(
url: string,
auth: AuthRecipe = {},
fetchImpl: typeof fetch = fetch,
policy: GitUrlPolicy = {},
)
| 82 | |
| 83 | // The cheap "did it change" check: GET info/refs. Returns the ref advertisement. |
| 84 | export async function checkRefs( |
| 85 | url: string, |
| 86 | auth: AuthRecipe = {}, |
| 87 | fetchImpl: typeof fetch = fetch, |
| 88 | policy: GitUrlPolicy = {}, |
| 89 | ): Promise<RefsResult> { |
| 90 | const repo = normalizeRepoUrl(url); |
| 91 | const infoUrl = `${repo}/info/refs?service=git-upload-pack`; |
| 92 | const t0 = Date.now(); |
| 93 | const res = await fetchGit( |
| 94 | infoUrl, |
| 95 | { |
| 96 | headers: { |
| 97 | ...baseHeaders(auth), |
| 98 | accept: "*/*", |
| 99 | }, |
| 100 | }, |
| 101 | fetchImpl, |
| 102 | policy, |
| 103 | ); |
| 104 | const buf = new Uint8Array(await res.arrayBuffer()); |
| 105 | const wallMs = Date.now() - t0; |
| 106 | if (!res.ok) { |
| 107 | throw new Error(`info/refs ${res.status}: ${new TextDecoder().decode(buf.subarray(0, 200))}`); |
| 108 | } |
| 109 | const ct = res.headers.get("content-type") || ""; |
| 110 | if (!ct.includes("git-upload-pack-advertisement")) { |
| 111 | // Some hosts (or a wrong URL) return HTML; treat as protocol failure. |
| 112 | throw new Error(`unexpected content-type: ${ct}`); |
| 113 | } |
| 114 | const adv = parseInfoRefs(buf); |
| 115 | return { adv, status: res.status, wallMs, bytes: buf.length }; |
| 116 | } |
| 117 | |
| 118 | export interface UploadPackOptions { |
| 119 | auth?: AuthRecipe; |
no test coverage detected