( client: GitClient, args: string[], input: GitCliInput, )
| 1285 | // --------------------------------------------------------------- |
| 1286 | |
| 1287 | async function runSwitch( |
| 1288 | client: GitClient, |
| 1289 | args: string[], |
| 1290 | input: GitCliInput, |
| 1291 | ): Promise<GitCliResult> { |
| 1292 | // `git switch [-c <new>] <branch> [<start>]`. The modern |
| 1293 | // spelling of `checkout` for branch movement; `-c` is the |
| 1294 | // `checkout -b` equivalent. |
| 1295 | const parsed = parseFlags(args, { |
| 1296 | c: { kind: "bool" }, |
| 1297 | }); |
| 1298 | if ("error" in parsed) { |
| 1299 | return { stdout: "", stderr: `git switch: ${parsed.error}\n`, exitCode: 129 }; |
| 1300 | } |
| 1301 | const dir = resolveDir(undefined, input.cwd); |
| 1302 | |
| 1303 | if (parsed.flags.c === true) { |
| 1304 | if (parsed.positional.length === 0) { |
| 1305 | return { stdout: "", stderr: "git switch: -c requires a branch name\n", exitCode: 129 }; |
| 1306 | } |
| 1307 | return createAndSwitch(client, dir, parsed.positional[0], parsed.positional[1], "switch"); |
| 1308 | } |
| 1309 | |
| 1310 | if (parsed.positional.length === 0) { |
| 1311 | return { stdout: "", stderr: "git switch: missing <branch>\n", exitCode: 129 }; |
| 1312 | } |
| 1313 | if (parsed.positional.length > 1) { |
| 1314 | return { |
| 1315 | stdout: "", |
| 1316 | stderr: `git switch: unexpected argument '${parsed.positional[1]}'\n`, |
| 1317 | exitCode: 129, |
| 1318 | }; |
| 1319 | } |
| 1320 | try { |
| 1321 | await client.checkout({ dir, ref: parsed.positional[0] }); |
| 1322 | return { stdout: "", stderr: "", exitCode: 0 }; |
| 1323 | } catch (cause) { |
| 1324 | return mapGitError("switch", cause); |
| 1325 | } |
| 1326 | } |
| 1327 | |
| 1328 | /** |
| 1329 | * Create a branch (optionally at a start point) and move HEAD to |
no test coverage detected