Documentation
¶
Overview ¶
Package git provides Git operations using go-git library. This package uses ONLY pure go-git - no exec.Command calls. CLI layers (go/clibase/git/, go/cli/eac/impl/) may use exec.Command.
Index ¶
- type Clock
- type CommitInfo
- type GitBranchComparer
- type GitReader
- type GitReleaseQuerier
- type GitRepository
- type GitWriter
- type LazyRepo
- type MockCommit
- type MockRepository
- func (m *MockRepository) Add(path string) error
- func (m *MockRepository) AddRemote(name, url string) error
- func (m *MockRepository) AddedFiles() []string
- func (m *MockRepository) Commit(message, authorName, authorEmail string) (string, error)
- func (m *MockRepository) Commits() []MockCommit
- func (m *MockRepository) CommitsBetween(fromRef, toRef string) ([]CommitInfo, error)
- func (m *MockRepository) CommitsSince(ref string) ([]CommitInfo, error)
- func (m *MockRepository) Config(section, key string) (string, bool)
- func (m *MockRepository) ConfigSet(section, key, value string) error
- func (m *MockRepository) CurrentBranch() (string, error)
- func (m *MockRepository) GetBranchCommits(baseBranch string) ([]CommitInfo, error)
- func (m *MockRepository) GetBranchDiff(baseBranch string) (string, error)
- func (m *MockRepository) GetBranchDiffStats(baseBranch string) (string, error)
- func (m *MockRepository) GetBranchFiles(baseBranch string) ([]string, error)
- func (m *MockRepository) GoGitRepo() *gogit.Repository
- func (m *MockRepository) HeadCommit() (string, error)
- func (m *MockRepository) HeadShortSHA() (string, error)
- func (m *MockRepository) IsFileIgnored(relPath string) bool
- func (m *MockRepository) IsFileTracked(relPath string) bool
- func (m *MockRepository) LatestTag(pattern string) (string, error)
- func (m *MockRepository) RemoteURL(remoteName string) (string, error)
- func (m *MockRepository) RootPath() string
- func (m *MockRepository) StagedDiff() (string, error)
- func (m *MockRepository) StagedDiffStats() (string, error)
- func (m *MockRepository) StagedFiles() ([]string, error)
- func (m *MockRepository) TagCommit(tagName string) (string, error)
- func (m *MockRepository) TagDate(tagName string) (time.Time, error)
- func (m *MockRepository) TagExists(tagName string) (bool, error)
- func (m *MockRepository) TagsMatching(pattern string) ([]string, error)
- func (m *MockRepository) TrackedFiles() ([]string, error)
- func (m *MockRepository) UncommittedFiles() ([]string, error)
- func (m *MockRepository) UpstreamBranch() (string, error)
- func (m *MockRepository) WithBranchCommits(commits []CommitInfo) *MockRepository
- func (m *MockRepository) WithBranchDiff(diff string) *MockRepository
- func (m *MockRepository) WithBranchDiffStats(stats string) *MockRepository
- func (m *MockRepository) WithBranchFiles(files []string) *MockRepository
- func (m *MockRepository) WithCommitHistory(commits []CommitInfo) *MockRepository
- func (m *MockRepository) WithCurrentBranch(branch string) *MockRepository
- func (m *MockRepository) WithError(operation string, err error) *MockRepository
- func (m *MockRepository) WithHeadSHA(sha string) *MockRepository
- func (m *MockRepository) WithIgnoredFile(path string) *MockRepository
- func (m *MockRepository) WithIgnoredFiles(paths []string) *MockRepository
- func (m *MockRepository) WithRemote(name, url string) *MockRepository
- func (m *MockRepository) WithStagedDiff(diff string) *MockRepository
- func (m *MockRepository) WithStagedDiffStats(stats string) *MockRepository
- func (m *MockRepository) WithStagedFiles(files []string) *MockRepository
- func (m *MockRepository) WithTag(name, commitSHA string, date time.Time) *MockRepository
- func (m *MockRepository) WithTrackedFiles(files []string) *MockRepository
- func (m *MockRepository) WithUncommittedFiles(files []string) *MockRepository
- func (m *MockRepository) WithUpstreamBranch(branch string) *MockRepository
- type MockTag
- type Repository
- func (r *Repository) Add(path string) error
- func (r *Repository) AddRemote(name, url string) error
- func (r *Repository) Commit(message, authorName, authorEmail string) (string, error)
- func (r *Repository) CommitsBetween(fromRef, toRef string) ([]CommitInfo, error)
- func (r *Repository) CommitsSince(ref string) ([]CommitInfo, error)
- func (r *Repository) ConfigSet(section, key, value string) error
- func (r *Repository) CurrentBranch() (string, error)
- func (r *Repository) GetBranchCommits(baseBranch string) ([]CommitInfo, error)
- func (r *Repository) GetBranchDiff(baseBranch string) (string, error)
- func (r *Repository) GetBranchDiffStats(baseBranch string) (string, error)
- func (r *Repository) GetBranchFiles(baseBranch string) ([]string, error)
- func (r *Repository) GoGitRepo() *gogit.Repository
- func (r *Repository) HeadCommit() (string, error)
- func (r *Repository) HeadShortSHA() (string, error)
- func (r *Repository) IsFileIgnored(relPath string) bool
- func (r *Repository) IsFileTracked(relPath string) bool
- func (r *Repository) LatestTag(pattern string) (string, error)
- func (r *Repository) RemoteURL(remoteName string) (string, error)
- func (r *Repository) RootPath() string
- func (r *Repository) StagedDiff() (string, error)
- func (r *Repository) StagedDiffStats() (string, error)
- func (r *Repository) StagedFiles() ([]string, error)
- func (r *Repository) TagCommit(tagName string) (string, error)
- func (r *Repository) TagDate(tagName string) (time.Time, error)
- func (r *Repository) TagExists(tagName string) (bool, error)
- func (r *Repository) TagsMatching(pattern string) ([]string, error)
- func (r *Repository) TrackedFiles() ([]string, error)
- func (r *Repository) UncommittedFiles() ([]string, error)
- func (r *Repository) UpstreamBranch() (string, error)
- type RepositoryManager
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Clock ¶
Clock is a function that returns the current time. It is used by Repository to timestamp commits, enabling deterministic tests via constructor injection rather than mutable package-level state.
type CommitInfo ¶
type CommitInfo struct {
// SHA is the full commit hash
SHA string
// ShortSHA is the abbreviated commit hash (7 chars)
ShortSHA string
// Message is the full commit message
Message string
// Subject is the first line of the commit message
Subject string
// Author is the commit author name
Author string
// AuthorEmail is the commit author email
AuthorEmail string
// Date is the commit timestamp
Date time.Time
// Files is the list of files changed in this commit
Files []string
}
CommitInfo represents minimal commit information for changelog generation.
type GitBranchComparer ¶
type GitBranchComparer interface {
// GetBranchCommits returns all commits from baseBranch..HEAD.
// Returns commits in reverse chronological order (newest first).
// Returns error if baseBranch doesn't exist or no commits ahead.
GetBranchCommits(baseBranch string) ([]CommitInfo, error)
// GetBranchDiff returns the cumulative diff from baseBranch...HEAD.
// Uses three-dot notation to compare against merge-base.
GetBranchDiff(baseBranch string) (string, error)
// GetBranchDiffStats returns diff statistics from baseBranch...HEAD.
// Returns summary like "3 files changed, 45 insertions(+), 12 deletions(-)".
GetBranchDiffStats(baseBranch string) (string, error)
// GetBranchFiles returns list of files changed in baseBranch...HEAD.
// Returns relative paths from repository root.
GetBranchFiles(baseBranch string) ([]string, error)
// UpstreamBranch returns the upstream tracking branch for the current branch.
// Returns ("", err) when no upstream is configured (detached HEAD or local-only branch).
UpstreamBranch() (string, error)
}
GitBranchComparer provides branch comparison operations. Use this sub-interface for tools that compare branches, such as squash commit message generators and PR diff viewers.
type GitReader ¶
type GitReader interface {
// RootPath returns the repository root directory path.
RootPath() string
// RemoteURL returns the URL for the named remote (typically "origin").
RemoteURL(remoteName string) (string, error)
// CurrentBranch returns the current branch name.
// If in detached HEAD state, returns "detached-<short-sha>".
CurrentBranch() (string, error)
// HeadShortSHA returns the short SHA of the HEAD commit.
HeadShortSHA() (string, error)
// HeadCommit returns the full SHA of the HEAD commit.
HeadCommit() (string, error)
// UncommittedFiles returns paths of files with uncommitted changes.
// Uses git status --porcelain format parsing.
UncommittedFiles() ([]string, error)
// TrackedFiles returns all files tracked by Git (in the index).
TrackedFiles() ([]string, error)
// StagedFiles returns files currently staged in the index.
StagedFiles() ([]string, error)
// StagedDiff returns the unified diff of all staged changes.
// Equivalent to `git diff --staged`.
StagedDiff() (string, error)
// StagedDiffStats returns the stat summary of staged changes.
// Equivalent to `git diff --staged --stat`.
StagedDiffStats() (string, error)
// IsFileTracked checks if a specific file is tracked by Git.
IsFileTracked(relPath string) bool
// IsFileIgnored checks if a file matches .gitignore patterns.
IsFileIgnored(relPath string) bool
// GoGitRepo returns the underlying go-git repository for advanced operations.
// Returns nil for mock implementations.
GoGitRepo() *gogit.Repository
}
GitReader provides read-only repository state queries. Use this sub-interface when a consumer only needs to inspect repository state without modifying it (e.g., change detection, file listing, status checks).
type GitReleaseQuerier ¶
type GitReleaseQuerier interface {
// CommitsBetween returns commits between two references (tag/SHA/branch).
// If fromRef is empty, returns all commits up to toRef.
// Returns commits in reverse chronological order (newest first).
CommitsBetween(fromRef, toRef string) ([]CommitInfo, error)
// CommitsSince returns all commits since a given tag or reference.
CommitsSince(ref string) ([]CommitInfo, error)
// TagsMatching returns tags matching a glob pattern (e.g., "clie/*").
TagsMatching(pattern string) ([]string, error)
// LatestTag returns the most recent tag matching the pattern.
LatestTag(pattern string) (string, error)
// TagCommit returns the commit SHA that a tag points to.
TagCommit(tagName string) (string, error)
// TagDate returns the date of a tag.
TagDate(tagName string) (time.Time, error)
// TagExists checks if a tag with the given name exists.
TagExists(tagName string) (bool, error)
}
GitReleaseQuerier provides changelog and tag operations. Use this sub-interface for release tooling that needs to query commit history and tag information (e.g., changelog generation, version resolution).
type GitRepository ¶
type GitRepository interface {
GitReader
GitWriter
GitReleaseQuerier
GitBranchComparer
}
GitRepository is the full repository interface combining all capabilities. This allows mocking in tests and supports alternative implementations.
Consumers should prefer accepting the narrowest sub-interface that satisfies their needs (GitReader, GitWriter, GitReleaseQuerier, or GitBranchComparer) rather than requiring the full GitRepository. This follows the Interface Segregation Principle and makes dependencies explicit.
type GitWriter ¶
type GitWriter interface {
// Add stages a file for commit.
Add(path string) error
// Commit creates a new commit with the staged changes.
// Returns the commit hash.
Commit(message, authorName, authorEmail string) (string, error)
// AddRemote adds a new remote to the repository.
AddRemote(name, url string) error
// ConfigSet sets a Git configuration value.
ConfigSet(section, key, value string) error
}
GitWriter provides repository mutation operations. Use this sub-interface when a consumer needs to stage files, create commits, or modify repository configuration.
type LazyRepo ¶
type LazyRepo struct {
// contains filtered or unexported fields
}
LazyRepo provides a lazy-initialized git repository with test injection support. Each consumer gets its own LazyRepo instance as a package-level var.
Usage in consumer packages:
var gitRepoProvider = &git.LazyRepo{}
func getGitRepo(workspaceRoot string) (git.GitRepository, error) {
return gitRepoProvider.Get(workspaceRoot)
}
func SetGitRepo(repo git.GitRepository) {
gitRepoProvider.Set(repo)
}
func (*LazyRepo) Get ¶
func (lr *LazyRepo) Get(workspaceRoot string) (GitRepository, error)
Get returns the git repository, opening one at workspaceRoot if needed.
func (*LazyRepo) Set ¶
func (lr *LazyRepo) Set(repo GitRepository)
Set injects a mock repository for testing.
type MockCommit ¶
MockCommit records commit information for assertions.
type MockRepository ¶
type MockRepository struct {
// Error injection for testing failure paths
RemoteURLError error
CurrentBranchError error
HeadSHAError error
HeadCommitError error
UncommittedFilesError error
TrackedFilesError error
StagedFilesError error
StagedDiffError error
StagedDiffStatsError error
AddError error
CommitError error
ConfigSetError error
AddRemoteError error
CommitsBetweenError error
TagsMatchingError error
TagCommitError error
TagDateError error
GetBranchCommitsError error
GetBranchDiffError error
GetBranchDiffStatsError error
GetBranchFilesError error
UpstreamBranchError error
// contains filtered or unexported fields
}
MockRepository implements GitRepository for testing. Use the builder methods to configure behavior.
func NewMockRepository ¶
func NewMockRepository(rootPath string) *MockRepository
NewMockRepository creates a new mock repository with the given root path.
func (*MockRepository) Add ¶
func (m *MockRepository) Add(path string) error
func (*MockRepository) AddRemote ¶
func (m *MockRepository) AddRemote(name, url string) error
func (*MockRepository) AddedFiles ¶
func (m *MockRepository) AddedFiles() []string
AddedFiles returns the list of files that were added via Add().
func (*MockRepository) Commit ¶
func (m *MockRepository) Commit(message, authorName, authorEmail string) (string, error)
func (*MockRepository) Commits ¶
func (m *MockRepository) Commits() []MockCommit
Commits returns the list of commits made via Commit().
func (*MockRepository) CommitsBetween ¶
func (m *MockRepository) CommitsBetween(fromRef, toRef string) ([]CommitInfo, error)
func (*MockRepository) CommitsSince ¶
func (m *MockRepository) CommitsSince(ref string) ([]CommitInfo, error)
func (*MockRepository) Config ¶
func (m *MockRepository) Config(section, key string) (string, bool)
Config returns a config value that was set.
func (*MockRepository) ConfigSet ¶
func (m *MockRepository) ConfigSet(section, key, value string) error
func (*MockRepository) CurrentBranch ¶
func (m *MockRepository) CurrentBranch() (string, error)
func (*MockRepository) GetBranchCommits ¶
func (m *MockRepository) GetBranchCommits(baseBranch string) ([]CommitInfo, error)
GetBranchCommits returns the mock branch commits.
func (*MockRepository) GetBranchDiff ¶
func (m *MockRepository) GetBranchDiff(baseBranch string) (string, error)
GetBranchDiff returns the mock branch diff.
func (*MockRepository) GetBranchDiffStats ¶
func (m *MockRepository) GetBranchDiffStats(baseBranch string) (string, error)
GetBranchDiffStats returns the mock branch diff stats.
func (*MockRepository) GetBranchFiles ¶
func (m *MockRepository) GetBranchFiles(baseBranch string) ([]string, error)
GetBranchFiles returns the mock branch files.
func (*MockRepository) GoGitRepo ¶
func (m *MockRepository) GoGitRepo() *gogit.Repository
func (*MockRepository) HeadCommit ¶
func (m *MockRepository) HeadCommit() (string, error)
func (*MockRepository) HeadShortSHA ¶
func (m *MockRepository) HeadShortSHA() (string, error)
func (*MockRepository) IsFileIgnored ¶
func (m *MockRepository) IsFileIgnored(relPath string) bool
func (*MockRepository) IsFileTracked ¶
func (m *MockRepository) IsFileTracked(relPath string) bool
func (*MockRepository) LatestTag ¶
func (m *MockRepository) LatestTag(pattern string) (string, error)
func (*MockRepository) RemoteURL ¶
func (m *MockRepository) RemoteURL(remoteName string) (string, error)
func (*MockRepository) RootPath ¶
func (m *MockRepository) RootPath() string
func (*MockRepository) StagedDiff ¶
func (m *MockRepository) StagedDiff() (string, error)
func (*MockRepository) StagedDiffStats ¶
func (m *MockRepository) StagedDiffStats() (string, error)
func (*MockRepository) StagedFiles ¶
func (m *MockRepository) StagedFiles() ([]string, error)
func (*MockRepository) TagCommit ¶
func (m *MockRepository) TagCommit(tagName string) (string, error)
func (*MockRepository) TagDate ¶
func (m *MockRepository) TagDate(tagName string) (time.Time, error)
func (*MockRepository) TagsMatching ¶
func (m *MockRepository) TagsMatching(pattern string) ([]string, error)
func (*MockRepository) TrackedFiles ¶
func (m *MockRepository) TrackedFiles() ([]string, error)
func (*MockRepository) UncommittedFiles ¶
func (m *MockRepository) UncommittedFiles() ([]string, error)
func (*MockRepository) UpstreamBranch ¶
func (m *MockRepository) UpstreamBranch() (string, error)
UpstreamBranch returns the mock upstream tracking branch.
func (*MockRepository) WithBranchCommits ¶
func (m *MockRepository) WithBranchCommits(commits []CommitInfo) *MockRepository
WithBranchCommits sets the mock branch commits.
func (*MockRepository) WithBranchDiff ¶
func (m *MockRepository) WithBranchDiff(diff string) *MockRepository
WithBranchDiff sets the mock branch diff.
func (*MockRepository) WithBranchDiffStats ¶
func (m *MockRepository) WithBranchDiffStats(stats string) *MockRepository
WithBranchDiffStats sets the mock branch diff stats.
func (*MockRepository) WithBranchFiles ¶
func (m *MockRepository) WithBranchFiles(files []string) *MockRepository
WithBranchFiles sets the mock branch files.
func (*MockRepository) WithCommitHistory ¶
func (m *MockRepository) WithCommitHistory(commits []CommitInfo) *MockRepository
WithCommitHistory sets the commit history for CommitsBetween/CommitsSince.
func (*MockRepository) WithCurrentBranch ¶
func (m *MockRepository) WithCurrentBranch(branch string) *MockRepository
WithCurrentBranch sets the current branch name.
func (*MockRepository) WithError ¶
func (m *MockRepository) WithError(operation string, err error) *MockRepository
WithError sets an error for a specific operation.
func (*MockRepository) WithHeadSHA ¶
func (m *MockRepository) WithHeadSHA(sha string) *MockRepository
WithHeadSHA sets the HEAD commit SHA.
func (*MockRepository) WithIgnoredFile ¶
func (m *MockRepository) WithIgnoredFile(path string) *MockRepository
WithIgnoredFile marks a file as ignored.
func (*MockRepository) WithIgnoredFiles ¶
func (m *MockRepository) WithIgnoredFiles(paths []string) *MockRepository
WithIgnoredFiles marks multiple files as ignored.
func (*MockRepository) WithRemote ¶
func (m *MockRepository) WithRemote(name, url string) *MockRepository
WithRemote adds a remote URL.
func (*MockRepository) WithStagedDiff ¶
func (m *MockRepository) WithStagedDiff(diff string) *MockRepository
WithStagedDiff sets the staged diff content.
func (*MockRepository) WithStagedDiffStats ¶
func (m *MockRepository) WithStagedDiffStats(stats string) *MockRepository
WithStagedDiffStats sets the staged diff stats.
func (*MockRepository) WithStagedFiles ¶
func (m *MockRepository) WithStagedFiles(files []string) *MockRepository
WithStagedFiles sets the list of staged files.
func (*MockRepository) WithTag ¶
func (m *MockRepository) WithTag(name, commitSHA string, date time.Time) *MockRepository
WithTag adds a mock tag.
func (*MockRepository) WithTrackedFiles ¶
func (m *MockRepository) WithTrackedFiles(files []string) *MockRepository
WithTrackedFiles sets the list of tracked files.
func (*MockRepository) WithUncommittedFiles ¶
func (m *MockRepository) WithUncommittedFiles(files []string) *MockRepository
WithUncommittedFiles sets the list of uncommitted files.
func (*MockRepository) WithUpstreamBranch ¶
func (m *MockRepository) WithUpstreamBranch(branch string) *MockRepository
WithUpstreamBranch sets the mock upstream branch.
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
Repository wraps a go-git repository with convenience methods. Should be created via RepositoryManager for proper logger injection.
func (*Repository) AddRemote ¶
func (r *Repository) AddRemote(name, url string) error
AddRemote adds a new remote to the repository.
func (*Repository) Commit ¶
func (r *Repository) Commit(message, authorName, authorEmail string) (string, error)
Commit creates a new commit with the staged changes.
func (*Repository) CommitsBetween ¶
func (r *Repository) CommitsBetween(fromRef, toRef string) ([]CommitInfo, error)
CommitsBetween returns commits between two references (tag/SHA/branch). If fromRef is empty, returns all commits up to toRef. Returns commits in reverse chronological order (newest first).
func (*Repository) CommitsSince ¶
func (r *Repository) CommitsSince(ref string) ([]CommitInfo, error)
CommitsSince returns all commits since a given tag or reference. This is a convenience wrapper around CommitsBetween.
func (*Repository) ConfigSet ¶
func (r *Repository) ConfigSet(section, key, value string) error
ConfigSet sets a Git configuration value.
func (*Repository) CurrentBranch ¶
func (r *Repository) CurrentBranch() (string, error)
CurrentBranch returns the current branch name. If in detached HEAD state, returns "detached-<short-sha>".
func (*Repository) GetBranchCommits ¶
func (r *Repository) GetBranchCommits(baseBranch string) ([]CommitInfo, error)
GetBranchCommits returns all commits from baseBranch..HEAD. Returns commits in reverse chronological order (newest first). Returns error if baseBranch doesn't exist or no commits ahead.
func (*Repository) GetBranchDiff ¶
func (r *Repository) GetBranchDiff(baseBranch string) (string, error)
GetBranchDiff returns the cumulative diff from baseBranch...HEAD. Uses three-dot notation semantics (compare against merge-base).
func (*Repository) GetBranchDiffStats ¶
func (r *Repository) GetBranchDiffStats(baseBranch string) (string, error)
GetBranchDiffStats returns diff statistics from baseBranch...HEAD. Returns summary like "3 files changed, 45 insertions(+), 12 deletions(-)".
func (*Repository) GetBranchFiles ¶
func (r *Repository) GetBranchFiles(baseBranch string) ([]string, error)
GetBranchFiles returns list of files changed in baseBranch...HEAD. Returns relative paths from repository root.
func (*Repository) GoGitRepo ¶
func (r *Repository) GoGitRepo() *gogit.Repository
GoGitRepo returns the underlying go-git repository for advanced operations. Use sparingly - prefer the wrapper methods when possible.
func (*Repository) HeadCommit ¶
func (r *Repository) HeadCommit() (string, error)
HeadCommit returns the full SHA of the HEAD commit.
func (*Repository) HeadShortSHA ¶
func (r *Repository) HeadShortSHA() (string, error)
HeadShortSHA returns the short SHA of the HEAD commit.
func (*Repository) IsFileIgnored ¶
func (r *Repository) IsFileIgnored(relPath string) bool
IsFileIgnored checks if a file matches .gitignore patterns.
func (*Repository) IsFileTracked ¶
func (r *Repository) IsFileTracked(relPath string) bool
IsFileTracked checks if a specific file is tracked by Git (in the index). This reflects the current index state, accounting for staged additions and deletions.
func (*Repository) LatestTag ¶
func (r *Repository) LatestTag(pattern string) (string, error)
LatestTag returns the most recent tag matching the pattern. Returns empty string if no matching tags found.
func (*Repository) RemoteURL ¶
func (r *Repository) RemoteURL(remoteName string) (string, error)
RemoteURL returns the URL for the named remote (typically "origin").
func (*Repository) RootPath ¶
func (r *Repository) RootPath() string
RootPath returns the repository root directory path.
func (*Repository) StagedDiff ¶
func (r *Repository) StagedDiff() (string, error)
StagedDiff returns the unified diff of all staged changes. Equivalent to `git diff --staged`.
func (*Repository) StagedDiffStats ¶
func (r *Repository) StagedDiffStats() (string, error)
StagedDiffStats returns the stat summary of staged changes. Equivalent to `git diff --staged --stat`.
func (*Repository) StagedFiles ¶
func (r *Repository) StagedFiles() ([]string, error)
StagedFiles returns files currently staged in the index (added, modified, renamed, copied). This corresponds to `git diff --cached --name-only --diff-filter=ACMR`.
func (*Repository) TagCommit ¶
func (r *Repository) TagCommit(tagName string) (string, error)
TagCommit returns the commit SHA that a tag points to. Works for both lightweight and annotated tags.
func (*Repository) TagDate ¶
func (r *Repository) TagDate(tagName string) (time.Time, error)
TagDate returns the date of a tag. For annotated tags, returns the tag date; for lightweight tags, returns the commit date.
func (*Repository) TagExists ¶
func (r *Repository) TagExists(tagName string) (bool, error)
TagExists checks if a tag with the given name exists.
func (*Repository) TagsMatching ¶
func (r *Repository) TagsMatching(pattern string) ([]string, error)
TagsMatching returns tags matching a glob pattern (e.g., "clie/*"). Tags are returned sorted by version (newest first for semver).
func (*Repository) TrackedFiles ¶
func (r *Repository) TrackedFiles() ([]string, error)
TrackedFiles returns all files tracked by Git (in the index). This reflects the current index state: HEAD files + staged additions - staged deletions.
func (*Repository) UncommittedFiles ¶
func (r *Repository) UncommittedFiles() ([]string, error)
UncommittedFiles returns paths of files with uncommitted changes. This includes staged, unstaged, and untracked files.
func (*Repository) UpstreamBranch ¶
func (r *Repository) UpstreamBranch() (string, error)
UpstreamBranch returns the upstream tracking branch for the current branch. Returns ("", err) when no upstream is configured (detached HEAD or local-only branch).
type RepositoryManager ¶
type RepositoryManager struct {
// contains filtered or unexported fields
}
RepositoryManager manages git repository instances with shared logging configuration. It implements constructor-based dependency injection where the logger is provided once during manager creation and shared across all repository instances.
Usage:
// Create manager once with logger gitMgr := git.NewManager(logging.C().Zap()) // Open repositories as needed - all share the manager's logger repo, err := gitMgr.Open(workspaceRoot) files, _ := repo.StagedFiles() diff, _ := repo.StagedDiff() // Can open multiple repos with same logger repo2, err := gitMgr.Open(otherPath)
func NewManager ¶
func NewManager(logger *zap.Logger) *RepositoryManager
NewManager creates a new RepositoryManager with the given logger. If logger is nil, a no-op logger is used (no logging output).
This follows constructor-based dependency injection: - Logger is provided once during manager creation - All repositories created by this manager share the same logger - No nil checks needed in repository methods
Example:
// With logging (commands layer) mgr := git.NewManager(logging.C().Zap()) // Without logging (core-to-core calls) mgr := git.NewManager(nil)
func (*RepositoryManager) Init ¶
func (m *RepositoryManager) Init(path string) (*Repository, error)
Init initializes a new Git repository at the given path. If path is empty, uses the current working directory.
The returned repository shares this manager's logger configuration.
Example:
mgr := git.NewManager(logger)
repo, err := mgr.Init("/path/to/new/repo")
if err != nil {
return fmt.Errorf("failed to init repository: %w", err)
}
func (*RepositoryManager) Open ¶
func (m *RepositoryManager) Open(path string) (*Repository, error)
Open opens an existing Git repository at the given path. If path is empty, uses the current working directory. It searches upward through parent directories to find the repository root.
The returned repository shares this manager's logger configuration.
Example:
mgr := git.NewManager(logger)
repo, err := mgr.Open("/path/to/workspace")
if err != nil {
return fmt.Errorf("failed to open repository: %w", err)
}
func (*RepositoryManager) WithClock ¶
func (m *RepositoryManager) WithClock(c Clock) *RepositoryManager
WithClock returns a copy of the manager that injects the given clock into every repository it creates. This is intended for tests that need deterministic timestamps without mutable package-level state.
Example:
fixed := time.Date(2024, 1, 1, 12, 0, 0, 0, time.UTC)
mgr := git.NewManager(nil).WithClock(func() time.Time { return fixed })
repo, _ := mgr.Init(tmpDir)
// repo.Commit(...) will use the fixed time