Git.Worktree (git v0.4.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.

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(),
  path: String.t()
}

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", bare: false, detached: false}]

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