Skip to content

l0.DependencyControl.GitRepository

GitRepository = require "l0.DependencyControl.GitRepository"
local GitRepository = require("l0.DependencyControl.GitRepository")

GitRepository

Interface to a local git repository for running git commands.

Constructor

gitRepository = GitRepository dir
local gitRepository = GitRepository(dir)

Creates an interface to the git repository rooted at dir.

param type description
dir string Absolute path to the repository root.

Instance methods

run

gitRepository\run args
gitRepository:run(args)

Runs a git command and returns trimmed stdout+stderr, or nil on failure or empty output.

param type description
args string Command and flags passed verbatim after git -C <dir>.

Returns:

  • output string?

getBranch

gitRepository\getBranch ref
gitRepository:getBranch(ref)

Returns the branch name the given ref resolves to.

param type description
ref? string Git ref to resolve (defaults to HEAD).

Returns:

  • branch string? — Short branch name, or nil when the command fails.

getCommitHash

gitRepository\getCommitHash ref
gitRepository:getCommitHash(ref)

Returns the abbreviated commit hash of the given ref.

param type description
ref? string Git ref to resolve (defaults to HEAD).

Returns:

  • hash string? — Seven-character commit hash, or nil when the command fails.

isAtTag

gitRepository\isAtTag ref
gitRepository:isAtTag(ref)

Reports whether the given ref sits exactly on a tag.

param type description
ref? string Git ref to test (defaults to HEAD).

Returns:

  • atTag boolean — True when the ref points exactly at a tag.

getVersionSuffix

gitRepository\getVersionSuffix ref
gitRepository:getVersionSuffix(ref)

Returns a git describe-style version suffix for the given ref. Returns "" when the ref is exactly on a tag, "--g" otherwise.

param type description
ref? string Git ref to describe (defaults to HEAD).

Returns:

  • suffix string