gitcli

package
v2.3.1 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2026 License: MPL-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBranchAlreadyExists   = errors.New("git: branch already exists")
	ErrAlreadyUpToDate       = errors.New("git: already up to date")
	ErrReferenceNotFound     = errors.New("git: reference not found")
	ErrRemoteRefNotFound     = errors.New("git: couldn't find remote ref")
	ErrWorktreeAlreadyExists = errors.New("git: worktree already checked out")
)

Functions

This section is empty.

Types

type ExecGit

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

ExecGit runs git commands via the system git binary.

func NewExecGit

func NewExecGit(ctx context.Context, showOutput bool, log *logrus.Entry) *ExecGit

func (*ExecGit) AddAll

func (g *ExecGit) AddAll(dir string) error

AddAll stages all changes.

func (*ExecGit) Checkout

func (g *ExecGit) Checkout(dir, branch string, create bool) error

Checkout switches to branch. When create=true it tries -b first, then falls back to a plain checkout if the branch already exists.

func (*ExecGit) Clone

func (g *ExecGit) Clone(tokenURL, dir, branch string, depth int) error

Clone performs a single-branch clone, optionally shallow.

func (*ExecGit) Commit

func (g *ExecGit) Commit(dir, message, authorName, authorEmail string) error

Commit creates a commit with the given message and author/committer identity. -c user.name/email sets the committer; --author sets the author explicitly.

func (*ExecGit) Fetch

func (g *ExecGit) Fetch(dir, tokenURL, branch string) (bool, error)

Fetch fetches branch from the given URL. Returns true if the branch was found on the remote, false if it does not exist. ErrAlreadyUpToDate, "refusing to fetch into current branch", and "shallow update not allowed" are swallowed (branch is considered found in those cases).

func (*ExecGit) IsClean

func (g *ExecGit) IsClean(dir string) (bool, error)

IsClean returns true when the working tree has no changes.

func (*ExecGit) Pull

func (g *ExecGit) Pull(dir, tokenURL, branch string) error

Pull hard-resets HEAD then fast-forward pulls from the given URL. ErrAlreadyUpToDate is swallowed; all other errors (including ErrReferenceNotFound when the remote branch does not exist) are surfaced to the caller.

func (*ExecGit) Push

func (g *ExecGit) Push(dir, tokenURL, branch string) error

Push pushes the current HEAD to branch on the remote using an unambiguous refs/heads/ refspec. ErrAlreadyUpToDate is swallowed.

func (*ExecGit) ResetToRef added in v2.3.0

func (g *ExecGit) ResetToRef(dir, ref string) error

ResetToRef hard-resets the current branch to the given ref (branch name, tag, or commit SHA). All uncommitted changes are discarded.

func (*ExecGit) WorktreeAdd added in v2.1.0

func (g *ExecGit) WorktreeAdd(repoDir, worktreeDir, branch string, create bool) error

WorktreeAdd creates a git worktree at worktreeDir for the given branch. When create=true, a new branch is created (-b). If the worktree already exists (stale from an interrupted run), it is removed and retried.

func (*ExecGit) WorktreePrune added in v2.1.0

func (g *ExecGit) WorktreePrune(repoDir string) error

WorktreePrune removes stale worktree metadata from the repo.

func (*ExecGit) WorktreeRemove added in v2.1.0

func (g *ExecGit) WorktreeRemove(repoDir, worktreeDir string) error

WorktreeRemove forcefully removes a git worktree.

type Git

type Git interface {
	Clone(tokenURL, dir, branch string, depth int) error
	Checkout(dir, branch string, create bool) error
	Fetch(dir, tokenURL, branch string) (bool, error)
	Pull(dir, tokenURL, branch string) error
	Push(dir, tokenURL, branch string) error
	ResetToRef(dir, ref string) error
	IsClean(dir string) (bool, error)
	AddAll(dir string) error
	Commit(dir, message, authorName, authorEmail string) error
	WorktreeAdd(repoDir, worktreeDir, branch string, create bool) error
	WorktreeRemove(repoDir, worktreeDir string) error
	WorktreePrune(repoDir string) error
}

type GitError

type GitError struct {
	Stderr string
}

GitError holds the raw stderr output when git exits non-zero and no sentinel applies.

func (*GitError) Error

func (e *GitError) Error() string

Jump to

Keyboard shortcuts

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