workspace

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const ConfigFileName = ".gitw"

Variables

View Source
var ErrNotFound = errors.New("no .gitw found in current directory or any parent")

Functions

func ConfigDir

func ConfigDir(configPath string) string

func Discover

func Discover(startDir string) (string, error)

Discover searches for .gitw starting from startDir and walking up to the filesystem root. If the GIT_W_CONFIG environment variable is set, it is returned directly without any filesystem check.

func Register

func Register(root *cobra.Command)

Register adds all workspace commands to root.

func RelPath

func RelPath(cfgPath, absPath string) (string, error)

RelPath returns absPath relative to the config file's directory.

func ResolveRepoPath

func ResolveRepoPath(cfgPath, repoPath string) (string, error)

ResolveRepoPath resolves a repo path from config against cfgPath's directory.

func Save

func Save(configPath string, cfg *WorkspaceConfig) error

Save writes cfg to configPath atomically (write to .tmp, then rename). Only the workspace, repos, and groups sections are written; context lives in .gitw.local.

func SaveLocal

func SaveLocal(configPath string, ctx ContextConfig) error

SaveLocal writes the context section to configPath+".local" atomically.

func SortedStringKeys

func SortedStringKeys[V any](values map[string]V) []string

SortedStringKeys returns string map keys in deterministic order.

func SortedWorktreeBranchNames

func SortedWorktreeBranchNames(branches map[string]string) []string

SortedWorktreeBranchNames returns branch names in deterministic order. It is an alias for SortedStringKeys, kept for semantic clarity at call sites.

func WorktreeRepoName

func WorktreeRepoName(setName, branch string) string

WorktreeRepoName returns the synthesized repo name for a set+branch.

Types

type ContextConfig

type ContextConfig struct {
	Active string `toml:"active"`
}

ContextConfig holds the active context (stored in .gitw.local).

type GroupConfig

type GroupConfig struct {
	Repos []string `toml:"repos"`
	Path  string   `toml:"path,omitempty"` // optional; used for auto-context detection
}

GroupConfig is a named set of repos.

type RepoConfig

type RepoConfig struct {
	Path  string   `toml:"path"`
	URL   string   `toml:"url,omitempty"`
	Flags []string `toml:"flags,omitempty"`
}

RepoConfig represents one tracked repository.

type WorkspaceConfig

type WorkspaceConfig struct {
	Workspace WorkspaceMeta             `toml:"workspace"`
	Context   ContextConfig             `toml:"context"` // sourced from .gitw.local
	Repos     map[string]RepoConfig     `toml:"repos"`
	Groups    map[string]GroupConfig    `toml:"groups"`
	Worktrees map[string]WorktreeConfig `toml:"worktrees"`
}

WorkspaceConfig is the merged result of `.gitw` and `.gitw.local`. Repos and Groups maps are always non-nil after loading.

func Load

func Load(configPath string) (*WorkspaceConfig, error)

Load reads configPath `.gitw` and merges `.gitw.local` if present. Returns a WorkspaceConfig with non-nil Repos and Groups maps.

func LoadCWD

func LoadCWD(override string) (*WorkspaceConfig, string, error)

LoadCWD discovers and loads the workspace config, starting from the current working directory. If override is non-empty it is used as the config path directly (e.g. from the --config flag), bypassing discovery.

func LoadConfig

func LoadConfig(cmd *cobra.Command) (*WorkspaceConfig, string, error)

LoadConfig reads the --config flag from the root command and loads the workspace config.

func (*WorkspaceConfig) AddRepoToGroup

func (c *WorkspaceConfig) AddRepoToGroup(group, name string)

AddRepoToGroup appends name to the named group, creating the group if absent. It is idempotent: if name is already in the group, it is not added again.

func (WorkspaceConfig) AutoGitignoreEnabled

func (c WorkspaceConfig) AutoGitignoreEnabled() bool

AutoGitignoreEnabled reports whether auto-gitignore is on (nil means default true).

func (*WorkspaceConfig) RemoveRepoFromManualGroups

func (c *WorkspaceConfig) RemoveRepoFromManualGroups(repoName string)

RemoveRepoFromManualGroups removes repoName from every group that is not synthesized from a worktree set. Must be called before deleting the set from cfg.Worktrees so the synthesized group can still be identified.

func (*WorkspaceConfig) RepoName

func (c *WorkspaceConfig) RepoName(absPath string) (string, error)

RepoName returns the base-name of absPath and errors if it is already registered.

type WorkspaceMeta

type WorkspaceMeta struct {
	Name          string `toml:"name"`
	AutoGitignore *bool  `toml:"auto_gitignore"` // nil means true (default on)
}

WorkspaceMeta holds top-level workspace settings.

type WorktreeConfig

type WorktreeConfig struct {
	URL      string            `toml:"url"`
	BarePath string            `toml:"bare_path"`
	Branches map[string]string `toml:"branches"`
}

WorktreeConfig describes one shared bare-repo + branch worktree set.

Jump to

Keyboard shortcuts

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