fix!: clone reports the checked-out branch or tag, not a default branch (#684) #851

Merged
hexajon merged 1 commit from issue-684-clone-tag-label into main 2026-10-20 17:54:33 +00:00
Owner

Summary

After madt_clone branch=v15.0.6 (a tag), the result line printed (branch: master), although the checkout was the tag.

The cause: the clone result field defaultBranch was misnamed. It was filled from git symbolic-ref --short HEAD, so it held the checked-out branch, and its only reader printed it as (branch: X). On a detached HEAD that command fails, and the code fell back to a hard-coded "master". Bare clones skipped the read and always got "master".

The change:

  • defaultBranch becomes branch: the branch HEAD is on after the clone, for bare clones too, and empty on a detached HEAD.
  • A new tag field holds the tag when the clone checked out a tag (git describe --tags --exact-match HEAD).
  • The result line prints (branch: X) or (tag: X, detached HEAD).
  • There is no hard-coded branch name, and no clone shape makes an extra remote call.

This is a breaking change to the JSON result of madt_clone and madtea clone --json: defaultBranch is gone. The commit carries a BREAKING CHANGE footer. Reporting the remote repository's default branch is a separate feature, #838.

Tests: a real clone of a local file:// repo (default branch trunk, tag v1, branch feature) in nine shapes: no -b, -b feature, and -b v1, each as a normal, a --depth 1, and a bare clone. Each shape checks branch and tag, and the formatter tests check the result line. The fixture builds its source repo with the same git command constructor that production code uses.

./scripts/gate.sh passes on this commit.

Closes #684

## Summary After `madt_clone branch=v15.0.6` (a tag), the result line printed `(branch: master)`, although the checkout was the tag. The cause: the clone result field `defaultBranch` was misnamed. It was filled from `git symbolic-ref --short HEAD`, so it held the checked-out branch, and its only reader printed it as `(branch: X)`. On a detached HEAD that command fails, and the code fell back to a hard-coded `"master"`. Bare clones skipped the read and always got `"master"`. The change: - `defaultBranch` becomes `branch`: the branch HEAD is on after the clone, for bare clones too, and empty on a detached HEAD. - A new `tag` field holds the tag when the clone checked out a tag (`git describe --tags --exact-match HEAD`). - The result line prints `(branch: X)` or `(tag: X, detached HEAD)`. - There is no hard-coded branch name, and no clone shape makes an extra remote call. This is a breaking change to the JSON result of `madt_clone` and `madtea clone --json`: `defaultBranch` is gone. The commit carries a `BREAKING CHANGE` footer. Reporting the remote repository's default branch is a separate feature, #838. Tests: a real clone of a local `file://` repo (default branch `trunk`, tag `v1`, branch `feature`) in nine shapes: no `-b`, `-b feature`, and `-b v1`, each as a normal, a `--depth 1`, and a bare clone. Each shape checks `branch` and `tag`, and the formatter tests check the result line. The fixture builds its source repo with the same git command constructor that production code uses. `./scripts/gate.sh` passes on this commit. Closes #684
fix!: clone reports the checked-out branch or tag, not a default branch (#684)
Some checks failed
drift / govulncheck (pull_request) Has been skipped
drift / surface-diff (pull_request) Successful in 41s
drift / forgejo-smoke (pull_request) Has been skipped
ci / mcp-conformance (pull_request) Successful in 1m29s
ci / mcp-conformance (push) Successful in 2m58s
drift / govulncheck (push) Has been skipped
drift / surface-diff (push) Successful in 2m18s
drift / forgejo-smoke (push) Has been skipped
ci / gate (push) Failing after 10m5s
ci / gate (pull_request) Failing after 13m8s
6d788d5a59
The clone result field defaultBranch always held the checked-out branch, and
on a detached HEAD it fell back to a hard-coded "master". I rename it to
branch, read it for bare clones too, and leave it empty on a detached HEAD.
A new tag field holds the tag when the clone checked out a tag. The result
line prints (branch: X) or (tag: X, detached HEAD). No clone shape makes an
extra remote call.

BREAKING CHANGE: madt_clone and madtea clone --json no longer return defaultBranch. branch holds the checked-out branch (empty on a detached HEAD), and the new tag field holds the tag when the clone checked out a tag.
Sign in to join this conversation.
No reviewers
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!851
No description provided.