refactor(git): consolidate ad-hoc git exec into internal/git#356
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.