Friday, November 29, 2013

Using Gerrit code review without code review

Committers who typically push to HEAD (the master branch) can hesitate to enable Gerrit simply because they don't want to add the extra step of reviewing code. Fortunately, with Gerrit, you don't have to.

In fact, EGit makes it easy to push directly to master on a regular basis yet still submit a change to Gerrit for code review.  Here's how:

1. Ask Webmaster to enable Gerrit on your repo, and explicitly state that your project committers should be able to bypass code review.  Moving forward, Gerrit is the only system that can write to your Git repo, even if you're pushing directly to master.

2. Using EGit, clone your repo using the Gerrit URLs, not the Git URLs.  These typically look like this:

I like to use the "Import from Git repository" functionality in Eclipse, since it will clone the repository and create a project at the same time.

3. By default, EGit will be configured to push directly to the master branch.  I use the Commit and Push button to bypass code review, and the Commit button to (later) push the changes to Gerrit for review.

EGit "Commit" dialog.

If Webmaster didn't activate the Push to Master permission, you'll likely see this:

Gerrit prohibits direct push to master

4. You're done.  Use the Commit and Push button to push directly to the master branch.  If you do wish to create a code review for your local commits, choose the Push to Gerrit item:

Right-click > Team shows Push to Upstream vs. Push to Gerrit

Push to Gerrit allows you to specify code review branch... in this case, refs/for/master, which differs from the master branch, refs/heads/master

5. If Push to Gerrit succeeds, you've effectively created a change, and Gerrit will provide a URL:

6. In the Gerrit UI, you can review your change then Submit it. Gerrit then merges your review branch into head and your change status becomes Merged.  Or, you can request review from others, who can  then Publish review commentary or Publish and Submit 

Gerrit code review

7. Watch your new Gerrit project!  Contributors may be submitting changes to Gerrit right now, and they are awaiting your review.


Blogger Lars Vogel said...

Don't we have to adjust the URL for Gerrit and normal Git push? I think the gitroot in the path and the port is different

6:55 AM  
Blogger Bananeweizen said...

If you have the Mylyn gerrit connector installed, then you don't have to use URLs for cloning (which is error prone). You can just connect to the gerrit server and clone any project from a simple selection list.

3:49 AM  
Blogger Denis Roy said...

@Lars: no, same url, different refspec.

3:44 PM  
Blogger Arlen Pledge said...

Nice post. I really appreciate it.

3:00 AM  

Post a Comment

<< Home