git

package
v0.44.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package git provides an abstraction for git operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractOwnerRepo

func ExtractOwnerRepo(remote string) (owner, repo string)

ExtractOwnerRepo extracts owner and repo from a git remote URL. Handles SSH (git@github.com:owner/repo.git) and HTTPS (https://github.com/owner/repo.git). Returns empty strings if parsing fails.

func ExtractRepoName

func ExtractRepoName(remote string) string

ExtractRepoName extracts the repository name from a git remote URL. Handles both SSH (git@github.com:user/repo.git) and HTTPS (https://github.com/user/repo.git) formats.

Types

type Executor

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

Executor implements Git using the git command-line tool.

func NewExecutor

func NewExecutor(gitPath string, exec executil.Executor) *Executor

NewExecutor creates a new git executor with the specified git binary path.

func (*Executor) Branch

func (e *Executor) Branch(ctx context.Context, dir string) (string, error)

func (*Executor) Checkout

func (e *Executor) Checkout(ctx context.Context, dir, branch string) error

func (*Executor) Clone

func (e *Executor) Clone(ctx context.Context, url, dest string) error

func (*Executor) CloneBare added in v0.35.0

func (e *Executor) CloneBare(ctx context.Context, url, dest string) error

func (*Executor) DefaultBranch

func (e *Executor) DefaultBranch(ctx context.Context, dir string) (string, error)

func (*Executor) DiffStats

func (e *Executor) DiffStats(ctx context.Context, dir string) (additions, deletions int, err error)

func (*Executor) Fetch added in v0.35.0

func (e *Executor) Fetch(ctx context.Context, dir string) error

func (*Executor) HasUnpushedCommits added in v0.44.0

func (e *Executor) HasUnpushedCommits(ctx context.Context, dir string) (bool, error)

func (*Executor) IsClean

func (e *Executor) IsClean(ctx context.Context, dir string) (bool, error)

func (*Executor) IsValidRepo

func (e *Executor) IsValidRepo(ctx context.Context, dir string) error

func (*Executor) Pull

func (e *Executor) Pull(ctx context.Context, dir string) error

func (*Executor) RemoteURL

func (e *Executor) RemoteURL(ctx context.Context, dir string) (string, error)

func (*Executor) ResetHard

func (e *Executor) ResetHard(ctx context.Context, dir string) error

func (*Executor) WorktreeAdd added in v0.35.0

func (e *Executor) WorktreeAdd(ctx context.Context, repoDir, path, branch string) error

func (*Executor) WorktreeRemove added in v0.35.0

func (e *Executor) WorktreeRemove(ctx context.Context, repoDir, path, branch string) error

func (*Executor) WorktreeReset added in v0.35.0

func (e *Executor) WorktreeReset(ctx context.Context, bareDir, worktreePath string) error

type Git

type Git interface {
	// Clone clones a repository from url to dest.
	Clone(ctx context.Context, url, dest string) error
	// Checkout switches to the specified branch in dir.
	Checkout(ctx context.Context, dir, branch string) error
	// Pull fetches and merges changes in dir.
	Pull(ctx context.Context, dir string) error
	// ResetHard discards all local changes in dir.
	ResetHard(ctx context.Context, dir string) error
	// RemoteURL returns the origin remote URL for dir.
	RemoteURL(ctx context.Context, dir string) (string, error)
	// IsClean returns true if there are no uncommitted changes in dir.
	IsClean(ctx context.Context, dir string) (bool, error)
	// Branch returns the current branch name, or short commit SHA if in detached HEAD state.
	Branch(ctx context.Context, dir string) (string, error)
	// DefaultBranch returns the default branch name (e.g., "main" or "master") for the repository.
	DefaultBranch(ctx context.Context, dir string) (string, error)
	// DiffStats returns the number of lines added and deleted compared to the default branch.
	DiffStats(ctx context.Context, dir string) (additions, deletions int, err error)
	// IsValidRepo checks if dir contains a valid git repository.
	IsValidRepo(ctx context.Context, dir string) error
	// CloneBare creates a bare clone of url at dest.
	CloneBare(ctx context.Context, url, dest string) error
	// WorktreeAdd creates a new worktree at path on a new branch named branch.
	WorktreeAdd(ctx context.Context, repoDir, path, branch string) error
	// WorktreeRemove removes the worktree at path and deletes the branch from repoDir.
	WorktreeRemove(ctx context.Context, repoDir, path, branch string) error
	// WorktreeReset resets the worktree at worktreePath to origin's default branch.
	// It fetches the default branch ref from bareDir, then resets the worktree.
	WorktreeReset(ctx context.Context, bareDir, worktreePath string) error
	// Fetch fetches all remotes in dir.
	Fetch(ctx context.Context, dir string) error
	// HasUnpushedCommits returns true if there are local commits not yet pushed to a remote.
	// It first checks the upstream tracking branch; if none is set, it falls back to comparing
	// against origin/<default branch>. Returns false (no risk) on any git error.
	HasUnpushedCommits(ctx context.Context, dir string) (bool, error)
}

Git defines git operations needed by hive.

Jump to

Keyboard shortcuts

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