setup

package
v0.0.0-...-f35b8df Latest Latest
Warning

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

Go to latest
Published: May 22, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package setup runs the post-creation steps after a worktree is added: copying env/config files and installing dependencies.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(changes []Change) (int, error)

Apply writes the non-identical changes to disk. Returns the number of files actually written and the first error encountered; per-file failures are logged to stderr and do not stop subsequent files.

func ApplySymlinks(changes []SymlinkChange) (int, error)

ApplySymlinks creates, repairs, or removes symlinks for the non-identical changes. Returns the number of symlink operations performed and the first error encountered.

func DeregisterClaudePlugins

func DeregisterClaudePlugins(worktreePath string) error

DeregisterClaudePlugins removes plugin entries whose projectPath matches worktreePath from ~/.claude/plugins/installed_plugins.json.

func DirenvAllow

func DirenvAllow(repoRoot, worktreePath string)

DirenvAllow runs `direnv allow` in worktreePath if:

  1. .envrc exists there, AND
  2. its SHA-256 matches the .envrc at repoRoot (i.e. it's the file we just copied, not something that changed out from under us)

If direnv is not on PATH the call is silently skipped.

func InstallDeps

func InstallDeps(worktreePath string) error

InstallDeps walks worktreePath, picks the highest-priority lockfile in each directory, and runs `<tool> install` there. Skips entirely if WTREE_SKIP_INSTALL is set.

func PlanAll

func PlanAll(srcRoot, dstRoot string) ([]Change, []SymlinkChange, error)

PlanAll loads config once and returns both copy and symlink plans together.

func RegisterClaudePlugins

func RegisterClaudePlugins(repoRoot, worktreePath string) error

RegisterClaudePlugins copies any local-scoped plugin entries for repoRoot into entries for worktreePath in ~/.claude/plugins/installed_plugins.json.

func SetupConfigs

func SetupConfigs(srcRoot, dstRoot string) error

SetupConfigs runs both copy and symlink plans and applies them. This is the add-time entry point.

Types

type Change

type Change struct {
	Rel  string // path relative to the source/destination roots
	Src  string
	Dst  string
	Kind ChangeKind
}

Change is one source→destination file copy in a Plan.

func Plan

func Plan(srcRoot, dstRoot string) ([]Change, error)

Plan resolves the configured copy patterns against srcRoot and reports the per-file changes that writing into dstRoot would produce. It does not touch the filesystem under dstRoot. Directory matches are walked recursively.

type ChangeKind

type ChangeKind int

ChangeKind classifies what an Apply call would do for one file.

const (
	ChangeNew       ChangeKind = iota // file does not exist at the destination
	ChangeOverwrite                   // file exists at the destination with different content
	ChangeIdentical                   // file exists with identical content (no-op on Apply)
)

type SymlinkChange

type SymlinkChange struct {
	Rel  string // path relative to the source/destination roots
	Src  string // absolute path in primary worktree
	Dst  string // absolute path in child worktree
	Kind SymlinkKind
}

SymlinkChange is one source→destination symlink in a PlanSymlinks result.

func PlanSymlinks(srcRoot, dstRoot string) ([]SymlinkChange, error)

PlanSymlinks resolves the configured symlink patterns against srcRoot and reports the per-entry changes that linking into dstRoot would produce. It does not touch the filesystem under dstRoot. Each pattern match (file or directory) becomes a single symlink — directories are not walked.

type SymlinkKind

type SymlinkKind int

SymlinkKind classifies what an ApplySymlinks call would do for one entry.

const (
	SymlinkNew      SymlinkKind = iota // nothing at dst — create symlink
	SymlinkExists                      // correct symlink already in place — no-op
	SymlinkWrong                       // symlink present but points elsewhere — re-link
	SymlinkConflict                    // regular file/dir at dst — skip
	SymlinkOrphaned                    // symlink points to srcRoot but pattern no longer active — remove
)

Jump to

Keyboard shortcuts

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