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

Function hardReset

packages/computer/src/git/worktree.ts:166–180  ·  view source on GitHub ↗
(opts: ResetWithDeps, dir: string, ref: string)

Source from the content-addressed store, hash-verified

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
168 // target commit when HEAD is symbolic, then rewrites the index
169 // and work tree. A plain checkout of a resolved oid would leave
170 // HEAD detached, so update the branch ref first and then
171 // checkout that branch name to materialize the tree.
172 const oid = await opts.git.resolveRef({ fs: opts.fs, dir, ref });
173 const branch = await opts.git.currentBranch({ fs: opts.fs, dir, fullname: true });
174 if (branch) {
175 await opts.git.writeRef({ fs: opts.fs, dir, ref: branch, value: oid, force: true });
176 await opts.git.checkout({ fs: opts.fs, dir, ref: branch, force: true, cache: opts.cache });
177 return;
178 }
179 await opts.git.checkout({ fs: opts.fs, dir, ref: oid, force: true, cache: opts.cache });
180}
181
182async function stagedPaths(opts: ResetWithDeps, dir: string): Promise<string[]> {
183 const matrix = await opts.git.statusMatrix({ fs: opts.fs, dir, cache: opts.cache });

Callers 1

resetWithFunction · 0.85

Calls 4

resolveRefMethod · 0.65
currentBranchMethod · 0.65
writeRefMethod · 0.65
checkoutMethod · 0.65

Tested by

no test coverage detected