summaryrefslogtreecommitdiff
path: root/internal/git/git.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-04-18 08:47:27 +0300
committerPaul Buetow <paul@buetow.org>2026-04-18 08:47:27 +0300
commit60f717b97ce6c375679080472750e60aab9dcd8f (patch)
treeb1028ea0e51ce6134ed3ea06da2a7205457319c5 /internal/git/git.go
parent526e3bd1bea7e2ef67c6984b91cdb9b3ac3be4e5 (diff)
refactor: move Gitter interface to consumer package internal/cli (task p6)
Per Go best practice (100 Go Mistakes #6): interfaces belong where they are used, not where they are implemented. Move Gitter from internal/git to internal/cli/git.go. Compile-time assertions (var _ Gitter = ...) kept in the new location. internal/git retains concrete *Git and *NoOp types. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/git/git.go')
-rw-r--r--internal/git/git.go34
1 files changed, 4 insertions, 30 deletions
diff --git a/internal/git/git.go b/internal/git/git.go
index 72d55af..e9a1b9b 100644
--- a/internal/git/git.go
+++ b/internal/git/git.go
@@ -2,10 +2,10 @@
// It mirrors the Git module from the original Ruby implementation (geheim.rb lines 79-123),
// running real git subprocesses rather than using a Go git library.
//
-// The package exposes a Gitter interface so that callers can accept either a
-// real *Git (backed by a git repository) or a *NoOp stub (for directories that
-// are not git repositories). This avoids nil-pointer panics in the CLI dispatch
-// loop and keeps git-related decisions local to this package.
+// The package exposes concrete types (*Git and *NoOp) but does NOT define a
+// Gitter interface. Per Go best practices (100 Go Mistakes #6), interfaces
+// belong in the consumer package — the Gitter interface lives in internal/cli,
+// which is the only package that needs to abstract over *Git vs *NoOp.
package git
import (
@@ -18,37 +18,11 @@ import (
"strings"
)
-// Gitter is the interface that both *Git (real git operations) and *NoOp
-// (informational no-ops) implement. The CLI holds a Gitter so that it can be
-// freely swapped without changing any dispatch logic.
-type Gitter interface {
- // Add stages a single file for the next commit.
- Add(ctx context.Context, filePath string) error
-
- // Remove stages a file deletion for the next commit.
- Remove(ctx context.Context, filePath string) error
-
- // Status prints the current git status of the working directory.
- Status(ctx context.Context) error
-
- // Commit records all staged changes with a generic commit message.
- Commit(ctx context.Context) error
-
- // Reset discards all uncommitted changes in the working directory.
- Reset(ctx context.Context) error
-
- // Sync pulls from and pushes to each configured remote repository.
- Sync(ctx context.Context, syncRepos []string) error
-}
-
// Git provides git operations scoped to the secret store's data directory.
type Git struct {
dataDir string
}
-// Compile-time assertion: *Git must satisfy Gitter.
-var _ Gitter = (*Git)(nil)
-
// New creates a Git helper for the given data directory.
func New(dataDir string) *Git {
return &Git{dataDir: dataDir}