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 ¶
- Variables
- func AddWorktree(ctx context.Context, dir, worktreePath, branch string, createBranch bool) error
- func Diff(ctx context.Context, dir string) (string, error)
- func IsGitAvailable() bool
- func ListBranches(ctx context.Context, dir string) ([]string, error)
- func RemoveWorktree(ctx context.Context, dir, worktreePath string, force bool) error
- func Status(ctx context.Context, dir string) (string, error)
- func SwitchBranch(ctx context.Context, dir, branch string, create bool) error
- type RepoInfo
- type RepoType
- type Worktree
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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 ¶
ListBranches returns the short names of all local branches (refs/heads/) in the repository at dir.
func RemoveWorktree ¶
RemoveWorktree removes a linked worktree at worktreePath from the repository at dir.
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.
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`.