Documentation
¶
Overview ¶
Package repo provides repository URL parsing and metadata extraction, converting host/owner/repo paths into a RepoLike abstraction that supports both GitHub (org/repo) and GitLab (group/subgroup/repo) path formats.
Index ¶
- Constants
- Variables
- func GetSSHKey(filePath string, localfs afero.Fs) (*ssh.PublicKeys, error)
- type CloneOption
- type Repo
- func (r *Repo) AddToFS(fs afero.Fs, gitFile *object.File, fullPath string) error
- func (r *Repo) Checkout(branch plumbing.ReferenceName) error
- func (r *Repo) CheckoutCommit(hash plumbing.Hash) error
- func (r *Repo) Clone(uri string, targetPath string, opts ...CloneOption) (*git.Repository, *git.Worktree, error)
- func (r *Repo) Commit(commitMsg string, opts *git.CommitOptions) (plumbing.Hash, error)
- func (r *Repo) CreateBranch(branchName string) error
- func (r *Repo) CreateRemote(name string, urls []string) (*git.Remote, error)
- func (r *Repo) DirectoryExists(relPath string) (bool, error)
- func (r *Repo) FileExists(relPath string) (bool, error)
- func (r *Repo) GetAuth() transport.AuthMethod
- func (r *Repo) GetFile(relPath string) (*object.File, error)
- func (r *Repo) Open(repoType RepoType, location string, branch string, opts ...CloneOption) (*git.Repository, *git.Worktree, error)
- func (r *Repo) OpenInMemory(location string, branch string, opts ...CloneOption) (*git.Repository, *git.Worktree, error)
- func (r *Repo) OpenLocal(location string, branch string) (*git.Repository, *git.Worktree, error)
- func (r *Repo) Push(opts *git.PushOptions) error
- func (r *Repo) Remote(name string) (*git.Remote, error)
- func (r *Repo) SetBasicAuth(username, password string)
- func (r *Repo) SetKey(key *ssh.PublicKeys)
- func (r *Repo) SetRepo(repo *git.Repository)
- func (r *Repo) SetSource(source int)
- func (r *Repo) SetTree(tree *git.Worktree)
- func (r *Repo) SourceIs(source int) bool
- func (r *Repo) WalkTree(fn func(*object.File) error) error
- func (r *Repo) WithRepo(fn func(*git.Repository) error) error
- func (r *Repo) WithTree(fn func(*git.Worktree) error) error
- type RepoLike
- type RepoOpt
- type RepoType
- type ThreadSafeRepo
- func (r *ThreadSafeRepo) AddToFS(fs afero.Fs, gitFile *object.File, fullPath string) error
- func (r *ThreadSafeRepo) Checkout(branch plumbing.ReferenceName) error
- func (r *ThreadSafeRepo) CheckoutCommit(hash plumbing.Hash) error
- func (r *ThreadSafeRepo) Clone(uri string, targetPath string, opts ...CloneOption) (*git.Repository, *git.Worktree, error)
- func (r *ThreadSafeRepo) Commit(commitMsg string, opts *git.CommitOptions) (plumbing.Hash, error)
- func (r *ThreadSafeRepo) CreateBranch(branchName string) error
- func (r *ThreadSafeRepo) DirectoryExists(relPath string) (bool, error)
- func (r *ThreadSafeRepo) FileExists(relPath string) (bool, error)
- func (r *ThreadSafeRepo) GetAuth() transport.AuthMethod
- func (r *ThreadSafeRepo) GetFile(relPath string) (*object.File, error)
- func (r *ThreadSafeRepo) Open(repoType RepoType, location string, branch string, opts ...CloneOption) (*git.Repository, *git.Worktree, error)
- func (r *ThreadSafeRepo) OpenInMemory(location string, branch string, opts ...CloneOption) (*git.Repository, *git.Worktree, error)
- func (r *ThreadSafeRepo) OpenLocal(location string, branch string) (*git.Repository, *git.Worktree, error)
- func (r *ThreadSafeRepo) Push(opts *git.PushOptions) error
- func (r *ThreadSafeRepo) SetBasicAuth(username, password string)
- func (r *ThreadSafeRepo) SetKey(key *ssh.PublicKeys)
- func (r *ThreadSafeRepo) SetRepo(repo *git.Repository)
- func (r *ThreadSafeRepo) SetSource(source int)
- func (r *ThreadSafeRepo) SetTree(tree *git.Worktree)
- func (r *ThreadSafeRepo) SourceIs(source int) bool
- func (r *ThreadSafeRepo) WalkTree(fn func(*object.File) error) error
- func (r *ThreadSafeRepo) WithRepo(fn func(*git.Repository) error) error
- func (r *ThreadSafeRepo) WithTree(fn func(*git.Worktree) error) error
Constants ¶
const ( SourceUnknown = iota SourceMemory SourceLocal )
Variables ¶
var ( // ErrNoRepository is returned by WithRepo when no *git.Repository has been set. ErrNoRepository = errors.New("repository not initialised; call Open, Clone, or SetRepo first") // ErrNoWorktree is returned by WithTree when no *git.Worktree has been set. ErrNoWorktree = errors.New("worktree not initialised; call Open, Clone, or SetTree first") )
Functions ¶
Types ¶
type CloneOption ¶
type CloneOption func(*git.CloneOptions)
CloneOption represents a function that configures clone options.
func WithNoTags ¶
func WithNoTags() CloneOption
WithNoTags configures the clone to skip fetching tags.
func WithRecurseSubmodules ¶
func WithRecurseSubmodules() CloneOption
WithRecurseSubmodules configures recursive submodule cloning.
func WithShallowClone ¶
func WithShallowClone(depth int) CloneOption
WithShallowClone configures a shallow clone with the specified depth.
func WithSingleBranch ¶
func WithSingleBranch(branch string) CloneOption
WithSingleBranch configures the clone to only fetch a single branch.
type Repo ¶
type Repo struct {
// contains filtered or unexported fields
}
func (*Repo) CheckoutCommit ¶
CheckoutCommit checks out a specific commit by hash.
func (*Repo) Clone ¶
func (r *Repo) Clone(uri string, targetPath string, opts ...CloneOption) (*git.Repository, *git.Worktree, error)
Clone clones a git repository to a target path on the filesystem Supports both remote URLs and local git repository paths with clone options.
func (*Repo) CreateBranch ¶
CreateBranch creates a branch in the git tree.
func (*Repo) CreateRemote ¶
func (*Repo) DirectoryExists ¶
DirectoryExists checks if a directory exists in the git repository at the given relative path In git, directories don't exist as separate entities - we check if any files exist under the path.
func (*Repo) FileExists ¶
FileExists checks if a file exists in the git repository at the given relative path.
func (*Repo) GetAuth ¶
func (r *Repo) GetAuth() transport.AuthMethod
func (*Repo) Open ¶
func (r *Repo) Open(repoType RepoType, location string, branch string, opts ...CloneOption) (*git.Repository, *git.Worktree, error)
Open opens a local git repository. if no repo exists will init a repo.
func (*Repo) OpenInMemory ¶
func (r *Repo) OpenInMemory(location string, branch string, opts ...CloneOption) (*git.Repository, *git.Worktree, error)
func (*Repo) SetBasicAuth ¶
func (*Repo) SetKey ¶
func (r *Repo) SetKey(key *ssh.PublicKeys)
func (*Repo) SetRepo ¶
func (r *Repo) SetRepo(repo *git.Repository)
func (*Repo) WithRepo ¶ added in v1.8.0
func (r *Repo) WithRepo(fn func(*git.Repository) error) error
WithRepo calls fn with the underlying *git.Repository. Repo is not safe for concurrent use; callers are responsible for external synchronisation if sharing a *Repo across goroutines.
Returns ErrNoRepository if the repository has not been initialised.
type RepoLike ¶
type RepoLike interface {
SourceIs(int) bool
SetSource(int)
SetRepo(*git.Repository)
SetKey(*ssh.PublicKeys)
SetBasicAuth(string, string)
GetAuth() transport.AuthMethod
SetTree(*git.Worktree)
Checkout(plumbing.ReferenceName) error
CheckoutCommit(plumbing.Hash) error
CreateBranch(string) error
Push(*git.PushOptions) error
Commit(string, *git.CommitOptions) (plumbing.Hash, error)
OpenInMemory(string, string, ...CloneOption) (*git.Repository, *git.Worktree, error)
OpenLocal(string, string) (*git.Repository, *git.Worktree, error)
Open(RepoType, string, string, ...CloneOption) (*git.Repository, *git.Worktree, error)
Clone(string, string, ...CloneOption) (*git.Repository, *git.Worktree, error)
// Git tree operations for in-memory repositories
WalkTree(func(*object.File) error) error
FileExists(string) (bool, error)
DirectoryExists(string) (bool, error)
GetFile(string) (*object.File, error)
AddToFS(fs afero.Fs, gitFile *object.File, fullPath string) error
// WithRepo calls fn with the underlying *git.Repository.
// Returns ErrNoRepository if the repository has not been initialised.
WithRepo(func(*git.Repository) error) error
// WithTree calls fn with the underlying *git.Worktree.
// Returns ErrNoWorktree if the worktree has not been initialised.
WithTree(func(*git.Worktree) error) error
}
type RepoOpt ¶
func WithConfig ¶
type ThreadSafeRepo ¶ added in v1.8.0
type ThreadSafeRepo struct {
// contains filtered or unexported fields
}
ThreadSafeRepo wraps a *Repo with a mutex so that all RepoLike methods are safe to call concurrently from multiple goroutines.
Thread-safety guarantee ¶
Every method acquires the internal mutex for its full duration. Concurrent callers are serialised; no two calls to any method execute simultaneously.
WithRepo and WithTree ¶
These are the only way to interact with the underlying go-git objects safely. The callback executes while the mutex is held. Callers must not:
- Retain the pointer after the callback returns.
- Call any ThreadSafeRepo method from inside the callback (deadlock).
- Spawn goroutines inside the callback that access the pointer after it returns.
go-git concurrency model ¶
go-git mutates internal caches during read operations. ThreadSafeRepo uses sync.Mutex (exclusive) rather than sync.RWMutex; concurrent reads are not permitted.
func NewThreadSafeRepo ¶ added in v1.8.0
func NewThreadSafeRepo(p *props.Props, opts ...RepoOpt) (*ThreadSafeRepo, error)
NewThreadSafeRepo creates a ThreadSafeRepo backed by a freshly constructed *Repo. The props and opts arguments have the same semantics as NewRepo.
func (*ThreadSafeRepo) Checkout ¶ added in v1.8.0
func (r *ThreadSafeRepo) Checkout(branch plumbing.ReferenceName) error
func (*ThreadSafeRepo) CheckoutCommit ¶ added in v1.8.0
func (r *ThreadSafeRepo) CheckoutCommit(hash plumbing.Hash) error
func (*ThreadSafeRepo) Clone ¶ added in v1.8.0
func (r *ThreadSafeRepo) Clone(uri string, targetPath string, opts ...CloneOption) (*git.Repository, *git.Worktree, error)
func (*ThreadSafeRepo) Commit ¶ added in v1.8.0
func (r *ThreadSafeRepo) Commit(commitMsg string, opts *git.CommitOptions) (plumbing.Hash, error)
func (*ThreadSafeRepo) CreateBranch ¶ added in v1.8.0
func (r *ThreadSafeRepo) CreateBranch(branchName string) error
func (*ThreadSafeRepo) DirectoryExists ¶ added in v1.8.0
func (r *ThreadSafeRepo) DirectoryExists(relPath string) (bool, error)
func (*ThreadSafeRepo) FileExists ¶ added in v1.8.0
func (r *ThreadSafeRepo) FileExists(relPath string) (bool, error)
func (*ThreadSafeRepo) GetAuth ¶ added in v1.8.0
func (r *ThreadSafeRepo) GetAuth() transport.AuthMethod
func (*ThreadSafeRepo) GetFile ¶ added in v1.8.0
func (r *ThreadSafeRepo) GetFile(relPath string) (*object.File, error)
func (*ThreadSafeRepo) Open ¶ added in v1.8.0
func (r *ThreadSafeRepo) Open(repoType RepoType, location string, branch string, opts ...CloneOption) (*git.Repository, *git.Worktree, error)
func (*ThreadSafeRepo) OpenInMemory ¶ added in v1.8.0
func (r *ThreadSafeRepo) OpenInMemory(location string, branch string, opts ...CloneOption) (*git.Repository, *git.Worktree, error)
func (*ThreadSafeRepo) OpenLocal ¶ added in v1.8.0
func (r *ThreadSafeRepo) OpenLocal(location string, branch string) (*git.Repository, *git.Worktree, error)
func (*ThreadSafeRepo) Push ¶ added in v1.8.0
func (r *ThreadSafeRepo) Push(opts *git.PushOptions) error
func (*ThreadSafeRepo) SetBasicAuth ¶ added in v1.8.0
func (r *ThreadSafeRepo) SetBasicAuth(username, password string)
func (*ThreadSafeRepo) SetKey ¶ added in v1.8.0
func (r *ThreadSafeRepo) SetKey(key *ssh.PublicKeys)
func (*ThreadSafeRepo) SetRepo ¶ added in v1.8.0
func (r *ThreadSafeRepo) SetRepo(repo *git.Repository)
func (*ThreadSafeRepo) SetSource ¶ added in v1.8.0
func (r *ThreadSafeRepo) SetSource(source int)
func (*ThreadSafeRepo) SetTree ¶ added in v1.8.0
func (r *ThreadSafeRepo) SetTree(tree *git.Worktree)
func (*ThreadSafeRepo) SourceIs ¶ added in v1.8.0
func (r *ThreadSafeRepo) SourceIs(source int) bool
func (*ThreadSafeRepo) WalkTree ¶ added in v1.8.0
func (r *ThreadSafeRepo) WalkTree(fn func(*object.File) error) error
func (*ThreadSafeRepo) WithRepo ¶ added in v1.8.0
func (r *ThreadSafeRepo) WithRepo(fn func(*git.Repository) error) error
WithRepo acquires the mutex and calls fn with the underlying *git.Repository. The callback executes while the lock is held.
Returns ErrNoRepository if the repository has not been initialised.
func (*ThreadSafeRepo) WithTree ¶ added in v1.8.0
func (r *ThreadSafeRepo) WithTree(fn func(*git.Worktree) error) error
WithTree acquires the mutex and calls fn with the underlying *git.Worktree. The callback executes while the lock is held.
Returns ErrNoWorktree if the worktree has not been initialised.