Skip to content

refactor(git): consolidate ad-hoc git exec into internal/git#356

Merged
geodro merged 2 commits into
mainfrom
feat/git-service
May 15, 2026
Merged

refactor(git): consolidate ad-hoc git exec into internal/git#356
geodro merged 2 commits into
mainfrom
feat/git-service

Conversation

@geodro
Copy link
Copy Markdown
Owner

@geodro geodro commented May 15, 2026

Seven production call sites outside internal/git/ were spawning git via exec.Command directly, each with its own stdout/stderr wiring. This routes them through four new helpers in internal/git/exec.go so the package owns every git invocation in the codebase.

The new surface: Output(dir, args...) (string, error) captures stdout; Run(dir, log, args...) sends both stdout and stderr to a single writer (the modal-log pattern); RunTTY(dir, args...) wires stdout/stderr straight to the user's terminal so shell redirects still work; RunCaptureStderr(dir, args...) mirrors stdout to the terminal while teeing stderr into a buffer the caller inspects for git's "use --force" hint. BranchExists(dir, branch) wraps the show-ref --verify pattern.

Routed sites: internal/cli/worktree_ui.go (3 sites: branch-exists, worktree add, worktree remove), internal/cli/worktree_add.go (worktree add), internal/cli/worktree_remove.go (2 sites: worktree remove with force-detection plus the generic runGit), internal/ui/server.go (runGitOutput wraps Output). Each preserves the original cmd.Dir, stream wiring, and exit-code semantics. The only behaviour delta is the wrap text on errors (the helper picks the first non-flag arg for context, so "git remove: ..." reads as "git worktree: ..."), and no caller pattern-matches on that text.

geodro added 2 commits May 15, 2026 22:42
Seven production call sites outside internal/git/ were spawning git via exec.Command directly, each with its own stdout/stderr wiring. This routes them through four new helpers in internal/git/exec.go so the package owns every git invocation in the codebase.

The new surface: Output(dir, args...) (string, error) captures stdout; Run(dir, log, args...) sends both stdout and stderr to a single writer (the modal-log pattern); RunTTY(dir, args...) wires stdout/stderr straight to the user's terminal so shell redirects still work; RunCaptureStderr(dir, args...) mirrors stdout to the terminal while teeing stderr into a buffer the caller inspects for git's "use --force" hint. BranchExists(dir, branch) wraps the show-ref --verify pattern.

Routed sites: internal/cli/worktree_ui.go (3 sites: branch-exists, worktree add, worktree remove), internal/cli/worktree_add.go (worktree add), internal/cli/worktree_remove.go (2 sites: worktree remove with force-detection plus the generic runGit), internal/ui/server.go (runGitOutput wraps Output). Each preserves the original cmd.Dir, stream wiring, and exit-code semantics. The only behaviour delta is the wrap text on errors (the helper picks the first non-flag arg for context, so "git remove: ..." reads as "git worktree: ..."), and no caller pattern-matches on that text.
@geodro geodro merged commit 6c043c1 into main May 15, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant