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

Function runRemote

packages/computer/src/git/cli.ts:1624–1718  ·  view source on GitHub ↗
(
  client: GitClient,
  args: string[],
  input: GitCliInput,
)

Source from the content-addressed store, hash-verified

1622// ---------------------------------------------------------------
1623
1624async function runRemote(
1625 client: GitClient,
1626 args: string[],
1627 input: GitCliInput,
1628): Promise<GitCliResult> {
1629 // `git remote` -> list (names only)
1630 // `git remote -v` -> list (name + url, tab separated, twice)
1631 // `git remote add <n> <u>` -> add
1632 // `git remote remove <n>` -> remove
1633 const dir = resolveDir(undefined, input.cwd);
1634 if (args.length === 0) {
1635 try {
1636 const remotes = await client.remoteList({ dir });
1637 if (remotes.length === 0) return { stdout: "", stderr: "", exitCode: 0 };
1638 return {
1639 stdout: `${remotes
1640 .slice()
1641 .sort((a, b) => a.name.localeCompare(b.name))
1642 .map((r) => r.name)
1643 .join("\n")}\n`,
1644 stderr: "",
1645 exitCode: 0,
1646 };
1647 } catch (cause) {
1648 return mapGitError("remote", cause);
1649 }
1650 }
1651 // `-v` lives at the top level, no subcommand.
1652 if (args.length === 1 && (args[0] === "-v" || args[0] === "--verbose")) {
1653 try {
1654 const remotes = await client.remoteList({ dir });
1655 if (remotes.length === 0) return { stdout: "", stderr: "", exitCode: 0 };
1656 const lines: string[] = [];
1657 for (const r of remotes.slice().sort((a, b) => a.name.localeCompare(b.name))) {
1658 lines.push(`${r.name}\t${r.url} (fetch)`);
1659 lines.push(`${r.name}\t${r.url} (push)`);
1660 }
1661 return { stdout: `${lines.join("\n")}\n`, stderr: "", exitCode: 0 };
1662 } catch (cause) {
1663 return mapGitError("remote", cause);
1664 }
1665 }
1666 const [sub, ...rest] = args;
1667 switch (sub) {
1668 case "add": {
1669 const parsed = parseFlags(rest, { force: { kind: "bool", alias: ["f"] } });
1670 if ("error" in parsed) {
1671 return { stdout: "", stderr: `git remote add: ${parsed.error}\n`, exitCode: 129 };
1672 }
1673 if (parsed.positional.length !== 2) {
1674 return {
1675 stdout: "",
1676 stderr: "git remote add: usage: git remote add [--force] <name> <url>\n",
1677 exitCode: 129,
1678 };
1679 }
1680 const [name, url] = parsed.positional;
1681 if (!isSupportedRemoteUrl(url)) {

Callers 1

runGitCliFunction · 0.85

Calls 8

resolveDirFunction · 0.85
mapGitErrorFunction · 0.85
isSupportedRemoteUrlFunction · 0.85
remoteListMethod · 0.80
remoteAddMethod · 0.80
remoteRemoveMethod · 0.80
parseFlagsFunction · 0.70
pushMethod · 0.65

Tested by

no test coverage detected