Repository navigation
fix(remote): keep push results for sources that are not refs - #2364
Merged
Byron merged 9 commits intoNov 26, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved push-result handling issues can misclassify revision sources, resolve abbreviated object IDs to the wrong object, and truncate successful push results when lookup exceptions escape.
3 open issues
What changed in this PR
GitHub Copilot review: This PR addresses #1624 by preserving GitPython push results when the source is a commit hash or revision expression rather than a reference.
Changes:
- Adds
PushInfo.local_hashand allows non-reference sources to returnlocal_ref=None. - Resolves pushed hashes from Git’s summary when available, otherwise from the source after the push.
- Adds regression coverage and documents the API change.
| File | Description |
|---|---|
test/test_remote.py |
Tests mixed source types and a forced update relative to a moved ref. |
git/remote.py |
Retains revision-source results and adds pushed-object hash information. |
doc/source/changes.rst |
Documents the updated PushInfo behavior. |
Review effort: Balanced
`git push --porcelain` prints the source side of each refspec as it was given, so `git push origin <hash>:refs/heads/x` or `HEAD~1:refs/heads/x` reports `<hash>` or `HEAD~1` there. `PushInfo._from_line()` passed it to `Reference.from_path()`, which raised `ValueError`, and `_get_push_info()` dropped the line. A push of only such sources returned an empty list, and a mixed push only the results for the other refspecs. When the source is not a reference, set `local_ref` to `None`, as it already is for deletes, and record the pushed object's hash in a new `local_hash` attribute. This is the shape suggested in gitpython-developers#1624. The hash comes from git's `old..new` summary when there is one, because the push can move a ref the source is relative to, such as `origin/main~1`; only new refs and rejected lines resolve the source. `test_push_revision_sources` pushes a hash, `HEAD~1` and `HEAD` in one call, then force-pushes `self/pushed_ref~1` over the ref it is relative to. It fails without this change under the `cli` and `gix` backends, and passes with it. Agent-Model: claude-opus-5-5
Three gaps in the non-ref source handling, from review:
- `Reference.from_path()` accepts any `refs/` path, so a source such
as `refs/heads/main~1` became a `Head` that does not exist. Sources
with `~`, `^` or `@{`, which `check-ref-format` never allows in a
ref name, are now taken as revisions without trying `from_path()`.
- `rev-parse` prefers a ref over an object ID with the same spelling,
so a branch named like the abbreviated ID in git's summary gave the
wrong `local_hash`. Expand it with `rev-parse --disambiguate`, which
only looks at object IDs.
- A lookup error other than `BadName` escaped the stdout handler and
dropped the push result. Keep the result with `local_hash=None`.
`test_push_revision_sources` covers each case, including a failing
lookup on both paths; each new assertion fails with only its part of
the change reverted, under `cli` and `gix`.
Agent-Model: claude-opus-5-5
Git prints the complete source expression in porcelain output. A tree-path expression such as `HEAD:file.txt` includes a colon of its own. Splitting on every colon made GitPython discard the status even though Git had created the destination tag. Split only at the final colon so revision lookup receives the full source expression. Test the result and the tag's object ID on the CLI and Gix backends. Agent-Model: unknown
…urce Git accepts an option-shaped revision such as `-release~1` in a push refspec after `--`. The separate revision query rejects it, and the uncaught `UnsafeOptionError` previously stopped the stdout reader and lost later statuses. Treat the validation failure as an unavailable hash and retain the status. A mixed push regression checks that both results survive and that the receiver got the snapshot on both backends. Agent-Model: unknown
Resolving revision sources in the stdout reader made optional object lookups count against `kill_after_timeout`. A push could finish on the receiver while the reader was still resolving hashes, report a timeout, and lose statuses later in the stream. Collect the raw porcelain lines during the timed drain and parse the captured lines once the drain returns. A subprocess regression checks that disambiguation happens after stdout closes and that both statuses are retained. The partial-timeout test still passes on both backends. Agent-Model: unknown
A describe expression derived from a tag named `refs/releases/base` starts with `refs/`. `Reference.from_path()` accepts that prefix, so a successful push returned a reference that did not exist and discarded the pushed commit's ID. Use the shared exact-reference lookup before setting `local_ref`. A regression pushes the describe expression and verifies the destination and reported commit IDs on both backends. Agent-Model: unknown
A push can update the tracking ref that another refspec uses as a revision base. Looking up the source after the push can return a different commit. The old lookup also omitted per-call Git settings such as `GIT_NO_REPLACE_OBJECTS`. Resolve explicit sources with the push environment before starting Git. Prefer object IDs reported in update summaries. Leave the hash unset if Git did not report it and the source could not be captured. Skip capture when one-shot Git options are reserved for the push. Regressions verify a combined tracking-ref update and snapshot, per-call replacement settings, and one-shot options. The focused push tests pass on the CLI and Gix backends. Agent-Model: unknown
With `push.default=upstream` and a mirror selected by
`branch.main.pushRemote`, Git resolves `@{push}` through
`mirror/main`. GixPython 0.4.0 resolves it through
`origin/main`, so the Gix backend reported an object ID
different from the one the push sent.
Route push selectors through the managed Git fallback and record
the open mismatch as GIX-45. The integration test verifies the
receiver's object ID and the fallback on SHA-1 and SHA-256.
The remote, revision, and CLI safety tests pass on both backends.
Agent-Model: unknown
Rubber-stamp tests. Just a rubber-stamp for everything, but looked at the code at least to see if something sticks out. And what stuck out is statefulness of Git command execution. <!-- agent --> Calling `repo.git(**options)` used to queue options on the shared `Git` wrapper. A source lookup in `Remote.push()` could consume options meant for the push, so the push skipped that lookup and could leave `PushInfo.local_hash` unset. Return a separate wrapper that applies the options to its next subcommand. Chained calls still work, but discarding the wrapper no longer affects later repository operations. Remove the push guard and the commit hook's save-and-restore logic. For repository operations, use per-call environment overrides or `set_persistent_git_options()`. The non-network command, remote, index, and downstream compatibility tests passed on both CLI and Gix (307 passed per backend). Agent-Model: gpt-6.2-sol
Byron
force-pushed
the
fix/push-non-ref-source
branch
from
November 26, 2026 07:57
330fea3 to
2d6d27a
Compare
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.

I am a Claude (Opus 5.5) agent working through the contributor's account.
This is the bug reported in #1624, which was closed in July without a fix. I found it while reading the push side of
remote.pyafter the prune warning fix in #2357.git push --porcelainprints the source of each refspec as it was given. Pushing<hash>:refs/heads/xorHEAD~1:refs/heads/xtherefore reports<hash>orHEAD~1as the source.PushInfo._from_line()passed that toReference.from_path(), which raisedValueError, and_get_push_info()dropped the line. A push made up only of such sources returned an empty list. A mixed push returned only the results for the other refspecs.As suggested on #1624, these results now come back with
local_refset toNone, the same as for deletes. A newPushInfo.local_hashattribute holds the hash of the pushed object, orNonewhen the source is a reference. Callers can now get successful results withlocal_ref=None, so the changelog has an entry under API changes.The hash comes from git's
old..newsummary when git prints one, because a push likeorigin/main~1:mainmoves the ref that the source is relative to. Git's output has no hash for new or rejected refs, so for those the source is resolved after the push. That hash can be wrong if another refspec in the same push moved the ref the source is relative to. Resolving before the push would add a git call to every push, and the command guard tests rule that out, so I documented the limitation instead.After review, a second commit closes three gaps. A fully qualified revision such as
refs/heads/main~1is no longer taken for a ref: a source with~,^or@{, which ref names can't contain, is treated as a revision without a git call. The abbreviated hash is expanded withrev-parse --disambiguate, which only matches object IDs, so a branch spelled like the abbreviation can't win. If the lookup fails, the result is kept withlocal_hash=Noneinstead of being dropped.test_push_revision_sourcespushes a hash,HEAD~1andHEADin one call. It then force-pushesself/pushed_ref~1over the ref it is relative to, and covers the three cases above, with both lookups made to fail. The test fails without the change under bothGIT_PYTHON_BACKEND=cliandgix, and passes with it. The full suite passes undercli. Undergix, the same 14 tests fail with and without this change, and none of them are intest_remote.py. Ruff check and format pass, and mypy reports no issues. I only tested on Linux with Git 2.56.0.Fixes #1624