config

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2026 License: MIT Imports: 9 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

ConfigDir returns the directory containing the config file.

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 RelPath

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

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

func RemoveLocalWorkgroup added in v1.6.0

func RemoveLocalWorkgroup(configPath, name string) error

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. Comments and formatting from the original file are preserved where possible.

func SaveLocal

func SaveLocal(configPath string, ctx ContextConfig) error

func SaveLocalWorkgroup added in v1.6.0

func SaveLocalWorkgroup(configPath, name string, wg WorkgroupConfig) error

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 WorkgroupWorktreePath added in v1.6.0

func WorkgroupWorktreePath(cfgPath, wgName, repoName string) string

WorkgroupWorktreePath returns the absolute path to a repo's worktree within a workgroup.

func WorktreeRepoName

func WorktreeRepoName(setName, branch string) string

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

func WorktreeRepoToSetIndex added in v1.3.0

func WorktreeRepoToSetIndex(c *WorkspaceConfig) map[string]string

WorktreeRepoToSetIndex returns a map of synthesized repo name to worktree set name.

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"`
	DefaultBranch string   `toml:"default_branch,omitempty"`
}

RepoConfig represents one tracked repository.

type WorkgroupConfig added in v1.6.0

type WorkgroupConfig struct {
	Repos   []string `toml:"repos"`
	Branch  string   `toml:"branch"`
	Created string   `toml:"created,omitempty"`
}

WorkgroupConfig is a local workgroup entry (stored only in .gitw.local).

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"`
	Workgroups map[string]WorkgroupConfig `toml:"workgroup"` // sourced from .gitw.local
}

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) BranchPushEnabled added in v1.3.0

func (c WorkspaceConfig) BranchPushEnabled() bool

BranchPushEnabled reports whether branch creation pushes by default (nil means true).

func (WorkspaceConfig) BranchSetUpstreamEnabled added in v1.3.0

func (c WorkspaceConfig) BranchSetUpstreamEnabled() bool

BranchSetUpstreamEnabled reports whether branch creation sets upstream (nil means true).

func (WorkspaceConfig) BranchSyncSourceEnabled added in v1.3.0

func (c WorkspaceConfig) BranchSyncSourceEnabled() bool

BranchSyncSourceEnabled reports whether branch creation syncs the source branch (nil means 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.

func (WorkspaceConfig) ResolveDefaultBranch added in v1.3.0

func (c WorkspaceConfig) ResolveDefaultBranch(repoName string) string

ResolveDefaultBranch returns the source branch for a repo.

func (WorkspaceConfig) SyncPushEnabled

func (c WorkspaceConfig) SyncPushEnabled() bool

SyncPushEnabled reports whether sync runs push by default (nil means true).

func (WorkspaceConfig) WorktreeBranchForRepo added in v1.3.0

func (c WorkspaceConfig) WorktreeBranchForRepo(repoName string) (string, bool)

WorktreeBranchForRepo returns the worktree branch for a synthesized repo name.

type WorkspaceMeta

type WorkspaceMeta struct {
	Name              string `toml:"name"`
	AutoGitignore     *bool  `toml:"auto_gitignore"` // nil means true (default on)
	SyncPush          *bool  `toml:"sync_push"`      // nil means true (default on)
	DefaultBranch     string `toml:"default_branch,omitempty"`
	BranchSyncSource  *bool  `toml:"branch_sync_source"`  // nil means true (default on)
	BranchSetUpstream *bool  `toml:"branch_set_upstream"` // nil means true (default on)
	BranchPush        *bool  `toml:"branch_push"`         // 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