Help us shape the future of Go! Take the 2026 Go Developer Survey

workspace

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package workspace decides where a local workspace folder is mounted in a single-container devcontainer and which container folder is its workspace folder. It follows upstream's getWorkspaceConfiguration (src/spec-node/utils.ts) and reads the host file system only; it never runs git. Compose configurations own their mounts and do not use this package.

Index

Constants

View Source
const (
	ConsistencyConsistent = "consistent"
	ConsistencyCached     = "cached"
	ConsistencyDelegated  = "delegated"
)

Consistency values accepted for bind mounts on Docker Desktop hosts.

Variables

This section is empty.

Functions

func GitRoot

func GitRoot(folder string) (string, error)

GitRoot returns the top folder of the Git working tree that contains folder, or "" when folder is not inside one. It follows Git's discovery without running git: walking up lexically (so symlinked names are kept, as upstream's `git rev-parse --show-cdup` result is), a .git folder that is a repository marks the root; a .git file marks the root when its gitdir is a repository, and otherwise ends discovery, as Git refuses an invalid gitfile. Environment overrides such as GIT_DIR and GIT_CEILING_DIRECTORIES and Git's ownership check are not applied.

func MountedFolder

func MountedFolder(localWorkspace string, binds []Bind) string

MountedFolder returns the container folder at which an existing container shows localWorkspace: the destination of the bind mount whose source is the workspace or its nearest mounted ancestor, with the rest of the workspace path below it. That is where the container placed the workspace, whatever options created it. It returns "" when no bind mount contains the workspace.

Types

type Bind

type Bind struct {
	Source, Destination string
}

Bind is an existing container's bind mount: the host source and the container destination, as the Engine reports them.

type Configuration

type Configuration struct {
	// WorkspaceFolder is the container workspace folder, or "" when the
	// configuration sets workspaceFolder itself.
	WorkspaceFolder string
	// WorkspaceMount is the workspace bind mount, or nil when the
	// configuration declares workspaceMount.
	WorkspaceMount *Mount
	// AdditionalMount is the linked worktree's common Git folder, if mounted.
	AdditionalMount *Mount
}

Configuration is the resolved workspace placement.

func Resolve

func Resolve(localWorkspace string, hasWorkspaceFolder, hasWorkspaceMount bool, opts Options) (Configuration, error)

Resolve places localWorkspace (an absolute host folder). hasWorkspaceFolder and hasWorkspaceMount report whether the configuration declares those properties; when it declares both, nothing is derived.

type Mount

type Mount struct {
	Source, Target, Consistency string
}

Mount is a bind mount from a host folder to a container folder.

func (Mount) String

func (m Mount) String() string

String renders the mount in upstream's devcontainer mount syntax, quoting a source or target that contains a comma.

type Options

type Options struct {
	// MountGitRoot mounts the top folder of the workspace's Git working tree
	// in place of the workspace folder (upstream default true).
	MountGitRoot bool
	// MountGitWorktreeCommonDir also mounts the common Git folder of a linked
	// worktree whose .git file holds a relative gitdir, so Git works in the
	// container. It applies only with MountGitRoot.
	MountGitWorktreeCommonDir bool
	// Consistency is set on the bind mounts on hosts other than Linux. Empty
	// means consistent.
	Consistency string
	// Platform is the host's GOOS. Linux mounts carry no consistency option,
	// as upstream omits it there.
	Platform string
}

Options select how the workspace is mounted.

func (Options) BindConsistency

func (o Options) BindConsistency() string

BindConsistency is the consistency option for these options' bind mounts: none on Linux, otherwise Consistency or consistent.

Jump to

Keyboard shortcuts

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