Pure-Lua git repository reader.
Parses .git directory structures directly, avoiding
the need to spawn git processes: loose and packed
objects (pack .idx v2, OFS/REF delta resolution), refs (loose,
packed, symbolic), HEAD, the staging index, commit and tree objects.
Works on bare repositories and worktrees alike, every function takes
an explicit git_dir.
Read-only. Higher layers build on this core: git.prompt (shell
prompt status) and git.pack (packfile generation for serving).
| Module | Description |
|---|---|
| git.pack | Packfile generation on top of the git core reader: walk the object graph from a set of wanted refs and serialize a version 2 packfile. |
| git.prompt | Git repository status for shell prompt integration, built on the git core reader. |
| Name | Signature |
|---|---|
| find_git_dir | find_git_dir(start_path) -> git_dir, worktree |
| resolve_ref | resolve_ref(git_dir, ref_path) -> sha |
| read_head | read_head(git_dir) -> head |
| read_object | read_object(git_dir, sha_hex) -> obj |
| parse_commit | parse_commit(content) -> commit |
| parse_tree | parse_tree(content) -> entries |
| list_refs | list_refs(git_dir) -> refs |
find_git_dir(
start_path) ->git_dir,worktree
Discover the .git directory by walking up from a starting path
Walks the directory tree upward from start_path (defaults to cwd)
looking for a .git directory or gitdir file (worktrees/submodules).
Returns the resolved git directory path and the worktree root,
or nil if not inside a git repository.
resolve_ref(
git_dir,ref_path) ->sha
Resolve a ref path (e.g. refs/heads/main) to a SHA, following symbolic refs and packed-refs
read_head(
git_dir) ->head
Read HEAD of a repository
Returns { type = "branch", name = short_name, ref = full_ref } for a
symbolic HEAD, or { type = "detached", sha = sha } for a detached one.
read_object(
git_dir,sha_hex) ->obj
Read an object from the object database (loose or packed, deltas resolved)
Returns { type = "commit"|"tree"|"blob"|"tag", size = n, content = raw }
or nil when the object is not found.
parse_commit(
content) ->commit
Parse a raw commit object's content
Returns { tree = sha, parents = {sha, ...}, author = str, committer = str, message = str }.
parse_tree(
content) ->entries
Parse a raw tree object's content
Returns an array of { mode = str, name = str, sha = hex_str } entries.
list_refs(
git_dir) ->refs
List all refs of a repository: loose and packed, with peeled ^{} entries for annotated tags