fix(remote): keep push results for sources that are not refs by JROtto5 路 Pull Request #2364 路 gitpython-developers/GitPython
Repository navigation
fix(remote): keep push results for sources that are not refs - #2364
Merged
Byron merged 9 commits into gitpython-developers:main from JROtto5:fix/push-non-ref-source Nov 26, 2026
Merged
fix(remote): keep push results for sources that are not refs #2364 Byron merged 9 commits into gitpython-developers:main from JROtto5:fix/push-non-ref-source
Conversation
JROtto5 commented Nov 25, 2026 · edited Loading
Copy link Copy Markdown
Contributor
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.py after the prune warning fix in #2357 . git push --porcelain prints the source of each refspec as it was given. Pushing <hash>:refs/heads/x or HEAD~1:refs/heads/x therefore reports <hash> or HEAD~1 as the source. PushInfo._from_line() passed that to Reference.from_path(), which raised ValueError, 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_ref set to None, the same as for deletes. A new PushInfo.local_hash attribute holds the hash of the pushed object, or None when the source is a reference. Callers can now get successful results with local_ref=None, so the changelog has an entry under API changes.
The hash comes from git's old..new summary when git prints one, because a push like origin/main~1:main moves 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~1 is 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 with rev-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 with local_hash=None instead of being dropped.
test_push_revision_sources pushes a hash, HEAD~1 and HEAD in one call. It then force-pushes self/pushed_ref~1 over 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 both GIT_PYTHON_BACKEND=cli and gix, and passes with it. The full suite passes under cli. Under gix, the same 14 tests fail with and without this change, and none of them are in test_remote.py. Ruff check and format pass, and mypy reports no issues. I only tested on Linux with Git 2.56.0.
Fixes #1624
Byron requested a balanced review from Copilot November 25, 2026 07:22 Copilot started reviewing on behalf of Byron November 25, 2026 07:23View session
Copilot PR reviewer Copilot
AI
reviewed Nov 25, 2026
View reviewed changes
Copilot
AI
left a comment
Copy link Copy Markdown
Contributor
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more .
馃煛 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- Validate fully qualified refs before constructing a Reference 路 New
- Expand pushed object IDs without revision-name precedence 路 New
- Handle post-push lookup failures without stopping output consumption 路 New
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/鈥媡est_remote.py |
Tests mixed source types and a forced update relative to a moved ref. |
git/鈥媟emote.py |
Retains revision-source results and adds pushed-object hash information. |
doc/鈥媠ource/鈥媍hanges.rst |
Documents the updated PushInfo behavior. |
Review effort: Balanced
JROtto5 and others added 9 commits November 26, 2026 08:55
fix(remote): keep push results for sources that are not refs
6ddc49c
`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
fix(remote): harden push source lookup for revision sources
c8aa12f
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
fix(remote): split push status refspecs at the final colon
056d90a
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
fix(remote): retain push status when revision validation rejects a so...
445287e
...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
fix(remote): drain push status output before resolving hashes
e021277
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
fix(remote): require an exact reference for a push source
c8ed494
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
fix(remote): capture revision sources before the push changes refs
b06a835
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
fix(gix): resolve push remote selectors with Git
b465842
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
fix(git)!: scope one-shot options to the returned wrapper
2d6d27a
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-solByron force-pushed the fix/push-non-ref-source branch from
330fea3 to
2d6d27a
Compare
November 26, 2026 07:57 Byron merged commit
1c9ef7d
into
gitpython-developers : main
Nov 26, 2026
64 checks passed
Sign up for free
to join this conversation on GitHub .
Already have an account?
Sign in to comment