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) 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) 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
- 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) IsValidRepo ¶
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.
Click to show internal directories.
Click to hide internal directories.