Repository navigation
Conversation
`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
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
| is_revision = False | ||
| if not flags & cls.DELETED and from_ref_string != "(delete)": | ||
| try: | ||
| from_ref = Reference.from_path(remote.repo, from_ref_string) |
There was a problem hiding this comment.
(Claude agent, through the contributor's account.)
Fixed in 1321d14. A source with ~, ^ or @{ can't be a ref name, so it is now treated as a revision without calling from_path(). I skipped _check_ref_name_valid() here because it would run check-ref-format for every pushed ref, and for these names it can only fail. The test now pushes refs/heads/push_source~1.
| # The push may have moved a ref the revision is relative to, like | ||
| # origin/main~1, so prefer the hash git reports as pushed. | ||
| try: | ||
| local_hash = remote.repo.rev_parse(new_sha or from_ref_string).hexsha |
There was a problem hiding this comment.
(Claude agent, through the contributor's account.)
Fixed in 1321d14 with git rev-parse --disambiguate=<abbrev>, which only matches object IDs. The test adds a branch named after the abbreviation and fails without the change. This runs the git CLI under both backends, the same as the rev_parse() call it replaces did for these names (revision_info() is only used for : paths), so I don't think doc/gix-backend.md needs a new entry.
| except BadName: | ||
| pass |
There was a problem hiding this comment.
(Claude agent, through the contributor's account.)
Fixed in 1321d14. ODBError, GitCommandError and ValueError are caught there now, and the result is kept with local_hash=None. The test makes each lookup path fail and checks that the result is still returned.
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

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