devcontainer

package
v0.0.0-...-3c8facb Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package devcontainer handles container lifecycle and git operations.

Overview

This package provides functionality for:

  • Discovering devcontainer projects in search paths
  • Managing container lifecycle (start, stop, restart)
  • Git worktree operations
  • tmux session management within containers

Key Types

  • ContainerInstance: Represents a discovered devcontainer project
  • WorktreeInfo: Git worktree metadata (branch, path, main repo status)

Key Files

  • discovery.go: Recursive devcontainer.json scanner
  • docker.go: Container lifecycle (up, stop, restart, status checks)
  • git.go: Worktree detection, creation, deletion, branch validation
  • tmux_ops.go: Session management, credential injection
  • types.go: Type definitions

Container Identification

Uses Docker label queries for reliability:

docker ps --filter label=devcontainer.local_folder=<path>

Git Worktree Integration

Each worktree is treated as a separate devcontainer instance. Worktrees share the same devcontainer.json from the main repo. The container mounts the main repo's .git directory for git operations.

Package devcontainer provides functionality for managing devcontainers, git worktrees, and tmux sessions within devcontainers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckCLI

func CheckCLI() error

CheckCLI verifies the devcontainer CLI is installed

func CreateTmuxSession

func CreateTmuxSession(projectPath, sessionName, launchCommand string) error

CreateTmuxSession creates a new tmux session in the container. If launchCommand is non-empty, it will be sent to the session after creation.

func CreateWorktree

func CreateWorktree(repoPath, branchName string, autoPush bool) (worktreePath string, pushWarning string, err error)

CreateWorktree creates a new git worktree with a new branch Returns the path to the new worktree directory and any push warning

func ExecInteractive

func ExecInteractive(projectPath string, args []string) error

ExecInteractive executes a command inside the devcontainer interactively This replaces the current process with the devcontainer exec

func GetMainRepo

func GetMainRepo(worktreePath string) (string, error)

GetMainRepo finds the main repository path from any worktree path

func HasTmux

func HasTmux(projectPath string) bool

HasTmux checks if tmux is available in the container

func KillTmuxSession

func KillTmuxSession(projectPath, sessionName string) error

KillTmuxSession kills a tmux session in the container

func ListTmuxSessions

func ListTmuxSessions(projectPath string) ([]string, error)

ListTmuxSessions lists tmux sessions inside the container Returns empty slice (not nil) if no sessions exist

func RemoveWorktree

func RemoveWorktree(worktreePath string, mainRepoPath ...string) error

RemoveWorktree removes a git worktree If mainRepoPath is provided, it will be used when the worktree directory doesn't exist

func Restart

func Restart(projectPath string) error

Restart restarts the devcontainer

func Stop

func Stop(projectPath string) error

Stop stops the devcontainer by finding and stopping its Docker container It waits for the container to fully exit before returning

func Up

func Up(projectPath string) error

Up starts the devcontainer for a project Returns error if it fails

func ValidateBranchName

func ValidateBranchName(name string) error

ValidateBranchName checks if a branch name is valid for git

Types

type ContainerInstance

type ContainerInstance struct {
	Project                  // Embedded: Name and Path (workspace folder)
	ConfigPath string        // Full path to devcontainer.json (from main repo)
	Worktree   *WorktreeInfo // Worktree info (nil for main repo if not a worktree)
}

ContainerInstance represents a specific devcontainer instance Each instance corresponds to a main repo or a git worktree

func DiscoverInstances

func DiscoverInstances(searchPaths []string, maxDepth int, excludedDirs []string) []ContainerInstance

DiscoverInstances finds all devcontainer instances in the given search paths For each project with a devcontainer.json, it finds all git worktrees and adds each worktree as a separate instance

func (ContainerInstance) DisplayName

func (c ContainerInstance) DisplayName() string

DisplayName returns the formatted name for UI display

type ContainerInstanceWithStatus

type ContainerInstanceWithStatus struct {
	ContainerInstance
	Status       ContainerStatus
	ContainerID  string
	SessionCount int
}

ContainerInstanceWithStatus extends ContainerInstance with runtime info

func GetAllInstancesStatus

func GetAllInstancesStatus(instances []ContainerInstance) []ContainerInstanceWithStatus

GetAllInstancesStatus returns all instances with their current Docker status

type ContainerStatus

type ContainerStatus string

ContainerStatus represents the runtime status of a devcontainer

const (
	StatusRunning ContainerStatus = "running"
	StatusStopped ContainerStatus = "stopped"
	StatusUnknown ContainerStatus = "unknown"
)

func GetContainerStatus

func GetContainerStatus(projectPath string) (ContainerStatus, string)

GetContainerStatus checks if a container is running for the given project path

type Project

type Project struct {
	Name string // Project directory name
	Path string // Full path to the project (workspace folder)
}

Project represents a devcontainer project

type WorktreeInfo

type WorktreeInfo struct {
	Path     string // Worktree directory path
	Branch   string // Current branch name
	MainRepo string // Path to main repository
	GitDir   string // Path to worktree gitdir (.git/worktrees/<name>)
	IsMain   bool   // True if this is the main worktree
}

WorktreeInfo represents a git worktree

func IsGitWorktree

func IsGitWorktree(path string) *WorktreeInfo

IsGitWorktree checks if the given path is a git worktree and returns its info Returns nil if the path is not a git worktree or not a git repository

func ListWorktrees

func ListWorktrees(repoPath string) ([]WorktreeInfo, error)

ListWorktrees returns all worktrees for a repository (including the main one)

Jump to

Keyboard shortcuts

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