Documentation
¶
Overview ¶
Package gitdir asks the installed git binary where a worktree and its admin directories are.
Index ¶
- Variables
- func CleanEnv(env []string) []string
- func WorktreeRoot(gitDir string) (root string, ok bool, err error)
- type Git
- func (g Git) AddWorktree(ctx context.Context, dir, path, branch, newBranch, base string) error
- func (g Git) Branch(ctx context.Context, dir string) (string, error)
- func (g Git) DeleteBranch(ctx context.Context, dir, branch string) error
- func (g Git) Dirty(ctx context.Context, dir string) (bool, error)
- func (g Git) Find(ctx context.Context, dir string) (info Info, ok bool, err error)
- func (g Git) RemoveWorktree(ctx context.Context, dir, path string, force bool) error
- func (g Git) Worktrees(ctx context.Context, commonDir string) ([]Worktree, error)
- type Info
- type Worktree
Constants ¶
This section is empty.
Variables ¶
var ErrNoGit = errors.New("git is not installed")
ErrNoGit means the git binary is not installed.
Functions ¶
func CleanEnv ¶
CleanEnv drops repository-local git variables from env and pins output to the C locale, so git's answer depends only on the directory it runs in.
func WorktreeRoot ¶
WorktreeRoot returns where the worktree of a per-worktree admin dir lives now. git keeps this current on `git worktree move`, so it is the reliable way back from an admin dir to its worktree. ok is false when the admin dir is gone (worktree removed and pruned).
Types ¶
type Git ¶
type Git struct {
Path string // git binary; empty means "git" from PATH
}
Git runs the git binary.
func (Git) AddWorktree ¶
AddWorktree adds a worktree at path. With newBranch it creates that branch from base (empty: the current HEAD); otherwise it checks out branch, which git also finds on a remote.
func (Git) Branch ¶
Branch returns the checked out branch of the worktree at dir, or "" for a detached HEAD.
func (Git) DeleteBranch ¶
DeleteBranch deletes a local branch, merged or not.
func (Git) Dirty ¶
Dirty reports whether the worktree at dir has uncommitted changes or untracked files.
func (Git) Find ¶
Find returns the worktree containing dir. ok is false when dir is not inside a worktree.
func (Git) RemoveWorktree ¶
RemoveWorktree removes the worktree at path; force also drops uncommitted changes.
type Info ¶
type Info struct {
Root string // worktree root
GitDir string // per-worktree admin dir: <root>/.git or <common>/worktrees/<id>
CommonDir string // shared admin dir of the repository
}
Info describes the worktree containing a path.