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

projects

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package projects discovers git repositories and worktrees below served roots and resolves project directories within them. It knows the .git marker and git's worktree and HEAD files, and nothing about file formats.

Index

Constants

This section is empty.

Variables

View Source
var ErrInsideRepository = fmt.Errorf("%w: inside a repository", ErrUnavailable)

ErrInsideRepository is returned for a directory inside a repository that is not itself a repository or worktree: repositories open whole.

View Source
var ErrUnavailable = errors.New("project unavailable")

ErrUnavailable is returned when a project ID does not name a servable directory.

Functions

func Branch

func Branch(dir string) string

Branch reads a worktree's HEAD: the branch name, another ref's name, or a short commit when detached. It is empty when dir is not a worktree or HEAD cannot be read.

func CanonicalRoots

func CanonicalRoots(paths []string) ([]string, error)

CanonicalRoots resolves served roots to absolute, symlink-evaluated directories in order, drops duplicates, and rejects roots nested in another.

func Resolve

func Resolve(roots []string, id string, excluded []string) (string, error)

Resolve returns the symlink-evaluated directory for a project ID, an absolute path. Below a root, a directory opens when it is a repository or worktree, or when no directory from the root down to it is one; .git and excluded names never open. Outside every root, only a linked worktree whose repository lies in a root opens.

Types

type Checkout

type Checkout struct {
	Kind       Kind
	Branch     string
	Repository string
	Worktrees  int
}

Checkout describes the repository checked out at a project directory. Repository is the origin remote's repository name, else the main worktree's folder; Worktrees counts the repository's verified checkouts. A folder outside any repository has KindFolder and nothing else.

func Inspect

func Inspect(dir string) Checkout

Inspect describes the checkout at a canonical project directory.

type Directory

type Directory struct {
	Name      string `json:"name"`
	Path      string `json:"path"`
	IsProject bool   `json:"isProject"`
}

Directory is a child directory listed while browsing for a project.

func Directories

func Directories(roots []string, id string, excluded []string) ([]Directory, error)

Directories lists the child directories of a folder for browsing; an empty ID lists the roots. Repositories and their contents are not browsed: they open whole. Hidden directories are listed; .git, excluded names, and symlinks are not.

type Discovery

type Discovery struct {
	Projects []Project
	Warnings []files.Warning
}

Discovery is the result of Discover. Warnings hold recoverable errors below the roots.

func Discover

func Discover(roots []string, maxDepth int, excluded []string) (Discovery, error)

Discover finds repositories up to maxDepth directories below each root (a root is depth zero) and every worktree of those repositories, wherever it lives. It stops descending at a repository, skips hidden and excluded directory names, and does not follow symlinks. A root that is not a repository is listed as a folder project.

type Kind

type Kind string

Kind describes why a directory is listed as a project.

const (
	// KindFolder is a served root that is not itself a repository.
	KindFolder Kind = "folder"
	// KindRepo is a repository's main worktree or a submodule.
	KindRepo Kind = "repo"
	// KindWorktree is a linked worktree created by git worktree add.
	KindWorktree Kind = "worktree"
)

type Project

type Project struct {
	ID         string `json:"id"`
	Name       string `json:"name"`
	Path       string `json:"path"`
	Kind       Kind   `json:"kind"`
	Group      string `json:"group"`
	Root       string `json:"root"`
	Branch     string `json:"branch"`
	Repository string `json:"repository"`
	Available  bool   `json:"available"`
}

Project is a directory that can be served as a workspace.

ID is the canonical absolute path; it is empty when the directory cannot be opened. Path is always the absolute path. Members of one repository with linked worktrees share Group, the Path of the group's main worktree (or of its first member when the main worktree is missing). Root is the served root the project, or its repository, lives in; empty when none. Branch is the checked-out branch, a short commit for a detached HEAD, or empty. Repository names the project's repository (see Checkout); empty for a folder.

type Root

type Root struct {
	Path   string `json:"path"`
	Name   string `json:"name"`
	IsRepo bool   `json:"isRepo"`
}

Root is a served root directory.

func Roots

func Roots(roots []string) []Root

Roots describes served roots for display.

Jump to

Keyboard shortcuts

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