fix(commit): madt_commit reports 0 files/insertions for a root (initial) commit #454

Closed
opened 2026-08-26 21:04:29 +00:00 by hexajon · 0 comments
Owner

madt_commit prints (0 file(s), +0 -0) for the FIRST commit in a brand-new repository, even when the commit contains files. The commit itself is correct; only the confirmation line is wrong, so a reader thinks nothing was committed.

Repro

  1. git init a fresh repo and write some files.
  2. madt_commit(files=[...], message="...") to make the first commit.
  3. The confirmation reads Committed <sha> on <branch> (0 file(s), +0 -0): ....
  4. git show --stat <sha> shows every file is in the commit.

Cause

internal/git/commit.go, GetCommitStats (line 39):

output, err := RunGit(stateCtx(), "diff-tree", "--shortstat", ref)

git diff-tree --shortstat <ref> emits nothing for a root commit, because diff-tree compares a commit to its parent and a root commit has none. With empty output, the files changed / insertions / deletions regexes match nothing and CommitStats{} stays all-zero.

Fix

Add --root, so diff-tree shows a parentless commit as a diff against the empty tree:

output, err := RunGit(stateCtx(), "diff-tree", "--root", "--shortstat", ref)

Verified on a root commit: --shortstat alone returns an empty string; --root --shortstat returns the expected N files changed, M insertions(+) line. --root is a no-op for a commit that already has a parent, so it is safe for every case.

Note

madt_commit already special-cases the no-HEAD bootstrap repo for its default-branch guard, so this stat path just missed the same first-commit edge. Impact is display only; the commit content is never affected.

`madt_commit` prints `(0 file(s), +0 -0)` for the FIRST commit in a brand-new repository, even when the commit contains files. The commit itself is correct; only the confirmation line is wrong, so a reader thinks nothing was committed. ## Repro 1. `git init` a fresh repo and write some files. 2. `madt_commit(files=[...], message="...")` to make the first commit. 3. The confirmation reads `Committed <sha> on <branch> (0 file(s), +0 -0): ...`. 4. `git show --stat <sha>` shows every file is in the commit. ## Cause `internal/git/commit.go`, `GetCommitStats` (line 39): ```go output, err := RunGit(stateCtx(), "diff-tree", "--shortstat", ref) ``` `git diff-tree --shortstat <ref>` emits nothing for a root commit, because diff-tree compares a commit to its parent and a root commit has none. With empty output, the `files changed` / `insertions` / `deletions` regexes match nothing and `CommitStats{}` stays all-zero. ## Fix Add `--root`, so diff-tree shows a parentless commit as a diff against the empty tree: ```go output, err := RunGit(stateCtx(), "diff-tree", "--root", "--shortstat", ref) ``` Verified on a root commit: `--shortstat` alone returns an empty string; `--root --shortstat` returns the expected ` N files changed, M insertions(+)` line. `--root` is a no-op for a commit that already has a parent, so it is safe for every case. ## Note `madt_commit` already special-cases the no-HEAD bootstrap repo for its default-branch guard, so this stat path just missed the same first-commit edge. Impact is display only; the commit content is never affected.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
sixfold-space/madtea#454
No description provided.