Documentation
¶
Overview ¶
Package git provides an abstraction for git operations.
Index ¶
- func ExtractOwnerRepo(remote string) (owner, repo string)
- func ExtractRepoName(remote string) string
- type Executor
- func (e *Executor) Branch(ctx context.Context, dir string) (string, error)
- func (e *Executor) Checkout(ctx context.Context, dir, branch string) error
- func (e *Executor) Clone(ctx context.Context, url, dest string) error
- func (e *Executor) CloneBare(ctx context.Context, url, dest string) error
- func (e *Executor) DefaultBranch(ctx context.Context, dir string) (string, error)
- func (e *Executor) DiffStats(ctx context.Context, dir string) (additions, deletions int, err error)
- func (e *Executor) Fetch(ctx context.Context, dir string) error
- func (e *Executor) HasUnpushedCommits(ctx context.Context, dir string) (bool, error)
- func (e *Executor) IsClean(ctx context.Context, dir string) (bool, error)
- func (e *Executor) IsValidRepo(ctx context.Context, dir string) error
- func (e *Executor) Pull(ctx context.Context, dir string) error
- func (e *Executor) RemoteURL(ctx context.Context, dir string) (string, error)
- func (e *Executor) ResetHard(ctx context.Context, dir string) error
- func (e *Executor) WorktreeAdd(ctx context.Context, repoDir, path, branch string) error
- func (e *Executor) WorktreeRemove(ctx context.Context, repoDir, path, branch string) error
- func (e *Executor) WorktreeReset(ctx context.Context, bareDir, worktreePath string) error
- type Git
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractOwnerRepo ¶
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 ¶
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 ¶
NewExecutor creates a new git executor with the specified git binary path.
func (*Executor) DefaultBranch ¶
func (*Executor) HasUnpushedCommits ¶ added in v0.44.0
func (*Executor) IsValidRepo ¶
func (*Executor) WorktreeAdd ¶ added in v0.35.0
func (*Executor) WorktreeRemove ¶ added in v0.35.0
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.
Click to show internal directories.
Click to hide internal directories.