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

Function runCatFile

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

Source from the content-addressed store, hash-verified

1774// ---------------------------------------------------------------
1775
1776async function runCatFile(
1777 client: GitClient,
1778 args: string[],
1779 input: GitCliInput,
1780): Promise<GitCliResult> {
1781 // `git cat-file -p <oid>` -- pretty-print the object's raw
1782 // bytes to stdout. Other forms (`-t`, `-s`) are out of scope.
1783 const parsed = parseFlags(args, {
1784 p: { kind: "bool" },
1785 });
1786 if ("error" in parsed) {
1787 return { stdout: "", stderr: `git cat-file: ${parsed.error}\n`, exitCode: 129 };
1788 }
1789 if (parsed.flags.p !== true) {
1790 return {
1791 stdout: "",
1792 stderr: "git cat-file: only -p is supported\n",
1793 exitCode: 129,
1794 };
1795 }
1796 if (parsed.positional.length !== 1) {
1797 return {
1798 stdout: "",
1799 stderr: "git cat-file: usage: git cat-file -p <oid>[:<path>]\n",
1800 exitCode: 129,
1801 };
1802 }
1803 // Support the <oid>:<path> shorthand for tree subreads.
1804 const spec = parsed.positional[0];
1805 const colon = spec.indexOf(":");
1806 const oid = colon === -1 ? spec : spec.slice(0, colon);
1807 const filepath = colon === -1 ? undefined : spec.slice(colon + 1);
1808 const dir = resolveDir(undefined, input.cwd);
1809 try {
1810 const result = await client.catFile({ dir, oid, filepath });
1811 const text = new TextDecoder("utf-8", { fatal: false }).decode(result.bytes);
1812 return { stdout: text, stderr: "", exitCode: 0 };
1813 } catch (cause) {
1814 return mapGitError("cat-file", cause);
1815 }
1816}
1817
1818// ---------------------------------------------------------------
1819// update-ref

Callers 1

runGitCliFunction · 0.85

Calls 4

resolveDirFunction · 0.85
mapGitErrorFunction · 0.85
catFileMethod · 0.80
parseFlagsFunction · 0.70

Tested by

no test coverage detected