worktree

package
v0.0.78 Latest Latest
Warning

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

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

Documentation

Overview

Package worktree manages cloned workspaces for instance isolation. When a workspace path is a git repository, a local clone is created so each instance gets its own self-contained .git directory that works inside containers without additional volume mounts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Create

func Create(repoDir, clonePath string, opts ...CreateOptions) error

Create creates a local clone at clonePath from the given repository directory. It uses `git clone --local --no-checkout` for efficiency (hardlinks objects on the same filesystem), then checks out a detached HEAD at origin/<default-branch> and fixes up the origin remote URL to point at the upstream remote rather than the local repo path.

Unless opts.NoFetch is set, origin is fetched first so the clone reflects the latest remote state. Fetch failures are non-fatal: a warning is emitted and creation continues with existing local state.

The resulting clone has a self-contained .git directory that works inside containers without additional volume mounts.

func DefaultBranch

func DefaultBranch(repoDir string) (string, error)

DefaultBranch returns the default branch of the remote "origin" in the given git repository. It runs `git symbolic-ref` and parses the HEAD branch. Falls back to "main" if the default branch cannot be determined.

func IsGitRepo

func IsGitRepo(dir string) bool

IsGitRepo reports whether the given directory is a git repository root (has a .git directory). Clones (.git file pointing elsewhere) are not considered since they are not suitable as clone sources.

func Remove

func Remove(repoDir, clonePath string) error

Remove removes a cloned workspace by deleting its directory. The repoDir parameter is accepted for backward compatibility but ignored, since clones are self-contained and do not require cleanup in the source repo.

Types

type CreateOptions

type CreateOptions struct {
	// NoFetch skips the "git fetch origin" step before cloning.
	// When false (the default), origin is fetched so the clone reflects
	// up-to-date remote state.
	NoFetch bool

	// Warnings receives non-fatal warning messages (e.g. fetch failures).
	// When nil, warnings are silently discarded.
	Warnings io.Writer
}

CreateOptions configures the behavior of Create.

Jump to

Keyboard shortcuts

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