repo

package
v0.0.0-...-2267940 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2025 License: Apache-2.0, MIT Imports: 20 Imported by: 5

Documentation

Index

Constants

View Source
const (
	DEFAULT_AUTHOR = "Catalyst Forge"
	DEFAULT_EMAIL  = "forge@projectcatalyst.io"
)

Variables

View Source
var (
	ErrTagNotFound = fmt.Errorf("tag not found")
)

Functions

func IsErrNoUpdates

func IsErrNoUpdates(err error) bool

IsErrNoUpdates returns true if the error is NoErrAlreadyUpToDate.

Types

type CloneOption

type CloneOption func(*gg.CloneOptions)

CloneOption is an option for cloning a repository.

func WithCloneDepth

func WithCloneDepth(depth int) CloneOption

WithCloneDepth sets the depth of the clone.

func WithRef

func WithRef(ref string) CloneOption

WithRef sets the reference name for the clone.

type FetchOption

type FetchOption func(*gg.FetchOptions)

FetchOption is an option for fetching a repository.

func WithFetchDepth

func WithFetchDepth(depth int) FetchOption

WithFetchDepth sets the depth of the fetch.

func WithRefSpec

func WithRefSpec(refSpec string) FetchOption

WithRefSpec sets the reference specification for the fetch.

func WithRemoteName

func WithRemoteName(name string) FetchOption

WithRemoteName sets the name of the remote to fetch.

type GitRepo

type GitRepo struct {
	// contains filtered or unexported fields
}

GitRepo is a high-level representation of a git repository.

func NewCachedRepo

func NewCachedRepo(url string, logger *slog.Logger, opts ...GitRepoOption) (GitRepo, error)

NewCachedRepo creates a new GitRepo instance that uses a predefined cache path. If the repository does not exist in the cache, it will be cloned. If the repository exists in the cache, it will be opened.

func NewGitRepo

func NewGitRepo(
	path string,
	logger *slog.Logger,
	opts ...GitRepoOption,
) (GitRepo, error)

NewGitRepo creates a new GitRepo instance.

func (*GitRepo) CheckoutBranch

func (g *GitRepo) CheckoutBranch(branch string) error

CheckoutBranch checks out a branch with the given name.

func (*GitRepo) CheckoutCommit

func (g *GitRepo) CheckoutCommit(hash string) error

CheckoutCommit checks out a commit with the given hash.

func (*GitRepo) CheckoutRef

func (g *GitRepo) CheckoutRef(reference string) error

CheckoutRef checks out a reference (commit, branch, or tag) with the given name.

func (*GitRepo) Clone

func (g *GitRepo) Clone(url string, opts ...CloneOption) error

Clone loads a repository from a git remote.

func (*GitRepo) Commit

func (g *GitRepo) Commit(msg string) (plumbing.Hash, error)

Commit creates a commit with the given message.

func (*GitRepo) CreateTag

func (g *GitRepo) CreateTag(name, hash, message string) error

CreateTag creates a tag with the given name and message.

func (*GitRepo) Exists

func (g *GitRepo) Exists(path string) (bool, error)

Exists checks if a file exists in the repository.

func (*GitRepo) Fetch

func (g *GitRepo) Fetch(opts ...FetchOption) error

Fetch fetches changes from the remote repository.

func (*GitRepo) FetchTags

func (g *GitRepo) FetchTags() error

FetchTags fetches tags from the remote repository.

func (*GitRepo) GetBranchReference

func (g *GitRepo) GetBranchReference(branchName string) (*plumbing.Reference, error)

GetBranchReference returns the reference for a given branch name.

func (*GitRepo) GetCommit

func (g *GitRepo) GetCommit(hash plumbing.Hash) (*object.Commit, error)

GetCommit returns the commit with the given hash.

func (*GitRepo) GetCurrentBranch

func (g *GitRepo) GetCurrentBranch() (string, error)

GetCurrentBranch returns the name of the current branch.

func (*GitRepo) GetCurrentTag

func (g *GitRepo) GetCurrentTag() (string, error)

GetCurrentTag returns the tag of the current HEAD commit, if it exists.

func (*GitRepo) GetTagCommit

func (g *GitRepo) GetTagCommit(tagName string) (*object.Commit, error)

GetTagCommit returns the commit object that the given tag is pointing to.

func (*GitRepo) GitFs

func (g *GitRepo) GitFs() fs.Filesystem

GitFs returns the filesystem for the .git directory.

func (*GitRepo) HasBranch

func (g *GitRepo) HasBranch(name string) (bool, error)

HasBranch returns true if the repository has a branch with the given name.

func (*GitRepo) HasChanges

func (g *GitRepo) HasChanges() (bool, error)

HasChanges returns true if the repository has changes.

func (*GitRepo) Head

func (g *GitRepo) Head() (*plumbing.Reference, error)

Head returns the HEAD reference of the current branch.

func (*GitRepo) Init

func (g *GitRepo) Init() error

Init initializes a new repository at the given path.

func (*GitRepo) ListTags

func (g *GitRepo) ListTags(fetch bool) ([]*object.Tag, error)

ListTags returns all annotated tags in the repository. If fetch is true, it will fetch tags from the remote repository before listing them. Lightweight tags are ignored and only annotated tag objects are returned.

func (*GitRepo) MkdirAll

func (g *GitRepo) MkdirAll(path string) error

MkdirAll creates a directory and all necessary parents.

func (*GitRepo) NewBranch

func (g *GitRepo) NewBranch(name string) error

NewBranch creates a new branch with the given name.

func (*GitRepo) NewTag

func (g *GitRepo) NewTag(commit plumbing.Hash, name, message string) (*plumbing.Reference, error)

NewTag creates a new tag with the given name and message.

func (*GitRepo) Open

func (g *GitRepo) Open() error

Open loads a repository from a local path.

func (*GitRepo) Patch

func (g *GitRepo) Patch(fromHash, toHash plumbing.Hash) (*object.Patch, error)

Patch generates a patch between two commits.

func (*GitRepo) PatchHead

func (g *GitRepo) PatchHead(fromHash plumbing.Hash) (*object.Patch, error)

PatchHead generates a patch between a given commit and the current HEAD.

func (*GitRepo) PatchToString

func (g *GitRepo) PatchToString(patch *object.Patch) string

PatchToString converts a patch to a unified diff string.

func (*GitRepo) Pull

func (g *GitRepo) Pull() error

Pull fetches changes from the remote repository and merges them into the current branch.

func (*GitRepo) Push

func (g *GitRepo) Push() error

Push pushes changes to the remote repository.

func (*GitRepo) Raw

func (g *GitRepo) Raw() *gg.Repository

Raw returns the underlying go-git repository.

func (*GitRepo) ReadDir

func (g *GitRepo) ReadDir(path string) ([]os.FileInfo, error)

ReadDir reads the contents of a directory in the repository.

func (*GitRepo) ReadFile

func (g *GitRepo) ReadFile(path string) ([]byte, error)

ReadFile reads the contents of a file in the repository.

func (*GitRepo) RemoveFile

func (g *GitRepo) RemoveFile(path string) error

RemoveFile removes a file from the repository.

func (*GitRepo) SetAuth

func (g *GitRepo) SetAuth(auth *http.BasicAuth)

SetAuth sets the authentication for the interacting with a remote repository.

func (*GitRepo) StageFile

func (g *GitRepo) StageFile(path string) error

StageFile adds a file to the staging area.

func (*GitRepo) UnstageFile

func (g *GitRepo) UnstageFile(path string) error

UnstageFile removes a file from the staging area.

func (*GitRepo) WalkTags

func (g *GitRepo) WalkTags(startTag, endTag *object.Tag) iter.Seq2[*object.Commit, error]

WalkTags walks the commits between two tags. Will return an error if the start tag is not an ancestor of the end tag.

func (*GitRepo) WorkFs

func (g *GitRepo) WorkFs() fs.Filesystem

WorkFs returns the filesystem for the working directory.

func (*GitRepo) WriteFile

func (g *GitRepo) WriteFile(path string, contents []byte) error

WriteFile writes the given contents to the given path in the repository. It also automatically adds the file to the staging area.

type GitRepoOption

type GitRepoOption func(*GitRepo)

func WithAuth

func WithAuth(username, password string) GitRepoOption

WithAuth sets the authentication for the interacting with a remote repository.

func WithAuthor

func WithAuthor(name, email string) GitRepoOption

WithAuthor sets the author for all commits.

func WithFS

func WithFS(fs fs.Filesystem) GitRepoOption

WithFS sets the filesystem for the repository.

func WithGitRemoteInteractor

func WithGitRemoteInteractor(remote remote.GitRemoteInteractor) GitRepoOption

WithGitRemoteInteractor sets the remote interactor for the repository.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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