From cfce2b1e706548491271640951309024755e8158 Mon Sep 17 00:00:00 2001 From: Steve Yegge Date: Sat, 1 Nov 2025 22:56:08 -0700 Subject: [PATCH] Add GitClient interface to daemonrunner/git.go for testability Amp-Thread-ID: https://ampcode.com/threads/T-3e38fcda-411e-41db-bfe4-eba7a7771b67 Co-authored-by: Amp --- internal/daemonrunner/git.go | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/internal/daemonrunner/git.go b/internal/daemonrunner/git.go index c84a8a2a..2094b8c5 100644 --- a/internal/daemonrunner/git.go +++ b/internal/daemonrunner/git.go @@ -8,6 +8,48 @@ import ( "time" ) +// GitClient provides an interface for git operations to enable testing +type GitClient interface { + HasUpstream() bool + HasChanges(ctx context.Context, filePath string) (bool, error) + Commit(ctx context.Context, filePath string, message string) error + Push(ctx context.Context) error + Pull(ctx context.Context) error +} + +// DefaultGitClient implements GitClient using os/exec +type DefaultGitClient struct{} + +// NewGitClient creates a new default git client +func NewGitClient() GitClient { + return &DefaultGitClient{} +} + +// HasUpstream checks if the current branch has an upstream configured +func (g *DefaultGitClient) HasUpstream() bool { + return gitHasUpstream() +} + +// HasChanges checks if the specified file has uncommitted changes +func (g *DefaultGitClient) HasChanges(ctx context.Context, filePath string) (bool, error) { + return gitHasChanges(ctx, filePath) +} + +// Commit commits the specified file +func (g *DefaultGitClient) Commit(ctx context.Context, filePath string, message string) error { + return gitCommit(ctx, filePath, message) +} + +// Push pushes to the current branch's upstream +func (g *DefaultGitClient) Push(ctx context.Context) error { + return gitPush(ctx) +} + +// Pull pulls from the current branch's upstream +func (g *DefaultGitClient) Pull(ctx context.Context) error { + return gitPull(ctx) +} + // isGitRepo checks if we're in a git repository func isGitRepo() bool { cmd := exec.Command("git", "rev-parse", "--git-dir")