Skip to content

[refactor-bot] Add a runGitSync helper for the repeated execFileSync(getGitExecutable()) calls #449

Done

Description

@404-Page-Found

Current state
Every synchronous git call repeats the same boilerplate: execFileSync(getGitExecutable(), [...], { cwd, encoding: 'utf-8', env: getGitEnv(), maxBuffer: ... }). That pattern appears about 17 times in src/git/diff.ts (lines 198, 208, 224, 243, 282, 294, 304, 319, 356, 373, 435, 439, 441, 470, 482, 494) and in src/git/hook.ts:64 and :828. Each call site decides its own env, stdio, and maxBuffer, so a change to git invocation (for example, the executable or env policy) must be applied in many places.

Proposed change
Add runGitSync(args, options) in src/git/diff.ts that calls getGitExecutable(), defaults encoding to utf-8, and returns trimmed or raw stdout as the caller needs. Migrate the call sites in place. Each migrated call keeps its exact current options.

Affected files

  • src/git/diff.ts (listed lines above)
  • src/git/hook.ts:64 and :828

Risk
Medium. Several calls intentionally omit env (diff.ts:144, :477; hook.ts:64, :828), so the helper must not add getGitEnv() by default. Preserve per-call stdio and maxBuffer. Existing diff and hook unit and e2e tests cover these paths. No behavior change is intended.

Activity

  1. added
    assignee:coding-bot
    on Dec 5, 2026
  2. 404-Page-Found commented on Dec 5, 2026

    @404-Page-Found
    ContributorAuthor

    Validity

    valid: a refactor proposal; the repeated execFileSync(getGitExecutable(), ...) boilerplate exists as described, and the call sites that omit env (diff.ts:144, :477; hook.ts:64, :828) match the issue's risk note.

    Likely location

    src/git/diff.ts:198 (repeated calls through ~:494); src/git/hook.ts:64 and :828

    Severity

    low

    Next step

    Add runGitSync(args, options) in src/git/diff.ts that uses getGitExecutable() and does not default env to getGitEnv(). Migrate call sites one at a time, keeping each call's exact options, and run the existing git-diff and hook tests.

  3. removed
    assignee:coding-bot
    on Dec 5, 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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions