Big pull-request for Gerrit code review

222 views
Skip to first unread message

rkohli2000 gmail

unread,
Mar 22, 2021, 4:24:18 AM3/22/21
to Repo and Gerrit Discussion
Hi, 
I'm a new user and apologize if this is not the right group for this post. Please 
me know the correct forum if so.

I'm running into some issues with issues on Crucible/Bitbucket due to a large
pull-request (greater than 1000 files, etc). So. I thought of trying Gerrit for code 
review if I can push my diff to gerrit. I can locally access the PR from git using 
"git checkout pull-requests/<PR#>". 

Can someone share the best way to get this PR to gerrit so I can setup a review ? 
Is there a way I can "git push ..." this PR ? I have setup Gerrit on a local Ubuntu 
18.04 server and it appears to be running ok (https://localhost:8443). Not sure
about user setup, etc.

Any detailed help will be great, I  am new to Gerrit as well  
Thanks in advance.

Matthias Sohn

unread,
Mar 22, 2021, 5:11:11 AM3/22/21
to rkohli2000 gmail, Repo and Gerrit Discussion
Here is a walk through of the basic workflow [1].
Which authentication type did you choose when installing Gerrit ?

For local playground experiments you can use DEVELOPMENT_BECOME_ANY_ACCOUNT
which is a quick and dirty way to play with Gerrit. Don't use this in production !


-Matthias

rkohli2000 gmail

unread,
Mar 22, 2021, 6:16:14 AM3/22/21
to Matthias Sohn, Repo and Gerrit Discussion
Hi Matthias, 

I have Gerrit up and running. I used DEVELOPMENT_BECOME_ANY_ACCOUT
for lab usage only. I see Gerrit running "OK" on my Linux server from the bin/gerrit.sh script.

My intention is to use Gerrit for code review of a large pull-request which Crucible is unable to
render from Bitbucket. Is this process of pushing the pull-request to Gerrit documented somewhere ?
I haven't become as familiar with Gerrit as yet and sorry if I missed some obvious explanation.

Thanks for your reply.

Regards
Ravi

Matthias Sohn

unread,
Mar 22, 2021, 11:27:15 AM3/22/21
to rkohli2000 gmail, Repo and Gerrit Discussion
On Mon, Mar 22, 2021 at 11:16 AM rkohli2000 gmail <rkohl...@gmail.com> wrote:
Hi Matthias, 

I have Gerrit up and running. I used DEVELOPMENT_BECOME_ANY_ACCOUT
for lab usage only. I see Gerrit running "OK" on my Linux server from the bin/gerrit.sh script.

My intention is to use Gerrit for code review of a large pull-request which Crucible is unable to
render from Bitbucket. Is this process of pushing the pull-request to Gerrit documented somewhere ?

git can't push PRs which are github specific and live on the server but git can push commits.
Follow [1] to learn how to push a change for review in Gerrit.

Basically you need to
  • create a project e.g. test in Gerrit here http://localhost:8080/admin/repos (assuming Gerrit runs on your local system and listens on port 8080)
  • push the current state of the default branch on github (e.g. master) from a local clone of the github repo to the new project in gerrit

    git push http://localhost:8080 master:master

  • push the branch representing the PR in github for review. Note that every commit on that branch will be one change in review in Gerrit
    since Gerrit implements a commit-centric review workflow

    git checkout <local branch of your PR>
    git push origin HEAD:refs/for/master
  • review the change in the WebUI

please avoid top-posting on this list

-Matthias 

rkohli2000 gmail

unread,
Mar 22, 2021, 7:42:25 PM3/22/21
to Matthias Sohn, Repo and Gerrit Discussion

On Mar 22, 2021, at 11:26 AM, Matthias Sohn <matthi...@gmail.com> wrote:

On Mon, Mar 22, 2021 at 11:16 AM rkohli2000 gmail <rkohl...@gmail.com> wrote:
Hi Matthias, 

I have Gerrit up and running. I used DEVELOPMENT_BECOME_ANY_ACCOUT
for lab usage only. I see Gerrit running "OK" on my Linux server from the bin/gerrit.sh script.

My intention is to use Gerrit for code review of a large pull-request which Crucible is unable to
render from Bitbucket. Is this process of pushing the pull-request to Gerrit documented somewhere ?

git can't push PRs which are github specific and live on the server but git can push commits.
Follow [1] to learn how to push a change for review in Gerrit.

Basically you need to
  • create a project e.g. test in Gerrit here http://localhost:8080/admin/repos (assuming Gerrit runs on your local system and listens on port 8080)
  • push the current state of the default branch on github (e.g. master) from a local clone of the github repo to the new project in gerrit

    git push http://localhost:8080 master:master

  • push the branch representing the PR in github for review. Note that every commit on that branch will be one change in review in Gerrit
    since Gerrit implements a commit-centric review workflow

    git checkout <local branch of your PR>
    git push origin HEAD:refs/for/master
  • review the change in the WebUI

please avoid top-posting on this list


Hi Mathias,

Thanks for your response. I tried the steps list below:
Then, I see the error below when I try to push the branch state to gerrit.
Is there any access or repo property I need to set ? Or any way around it ?

Regards
Ravi
* git remote add gerrit_origin //MY_HOST/REPO_NAME
* git push gerrit_origin master:master
Username for 'http://MY_HOST:8080': admin
 ! [rejected]          master -> master (non-fast-forward)
error: failed to push some refs to 'http://MY_HOST:8080/MY_REPO'
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.

git pull doesn't help....

* git push  --force g_origin master:master
Username for 'http://MY_HOST:8080': admin
Counting objects: 21306, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (15715/15715), done.
Writing objects: 100% (21306/21306), 112.74 MiB | 50.79 MiB/s, done.
Total 21306 (delta 4961), reused 15884 (delta 4839)
remote: Resolving deltas: 100% (4961/4961)
remote: error: branch refs/heads/master:
remote: You need 'Push' rights with 'Force' flag set to do a non-fastforward push.
remote: User: admin
remote: Contact an administrator to fix the permissions
remote: Processing changes: refs: 1, done
 ! [remote rejected]   master -> master (prohibited by Gerrit: not permitted: force update)
error: failed to push some refs to 'http://MY_HOST:8080/MY_REPO'

Matthias Sohn

unread,
Mar 22, 2021, 8:17:27 PM3/22/21
to rkohli2000 gmail, Repo and Gerrit Discussion
I guess you created the new repo in Gerrit with an initial commit so that pushing the master branch
is not a fast-forward. Either do this push forceful using -f option or recreate the project without
an initial commit. 

rkohli2000 gmail

unread,
Mar 23, 2021, 10:36:22 AM3/23/21
to Matthias Sohn, Repo and Gerrit Discussion
Matthias,
Thanks for this suggestion. It helped. I re-setup the identical repo on Gerrit without an initial commit and the command works.
When setting up a branch (for the new code for review) and trying to push "HEAD:refs/for/master" I see a "Missing change-id" error.
Can you please suggest a way around ? Thanks again for helping. I think Gerrit may be an option for us.

Console:

$ git push --force --no-verify g_origin master:master
Username for 'http://MY_HOST:8080': admin
Password for 'http://admin@MY_HOST:8080':
Counting objects: 21306, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (15715/15715), done.
Writing objects: 100% (21306/21306), 112.74 MiB | 51.86 MiB/s, done.
Total 21306 (delta 4961), reused 15884 (delta 4839)
remote: Resolving deltas: 100% (4961/4961)
remote: Processing changes: refs: 1, done
 * [new branch]        master -> master

$ git checkout origin/remotes/origin/MY_BRANCH-GERRIT
Switched to branch 'origin/remotes/origin/MY_BRANCH-GERRIT'
$ git status
On branch origin/remotes/origin/MY_BRANCH-GERRIT
nothing to commit, working tree clean

$ git push g_origin HEAD:refs/for/master
Username for 'http://MY_HOST:8080': admin
Password for 'http://admin@MY_HOST:8080':
Counting objects: 23308, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (16071/16071), done.
Writing objects: 100% (23308/23308), 61.05 MiB | 38.12 MiB/s, done.
Total 23308 (delta 6447), reused 19202 (delta 6370)
remote: Resolving deltas: 100% (6447/6447)
remote: Processing changes: refs: 1, done
remote: ERROR: commit fba7b7e: missing Change-Id in message footer
remote:
remote: Hint: to automatically insert a Change-Id, install the hook:
remote:   gitdir=$(git rev-parse --git-dir); scp -p -P 29418 admin@MY_HOST:hooks/commit-msg ${gitdir}/hooks/
remote: and then amend the commit:
remote:   git commit --amend --no-edit
remote: Finally, push your changes again
remote:
 ! [remote rejected]   HEAD -> refs/for/master (commit fba7b7e: missing Change-Id in message footer)
error: failed to push some refs to 'http://MY_HOST:8080/MY_REPO'
$ git push --force --no-verify g_origin HEAD:refs/for/master
Username for 'http://MY_HOST:8080': admin
Password for 'http://admin@MY_HOST:8080':
Counting objects: 23308, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (16071/16071), done.
Writing objects: 100% (23308/23308), 61.05 MiB | 39.74 MiB/s, done.
Total 23308 (delta 6447), reused 19202 (delta 6370)
remote: Resolving deltas: 100% (6447/6447)
remote: Processing changes: refs: 1, done
remote: ERROR: commit fba7b7e: missing Change-Id in message footer
remote:
remote: Hint: to automatically insert a Change-Id, install the hook:
remote:   gitdir=$(git rev-parse --git-dir); scp -p -P 29418 admin@MY_HOST:hooks/commit-msg ${gitdir}/hooks/
remote: and then amend the commit:
remote:   git commit --amend --no-edit
remote: Finally, push your changes again
remote:
 ! [remote rejected]   HEAD -> refs/for/master (commit fba7b7e: missing Change-Id in message footer)
error: failed to push some refs to 'http://MY_HOST/NY_REPO'

Matthias Sohn

unread,
Mar 23, 2021, 11:23:00 AM3/23/21
to rkohli2000 gmail, Repo and Gerrit Discussion
install the commit-msg hook in your local clone as described in [2] and amend the commits you want to push for review.
If it's a single commit use commit --amend to do that, otherwise rebase -i. Then push to refs/for/master again.

rkohli2000 gmail

unread,
Mar 23, 2021, 1:11:48 PM3/23/21
to Matthias Sohn, Repo and Gerrit Discussion
Matthias, Thanks for your prompt reply. I can install commit-msg as you instructed. But, I'd like to amend all the commits, not just a few.
I'm worried about impacting the branch history by incorrectly running "rebase -i" (git newbie). Can you clarify the command I can run
to safely amend all the commits at once ?
Regards, Ravi

Matthias Sohn

unread,
Mar 23, 2021, 1:22:21 PM3/23/21
to rkohli2000 gmail, Repo and Gerrit Discussion
how many commits do you have in the PR you want to try reviewing in Gerrit ?

Let's assume you have 3 commits in the PR which sits on top of origin/master

yourPR -> commit-3
             |
          commit-2
             |
          commit-1
             |
master ->    c75
             |
             c74
             |
            ...

in order to amend the commit messages of commit-1,2,3 you would run

git rebase -i master
or
git rebase -i HEAD~3

then follow [3] to amend commit-1, commit-2, commit-3.

If you want to do this for many commits you may look into [4] and write a script doing this.

rkohli2000 gmail

unread,
Mar 24, 2021, 7:12:23 AM3/24/21
to Matthias Sohn, Repo and Gerrit Discussion
Hi Matthias,
Sorry if this is a repeat. I don't know if my earlier email was sent from another machine. 

I have 204 commits I can see from git log. Is it safe to "git rebase -i HEAD~204" on the PR
local branch then try the final push command ? I haven't pushed anything to remote.

 Thanks
Ravi

Matthias Sohn

unread,
Mar 24, 2021, 1:33:47 PM3/24/21
to rkohli2000 gmail, Repo and Gerrit Discussion
That's a pretty large number of commits in a single pull request. I guess you don't want to
manually amend 204 commits using git rebase -i, you can use filter-repo to write a script
doing that. Also I recommend you first check if these commits are cut in a meaningful way
which can be reviewed commit by commit (review in Gerrit is commit centric) or if you
first want to squash some of them e.g. if there is a commit implementing some
part of a feature followed by 3 more commits fixing mistakes in that commit.

Nasser Grainawi

unread,
Mar 29, 2021, 5:10:55 PM3/29/21
to rkohli2000 gmail, Matthias Sohn, Repo and Gerrit Discussion
Is that 204 commits *after* master or 204 commits total?

What does this return? git log --oneline ^master origin/remotes/origin/MY_BRANCH-GERRIT | wc -l

I think you’ll see how many commits you need to rebase/fix if you run: ‘git rebase -i master’ after you see that Change-Id error. If it looks like too many, you can delete everything from the editor that pops up (should be a list of commits) and it’ll abort the rebase.

Nasser


-- 
-- 
To unsubscribe, email repo-discuss...@googlegroups.com
More info at http://groups.google.com/group/repo-discuss?hl=en

--- 
You received this message because you are subscribed to the Google Groups "Repo and Gerrit Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to repo-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/repo-discuss/CACAbcoswGTbfkRWthU%2BCR2Z%3DHqVpaKS%2BH-ktf7_3_2ou69LaAQ%40mail.gmail.com.

rkohli2000 gmail

unread,
Mar 30, 2021, 10:33:34 PM3/30/21
to Nasser Grainawi, Matthias Sohn, Repo and Gerrit Discussion
Its 204 total commits. I haven't taken any further action yet on Gerrit. 

I tried another approach get a huge unified diff of the code against the 
original files. Then, I manually bisected this diff to create multiple smaller
files and then uploaded those as separate reviews in Crucible. This is clumsy
but hopefully will not happen frequently. I will continue investigating Gerrit
as soon as I get some bandwidth to play with it. 

Thanks Matthias and Nasser for providing these steps under Gerrit.
Reply all
Reply to author
Forward
0 new messages