summaryrefslogtreecommitdiff
path: root/internal/cli/git.go
blob: 4921a38b6f1e7ad7c8b038646f2d9e03408d5e66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Package cli — git abstraction for the CLI layer.
//
// This file defines the Gitter interface, which the CLI uses to abstract over
// real git operations (*git.Git) and no-op stubs (*git.NoOp).  The interface
// lives here in the consumer package (internal/cli) rather than in the
// producer package (internal/git), following Go best practice #6 from
// "100 Go Mistakes": interfaces should be defined where they are used, not
// where they are implemented.
//
// Keeping the interface here avoids tight coupling between internal/git and its
// callers: internal/git does not need to know who depends on it, and new
// consumers can define their own narrower interfaces as needed.
package cli

import (
	"context"

	"codeberg.org/snonux/foostore/internal/git"
)

// Gitter abstracts git operations so that the CLI dispatch logic works
// identically whether backed by a real git repository (*git.Git) or a no-op
// stub (*git.NoOp — used when the KeePass database file lives outside a repo).
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
}

// Compile-time assertions: both concrete git types must satisfy Gitter.
// These assertions live in the consumer (cli), not the producer (git),
// so that internal/git remains free of any dependency on this package.
var _ Gitter = (*git.Git)(nil)
var _ Gitter = (*git.NoOp)(nil)