Documentation
¶
Overview ¶
Package git provides utilities for interacting with Git repositories including operations for branches, commits, and worktrees.
Index ¶
- func GetBranchFromDir(dir string) (string, error)
- type Repository
- func (r *Repository) AddWorktree(worktreePath, branchName, baseBranch string) error
- func (r *Repository) CreateAndCheckoutBranch(name string) error
- func (r *Repository) IsClean() (bool, error)
- func (r *Repository) Push(remoteName string, branchName string) error
- func (r *Repository) RemoveWorktree(worktreePath string) error
- func (r *Repository) RemoveWorktreeForce(worktreePath string) error
- func (r *Repository) Stash() error
- func (r *Repository) StashPop() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetBranchFromDir ¶ added in v0.7.0
GetBranchFromDir returns the current branch name for the given directory. This works correctly inside git worktrees, because the command runs with cmd.Dir set to that worktree.
Types ¶
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
Repository represents a Git repository
func Open ¶
func Open(path string) (*Repository, error)
Open opens a Git repository at the given path
func (*Repository) AddWorktree ¶
func (r *Repository) AddWorktree(worktreePath, branchName, baseBranch string) error
AddWorktree creates a new git worktree at worktreePath with a new branch branchName, based on baseBranch (e.g. "main"). Runs: git worktree add <worktreePath> -b <branchName> <baseBranch>
func (*Repository) CreateAndCheckoutBranch ¶ added in v0.10.2
func (r *Repository) CreateAndCheckoutBranch(name string) error
CreateAndCheckoutBranch creates a new branch from the current HEAD and checks it out. Runs: git checkout -b <name>
func (*Repository) IsClean ¶
func (r *Repository) IsClean() (bool, error)
IsClean checks if the working directory is clean
func (*Repository) Push ¶
func (r *Repository) Push(remoteName string, branchName string) error
Push pushes the current branch to the remote repository
func (*Repository) RemoveWorktree ¶
func (r *Repository) RemoveWorktree(worktreePath string) error
RemoveWorktree removes the git worktree at worktreePath. Runs: git worktree remove <worktreePath>
func (*Repository) RemoveWorktreeForce ¶ added in v0.7.2
func (r *Repository) RemoveWorktreeForce(worktreePath string) error
RemoveWorktreeForce force-removes the git worktree at worktreePath. Runs: git worktree remove --force <worktreePath>
func (*Repository) Stash ¶ added in v0.8.0
func (r *Repository) Stash() error
Stash saves all working directory changes (including untracked files) to the stash
func (*Repository) StashPop ¶ added in v0.8.0
func (r *Repository) StashPop() error
StashPop restores the most recently stashed changes