git

package
v1.0.16 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package git provides Git operations for repository management

Index

Constants

This section is empty.

Variables

View Source
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

View Source
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 New

func New() (*Git, error)

New creates a new Git instance

func NewQuiet

func NewQuiet() (*Git, error)

NewQuiet creates a new Git instance that suppresses output

func NewQuietWithToken

func NewQuietWithToken(token string) (*Git, error)

NewQuietWithToken creates a new Git instance that suppresses output and uses auth token

func NewWithToken

func NewWithToken(token string) (*Git, error)

NewWithToken creates a new Git instance with authentication token

func (*Git) Clone

func (g *Git) Clone(ctx context.Context, url, targetDir string) error

Clone clones a repository to the target directory

func (*Git) Fetch

func (g *Git) Fetch(ctx context.Context, repoDir string) error

Fetch performs a git fetch in the specified directory

func (*Git) FetchAll

func (g *Git) FetchAll(ctx context.Context, repoDir string) error

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

func (g *Git) GetDefaultBranch(ctx context.Context, repoDir string) (string, error)

GetDefaultBranch returns the default branch of a repository

func (*Git) GetHEAD

func (g *Git) GetHEAD(ctx context.Context, repoDir string) (string, error)

GetHEAD returns the SHA of HEAD in the repository

func (*Git) GetLastFetchTime

func (g *Git) GetLastFetchTime(repoDir string) (time.Time, error)

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

func (g *Git) GetRemoteURL(ctx context.Context, repoDir string) (string, error)

GetRemoteURL returns the remote origin URL for a repository

func (*Git) IsGitRepo

func (g *Git) IsGitRepo(dir string) bool

IsGitRepo checks if a directory is a git repository

func (*Git) Pull

func (g *Git) Pull(ctx context.Context, repoDir string) error

Pull performs a git pull in the specified directory

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 NewLFS

func NewLFS(git *Git) *LFS

NewLFS creates a new LFS instance

func (*LFS) EnsureLFS

func (l *LFS) EnsureLFS(ctx context.Context) error

EnsureLFS ensures Git LFS is installed and configured

func (*LFS) Fetch

func (l *LFS) Fetch(ctx context.Context, repoDir string) error

Fetch runs 'git lfs fetch' to download LFS objects

func (*LFS) Initialize

func (l *LFS) Initialize(ctx context.Context) error

Initialize runs 'git lfs install' to set up Git LFS hooks

func (*LFS) Install

func (l *LFS) Install(ctx context.Context) error

Install attempts to install git-lfs using the system package manager

func (*LFS) IsInstalled

func (l *LFS) IsInstalled() bool

IsInstalled checks if git-lfs is installed

func (*LFS) Pull

func (l *LFS) Pull(ctx context.Context, repoDir string) error

Pull runs 'git lfs pull' to download LFS objects

func (*LFS) RepoUsesLFS

func (l *LFS) RepoUsesLFS(repoDir string) bool

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

func (*MockCommander) Output

func (m *MockCommander) Output(ctx context.Context, dir string, args ...string) (string, error)

Output implements Commander.Output

func (*MockCommander) Reset

func (m *MockCommander) Reset()

Reset clears all recorded calls

func (*MockCommander) Run

func (m *MockCommander) Run(ctx context.Context, dir string, args ...string) error

Run implements Commander.Run

type MockCommanderCall

type MockCommanderCall struct {
	Method string
	Dir    string
	Args   []string
}

MockCommanderCall records a method call

Jump to

Keyboard shortcuts

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