wiki:Git Gerrit

Git

Git style

When making a commit please use default git guidelines:

  • First sentence should be a short description of the commit (<= 50 characters)
  • First sentence should be formed as if you were instructing Git to do something e.g.:
    • Add new communication layer.
    • Fix bug #530.

Git Gerrit

Scheme

  • Developers pull from github.
  • Each change must be reviewed; a change is submitted to gerrit.
  • Once a change is accepted by others, gerrit pushes the change to github.

Repo addresses

Our Git repositories are located on GitHub:

https://github.com/nebulostore/nebulostore - nebulostore repository

Git Config

In Linux systems in ~/.gitconfig file there is a git configuration. I encourage You to add https://github.com/jakubnabrdalik/gitkurwa/blob/master/config to Your config (please ignore vulgar name of the project).

Add specific to Nebulostore project aliases (under [alias] section), please user Your own gerrit username:

gerritinit = !sh -c 'git remote add gerrit ssh://rhryciuk@naan.mimuw.edu.pl:29418/nebulostore.git && curl -o .git/hooks/commit-msg http://naan.mimuw.edu.pl:8001/tools/hooks/commit-msg && chmod u+x .git/hooks/commit-msg'
gerritpush = push gerrit HEAD:refs/for/master

First use

We use Gerrit running on naan: http://naan.mimuw.edu.pl:8001. The most important steps needed to perform before working with our repositories:

  1. Get an account on Gerrit (using OpenId, e.g. Google account). To gain full access to our Gerrit projects you need administrator rights.
  2. Set your username in Gerrit web interface (Settings -> Profile)
  3. Add your public key to account in Gerrit web interface (Settings -> SSH Public Keys)
  4. Clone the repository from GitHub:
    git clone https://github.com/nebulostore/nebulostore.git
    
  5. Init working with gerrit:
    git gerritinit
    
  6. Go to Settings -> Watched projects in Gerrit web interface. Add All-Projects project to Watched projects. After this you will receive e-mails about any changes in our projects.
  7. (optional) If you want to receive e-mail notifications about your own comments, go to Settings -> Preferences and check CC Me On Comments I Write option.

Working scheme

  1. Pull changes from GitHub repository (default name: origin):
    git pull origin
    
  2. Commit your local changes (remember about the style of git comments!)
    git commit -m "Message"
    
  3. Push changes to Gerrit remote repository:
    git gerritpush
    
  4. Convince someone to review the change
  5. To submit a change you need to get scores: review +2 and verify +1 (and no review -2 or verify -1). Then, a 'Submit' button will be available.

The author of the change submits the change (and not the reviewer).

For more information about reviewing in Gerrit, see documentation: http://naan.mimuw.edu.pl:8001/Documentation/intro-quick.html

Updating existing change

If you want to update change you created before, follow these steps:

  1. Checkout commit with the change you want to update.
  2. Rework your code.
  3. Add the changed code to the commit (git add)
  4. Amend the commit:
    git commit --amend
    
  5. Push changes to gerrit:
    git gerritpush
    

Reviewing someone's change

  1. Copy-paste the change address from gerrit, e.g.
    git fetch ssh://krz@naan.mimuw.edu.pl:29418/nebulostore refs/changes/89/89/6 && git checkout FETCH_HEAD
    
  2. play around
  3. To go back to your codebase (discarding the change under review),
    git checkout master
    

Creating a branch

If you want to create a new brach you should do this in two places:

  • Gerrit
  • GitHub

Gerrit

  1. Go to the Gerrit web interface.
  2. Select "Projects" tab, then project name.
  3. From the left side menu select "Branches".
  4. Select branch name and initial revision.
  5. Click "Create branch" button.

GitHub

  1. Login to nebulostore account using credentials from this wiki page.
  2. In "code" view of a project, click current branch name.
  3. Write your branch name in field "Find or create a branch".
  4. Click "Create branch".

Pushing changes without a review

If you work on your own code (e.g. in your branch), you will probably want to push your changes directly without creating a new review in Gerrit. You should change permissions to your branch in Gerrit and use a bit different command to commit your changes.

  1. Go to the Gerrit web interface.
  2. Select "Projects" tab, then project name.
  3. From the left side menu select "Access". Click "edit" button.
  4. Add (or modify) access rights for your branch.
    • Click "Add reference".
    • Write "refs/heads/<branch-name>" in the input field.
    • Add following permissions for the "Administators" group:
      • Create reference
      • Push
      • Push Merge Commit

After settings permissions you can push your changes directly to the repository by using the following command:

git push gerrit <branch_name>:refs/heads/<branch_name>

Integration with Jenkins

Each patch set sent to Gerrit is automatically built on Jenkins.

Retriggering a build

Sometimes you may want to build a specific patch set again, because something went wrong earlier. To do so, you should:

  1. Login into your Jenkins account.
  2. Select "NebuloStore-Gerrit" project.
  3. Select build which you would like to retrigger.
  4. On the build page click "Retrigger" button. The build will start and the verification status on Gerrit will be updated.
Last modified 4 years ago Last modified on 02/10/15 20:45:04