Repository navigation
Commit e3adb9b
committed
fix(remote): resolve fetched tags whose names look like full refs
`FetchInfo._from_line` turns the verbose output of `git fetch` into the
`FetchInfo` results returned by `Remote.fetch` and `Remote.pull`. It took
any displayed destination starting with `refs/` as a full reference name.
Git displays local references through `prettify_refname`, which strips
`refs/heads/`, `refs/tags/` and `refs/remotes/`, so the tag
`refs/tags/refs/heads/main` is displayed as `refs/heads/main`. Such a tag
name is valid and reaches a clone through ordinary tag auto-following
from any remote.
Before this change, fetching from a remote that carries the tag
`refs/heads/main` produced a `FetchInfo` flagged `NEW_TAG` whose `ref` was
the local branch `refs/heads/main`: `info.commit` returned the local
branch commit instead of the fetched tag's commit, and code acting on new
tags through `info.ref` (inspecting or deleting them) acted on the user's
branch. A tag named `refs/remotes/origin/main` was reported as the
remote-tracking branch in the same way. Both backends were affected,
since this parses Git CLI output.
The displayed name is now matched against the refspec mappings and then
against existing references by their displayed form, and taken as a full
name only when no reference displays as it. Results from refspec
mappings are no longer overridden either, so a refspec that stores into
`refs/tags/refs/heads/x` resolves to that reference. References outside
the three shortened namespaces, such as `refs/notes/x`, display as
themselves and resolve as before, as do deleted references that no
longer exist.
Adds a `tag-named-like-branch` case to `tests/fixtures/remote-cli.sh` and
`test_fetch_resolves_tag_named_like_a_full_branch_ref` in
`test/test_remote_cli.py`, which fails before the change
(`'refs/heads/main' == 'refs/tags/refs/heads/main'`) and passes after.
`test/test_remote.py` and `test/test_remote_cli.py` pass with
`GIT_PYTHON_BACKEND=cli` and `gix` (`-m "not net"`; the `net` cases were
skipped on this Windows machine), and `ruff check`, `ruff format --check`
and `mypy` are clean.
Agent-Model: claude-opus-5-51 parent 60a2715 commit e3adb9b
3 files changed
Lines changed: 21 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
410 | 410 | | |
411 | 411 | | |
412 | 412 | | |
413 | | - | |
414 | | - | |
415 | 413 | | |
416 | 414 | | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
417 | 419 | | |
418 | 420 | | |
419 | 421 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
56 | 67 | | |
57 | 68 | | |
58 | 69 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
12 | 18 | | |
13 | 19 | | |
14 | 20 | | |
| |||
0 commit comments