( client: GitClient, args: string[], input: GitCliInput, )
| 2067 | // --------------------------------------------------------------- |
| 2068 | |
| 2069 | async function runClean( |
| 2070 | client: GitClient, |
| 2071 | args: string[], |
| 2072 | input: GitCliInput, |
| 2073 | ): Promise<GitCliResult> { |
| 2074 | // `git clean -f [-d] [-n|--dry-run]`. Real git refuses to act |
| 2075 | // without `-f`; mirror that so a bare `git clean` is a no-op |
| 2076 | // error rather than a destructive surprise. The flags are all |
| 2077 | // boolean, so expand any combined short cluster (`-fd`, `-fdn`) |
| 2078 | // into separate tokens before parsing. |
| 2079 | const expanded = expandShortBoolCluster(args, new Set(["f", "d", "n"])); |
| 2080 | const parsed = parseFlags(expanded, { |
| 2081 | force: { kind: "bool", alias: ["f"] }, |
| 2082 | d: { kind: "bool" }, |
| 2083 | "dry-run": { kind: "bool", alias: ["n"] }, |
| 2084 | }); |
| 2085 | if ("error" in parsed) { |
| 2086 | return { stdout: "", stderr: `git clean: ${parsed.error}\n`, exitCode: 129 }; |
| 2087 | } |
| 2088 | const dryRun = parsed.flags["dry-run"] === true; |
| 2089 | if (parsed.flags.force !== true && !dryRun) { |
| 2090 | return { |
| 2091 | stdout: "", |
| 2092 | stderr: "git clean: refusing to clean without -f (or use -n to preview)\n", |
| 2093 | exitCode: 129, |
| 2094 | }; |
| 2095 | } |
| 2096 | const dir = resolveDir(undefined, input.cwd); |
| 2097 | try { |
| 2098 | const removed = await client.clean({ |
| 2099 | dir, |
| 2100 | directories: parsed.flags.d === true, |
| 2101 | dryRun, |
| 2102 | }); |
| 2103 | if (removed.length === 0) return { stdout: "", stderr: "", exitCode: 0 }; |
| 2104 | const verb = dryRun ? "Would remove" : "Removing"; |
| 2105 | const lines = removed.map((p) => `${verb} ${p}`); |
| 2106 | return { stdout: `${lines.join("\n")}\n`, stderr: "", exitCode: 0 }; |
| 2107 | } catch (cause) { |
| 2108 | return mapGitError("clean", cause); |
| 2109 | } |
| 2110 | } |
| 2111 | |
| 2112 | // --------------------------------------------------------------- |
| 2113 | // shared error mapping |
no test coverage detected