Gerrit Setup

From KitwarePublic
Jump to navigationJump to search

Gerrit is a web based code review and project management system for Git based projects. Some of the highlights include tight integration with Git, command line tools, showing changes in a side-by-side display, and allowing inline comments to be added by reviewers. It also includes access control to repositories using group based policies, and has many generalized functions for managing access to a central Git repository. It is written mainly in Java.

Initial Setup

Download Gerrit from here, I have been testing out 2.1.4 release candidates that have some of the new topic branch features recently added. So a typical initial install of Gerrit would be something like (after creating a Gerrit user),

$ wget http://gerrit.googlecode.com/files/gerrit-2.1.4-rc1.war
$ java -jar gerrit-2.1.4-rc1.war init -d review

At this point the Gerrit installation will be configured in the review directory, and you will be asked a series of questions. All paths are below the review directory, and so if you place Git repositories in repos it will go into review/repos. You will want to set up email, the SMTP server hostname is smtp.gmail.com, default port, using SSL, your username/password.

The canonical URL I used was http://londinium.kitwarein.com:8080/ for the test server, which you are welcome to take a look at if you are in the internal Kitware network. Now you will need to start Gerrit,

$ ./review/bin/gerrit.sh start

You can now point your web browser at the canonical URL you specified, and you should have a Gerrit instant up and running. The first user to sign in is the administrator, and from there you can set up groups, projects and permissions. You will want to set up your username and upload your public SSH key so that you can authenticate.

Adding Projects

Now you have your Gerrit installation it would be good to add a project. Assuming you set up your administrator with a username and SSH key, the easiest way to set up a new project is outlined below.

$ ssh -p 29418 londinium gerrit ls-projects # List of projects (should be empty)
$ ssh -p 29418 londinium gerrit create-project --name VTK
$ ssh -p 29418 londinium gerrit ls-projects # Should now list the VTK project

You will need to go into the Gerrit interface, and under admin create a group for VTK core developers, and then add some extra permissions for the VTK group on the VTK project. At a minimum this would be Forge Identity +2 (to push the initial repository), and Push Branch +2 to create and push branches. In your VTK checkout you can add a new remote for Gerrit,

$ git remote add gerrit ssh://marcus@londinium:29418/VTK
$ git push gerrit master

Uploading Changes to Gerrit

Now you have your project, and you want to upload some changes for review. Once you have committed these changes in your local clone of your project you will want to push them. If you added the remote, as shown above, for Gerrit, the following would push your local commits to Gerrit for review, destined for the master branch.

$ git push gerrit HEAD:refs/for/master/charts_defaults

This pushes all local commits to Gerrit for review, marking them as destined for the master branch, in the topic branch charts_defaults. If once you are done you wish to merge these changes into master, and push directly to Gerrit,

$ git checkout master
$ git merge --no-ff charts_defaults
$ git push gerrit master

Gerrit will then register that these commits were merged in the web interface, and move them from the open queue. There is a lot more that Gerrit is capable of doing, this page scratches the surface on getting an initial installation up and running.