(opts: CheckoutWithDeps)
| 223 | } |
| 224 | |
| 225 | export async function checkoutWith(opts: CheckoutWithDeps): Promise<void> { |
| 226 | const dir = opts.dir ?? "/"; |
| 227 | // git checkout <ref> -- <paths>: update the working tree but |
| 228 | // leave HEAD where it was. isomorphic-git's `noUpdateHead` |
| 229 | // achieves this; without it a path-restricted checkout would |
| 230 | // detach HEAD onto the source commit. |
| 231 | const pathScoped = opts.paths !== undefined && opts.paths.length > 0; |
| 232 | try { |
| 233 | await opts.git.checkout({ |
| 234 | fs: opts.fs, |
| 235 | dir, |
| 236 | ref: opts.ref, |
| 237 | filepaths: pathScoped ? opts.paths : undefined, |
| 238 | force: opts.force, |
| 239 | noUpdateHead: pathScoped, |
| 240 | cache: opts.cache, |
| 241 | }); |
| 242 | } catch (cause) { |
| 243 | if (isNotARepositoryCause(cause)) throw new NotARepositoryError(dir, { cause }); |
| 244 | throw new GitError("ECHECKOUTFAIL", `git checkout failed: ${errorMessage(cause)}`, { |
| 245 | cause, |
| 246 | }); |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | function errorMessage(cause: unknown): string { |
| 251 | if (cause instanceof Error) return cause.message; |
no test coverage detected