vcs

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package vcs provides Git repository topology inspection and worktree, branch, diff, and status operations for TaskSmith workspaces.

Repository Topologies

TaskSmith workspaces can exist in one of four version-control topologies, represented by RepoType and returned by Inspect:

  • RepoTypeNone ("none"): A plain directory that is not tracked by Git, or an environment where the git binary is unavailable on PATH.
  • RepoTypeNormal ("normal"): A standard Git working tree with an embedded .git directory.
  • RepoTypeWorktree ("worktree"): A linked Git worktree created via git-worktree(1) whose Git metadata resides in a shared common directory.
  • RepoTypeBare ("bare"): A bare Git repository (core.bare=true) or a worktree hub directory containing a .bare repository subdirectory.

Canonical Origin Resolution

When multiple linked worktrees belong to the same underlying repository, RepoInfo.CommonDir identifies the shared Git metadata directory and RepoInfo.OriginDir resolves the canonical repository root (the parent of .git or .bare). This allows TaskSmith to group sibling worktrees under a single logical project regardless of which worktree path was opened.

Non-Interactive Subprocess Execution

All Git commands are executed via os/exec with context cancellation and non-interactive environment overrides (GIT_TERMINAL_PROMPT=0 and GIT_SSH_COMMAND="ssh -o BatchMode=yes") so daemon operations never block on interactive credential prompts.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotGitRepo = errors.New("vcs: not a git repository")

ErrNotGitRepo is returned when a Git operation is invoked on a non-Git directory.

Functions

func AddWorktree

func AddWorktree(ctx context.Context, dir, worktreePath, branch string, createBranch bool) error

AddWorktree creates a new linked worktree at worktreePath for the repository at dir. If createBranch is true, a new branch with the given name is created (`git worktree add -b <branch> <worktreePath>`). If createBranch is false, the existing branch is checked out (`git worktree add <worktreePath> <branch>`).

func Diff

func Diff(ctx context.Context, dir string) (string, error)

Diff returns the unstaged and staged diff against HEAD for the working tree at dir. If dir is RepoTypeNone or RepoTypeBare, Diff returns ("", nil).

func IsGitAvailable

func IsGitAvailable() bool

IsGitAvailable reports whether the `git` executable is available on PATH.

func ListBranches

func ListBranches(ctx context.Context, dir string) ([]string, error)

ListBranches returns the short names of all local branches (refs/heads/) in the repository at dir.

func RemoveWorktree

func RemoveWorktree(ctx context.Context, dir, worktreePath string, force bool) error

RemoveWorktree removes a linked worktree at worktreePath from the repository at dir.

func Status

func Status(ctx context.Context, dir string) (string, error)

Status returns the porcelain working-tree status (`git status --porcelain`) for dir. If dir is RepoTypeNone or RepoTypeBare, Status returns ("", nil).

func SwitchBranch

func SwitchBranch(ctx context.Context, dir, branch string, create bool) error

SwitchBranch switches the working tree at dir to branch, creating it if create is true.

Types

type RepoInfo

type RepoInfo struct {
	Type      RepoType `json:"type"`
	RootDir   string   `json:"root_dir"`   // Working tree root (or directory path for RepoTypeNone / RepoTypeBare)
	CommonDir string   `json:"common_dir"` // Shared Git directory (e.g. /path/to/repo/.git or /path/to/hub/.bare)
	OriginDir string   `json:"origin_dir"` // Canonical repository root (parent of CommonDir when CommonDir is .git or .bare; equals RootDir for RepoTypeNone)
	Branch    string   `json:"branch,omitempty"`
	Commit    string   `json:"commit,omitempty"`
	Detached  bool     `json:"detached,omitempty"`
}

RepoInfo describes the Git topology and state of an inspected directory.

func Inspect

func Inspect(ctx context.Context, dir string) (*RepoInfo, error)

Inspect determines the Git topology, canonical directories, and HEAD state for dir.

type RepoType

type RepoType string

RepoType classifies the version-control topology of a directory.

const (
	// RepoTypeNone indicates a plain directory (not a Git repo, or git unavailable).
	RepoTypeNone RepoType = "none"
	// RepoTypeNormal indicates a standard Git working tree.
	RepoTypeNormal RepoType = "normal"
	// RepoTypeWorktree indicates a linked Git worktree.
	RepoTypeWorktree RepoType = "worktree"
	// RepoTypeBare indicates a bare Git repository or worktree hub (e.g. .bare/ or core.bare=true).
	RepoTypeBare RepoType = "bare"
)

type Worktree

type Worktree struct {
	Path     string `json:"path"`
	Head     string `json:"head,omitempty"`
	Branch   string `json:"branch,omitempty"` // Short branch name (stripped of "refs/heads/")
	Bare     bool   `json:"bare,omitempty"`
	Detached bool   `json:"detached,omitempty"`
	Locked   bool   `json:"locked,omitempty"`
	Prunable bool   `json:"prunable,omitempty"`
}

Worktree represents an entry from `git worktree list --porcelain`.

func ListWorktrees

func ListWorktrees(ctx context.Context, dir string) ([]Worktree, error)

ListWorktrees returns all worktrees registered with the repository at dir.

Jump to

Keyboard shortcuts

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