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 ¶
- func CheckCLI() error
- func CreateTmuxSession(projectPath, sessionName, launchCommand string) error
- func CreateWorktree(repoPath, branchName string, autoPush bool) (worktreePath string, pushWarning string, err error)
- func ExecInteractive(projectPath string, args []string) error
- func GetMainRepo(worktreePath string) (string, error)
- func HasTmux(projectPath string) bool
- func KillTmuxSession(projectPath, sessionName string) error
- func ListTmuxSessions(projectPath string) ([]string, error)
- func RemoveWorktree(worktreePath string, mainRepoPath ...string) error
- func Restart(projectPath string) error
- func Stop(projectPath string) error
- func Up(projectPath string) error
- func ValidateBranchName(name string) error
- type ContainerInstance
- type ContainerInstanceWithStatus
- type ContainerStatus
- type Project
- type WorktreeInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateTmuxSession ¶
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 ¶
ExecInteractive executes a command inside the devcontainer interactively This replaces the current process with the devcontainer exec
func GetMainRepo ¶
GetMainRepo finds the main repository path from any worktree path
func KillTmuxSession ¶
KillTmuxSession kills a tmux session in the container
func ListTmuxSessions ¶
ListTmuxSessions lists tmux sessions inside the container Returns empty slice (not nil) if no sessions exist
func RemoveWorktree ¶
RemoveWorktree removes a git worktree If mainRepoPath is provided, it will be used when the worktree directory doesn't exist
func Stop ¶
Stop stops the devcontainer by finding and stopping its Docker container It waits for the container to fully exit before returning
func ValidateBranchName ¶
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)