From 58349705d5adafa60b8a1dddd0f5c72bad568d3b Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Fri, 17 Apr 2026 09:04:29 +0300 Subject: 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 --- internal/git/git_test.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'internal/git/git_test.go') diff --git a/internal/git/git_test.go b/internal/git/git_test.go index fa1f8f7..462c747 100644 --- a/internal/git/git_test.go +++ b/internal/git/git_test.go @@ -264,3 +264,49 @@ func TestSync_bad_remote(t *testing.T) { t.Fatal("expected error when syncing with a nonexistent remote, got nil") } } + +// TestIsGitRepo_inside verifies that IsGitRepo returns true for a directory +// that is a git repository. +func TestIsGitRepo_inside(t *testing.T) { + dir := initRepo(t) + if !git.IsGitRepo(dir) { + t.Errorf("expected IsGitRepo(%q) = true for a git repo, got false", dir) + } +} + +// TestIsGitRepo_outside verifies that IsGitRepo returns false for a plain +// directory that is not a git repository. +func TestIsGitRepo_outside(t *testing.T) { + dir := t.TempDir() // just a plain temp dir, not git-initialised + if git.IsGitRepo(dir) { + t.Errorf("expected IsGitRepo(%q) = false for a non-git dir, got true", dir) + } +} + +// TestNoOp_satisfies_Gitter verifies that *git.NoOp compiles as a Gitter and +// that all its methods return nil (no-op, no error) so they are safe to call +// unconditionally from CLI dispatch. +func TestNoOp_satisfies_Gitter(t *testing.T) { + var g git.Gitter = git.NewNoOp() + ctx := context.Background() + + table := []struct { + name string + fn func() error + }{ + {"Add", func() error { return g.Add(ctx, "/some/path") }}, + {"Remove", func() error { return g.Remove(ctx, "/some/path") }}, + {"Status", func() error { return g.Status(ctx) }}, + {"Commit", func() error { return g.Commit(ctx) }}, + {"Reset", func() error { return g.Reset(ctx) }}, + {"Sync", func() error { return g.Sync(ctx, []string{"origin"}) }}, + } + + for _, tt := range table { + t.Run(tt.name, func(t *testing.T) { + if err := tt.fn(); err != nil { + t.Errorf("NoOp.%s returned error: %v", tt.name, err) + } + }) + } +} -- cgit v1.2.3