Skip to content

refactor(git): one runGit helper in git-diff-utils replaces the four local git() spawnSync wrappers #1592

Open

Description

@admarble

Follow-up of #1520 (PR #1587); from the independent code review. This is the synchronous consolidation; the async move is #506 and stays there.

Problem

Four modules carry their own function git( wrapper over spawnSync("git", …): src/lib/skills-commit-state.ts:36 (returns null on failure), src/lib/worktree-isolation.ts:102 (takes the command as one string), src/lib/merge-check/combined-branch-test.ts:70 and src/lib/workflow/review-residue.post.ts:28 (both throw, with different error text; the last one picks a 64 MB maxBuffer, the others the default). grep -lE '^function git\(' <the four files> | wc -l → 4 today. Each copy drifts on its own: a change to how a failed git read is reported, or to the buffer a large diff needs, lands in one and not the others. src/lib/workflow/git-diff-utils.ts already hosts the shared git reads (resolveDiffBase, getCommitHash, getGitDiffStats) and is where one helper belongs.

Acceptance Criteria

  • AC-1: One exported helper in git-diff-utils.ts (for example runGit(cwd, args, { maxBuffer? }), throwing with one error shape) replaces the four local wrappers; each former site calls it and keeps its own failure policy at the call site (catch and return null where it did). Evidence: grep -lE '^function git\(' src/lib/skills-commit-state.ts src/lib/worktree-isolation.ts src/lib/merge-check/combined-branch-test.ts src/lib/workflow/review-residue.post.ts | wc -l | tr -d ' ' → 0 (today 4)
  • AC-2: The helper has its own test for the two outcomes (stdout on success; a thrown error that names the args and stderr on failure). Evidence: npx vitest run src/lib/workflow/git-diff-utils.test.ts -t "runGit" → ≥ 2 passed, 0 failed (new cases)
  • AC-3: The four callers' tests still pass. Evidence: npx vitest run src/lib/skills-commit-state.integration.test.ts src/lib/worktree-isolation.test.ts src/lib/merge-check/combined-branch-test.test.ts src/lib/workflow/review-residue.post.test.ts → 0 failed
  • AC-4: No function grows past the refactor(workflow): split run, ensureWorktree, executePhaseWithRetry and executePhase to ≤ 200 counted lines; max-lines-per-function ratchet for src/lib/workflow #1508 ratchet and no metric rises. Evidence: npm run lint && npm run lint:health → exit 0, no metric rose above the baseline

May touch

src/lib/workflow/git-diff-utils.ts and its test, the four listed files, CHANGELOG.

Non-Goals

Activity

  1. added
    refactor
    on Oct 26, 2026
  2. added a commit that references this issue on Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    refactor

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions