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

Function runDiff

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

Source from the content-addressed store, hash-verified

316// ---------------------------------------------------------------
317
318async function runDiff(
319 client: GitClient,
320 args: string[],
321 input: GitCliInput,
322): Promise<GitCliResult> {
323 // `git diff [--stat|--name-only|--name-status] [<ref> | <from>
324 // <to>] [-- <path>...]`. Two refs before `--` switch to
325 // ref-to-ref mode; paths after `--` filter the output. The
326 // summary flags swap the unified patch for a per-file summary.
327 const parsed = parseFlags(args, {
328 stat: { kind: "bool" },
329 "name-only": { kind: "bool" },
330 "name-status": { kind: "bool" },
331 });
332 if ("error" in parsed) {
333 return { stdout: "", stderr: `git diff: ${parsed.error}\n`, exitCode: 129 };
334 }
335 const wantStat = parsed.flags.stat === true;
336 const wantNameOnly = parsed.flags["name-only"] === true;
337 const wantNameStatus = parsed.flags["name-status"] === true;
338 // Split positional on '--' — anything after is a path filter.
339 // The parser already consumes '--' and treats the rest as
340 // positional, so we need to remember where it was. Rebuild
341 // from raw argv.
342 const sep = args.indexOf("--");
343 const refArgs =
344 sep === -1 ? parsed.positional : args.slice(0, sep).filter((a) => !a.startsWith("-"));
345 const pathArgs = sep === -1 ? [] : args.slice(sep + 1);
346
347 if (refArgs.length > 2) {
348 return {
349 stdout: "",
350 stderr: `git diff: too many refs (expected at most 2, got ${refArgs.length})\n`,
351 exitCode: 129,
352 };
353 }
354 const [from, to] = refArgs;
355 const dir = resolveDir(undefined, input.cwd);
356 try {
357 const fromResolved = await resolveRevisionRef(client, dir, from);
358 const toResolved = await resolveRevisionRef(client, dir, to);
359 const paths = pathArgs.length > 0 ? pathArgs : undefined;
360
361 if (wantStat || wantNameOnly || wantNameStatus) {
362 const summary = await client.diffSummary({
363 dir,
364 ref: fromResolved,
365 to: toResolved,
366 paths,
367 });
368 const stdout = wantNameOnly
369 ? formatDiffNameOnly(summary)
370 : wantNameStatus
371 ? formatDiffNameStatus(summary)
372 : formatDiffStat(summary);
373 return { stdout, stderr: "", exitCode: 0 };
374 }
375

Callers 1

runGitCliFunction · 0.70

Calls 9

resolveDirFunction · 0.85
resolveRevisionRefFunction · 0.85
formatDiffNameOnlyFunction · 0.85
formatDiffNameStatusFunction · 0.85
formatDiffStatFunction · 0.85
mapGitErrorFunction · 0.85
diffSummaryMethod · 0.80
diffMethod · 0.80
parseFlagsFunction · 0.70

Tested by

no test coverage detected