Repository navigation
fix(remote): un fetched tags ko resolve karna jinke naam full refs jaise dikhte hain - #2360
Open
Keerthana-64 wants to merge 5 commits into
Open
Keerthana-64 wants to merge 5 commits into
Keerthana-64 wants to merge 5 commits into
Conversation
`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-5
Git resolves `tags/v1` in a fetch refspec to `refs/tags/v1` and prints the source as `v1`. The result decoder missed that mapping and reported a pre-existing tag named `refs/archive/v1` in place of the explicitly requested destination `refs/archive/v1`. Compare exact refspec sources with the display forms of both the provided source and its `refs/`-qualified form. This lets the explicit mapping resolve the destination before consulting the local inventory. A scripted fixture reproduces the collision and checks the destination and both commits. The non-network remote tests passed on each backend with 38 tests, and Ruff and Bash syntax checks passed. Agent-Model: unknown
Git reports `refs/notes/commits` as a full name, but applying wildcard refspecs to the displayed text also invented the tag destination `refs/tags/refs/notes/commits`. The ambiguity dropped the notes result even though Git had fetched it successfully. Match wildcard refspecs against full source paths consistent with Git's display and use the source namespace from Git's new-ref status when available. For unchanged and updated refs, discard ambiguous candidates that do not appear in the local ref inventory. The scripted regression failed on the new notes result before the fix. The remote CLI tests now pass on both backend selections and cover new, unchanged, and fast-forwarded notes. Ruff and Bash syntax checks passed. Agent-Model: unknown
With `--prefetch`, Git writes destinations under `refs/prefetch/`. Those paths do not match the configured tracking refspec, so parsing each result used to scan and format the whole local ref inventory. Index the inventory by displayed name once and reuse the matching bucket for each result. Preserve every full path in each bucket so the decoder can still handle display-name collisions. The scripted prefetch regression detected repeated formatting before the change and passes on both backend selections. A local CLI prefetch of 4,001 unchanged branches took a median of 0.47 seconds over five runs, down from 4.77 seconds before indexing. Ruff and mypy passed. Agent-Model: unknown
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
FetchInfo._from_line pehle kisi bhi displayed fetch destination ko, jo refs/ se shuru hota tha, ek full ref name samajh leta tha. Lekin Git local refs ko prettify_refname ke through print karta hai.
Is wajah se refs/tags/refs/heads/main naam ka tag, refs/heads/main ke roop mein dikhai deta hai.
Koi bhi remote normal tag auto-following ke through is tarah ka tag bhej sakta hai. Iske baad Remote.fetch() ek NEW_TAG result return karta tha, jisme ref ki value local branch refs/heads/main hoti thi.
info.commit fetched tag ke commit ke bajay branch ka commit deta tha. Isliye jo code info.ref ke through naye tags ko delete ya inspect karta tha, woh galti se user ki branch par kaam kar sakta tha.
Isi tarah, agar kisi tag ka naam refs/remotes/origin/main ho, toh woh remote-tracking branch ko bhi tag samajh sakta tha.
Ab displayed name ko pehle refspec mappings aur existing refs ke saath displayed form ke basis par match kiya jata hai. Aur use literal ref tabhi maana jata hai jab kisi bhi existing ref ka displayed naam usse match nahi karta.
Isse refs/notes/* aur deleted refs pehle ki tarah hi resolve hote hain.
Naya test test/test_remote_cli.py pehle fail hota tha, lekin ab pass hota hai.
test_remote.py aur test_remote_cli.py dono backends par -m "not net" ke saath successfully pass hue hain.
(Windows machine par net wale test cases skip kiye gaye the.)
Saath hi, Ruff aur mypy mein bhi koi error nahi hai.
motivation: this turned up while auditing how GitPython maps git's output back to ref names, after the exact-name lookup fixes in #2313 and #2336, which did not cover fetch results.