git

package
v0.0.0-...-551d305 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 25, 2026 License: MIT Imports: 15 Imported by: 9

README

git

Pure Go git operations using the go-git library, providing repository access, commit history, tag management, and branch comparison without shelling out to the git CLI.

Key Types

  • GitRepository -- Interface for all git operations
  • Repository -- go-git backed implementation of GitRepository
  • RepositoryManager -- Factory that opens/inits repos with shared logger
  • CommitInfo -- Commit metadata for changelog generation
  • MockRepository -- Builder-pattern test double with error injection
  • LazyRepo -- Lazy-initialized repo with test injection support
  • Clock -- Function type func() time.Time for injectable time source

Patterns

  • Interface abstraction: GitRepository enables mock injection in tests
  • Constructor injection: RepositoryManager injects logger and clock into all repos
  • Builder pattern: MockRepository uses With* methods for test setup
  • Lazy initialization: LazyRepo defers repo open until first access
  • Clock injection: RepositoryManager.WithClock() enables deterministic commit timestamps in tests

Internal Structure

File Responsibility
interface.go GitRepository interface definition
git.go Repository struct, basic info methods (RootPath, RemoteURL, CurrentBranch, HeadSHA), and shared helpers (resolveBaseRef, resolveToCommit, findMergeBase)
git_status.go Status and tracking operations (UncommittedFiles, TrackedFiles, StagedFiles, IsFileTracked, IsFileIgnored)
git_staging.go Staging and commit operations (ConfigSet, Add, Commit, AddRemote)
git_diff.go Diff and branch comparison operations (StagedDiff, StagedDiffStats, GetBranchCommits, GetBranchDiff, GetBranchDiffStats, GetBranchFiles, formatDiffStats)
manager.go RepositoryManager for opening and initializing repos
history.go Commit history, tag queries, and ref resolution
mock.go MockRepository with builder methods and error injection
testutil.go LazyRepo lazy-init helper for consumers
time.go Clock type definition for injectable time source

Dependencies

No internal repository imports -- this is a leaf package.

Role in System

This package is a foundational leaf dependency in the core module, providing git operations to higher-level packages like changedetect, changelog, and repository. The GitRepository interface allows the rest of the system to work against mocks in tests while using real go-git operations in production.

Code Health

Tech Debt
  • None -- time.go mutable var replaced with Clock type injected via RepositoryManager.WithClock() (TD-124)
Assessed and Accepted
  • mock.go (~490 lines) explicitly implements all 28 GitRepository interface methods. This was assessed as part of TD-124. Embedding a base type with default no-op implementations would reduce line count but would hide missing method implementations at compile time when the interface changes. The current explicit approach is verbose but provides immediate compiler errors on interface drift, which is the safer trade-off for a foundational package with many consumers.
Optimization Opportunities
  • No TODO/FIXME markers found -- codebase is clean of deferred work items

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clock

type Clock func() time.Time

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) Reset

func (lr *LazyRepo) Reset()

Reset clears the injected repository.

func (*LazyRepo) Set

func (lr *LazyRepo) Set(repo GitRepository)

Set injects a mock repository for testing.

type MockCommit

type MockCommit struct {
	Message     string
	AuthorName  string
	AuthorEmail string
	Hash        string
}

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) TagExists

func (m *MockRepository) TagExists(tagName string) (bool, 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 MockTag

type MockTag struct {
	CommitSHA string
	Date      time.Time
}

MockTag represents a mock tag for testing.

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) Add

func (r *Repository) Add(path string) error

Add stages a file for commit.

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL