#1001163 git-buildpackage: gbp push: tries to overwrite upstream and pristine-tar branches with older content (and fails)

#1001163#5
Date:
2021-12-05 15:35:44 UTC
From:
To:
Hi,

I just uploaded a stable update for ruby-httpclient. Since the bullseye
branch was created, a new upstream release has been uploaded to sid,
thus upstream and pristine-tar had moved on. `gbp push` then fails like
this:
----------------8<----------------8<----------------8<-----------------
gbp:info: Tagging Debian package 2.8.3-3+deb11u1 as debian/2.8.3-3+deb11u1 in git
gbp:info: Pushing debian/2.8.3-3+deb11u1 to origin
gbp:info: Pushing upstream/2.8.3 to origin
gbp:info: Pushing refs/heads/debian/bullseye to origin:refs/heads/debian/bullseye
gbp:info: Pushing 0d9e030d58de2a5c9b64adc5ca1571f1aa1b81bc to origin:refs/heads/upstream
gbp:error: Error running git push: To salsa.debian.org:ruby-team/ruby-httpclient.git
 ! [rejected]        0d9e030d58de2a5c9b64adc5ca1571f1aa1b81bc -> upstream (non-fast-forward)
error: failed to push some refs to 'salsa.debian.org:ruby-team/ruby-httpclient.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and integrate the remote changes
hint: (e.g. 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
gbp:info: Pushing 6a9377d36b2e2247621033196efc88c36004e940 to origin:refs/heads/pristine-tar
gbp:error: Error running git push: To salsa.debian.org:ruby-team/ruby-httpclient.git
 ! [rejected]        6a9377d36b2e2247621033196efc88c36004e940 -> pristine-tar (non-fast-forward)
error: failed to push some refs to 'salsa.debian.org:ruby-team/ruby-httpclient.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and integrate the remote changes
hint: (e.g. 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
gbp:error: Failed to push some refs.
----------------8<----------------8<----------------8<-----------------

Looking at the case for the upstream branch, it's trying to push commit
0d9e030d58de2a5c9b64adc5ca1571f1aa1b81bc. That commit was already
present in the corresponding remote branch, but there was a newer
commit on top of that. The same situation happends with the pristine-tar
branch.

Maybe gbp push could detect that the corresponding upstream/pristine-tar
commits is are already present at the remote branch, and skip the push.

#1001163#10
Date:
2022-04-23 12:02:10 UTC
From:
To:
Hi, the attached patch fixes this issue on my side.
#1001163#17
Date:
2022-04-23 13:55:32 UTC
From:
To:
tag 1001163 pending
thanks

Date:   Sat Apr 23 09:02:10 2022 -0300
Author: Antonio Terceiro <terceiro@debian.org>
Commit ID: 2405e15805c68b53628cb4fb55e1e6313c8e114c
Commit URL: https://git.sigxcpu.org/cgit/git-buildpackage//commit/?id=2405e15805c68b53628cb4fb55e1e6313c8e114c
Patch URL: https://git.sigxcpu.org/cgit/git-buildpackage//patch/?id=2405e15805c68b53628cb4fb55e1e6313c8e114c

    push: skip pristine-tar push if already present remotely

    When one is working on an older branch (stable update or backport), the
    pristine-tar branch may already contain new commits after the one
    corresponding to the upstream version in question.

    Closes: #1001163

#1001163#24
Date:
2022-05-16 09:03:58 UTC
From:
To:
control: tag -1 -pending

Hi Antonio,

This helps for a lot of cases (pushing to the default remote when you've
already fetched from that remote) so thanks for that! We need some
improvements when:

- using another remote like: git push other-remote
- the user didn't fetch but someone else already pushed the same data

Ideally `git-push` would be clever enough so we can just figure the
out from e.g. the exit status.

I'll leave the bug open as there's still cases we need to fix.

Cheers,
 -- Guido