Git.Worktree (git v0.7.0)

Copy Markdown View Source

Parsed representation of a git worktree entry.

Contains the path, HEAD commit SHA, branch reference, and flags indicating whether the worktree is bare or has a detached HEAD.

Two annotation fields carry the porcelain locked and prunable markers. Each is nil when absent and otherwise the reason git reported (the empty string when git gave no reason). prunable marks a worktree whose directory is gone, recoverable with git worktree prune.

Summary

Functions

Parses the porcelain output of git worktree list --porcelain into a list of Git.Worktree structs.

Types

t()

@type t() :: %Git.Worktree{
  bare: boolean(),
  branch: String.t() | nil,
  detached: boolean(),
  head: String.t(),
  locked: String.t() | nil,
  path: String.t(),
  prunable: String.t() | nil
}

Functions

parse(output)

@spec parse(String.t()) :: [t()]

Parses the porcelain output of git worktree list --porcelain into a list of Git.Worktree structs.

The porcelain format separates entries with blank lines. Each entry has key-value lines like:

worktree /path/to/main
HEAD abc1234
branch refs/heads/main

Examples

iex> Git.Worktree.parse("worktree /tmp/main\nHEAD abc1234\nbranch refs/heads/main\n\n")
[%Git.Worktree{path: "/tmp/main", head: "abc1234", branch: "refs/heads/main", locked: nil, prunable: nil, bare: false, detached: false}]

iex> Git.Worktree.parse("worktree /tmp/gone\nHEAD abc1234\nbranch refs/heads/wt\nprunable gitdir file points to non-existent location\n\n") |> hd() |> Map.get(:prunable)
"gitdir file points to non-existent location"

iex> Git.Worktree.parse("")
[]