Documentation
¶
Overview ¶
Package gitbranch builds branch names from task data and manages branches, worktrees, statuses and commit hooks through the git CLI (contract C2).
Index ¶
- Variables
- func CommitMessage(template string, it Item) (string, error)
- func Render(template string, it Item) (string, error)
- func Slug(title string, max int) string
- func ValidName(name string) error
- func WorktreePath(template, toplevel, branch string) string
- type BranchStatus
- type Brancher
- type Git
- type Item
- type Options
- type Repo
- func (r *Repo) AddWorktree(name, path string, o Options) (Result, error)
- func (r *Repo) Branches() ([]string, error)
- func (r *Repo) Create(name string, o Options) (Result, error)
- func (r *Repo) Current() (string, error)
- func (r *Repo) Delete(name string, force bool) error
- func (r *Repo) DiffStat(base, branch string) (Stat, error)
- func (r *Repo) Dirty() (bool, error)
- func (r *Repo) Exists(name string) (bool, error)
- func (r *Repo) InstallHook() (path string, installed bool, err error)
- func (r *Repo) Push(remote, name string) error
- func (r *Repo) ReadCommitMsg(branch string) (msg string, ok bool, err error)
- func (r *Repo) RemoteURL(remote string) (string, error)
- func (r *Repo) Statuses(names []string, remote, base string) (map[string]BranchStatus, error)
- func (r *Repo) Switch(name string) (Result, error)
- func (r *Repo) Toplevel() (string, error)
- func (r *Repo) WriteCommitMsg(branch, msg string) error
- type Result
- type Stat
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotRepo = errors.New("not a git repository") ErrBranchExists = errors.New("branch already exists") ErrDetached = errors.New("HEAD is detached") ErrCurrentBranch = errors.New("cannot delete the current branch") ErrNotMerged = errors.New("branch is not fully merged") ErrHookExists = errors.New("foreign prepare-commit-msg hook exists") ErrWorktreeBusy = errors.New("branch is checked out in another worktree") )
Errors returned by Repo methods.
Functions ¶
func CommitMessage ¶
CommitMessage fills {identifier}, {sequence}, {title} (single line) and {slug}; an unknown placeholder is an error.
func Render ¶
Render fills the template placeholders {identifier}, {sequence}, {slug} and validates the resulting name.
func Slug ¶
Slug converts a title to a branch-safe slug of at most max characters (max <= 0 means 40). An empty result is "task".
func ValidName ¶
ValidName checks name by the rules of `git check-ref-format --branch` (go-git, no process per call).
func WorktreePath ¶
WorktreePath expands {repo} (base name of toplevel) and {branch} (name with "/" replaced by "-"); relative results are taken from toplevel. The result is absolute and cleaned.
Types ¶
type BranchStatus ¶
type BranchStatus struct {
Name string
Local bool // refs/heads/<name>
Remote bool // refs/remotes/<remote>/<name>
Current bool // branch of HEAD in this working tree
Worktree string // other worktree where the branch is checked out
Ahead, Behind int // commits relative to base; 0, 0 if unknown
}
BranchStatus describes where a branch lives and how far it is from base.
type Brancher ¶
type Brancher interface {
Create(name string, o Options) (Result, error)
Switch(name string) (Result, error)
}
Brancher is the interface consumed by the TUI.
type Git ¶
type Git interface {
Brancher
Exists(name string) (bool, error)
Dirty() (bool, error)
Toplevel() (string, error)
Current() (string, error)
Branches() ([]string, error)
Statuses(names []string, remote, base string) (map[string]BranchStatus, error)
AddWorktree(name, path string, o Options) (Result, error)
Delete(name string, force bool) error
WriteCommitMsg(branch, msg string) error
ReadCommitMsg(branch string) (msg string, ok bool, err error)
InstallHook() (string, bool, error)
Push(remote, name string) error
RemoteURL(remote string) (string, error)
DiffStat(base, branch string) (Stat, error)
}
Git is the full repository interface for app, tui and cli.
type Item ¶
Item is the task data for the branch name template.
func ParseBranch ¶
ParseBranch extracts the task identifier and sequence from a branch name: first by the branch template, then by a generic ID-N pattern. The identifier is upper-cased; Title is empty.
type Repo ¶
type Repo struct{ Dir string }
Repo is a git repository working directory.
func (*Repo) AddWorktree ¶
AddWorktree checks out name in a separate worktree at path. A missing branch is created from o.Base (empty: HEAD). If the branch is already checked out somewhere, the result carries that path and ErrWorktreeBusy.
func (*Repo) DiffStat ¶
DiffStat returns `git diff --shortstat base...branch`. Empty base is resolved as in Statuses (remote HEAD, main, master).
func (*Repo) InstallHook ¶
InstallHook installs the prepare-commit-msg hook. installed is false when the same hook was already in place; a foreign hook gives ErrHookExists.
func (*Repo) ReadCommitMsg ¶
ReadCommitMsg reads the stored commit message; a missing file gives ok=false.
func (*Repo) Statuses ¶
Statuses returns statuses for names (empty: all local branches). base empty means refs/remotes/<remote>/HEAD, then main, then master.
func (*Repo) WriteCommitMsg ¶
WriteCommitMsg stores the commit message for branch (atomic write).
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package gitbranchtest provides an in-memory gitbranch.Git for tests.
|
Package gitbranchtest provides an in-memory gitbranch.Git for tests. |