git

package
v0.0.0-...-380f8d5 Latest Latest
Warning

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

Go to latest
Published: May 7, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Checkout = sh.RunCmd("git", "checkout")
	Branch   = sh.OutCmd("git", "rev-parse", "--abbrev-ref", "HEAD")
)
View Source
var Email = "unknown@github"
View Source
var (
	ErrCommitNotDefined = errors.New("commit not defined")
)
View Source
var ErrNotAGitRepo = errors.New("not a git repo")
View Source
var Name = "Repo Maintainer"

Functions

func CurrentCommit

func CurrentCommit() (commit string, err error)

CurrentCommit retrieves the current commit hash of the Git repository.

It returns the commit hash as a string and an error if the command fails.

func EnsureBranchInRepository

func EnsureBranchInRepository(path string, branchName string) error

EnsureBranchInRepository ensures that a branch is checked out in a repository.

It takes two parameters: - path (string): the path to the repository. - branchName (string): the name of the branch to ensure.

It returns an error if there was a problem ensuring the branch.

func EnsureBranchInRepositoryCmd

func EnsureBranchInRepositoryCmd(path string, branchName string) magelib.Cmd

EnsureBranchInRepositoryCmd returns a function that ensures that a branch is checked out in a repository.

The function takes two parameters: - path (string): the path to the repository. - branchName (string): the name of the branch to ensure.

It returns a function that, when called, ensures the specified branch exists in the repository. The returned function returns an error if there was a problem ensuring the branch.

func FormatStatusError

func FormatStatusError(path string, status *StatusInfo) error

func GitStatusOutput

func GitStatusOutput(cwd string) (io.Reader, error)

func IsCommitTagged

func IsCommitTagged(commit string) (bool, error)

IsCommitTagged checks if a commit is tagged in a Git repository.

It takes a commit hash string as a parameter and returns a boolean indicating whether the commit is tagged and an error.

func IsInsideWorkTree

func IsInsideWorkTree(cwd string) (bool, error)

func IsRepoClean

func IsRepoClean(path string) error

func IsRepoCleanCmd

func IsRepoCleanCmd(path string) magelib.Cmd

func MostRecentTag

func MostRecentTag() (tag string, err error)

MostRecentTag retrieves the current tag of a Git repository at the specified path.

It takes a path string as a parameter and returns a string representing the current tag and an error.

func PathToGitDir

func PathToGitDir(cwd string) (string, error)

func TagsByCommit

func TagsByCommit(commit string) ([]string, error)

TagsByCommit retrieves the tags associated with a given commit in a Git repository.

It takes a commit string as a parameter and returns a slice of strings representing the tags and an error. The commit string should not be empty. If it is, the function returns an error with the value ErrCommitNotDefined. The function executes the "git tag --contains <commit> --sort=-creatordate" command to retrieve the tags. If the command fails, the function returns an error. The function splits the output of the command into tags using the newline character as a delimiter. If the output contains only an empty string, the function returns an empty slice. Otherwise, it returns the slice of tags.

Types

type GitArea

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

type GitRepository

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

func NewGitRepository

func NewGitRepository(repoPath, repoURL string) (*GitRepository, error)

func (*GitRepository) Clone

func (p *GitRepository) Clone(w io.Writer) error

func (*GitRepository) CommitAll

func (p *GitRepository) CommitAll(message string) error

type StatusInfo

type StatusInfo struct {
	Unstaged GitArea
	Staged   GitArea
	// contains filtered or unexported fields
}

func GitStatus

func GitStatus(path string) (*StatusInfo, error)

func NewStatusInfo

func NewStatusInfo(path string) *StatusInfo

func (*StatusInfo) Debug

func (pi *StatusInfo) Debug() string

Debug retrieves StatusInfo as string

func (*StatusInfo) IsDirty

func (pi *StatusInfo) IsDirty() bool

IsDirty returns true if staged files have changed

func (*StatusInfo) IsModified

func (pi *StatusInfo) IsModified() bool

IsDirty returns true if unstaged files have changed

func (*StatusInfo) IsSynced

func (pi *StatusInfo) IsSynced() bool

IsSynced returns true if repo is in sync with remote

Jump to

Keyboard shortcuts

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