identity

package
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package identity derives, stores and validates instance names.

Index

Constants

View Source
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

func EnsureExcluded(commonDir, pattern string) error

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

func EnsureLocalIgnored(muttiDir string) error

EnsureLocalIgnored makes sure <muttiDir>/.gitignore exists, ignoring local/: machine-local files such as run logs never show up in git.

func FilePath

func FilePath(gitDir, root string) string

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

func InstanceName(project, worktree string) string

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 NewID

func NewID() string

NewID returns a random identity id.

func Sanitize

func Sanitize(s string) string

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

func Save(path string, id Identity) error

Save writes an identity file atomically. For a file under .mutti/local it also makes sure .mutti/.gitignore ignores local/.

func Shorten

func Shorten(name string) string

Shorten caps name at MaxLen, appending a hash of the full name when it had to cut.

func Valid

func Valid(name string) bool

Valid reports whether name is a usable DNS label.

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.

func Load

func Load(path string) (id Identity, ok bool, err error)

Load reads an identity file. ok is false if it does not exist.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL