Documentation
¶
Overview ¶
Package git provides helpers for interacting with git repositories and worktrees.
Package git provides helpers for interacting with git repositories and worktrees.
Index ¶
- Constants
- type Repository
- func (r *Repository) BranchExists(branch string) (bool, error)
- func (r *Repository) CreateWorktree(path, branch string) error
- func (r *Repository) ExecuteGitCommand(args ...string) error
- func (r *Repository) GetMainWorktreePath() (string, error)
- func (r *Repository) GetRemoteBranches(branch string) (map[string]string, error)
- func (r *Repository) GetRepositoryName() string
- func (r *Repository) GetWorktrees() ([]Worktree, error)
- func (r *Repository) Path() string
- func (r *Repository) RemoveWorktree(path string, force bool) error
- func (r *Repository) ResolveBranch(branch string) (resolvedBranch string, isRemote bool, err error)
- type Worktree
Constants ¶
const ( // MainBranch is the default branch name used for primary repositories. MainBranch = "main" // MasterBranch is kept for backward compatibility with repositories using master. MasterBranch = "master" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
Repository represents a git repository and offers helper methods for worktree operations.
func NewRepository ¶
func NewRepository(path string) (*Repository, error)
NewRepository constructs a Repository for the given path after validating it is a git repository.
func (*Repository) BranchExists ¶
func (r *Repository) BranchExists(branch string) (bool, error)
BranchExists checks if a branch exists locally
func (*Repository) CreateWorktree ¶
func (r *Repository) CreateWorktree(path, branch string) error
CreateWorktree creates a new worktree at the given path and optionally checks out the branch.
func (*Repository) ExecuteGitCommand ¶
func (r *Repository) ExecuteGitCommand(args ...string) error
ExecuteGitCommand executes a git command in the repository directory
func (*Repository) GetMainWorktreePath ¶
func (r *Repository) GetMainWorktreePath() (string, error)
GetMainWorktreePath returns the path to the main worktree (original repository) This is useful when running commands from within a worktree
func (*Repository) GetRemoteBranches ¶
func (r *Repository) GetRemoteBranches(branch string) (map[string]string, error)
GetRemoteBranches returns a map of remote branches by remote name
func (*Repository) GetRepositoryName ¶
func (r *Repository) GetRepositoryName() string
GetRepositoryName returns the name of the repository
func (*Repository) GetWorktrees ¶
func (r *Repository) GetWorktrees() ([]Worktree, error)
GetWorktrees lists the worktrees associated with the repository.
func (*Repository) Path ¶
func (r *Repository) Path() string
Path returns the root path for the repository.
func (*Repository) RemoveWorktree ¶
func (r *Repository) RemoveWorktree(path string, force bool) error
RemoveWorktree removes the worktree at the provided path, optionally forcing removal.
func (*Repository) ResolveBranch ¶
func (r *Repository) ResolveBranch(branch string) (resolvedBranch string, isRemote bool, err error)
ResolveBranch resolves a branch name following git's behavior: 1. Check if branch exists locally 2. If not, check remote branches 3. If multiple remotes have the branch, return an error
type Worktree ¶
type Worktree struct {
Path string
Branch string
HEAD string
IsMain bool // True if this is the main/root worktree
}
Worktree represents a git worktree with basic metadata.
func (*Worktree) CompletionName ¶
CompletionName returns the name to display for shell completion.
Format: <worktreeName>@<commit-ish>[(root worktree)]
Examples:
- Root worktree: "giselle@fix-nodes(root worktree)"
- Matching names: "develop" (when worktree dir and branch both = "develop")
- Different names: "feature-awesome@feature/awesome"
- Full path match: "feature/new-top-page" (when path ends with branch name)
func (*Worktree) IsMainWorktree ¶
IsMainWorktree returns true if this is the main/root worktree