Skip to content

Commit d8152e4

Browse files
AriehSchneierclaude
andcommitted
docs: Clarify TagFollowing implementation fix in v6
Section 3 was misleading - it said tag defaults didn't change, but missed the key point: the *implementation* of TagFollowing was fixed in v6. What actually happened: - The default (TagFollowing) did not change - BUT v5 had a bug where TagFollowing fetched ALL tags (including those pointing to tree/blob objects) - v6 transport refactor (Dec 2024) fixed TagFollowing to correctly match git's behavior: only fetch tags pointing to commits being fetched - PR #1459 fixed a test that relied on the buggy behavior TagFollowing should use git's include-tag capability to fetch only annotated tags pointing to commits in the fetched history. The v5 implementation incorrectly fetched all tags. Impact: Users who relied on TagFollowing fetching all tags (bug) now need to explicitly set Tags: AllTags. Changes made: - Corrected section title to reflect the bug fix - Explained v5 had buggy TagFollowing implementation - Clarified v6 fixed it to match git CLI behavior - Updated migration guidance for users who relied on the bug - Added clear examples showing the before/after behavior Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Signed-off-by: Arieh Schneier <15041913+AriehSchneier@users.noreply.github.com>
1 parent d64a003 commit d8152e4

File tree

1 file changed

+32
-17
lines changed

1 file changed

+32
-17
lines changed

src/tutorials/migrating-from-v5-to-v6.md

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ Use this checklist to audit your codebase before upgrading:
2626
- [ ] Update the module import path from `github.com/go-git/go-git/v5` to `github.com/go-git/go-git/v6`
2727
- [ ] Call `defer r.Close()` on every `*git.Repository` obtained from filesystem-backed operations
2828
- [ ] Remove the `isBare bool` positional argument from `git.PlainClone` calls; set `CloneOptions.Bare` instead
29-
- [ ] Update any explicit `git.AllTags` / tag-fetch logic — tags are **no longer fetched by default** on `Fetch`
3029
- [ ] Update explicit `git.TagMode` type references to `plumbing.TagMode` (constant usage like `git.AllTags` is unchanged)
3130
- [ ] Rename `config.Version_0` / `config.Version_1` constants to `config.Version0` / `config.Version1`
3231
- [ ] Update code that implements or embeds `commitgraph.Index` — the interface gained `io.Closer` and new methods
@@ -110,37 +109,53 @@ r, err := git.PlainClone("/path/to/repo", &git.CloneOptions{
110109

111110
---
112111

113-
### 3. Tags are no longer fetched by default on `Fetch` ✅ Merged
112+
### 3. `TagFollowing` implementation fixed to match git behavior ✅ Merged
114113

115-
**What changed:** `git.FetchOptions` previously defaulted to fetching all
116-
tags (`AllTags`). In v6 the default is **no tags**. This aligns go-git's
117-
behaviour with the `git fetch` CLI, which only auto-follows tags
118-
reachable from fetched commits when no explicit tag refspec is given.
114+
**What changed:** The default tag fetch mode remains `TagFollowing` in both v5 and v6, but v6 fixed a bug in how `TagFollowing` was implemented. In v5, `TagFollowing` incorrectly fetched **all** tags (including those pointing to tree/blob objects). In v6, `TagFollowing` correctly fetches only tags that point to commits in the fetched history, matching git CLI behavior.
119115

120-
**Why:** When comparing actual `git fetch` behaviour with the test
121-
expectations in go-git, it became clear that the tests expected all tags to
122-
be pulled without the user explicitly requesting them.
116+
**Defaults (unchanged):**
117+
- `CloneOptions.Tags` defaults to `AllTags` (fetch all tags)
118+
- `FetchOptions.Tags` defaults to `TagFollowing` (fetch tags pointing to fetched commits)
123119

124-
**Impact:** Code that relied on tags being silently included in every
125-
`Fetch` call will no longer receive them.
120+
**What `TagFollowing` should do (and now does correctly):**
121+
`TagFollowing` uses git's `include-tag` capability to fetch annotated tags that point to commits being fetched. This matches `git fetch` behavior. It should **not** fetch:
122+
- Tags pointing to tree or blob objects
123+
- Tags not reachable from the commits being fetched
124+
- All tags indiscriminately (that's `AllTags`)
126125

127-
**How to migrate:** If you need all remote tags, set `Tags: git.AllTags`
128-
explicitly:
126+
**Why the change:** The v6 transport layer refactor (Dec 2024) fixed the implementation to correctly use the `include-tag` capability. Previously, `TagFollowing` was fetching all tags, which was incorrect.
127+
128+
**Impact:** If your v5 code relied on `TagFollowing` fetching all tags (including those pointing to trees/blobs), you now need to explicitly set `Tags: git.AllTags`.
129+
130+
**How to migrate:**
131+
132+
If you need all tags (including those pointing to non-commit objects):
129133

130134
```go
131-
// v5 — tags were returned by default
135+
// v5 — TagFollowing incorrectly fetched all tags (bug)
132136
err := r.Fetch(&git.FetchOptions{
133137
RemoteName: "origin",
138+
// Tags defaults to TagFollowing, but was fetching all tags
134139
})
135140

136-
// v6 — must opt in to fetching all tags
141+
// v6 — explicitly request all tags
142+
err := r.Fetch(&git.FetchOptions{
143+
RemoteName: "origin",
144+
Tags: git.AllTags, // now required for all tags
145+
})
146+
```
147+
148+
If you only need tags pointing to fetched commits (correct behavior):
149+
150+
```go
151+
// v6 — default behavior now works correctly
137152
err := r.Fetch(&git.FetchOptions{
138153
RemoteName: "origin",
139-
Tags: git.AllTags,
154+
// Tags defaults to TagFollowing (now correctly implemented)
140155
})
141156
```
142157

143-
**References:** [PR #1459](https://github.com/go-git/go-git/pull/1459)
158+
**References:** [PR #1459](https://github.com/go-git/go-git/pull/1459) (test fix revealing the bug)
144159

145160
---
146161

0 commit comments

Comments
 (0)