You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As a general question: What about submitting a PR with a new push_or_throw(…) method, which does as it says? There should be enough references in this thread to implement it without spending too much time on research.
In case someone else stumbles on this very strange behaviour, and doesn't immediately dive into Sjord's commits (mentioned in this issue, above this comment): raise_if_error() can now be called on the object returned by the push() call.
That landed in 3.1.25, and the tutorial has an example:
# push and pull behaves similarly to `git push|pull`origin.pull()
origin.push() # attempt push, ignore errorsorigin.push().raise_if_error() # push and raise error if it fails
For some reason, the PushInfoList class has been shipped since 35f7e94 aka. 3.1.25~10 but can't be found by searching for it on https://gitpython.readthedocs.io/en/latest/ (latest or specific versions). So I suppose some extra doc metadata is needed to improve discoverability?
In case someone needs to work with a slightly older version (e.g. 3.1.14, available in Debian 11), here's something that seems to do the trick for me (keeping in mind raising a generic Exception works well enough for me since I'm in a retry loop doing fetch & push inside a try/except block):
origin.pull(rebase=True)
# Workaround for missing origin.push().raise_if_error() in 3.1.14# (see https://github.com/gitpython-developers/GitPython/issues/621):pushinfolist=origin.push()
forpiinpushinfolist: # pylint: disable=invalid-nameforflagin [pi.REJECTED, pi.REMOTE_REJECTED, pi.REMOTE_FAILURE, pi.ERROR]:
ifpi.flags&flag:
raiseException("error flag %d set"%flag)
Caveat: I had to hardcode which flags look like errors I should care about; not sure how stable it is going to be across releases.
Activity
artgoldberg commentedon May 18, 2019
Agree. Errors should be reported as exceptions.
KalenWessel commentedon Jun 10, 2019
Also was just bit by this issue.
dns: handle push failures
rfrancois commentedon Jul 15, 2021
Also was just bit by this issue.
Byron commentedon Jul 15, 2021
As a general question: What about submitting a PR with a new
push_or_throw(…)method, which does as it says? There should be enough references in this thread to implement it without spending too much time on research.Raise exception when push fails
Raise exception when push fails
Raise exception when push fails
Let remote.push return a PushInfoList
Let remote.push return a PushInfoList
Let remote.push return a PushInfoList
Let remote.push return a PushInfoList
CyrilBrulebois commentedon Apr 9, 2022
In case someone else stumbles on this very strange behaviour, and doesn't immediately dive into Sjord's commits (mentioned in this issue, above this comment):
raise_if_error()can now be called on the object returned by thepush()call.That landed in 3.1.25, and the tutorial has an example:
CyrilBrulebois commentedon Apr 9, 2022
For some reason, the
PushInfoListclass has been shipped since 35f7e94 aka.3.1.25~10but can't be found by searching for it on https://gitpython.readthedocs.io/en/latest/ (latest or specific versions). So I suppose some extra doc metadata is needed to improve discoverability?CyrilBrulebois commentedon Apr 9, 2022
In case someone needs to work with a slightly older version (e.g. 3.1.14, available in Debian 11), here's something that seems to do the trick for me (keeping in mind raising a generic
Exceptionworks well enough for me since I'm in a retry loop doing fetch & push inside atry/exceptblock):Caveat: I had to hardcode which flags look like errors I should care about; not sure how stable it is going to be across releases.
Byron commentedon Apr 9, 2022
Thanks for sharing! The flags should not change across releases as breaking changes are generally avoided.
reposync: improve push error handeling