Documentation
¶
Overview ¶
Package git provides Git operations for repository management
Index ¶
- Variables
- type Commander
- type Git
- func (g *Git) Clone(ctx context.Context, url, targetDir string) error
- func (g *Git) Fetch(ctx context.Context, repoDir string) error
- func (g *Git) FetchAll(ctx context.Context, repoDir string) error
- func (g *Git) GetDefaultBranch(ctx context.Context, repoDir string) (string, error)
- func (g *Git) GetHEAD(ctx context.Context, repoDir string) (string, error)
- func (g *Git) GetLastFetchTime(repoDir string) (time.Time, error)
- func (g *Git) GetRemoteBranchSHA(ctx context.Context, repoDir, remote, branch string) (string, error)
- func (g *Git) GetRemoteURL(ctx context.Context, repoDir string) (string, error)
- func (g *Git) IsGitRepo(dir string) bool
- func (g *Git) Pull(ctx context.Context, repoDir string) error
- type LFS
- func (l *LFS) EnsureLFS(ctx context.Context) error
- func (l *LFS) Fetch(ctx context.Context, repoDir string) error
- func (l *LFS) Initialize(ctx context.Context) error
- func (l *LFS) Install(ctx context.Context) error
- func (l *LFS) IsInstalled() bool
- func (l *LFS) Pull(ctx context.Context, repoDir string) error
- func (l *LFS) RepoUsesLFS(repoDir string) bool
- type MockCommander
- type MockCommanderCall
Constants ¶
This section is empty.
Variables ¶
var ( ErrGitNotInstalled = errors.New("git is not installed or not in PATH") ErrNotAGitRepo = errors.New("not a git repository") ErrCloneFailed = errors.New("git clone failed") ErrPullFailed = errors.New("git pull failed") ErrFetchFailed = errors.New("git fetch failed") )
Common errors
var ( ErrLFSNotInstalled = errors.New("git-lfs is not installed") ErrLFSInstallFail = errors.New("failed to install git-lfs") )
Common LFS errors
Functions ¶
This section is empty.
Types ¶
type Commander ¶
type Commander interface {
// Run executes a git command and returns an error if it fails
Run(ctx context.Context, dir string, args ...string) error
// Output executes a git command and returns its output
Output(ctx context.Context, dir string, args ...string) (string, error)
}
Commander provides an interface for executing git commands This interface is used for mocking in tests
type Git ¶
type Git struct {
// GitPath is the path to the git executable
GitPath string
// Quiet suppresses stdout/stderr output (for TUI mode)
Quiet bool
// Token is the authentication token for HTTPS operations
Token string
}
Git provides Git operations
func NewQuietWithToken ¶
NewQuietWithToken creates a new Git instance that suppresses output and uses auth token
func NewWithToken ¶
NewWithToken creates a new Git instance with authentication token
func (*Git) FetchAll ¶
FetchAll fetches all branches from all remotes with pruning. This updates all remote-tracking branches without modifying the working directory. Use --prune to remove local references to branches deleted on remote.
func (*Git) GetDefaultBranch ¶
GetDefaultBranch returns the default branch of a repository
func (*Git) GetLastFetchTime ¶
GetLastFetchTime returns the modification time of .git/FETCH_HEAD, which indicates when the repository was last fetched. Returns zero time if never fetched.
func (*Git) GetRemoteBranchSHA ¶
func (g *Git) GetRemoteBranchSHA(ctx context.Context, repoDir, remote, branch string) (string, error)
GetRemoteBranchSHA returns the SHA of a remote-tracking branch (e.g., origin/main)
func (*Git) GetRemoteURL ¶
GetRemoteURL returns the remote origin URL for a repository
type LFS ¶
type LFS struct {
// LFSPath is the path to the git-lfs executable
LFSPath string
// Git is the underlying git instance
Git *Git
// Quiet suppresses stdout/stderr output (inherited from Git)
Quiet bool
}
LFS provides Git LFS operations
func (*LFS) Initialize ¶
Initialize runs 'git lfs install' to set up Git LFS hooks
func (*LFS) IsInstalled ¶
IsInstalled checks if git-lfs is installed
func (*LFS) RepoUsesLFS ¶
RepoUsesLFS checks if a repository uses Git LFS
type MockCommander ¶
type MockCommander struct {
// RunFunc is called when Run is invoked
RunFunc func(ctx context.Context, dir string, args ...string) error
// OutputFunc is called when Output is invoked
OutputFunc func(ctx context.Context, dir string, args ...string) (string, error)
// Calls records all method calls for verification
Calls []MockCommanderCall
}
MockCommander is a mock implementation of Commander for testing
func NewMockCommander ¶
func NewMockCommander() *MockCommander
NewMockCommander creates a new mock commander
func (*MockCommander) CallCount ¶
func (m *MockCommander) CallCount(method string) int
CallCount returns the number of times a method was called
type MockCommanderCall ¶
MockCommanderCall records a method call