Skip to content

Refactor Bun.spawn to runGitCommand helper in git-workflow.ts and repo-manager.ts #267

Description

@amondnet

Summary

Refactor direct Bun.spawn calls to use the centralized runGitCommand helper for consistency, testability, and maintainability.

Background

During PR #259 code review, @gemini-code-assist identified that several functions still use Bun.spawn directly instead of the new runGitCommand helper introduced in src/lib/git-exec.ts.

Related PR: #259
Review threads:

Tasks

src/lib/git-workflow.ts

  • fetchBranch() - Convert to use runGitCommand
  • getAllLinkedBranches() - Convert to use runGitCommand
  • startDevelopWorkflow() - Convert to use runGitCommand

src/lib/repo-manager.ts

  • getGitDir() - Convert to use runGitCommand
  • isInGitRepo() - Convert to use runGitCommand
  • cloneBareRepo() - Convert to use runGitCommand
  • getCurrentRepoInfo() - Convert to use runGitCommand

Benefits

  • Consistency: All git commands use the same execution pattern
  • Testability: Easier to mock in tests (single point of mocking)
  • Maintainability: Centralized error handling and logging
  • Debugging: Unified command execution for easier debugging

Example Refactoring

Before:

const proc = Bun.spawn(['git', 'rev-parse', '--absolute-git-dir'], {
  stdout: 'pipe',
  stderr: 'pipe',
})
const exitCode = await proc.exited
const stdout = await new Response(proc.stdout).text()

After:

import { runGitCommand } from './git-exec'

const result = await runGitCommand(['git', 'rev-parse', '--absolute-git-dir'])
if (result.exitCode !== 0) {
  return null
}
return result.stdout.trim()

Acceptance Criteria

  • All Bun.spawn calls for git commands replaced with runGitCommand
  • Existing tests still pass
  • No behavior changes (pure refactoring)

Metadata

Metadata

Assignees

Labels

area:coreCore CLI functionalityp3Priority 3 - Lowtype:refactorCode refactoring without behavior change

Type

Fields

No fields configured for Chore.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions