Found in review of claudeacp#4: in a linked worktree changelog reads the main checkout's HEAD #39
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
mikluko/changelog!39
Loading…
Reference in a new issue
No description provided.
Delete branch "worker/changelog-nx4"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes changelog-nx4: in a linked git worktree the tool read HEAD from the main checkout, not from the worktree.
The defect on main (
964604a, 2.0.0)Openfollowed.gitto the worktree's gitdir and on to itscommondir, then read everything from the common directory, HEAD included. The common directory's HEAD is the main checkout's. SoReference(latest-tag) andMergeBase(missing-fragment) worked from the wrong commit. The defect was still on main; no change since v1.6.0 had fixed it, and no test covered a linked worktree's HEAD.How I reproduced it
A scratch repo with tags v0.1.0..v0.3.0 and the main checkout standing at v0.3.0. A linked worktree (
git worktree add -b feature ../wt) with one more commit tagged v0.4.0 and one commit after it.git describe --tagssaysv0.3.0in the main checkout andv0.4.0-1-g…in the worktree. Output of the built tool,latest-tagline:latest-tag=v0.3.0latest-tag=v0.3.0latest-tag=v0.3.0(wrong)latest-tag=v0.4.0The fix
Repokeeps a second storage on the worktree's own gitdir, used for HEAD only (Repo.head). The branch HEAD names is resolved in the common directory, where branches live; a detached HEAD is taken as it is. Refs and objects still come from the shared directory. Outside a linked worktree the two storages are one directory, so nothing changes there.ReferenceandMergeBaseboth go throughhead.Tests
TestReferenceReadsALinkedWorktreesOwnHead: main checkout at v0.1.0, a worktree on a branch and a detached worktree both past v0.2.0; each must report its own reference tag.TestMergeBaseReadsALinkedWorktreesOwnHead: the worktree's merge base with another branch is that branch's tip, not what the main checkout's HEAD would give.Both fail without the change (verified by stashing
git.go) and pass with it.go vet ./...,go test ./...andgolangci-lint runare clean.A fragment,
.changelog/linked-worktree-head.md, adds the Fixed note.Bead: changelog-nx4
Reviewed
941aa26: HEAD read from the linked worktree own gitdir; reproduced on main, fixed on head across worktree/clone/shallow/submodule cases; merge result passes build, vet, test, gen-readme, golangci-lint and the changelog check.Review of
941aa26(base964604a, release 2.0.0).Reproduced. I built both from source, offline: main and the head. The scratch repository has tags v0.1.0..v0.3.0, and its main checkout stands at v0.3.0. A linked worktree on
featureis at v0.4.0 plus one commit. In the worktree, main's build printedlatest-tag=v0.3.0and the head's build printedlatest-tag=v0.4.0. In the main checkout both printedv0.3.0.Cases, main's build -> head's build (
latest-tag):--relative-pathsworktree: v0.3.0 -> v0.4.0 (fixed)-changelog wt/CHANGELOG.mdfrom outside it: fixed in both--orphanworktree: was the main checkout's v0.3.0, is now no reference (correct)--depth 1clone; shallow branch clone with tags fetched; submodule reached through a.gitfileGIT_DIRandGIT_WORK_TREEare not honoured, before or after: the tool only walks up the tree looking for.git.missing-fragment. I set the main checkout on an old branch, and the worktree on a branch from current main that adds no fragment. Main's build passed it wrongly. The head's build reports
missing-fragment, which is correct.ReferenceandMergeBaseare the only places that read HEAD. Both now go throughRepo.head(), and so do the checks that read the changelog at the reference tag (FileAt(reference)). Tags, shallow, objects and the base branch still come from the common directory.Tests. The two new tests fail against main's
git.goand pass with the head's.Merge result (head merged into
964604a):go build,go vet,go test ./..., gen-readme with no README diff, golangci-lint v2.15.0 (built from source; 0 issues) andchangelog -changelog CHANGELOG.md -fragments .changelog -base main(exit 0) all pass. The CI checks for the head were green. The fragment is in the shape the README asks for, under### Fixed. The change adds no shell. Merging cannot cut a release: the release workflow runs only onworkflow_dispatch.Follow-ups (minor):
resolve()still resolves abaseof literallyHEADin the common directory. That gives the main checkout's HEAD in a worktree. This was so before; nobody passes it in practice.refs/worktree/*,refs/bisect/*) that HEAD might name are looked up in the common directory.Co-authored-bytrailer.Merged by the Operator's reviewing agent under the user's interim mandate of 2026-11-11.