Skip to content

@saflib/git


@saflib/git

Classes

ClassDescription
GitCommandErrorRaised when a git plumbing command exits non-zero or produces unparseable output. Consumers should treat this as an expected, typed failure (missing ref, corrupt object, not a git repo, etc.) rather than an unexpected exception.

Interfaces

InterfaceDescription
GitCommitOne commit returned by log.
GitRef-
GitTreeEntryOne tree entry returned by listTree (blobs only).
LogOptions-

Functions

FunctionDescription
currentBranchShort name of the branch HEAD points at (e.g. main), or null when detached.
isAncestorTrue when maybeAncestor is an ancestor of maybeDescendant (or they are the same commit). Wraps git merge-base --is-ancestor.
listRefsList local branch and tag refs via git for-each-ref. Does not include remote-tracking refs.
listRenamesFile rename pairs from fromRef to toRef (git diff --find-renames -z --name-status --diff-filter=R).
listTreeList every blob at commitHash (recursive) without checking anything out. Directories / trees / commits / tags are skipped — only blob entries are returned. Paths are relative to the repo root.
logWalk commits on ref (default HEAD), newest first — same order as git log. Uses --first-parent so merge commits don't fan the walk out.
mergeBaseBest common ancestor of two commits/refs (git merge-base <a> <b>).
readBlobRead a blob's contents by hash without checking anything out. Returns the raw file text (git stores blobs without a trailing newline of its own beyond what the file itself contained).
readBlobsRead many blobs in one git cat-file --batch invocation. Missing/invalid objects are omitted from the result map (caller treats as miss).
resolveRefResolve a ref (default HEAD) to a full commit hash via git rev-parse.