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

Function resetWith

packages/computer/src/git/worktree.ts:144–164  ·  view source on GitHub ↗
(opts: ResetWithDeps)

Source from the content-addressed store, hash-verified

142}
143
144export async function resetWith(opts: ResetWithDeps): Promise<void> {
145 const dir = opts.dir ?? "/";
146 const ref = opts.ref ?? "HEAD";
147 try {
148 if (opts.hard) {
149 await hardReset(opts, dir, ref);
150 return;
151 }
152 // Path reset: unstage each path back to `ref` without
153 // touching the working tree. When no paths are supplied,
154 // reset every staged entry — the common `git reset` / `git
155 // reset HEAD` behavior.
156 const paths = opts.paths ?? (await stagedPaths(opts, dir));
157 for (const filepath of paths) {
158 await opts.git.resetIndex({ fs: opts.fs, dir, filepath, ref, cache: opts.cache });
159 }
160 } catch (cause) {
161 if (isNotARepositoryCause(cause)) throw new NotARepositoryError(dir, { cause });
162 throw new GitError("ERESETFAIL", `git reset failed: ${errorMessage(cause)}`, { cause });
163 }
164}
165
166async function hardReset(opts: ResetWithDeps, dir: string, ref: string): Promise<void> {
167 // Real `git reset --hard <ref>` moves the current branch to the

Callers 2

resetFunction · 0.85
worktree.test.tsFile · 0.85

Calls 5

hardResetFunction · 0.85
stagedPathsFunction · 0.85
isNotARepositoryCauseFunction · 0.85
resetIndexMethod · 0.80
errorMessageFunction · 0.70

Tested by

no test coverage detected