git

package
v0.31.1 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 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) 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) 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

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
}

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