MCPcopy Create free account
hub / github.com/cloudflare/computer / isNotARepositoryCause

Function isNotARepositoryCause

packages/computer/src/git/errors.ts:101–130  ·  view source on GitHub ↗
(cause: unknown)

Source from the content-addressed store, hash-verified

99 * internal shape.
100 */
101export function isNotARepositoryCause(cause: unknown): boolean {
102 if (!(cause instanceof Error)) return false;
103 // isomorphic-git's NotFoundError shows up in three flavours
104 // depending on how deep we got before the failure:
105 //
106 // - VFS-level ENOENT on the gitdir itself: message contains
107 // `.git` plus an ENOENT-shaped phrase.
108 // - HEAD lookup before any other read: a NotFoundError whose
109 // message reads "Could not find HEAD." / "Could not find
110 // refs/heads/main."
111 // - Object-store lookup: a NotFoundError on a SHA or pack.
112 //
113 // For the not-a-repo signal we want the first two: missing
114 // .git or missing HEAD. Object-store misses are a different
115 // failure mode and should not collapse to NotARepositoryError.
116 const code = (cause as { code?: unknown }).code;
117 const name = cause.name;
118 const message = cause.message;
119 if (
120 (name === "NotFoundError" || code === "NotFoundError") &&
121 /Could not find (HEAD|refs\/)/.test(message)
122 ) {
123 return true;
124 }
125 const m = message.toLowerCase();
126 return (
127 m.includes(".git") &&
128 (m.includes("enoent") || m.includes("could not find") || m.includes("does not exist"))
129 );
130}

Callers 15

fetchWithFunction · 0.85
pushWithFunction · 0.85
pullWithFunction · 0.85
mergeWithFunction · 0.85
remoteAddWithFunction · 0.85
remoteRemoveWithFunction · 0.85
remoteListWithFunction · 0.85
statusWithFunction · 0.85
logWithFunction · 0.85
showWithFunction · 0.85
revParseWithFunction · 0.85
currentBranchWithFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected