Git.Branch (git v0.4.0)

Copy Markdown View Source

Parsed representation of a git branch entry.

Contains the branch name, whether it is the currently checked-out branch, whether it is a remote-tracking branch, its upstream tracking reference, and the ahead/behind commit counts relative to the upstream.

Summary

Functions

Parses the output of git branch -vv into a list of Git.Branch structs.

Types

t()

@type t() :: %Git.Branch{
  ahead: non_neg_integer(),
  behind: non_neg_integer(),
  current: boolean(),
  name: String.t(),
  remote: boolean(),
  upstream: String.t() | nil,
  worktree: boolean()
}

Functions

parse(output)

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

Parses the output of git branch -vv into a list of Git.Branch structs.

Each line has the form:

* main                abc1234 [origin/main: ahead 1] subject
  feature/foo         def5678 [origin/feature/foo] subject
  remotes/origin/HEAD -> origin/main

Lines beginning with remotes/ are remote-tracking refs. Lines containing -> are symbolic refs (e.g. HEAD -> main) and are skipped.

Examples

iex> Git.Branch.parse("* main abc1234 subject\n")
[%Git.Branch{name: "main", current: true, remote: false}]