Documentation
¶
Overview ¶
Package identity derives, stores and validates instance names.
Index ¶
- Constants
- func EnsureExcluded(commonDir, pattern string) error
- func EnsureLocalIgnored(muttiDir string) error
- func FilePath(gitDir, root string) string
- func InstanceName(project, worktree string) string
- func NewID() string
- func Sanitize(s string) string
- func Save(path string, id Identity) error
- func Shorten(name string) string
- func Valid(name string) bool
- type Identity
Constants ¶
const MaxLen = 63
MaxLen is the DNS label limit, which also bounds Compose project names and hostnames.
Variables ¶
This section is empty.
Functions ¶
func EnsureExcluded ¶
EnsureExcluded adds pattern to the repository's info/exclude (in its common git dir, so it applies to every worktree) unless it is there: git ignores it without any change to the repo.
func EnsureLocalIgnored ¶
EnsureLocalIgnored makes sure <muttiDir>/.gitignore exists, ignoring local/: machine-local files such as run logs never show up in git.
func FilePath ¶
FilePath returns where the identity of a worktree lives: inside its git admin dir when there is one (moves with `git worktree move`, needs no gitignore), else under <root>/.mutti/local.
func InstanceName ¶
InstanceName joins project and worktree names into the instance name, which is also the Compose project name. A worktree named like its project (usually the main worktree) is just the project. Names longer than MaxLen are cut and get a hash of the full name, so two long names sharing a prefix stay distinct.
func Sanitize ¶
Sanitize turns an arbitrary string into a DNS label: lower case, every run of other characters becomes one "-", no leading or trailing "-". The result may be empty and is not length-capped.
func Save ¶
Save writes an identity file atomically. For a file under .mutti/local it also makes sure .mutti/.gitignore ignores local/.
Types ¶
type Identity ¶
type Identity struct {
Name string `json:"name"` // worktree part of the instance name
ID string `json:"id"` // random, tells a moved worktree apart from a copied one
}
Identity is the name tag of one worktree's instance. It is written once and never recomputed, so renaming a directory or switching branches keeps the instance.