1

I have just created a new change, that I wish to pull to Gerrit. I did it (I hope) the usual way, i.e. create new branch, do magic, commit. Now, I want to push changes to Gerrit. So...

git checkout 82-changes-and-fixes-to-files-view
git push origin HEAD:refs/for/82-changes-and-fixes-to-files-view

(crunch, crunch)

! [remote rejected] HEAD -> refs/for/82-changes-and-fixes-to-files-view (branch 82-changes-and-fixes-to-files-view not found)

Branch not found? Hm... Something came to my mind, that docs said something about manually creating a branch, via Gerrit UI, before pushing changes. Am I right? Anyway, I'm doing so. I'm creating a branch, through UI, giving it above name (82-changes-and-fixes-to-files-view) and corresponding revision, taken from git status (2b25fe7612f1563a78c9dc2d1574ae3dcfe9d5a1). And, again...

git push origin HEAD:refs/for/82-changes-and-fixes-to-files-view

(crunch, cruch)

! [remote rejected] HEAD -> refs/for/82-changes-and-fixes-to-files-view (no new changes) 

Eee... What am I missing? How can Gerrit claim, that there are no changes, if I actually haven't pushed any code to it yet (there is no such change, of course, of above name, recorded in neither open nor merged changes in Gerrit UI)?

trejder
  • 17,148
  • 27
  • 124
  • 216

1 Answers1

1

The solution to this problem is to always use current HEAD's last commit ID, not the one from commit made to your branch. Using branch's last commit ID is wrong. Why -- this is beyond my imagination.

So, correct path is:

  1. Create branch using UI and giving HEAD's revision.
  2. Push changes (that branch) to Gerrit, don't forget about correct refs.
  3. Visit page, which URL Gerrit gave you as a result of your push and review your change or wait for someone else to review it.

As alternative, you can simply click Create Branch with Initial Revision field empty, so Gerrit will auto-fill it. Then push Create Branch button again.

EDIT: This answer only explains, what to do, to get change accepted by Gerrit. It doesn't explains, why in previous approach (explained in question), Gerrit is claiming, that there are no changes and does not accept the code, while it actually have not code at all (for that particular branch). For me, this is a huge bug, that leads to a code losses. (incorrect as per comment below)

trejder
  • 17,148
  • 27
  • 124
  • 216
  • 1
    If you create a new branch that points to commit 2b25fe76, pushing the same commit for review on the same branch will obviously be a no-op since the branch already points to that commit. Like Gerrit says, there are no new changes. – Magnus Bäck Dec 16 '13 at 01:27
  • The real question for me, is why do I have to create that branch manually, via UI, at all? Why Gerrit is unable to handle this itself? I'm pushing a particular branch, so what is the problem in creating it automatically? – trejder Dec 16 '13 at 07:44
  • Magnus, read my question again and revised answer. Branch `82-changes-and-fixes-to-files-view` was rejected at first time as missing, and second time (because I pointed a branch created via UI to wrong commit -- `2b25fe76`) also rejected as no changes. In the effect Gerrit **hasn't got any byte of code** for branch `82-changes-and-fixes-to-files-view` (there was no actual push of this code as both attempts were rejected), while it claims it has (_no changes_). This seems to be a huge bug, or I'm missing something obvious. – trejder Dec 16 '13 at 08:34
  • 2
    The `git push` command sends the refs to be updated and the objects themselves in a single request, so it's not entirely strange that Gerrit rejects a request but keeps the object payload in its database. Since you are in fact able to start a branch from commit 2b25fe76 it means Gerrit _did_ receive and store the payload, although the commit was at that point unreferenced and would eventually be garbage collected. One could argue that Gerrit shouldn't keep the packfiles of rejected pushes, but it's not a huge bug and your claim that it leads to code losses is completely unsubstantiated. – Magnus Bäck Dec 16 '13 at 15:19
  • @MagnusBäck Once again, thank you for sorting out my problems with Gerrit! :] – trejder Dec 17 '13 at 09:16