repo

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SourceUnknown = iota
	SourceMemory
	SourceLocal
)

Variables

This section is empty.

Functions

func GetSSHKey

func GetSSHKey(filePath string, localfs afero.Fs) (*ssh.PublicKeys, error)

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 NewRepo

func NewRepo(props *props.Props, ops ...RepoOpt) (*Repo, error)

func (*Repo) AddToFS

func (r *Repo) AddToFS(fs afero.Fs, gitFile *object.File, fullPath string) error

AddToFS ensures that a git file is available in the afero filesystem.

func (*Repo) Checkout

func (r *Repo) Checkout(branch plumbing.ReferenceName) error

func (*Repo) CheckoutCommit

func (r *Repo) CheckoutCommit(hash plumbing.Hash) error

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

func (r *Repo) Commit(commitMsg string, opts *git.CommitOptions) (plumbing.Hash, error)

func (*Repo) CreateBranch

func (r *Repo) CreateBranch(branchName string) error

CreateBranch creates a branch in the git tree.

func (*Repo) CreateRemote

func (r *Repo) CreateRemote(name string, urls []string) (*git.Remote, error)

func (*Repo) DirectoryExists

func (r *Repo) DirectoryExists(relPath string) (bool, error)

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

func (r *Repo) FileExists(relPath string) (bool, error)

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

func (r *Repo) GetFile(relPath string) (*object.File, error)

GetFile retrieves a file from the git repository at the given relative path.

func (*Repo) GetRepo

func (r *Repo) GetRepo() *git.Repository

func (*Repo) GetTree

func (r *Repo) GetTree() *git.Worktree

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

func (r *Repo) OpenLocal(location string, branch string) (*git.Repository, *git.Worktree, error)

Open opens a local git repository. if no repo exists will init a repo.

func (*Repo) Push

func (r *Repo) Push(opts *git.PushOptions) error

func (*Repo) Remote

func (r *Repo) Remote(name string) (*git.Remote, error)

func (*Repo) SetBasicAuth

func (r *Repo) SetBasicAuth(username, password string)

func (*Repo) SetKey

func (r *Repo) SetKey(key *ssh.PublicKeys)

func (*Repo) SetRepo

func (r *Repo) SetRepo(repo *git.Repository)

func (*Repo) SetSource

func (r *Repo) SetSource(source int)

func (*Repo) SetTree

func (r *Repo) SetTree(tree *git.Worktree)

func (*Repo) SourceIs

func (r *Repo) SourceIs(source int) bool

func (*Repo) WalkTree

func (r *Repo) WalkTree(fn func(*object.File) error) error

WalkTree walks the git tree and calls the provided function for each file.

type RepoLike

type RepoLike interface {
	SourceIs(int) bool
	SetSource(int)
	SetRepo(*git.Repository)
	GetRepo() *git.Repository
	SetKey(*ssh.PublicKeys)
	SetBasicAuth(string, string)
	GetAuth() transport.AuthMethod
	SetTree(*git.Worktree)
	GetTree() *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
}

type RepoOpt

type RepoOpt func(*Repo) error

func WithConfig

func WithConfig(cfg *config.Config) RepoOpt

type RepoType

type RepoType = string
var (
	LocalRepo    RepoType = "local"
	InMemoryRepo RepoType = "inmemory"
)

Jump to

Keyboard shortcuts

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