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

Function runHashObject

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

Source from the content-addressed store, hash-verified

1722// ---------------------------------------------------------------
1723
1724async function runHashObject(
1725 client: GitClient,
1726 args: string[],
1727 input: GitCliInput,
1728): Promise<GitCliResult> {
1729 // `git hash-object [-w] --stdin` -- the only mode we cover.
1730 // The on-disk file path form (`git hash-object <file>`) would
1731 // pull in path resolution and a Uint8Array readback through
1732 // the workspace's fs; the stdin form is enough for the agent
1733 // scripts that drive the shell side.
1734 const parsed = parseFlags(args, {
1735 w: { kind: "bool" },
1736 stdin: { kind: "bool" },
1737 });
1738 if ("error" in parsed) {
1739 return {
1740 stdout: "",
1741 stderr: `git hash-object: ${parsed.error}\n`,
1742 exitCode: 129,
1743 };
1744 }
1745 if (parsed.flags.stdin !== true) {
1746 return {
1747 stdout: "",
1748 stderr: "git hash-object: only --stdin is supported\n",
1749 exitCode: 129,
1750 };
1751 }
1752 if (parsed.positional.length > 0) {
1753 return {
1754 stdout: "",
1755 stderr: `git hash-object: unexpected argument '${parsed.positional[0]}'\n`,
1756 exitCode: 129,
1757 };
1758 }
1759 const dir = resolveDir(undefined, input.cwd);
1760 try {
1761 const oid = await client.hashObject({
1762 dir,
1763 content: input.stdin ?? "",
1764 write: parsed.flags.w === true,
1765 });
1766 return { stdout: `${oid}\n`, stderr: "", exitCode: 0 };
1767 } catch (cause) {
1768 return mapGitError("hash-object", cause);
1769 }
1770}
1771
1772// ---------------------------------------------------------------
1773// cat-file

Callers 1

runGitCliFunction · 0.85

Calls 4

resolveDirFunction · 0.85
mapGitErrorFunction · 0.85
hashObjectMethod · 0.80
parseFlagsFunction · 0.70

Tested by

no test coverage detected