Documentation
¶
Overview ¶
Package projects discovers git repositories and worktrees below served roots and resolves project directories within them. It knows the .git marker and git's worktree and HEAD files, and nothing about file formats.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInsideRepository = fmt.Errorf("%w: inside a repository", ErrUnavailable)
ErrInsideRepository is returned for a directory inside a repository that is not itself a repository or worktree: repositories open whole.
ErrUnavailable is returned when a project ID does not name a servable directory.
Functions ¶
func Branch ¶
Branch reads a worktree's HEAD: the branch name, another ref's name, or a short commit when detached. It is empty when dir is not a worktree or HEAD cannot be read.
func CanonicalRoots ¶
CanonicalRoots resolves served roots to absolute, symlink-evaluated directories in order, drops duplicates, and rejects roots nested in another.
func Resolve ¶
Resolve returns the symlink-evaluated directory for a project ID, an absolute path. Below a root, a directory opens when it is a repository or worktree, or when no directory from the root down to it is one; .git and excluded names never open. Outside every root, only a linked worktree whose repository lies in a root opens.
Types ¶
type Checkout ¶
Checkout describes the repository checked out at a project directory. Repository is the origin remote's repository name, else the main worktree's folder; Worktrees counts the repository's verified checkouts. A folder outside any repository has KindFolder and nothing else.
type Directory ¶
type Directory struct {
Name string `json:"name"`
Path string `json:"path"`
IsProject bool `json:"isProject"`
}
Directory is a child directory listed while browsing for a project.
func Directories ¶
Directories lists the child directories of a folder for browsing; an empty ID lists the roots. Repositories and their contents are not browsed: they open whole. Hidden directories are listed; .git, excluded names, and symlinks are not.
type Discovery ¶
Discovery is the result of Discover. Warnings hold recoverable errors below the roots.
func Discover ¶
Discover finds repositories up to maxDepth directories below each root (a root is depth zero) and every worktree of those repositories, wherever it lives. It stops descending at a repository, skips hidden and excluded directory names, and does not follow symlinks. A root that is not a repository is listed as a folder project.
type Project ¶
type Project struct {
ID string `json:"id"`
Name string `json:"name"`
Path string `json:"path"`
Kind Kind `json:"kind"`
Group string `json:"group"`
Root string `json:"root"`
Branch string `json:"branch"`
Repository string `json:"repository"`
Available bool `json:"available"`
}
Project is a directory that can be served as a workspace.
ID is the canonical absolute path; it is empty when the directory cannot be opened. Path is always the absolute path. Members of one repository with linked worktrees share Group, the Path of the group's main worktree (or of its first member when the main worktree is missing). Root is the served root the project, or its repository, lives in; empty when none. Branch is the checked-out branch, a short commit for a detached HEAD, or empty. Repository names the project's repository (see Checkout); empty for a folder.