(opts: ResetWithDeps)
| 142 | } |
| 143 | |
| 144 | export 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 | |
| 166 | async function hardReset(opts: ResetWithDeps, dir: string, ref: string): Promise<void> { |
| 167 | // Real `git reset --hard <ref>` moves the current branch to the |
no test coverage detected