( client: GitClient, args: string[], input: GitCliInput, )
| 1998 | // --------------------------------------------------------------- |
| 1999 | |
| 2000 | async function runReset( |
| 2001 | client: GitClient, |
| 2002 | args: string[], |
| 2003 | input: GitCliInput, |
| 2004 | ): Promise<GitCliResult> { |
| 2005 | // `git reset [--hard] [<ref>] [-- <paths>...]`. Path reset |
| 2006 | // unstages; `--hard` restores tracked files to the ref. |
| 2007 | const parsed = parseFlags(args, { |
| 2008 | hard: { kind: "bool" }, |
| 2009 | soft: { kind: "bool" }, |
| 2010 | mixed: { kind: "bool" }, |
| 2011 | }); |
| 2012 | if ("error" in parsed) { |
| 2013 | return { stdout: "", stderr: `git reset: ${parsed.error}\n`, exitCode: 129 }; |
| 2014 | } |
| 2015 | if (parsed.flags.soft === true) { |
| 2016 | return { stdout: "", stderr: "git reset: --soft is not supported\n", exitCode: 129 }; |
| 2017 | } |
| 2018 | if (parsed.flags.mixed === true) { |
| 2019 | return { stdout: "", stderr: "git reset: --mixed is not supported\n", exitCode: 129 }; |
| 2020 | } |
| 2021 | const sep = args.indexOf("--"); |
| 2022 | const positional = |
| 2023 | sep === -1 ? parsed.positional : args.slice(0, sep).filter((a) => !a.startsWith("-")); |
| 2024 | const pathArgs = sep === -1 ? [] : args.slice(sep + 1); |
| 2025 | const dir = resolveDir(undefined, input.cwd); |
| 2026 | const hard = parsed.flags.hard === true; |
| 2027 | |
| 2028 | // A leading positional before `--` can be a ref; everything |
| 2029 | // after `--` is paths. Real git is more context-sensitive than |
| 2030 | // this subset, but handle the ubiquitous `git reset HEAD` |
| 2031 | // spelling explicitly so it resets all staged changes instead |
| 2032 | // of silently treating HEAD as a pathspec. |
| 2033 | let ref: string | undefined; |
| 2034 | let paths = pathArgs; |
| 2035 | if (sep === -1) { |
| 2036 | if (hard || isResetRefOnly(positional)) { |
| 2037 | ref = positional[0]; |
| 2038 | } else { |
| 2039 | paths = positional; |
| 2040 | } |
| 2041 | } else { |
| 2042 | ref = positional[0]; |
| 2043 | } |
| 2044 | |
| 2045 | try { |
| 2046 | const resolvedRef = await resolveRevisionRef(client, dir, ref); |
| 2047 | await client.reset({ |
| 2048 | dir, |
| 2049 | hard, |
| 2050 | ref: resolvedRef, |
| 2051 | paths: paths.length > 0 ? paths : undefined, |
| 2052 | }); |
| 2053 | return { stdout: "", stderr: "", exitCode: 0 }; |
| 2054 | } catch (cause) { |
| 2055 | return mapGitError("reset", cause); |
| 2056 | } |
| 2057 | } |
no test coverage detected