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

Function checkoutWith

packages/computer/src/git/refs.ts:225–248  ·  view source on GitHub ↗
(opts: CheckoutWithDeps)

Source from the content-addressed store, hash-verified

223}
224
225export 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
250function errorMessage(cause: unknown): string {
251 if (cause instanceof Error) return cause.message;

Callers 2

checkoutFunction · 0.85
refs.test.tsFile · 0.85

Calls 3

isNotARepositoryCauseFunction · 0.85
errorMessageFunction · 0.70
checkoutMethod · 0.65

Tested by

no test coverage detected