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

Function createAndSwitch

packages/computer/src/git/cli.ts:1334–1352  ·  view source on GitHub ↗

* Create a branch (optionally at a start point) and move HEAD to * it — the shared core of `checkout -b` and `switch -c`. The * branch is created first; only on success does HEAD move, so a * name collision leaves the working tree untouched.

(
  client: GitClient,
  dir: string,
  name: string,
  startPoint: string | undefined,
  subcommand: string,
)

Source from the content-addressed store, hash-verified

1332 * name collision leaves the working tree untouched.
1333 */
1334async function createAndSwitch(
1335 client: GitClient,
1336 dir: string,
1337 name: string,
1338 startPoint: string | undefined,
1339 subcommand: string,
1340): Promise<GitCliResult> {
1341 try {
1342 await client.branch({ dir, name, startPoint, force: false });
1343 } catch (cause) {
1344 return mapGitError(subcommand, cause);
1345 }
1346 try {
1347 await client.checkout({ dir, ref: name });
1348 return { stdout: "", stderr: "", exitCode: 0 };
1349 } catch (cause) {
1350 return mapGitError(subcommand, cause);
1351 }
1352}
1353
1354// ---------------------------------------------------------------
1355// fetch

Callers 2

runCheckoutFunction · 0.85
runSwitchFunction · 0.85

Calls 3

mapGitErrorFunction · 0.85
branchMethod · 0.65
checkoutMethod · 0.65

Tested by

no test coverage detected