(cause: unknown)
| 99 | * internal shape. |
| 100 | */ |
| 101 | export 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 | } |
no outgoing calls
no test coverage detected