summaryrefslogtreecommitdiff
path: root/internal/git/noop.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-04-17 09:04:29 +0300
committerPaul Buetow <paul@buetow.org>2026-04-17 09:04:29 +0300
commit58349705d5adafa60b8a1dddd0f5c72bad568d3b (patch)
treeeefad461de05ad027936c44a3f73925ed1fce652 /internal/git/noop.go
parenteb89e32c6675d4ed50f66580346e5ea8f3d7b5b2 (diff)
refactor: extract buildGeheimGit helper to keep buildGeheimBackend under 30 lines
Extracts a 3-line buildGeheimGit(cfg) helper from buildGeheimBackend, mirroring the existing buildKeepassGit pattern and satisfying the project guideline of keeping functions under 30 lines. Also includes the full o4 backend-abstraction changeset: Gitter interface, git.NoOp, --backend flag parsing, keepass backend wiring, and effectiveBackend guard for migrate-kdbx. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/git/noop.go')
-rw-r--r--internal/git/noop.go65
1 files changed, 65 insertions, 0 deletions
diff --git a/internal/git/noop.go b/internal/git/noop.go
new file mode 100644
index 0000000..44dc68c
--- /dev/null
+++ b/internal/git/noop.go
@@ -0,0 +1,65 @@
+package git
+
+import (
+ "context"
+ "fmt"
+)
+
+// noOpMessage is the message printed whenever a git operation is skipped
+// because the kdbx file is not inside a git repository.
+const noOpMessage = "kdbx file is not in a git repo; skipping"
+
+// NoOp is a Gitter implementation whose every method prints an informational
+// message and returns nil. It is used when the KeePass database file lives
+// outside of a git repository so that sync/status/commit/reset commands remain
+// functional and transparent rather than crashing or returning errors.
+//
+// Keeping the no-op behaviour in its own type (rather than nil-checking in the
+// CLI dispatch) respects the Open/Closed Principle: the CLI is open for
+// extension (new backends, new git behaviours) without modification.
+type NoOp struct{}
+
+// Compile-time assertion: *NoOp must satisfy Gitter.
+var _ Gitter = (*NoOp)(nil)
+
+// NewNoOp returns a *NoOp that satisfies Gitter with all operations being
+// informational no-ops.
+func NewNoOp() *NoOp {
+ return &NoOp{}
+}
+
+// Add prints the no-op message and returns nil.
+func (n *NoOp) Add(_ context.Context, _ string) error {
+ fmt.Printf("> %s\n", noOpMessage)
+ return nil
+}
+
+// Remove prints the no-op message and returns nil.
+func (n *NoOp) Remove(_ context.Context, _ string) error {
+ fmt.Printf("> %s\n", noOpMessage)
+ return nil
+}
+
+// Status prints the no-op message and returns nil.
+func (n *NoOp) Status(_ context.Context) error {
+ fmt.Printf("> %s\n", noOpMessage)
+ return nil
+}
+
+// Commit prints the no-op message and returns nil.
+func (n *NoOp) Commit(_ context.Context) error {
+ fmt.Printf("> %s\n", noOpMessage)
+ return nil
+}
+
+// Reset prints the no-op message and returns nil.
+func (n *NoOp) Reset(_ context.Context) error {
+ fmt.Printf("> %s\n", noOpMessage)
+ return nil
+}
+
+// Sync prints the no-op message and returns nil.
+func (n *NoOp) Sync(_ context.Context, _ []string) error {
+ fmt.Printf("> %s\n", noOpMessage)
+ return nil
+}