Setting Up Gerrit

All projects under the Qt Open Governance umbrella are hosted at codereview.qt-project.org [codereview.qt-project.org]. These repositories are mirrored on Gitorious [qt.gitorious.org].

How to get started – Gerrit registration

Go to codereview.qt-project.org [codereview.qt-project.org]

  • Log in with your Qt JIRA [bugreports.qt-project.org] credentials (see VIDEO: Account set up and getting the source – 1min 55 sec [qt-project.org] )
    • Note: Gerrit usernames are case-sensitive, but JIRA usernames are not. If you attempt to log into Gerrit with different capitalizations, you will end up with multiple accounts.
  • Go to settings, configure username (under contact information), upload public SSH key [help.github.com]
  • If you are behind a firewall that blocks SSH access:
    • Open HTTP Password setting
    • Click “Generate Password”
    • Add the following line to your ~/.netrc (Windows: ‚Äč%USERPROFILE%\_netrc):
      1. machine codereview.qt-project.org login <Gerrit username> password <Generated password>
  • Add an e-mail, confirm it by clicking the link in the e-mail
    • Both the e-mail and the username will be readable by everyone. Use an alias + a custom e-mail address if you want to stay anonymous (note that this is discouraged).

Local Setup

Configure SSH properly (the URLs below rely on this). Add this to your ~/.ssh/config (Windows: C:\Users\%USERNAME%\.ssh\config):

  1.  Host codereview.qt-project.org
  2.     Port 29418
  3.     User <Gerrit/Jira username>

NOTE: The following steps need to be applied to every clone:

Install the hook generating Commit-Id files into your top level project directory, as well as all sub-repositories (e.g. qtbase.git) either through

  1.  $ scp -p codereview.qt-project.org:hooks/commit-msg .git/hooks

or by downloading the file via browser: commit-msg [codereview.qt-project.org] and putting it into the .git/hooks directory (make sure it is executable).

It is recommended to install the git_post_commit_hook from the qtrepotools [qt.gitorious.org] repository. This gives you the checks of the Sanity Bot locally. To do this, save the script

  1. #! /bin/sh
  2. exec "<path to git clone>/qtrepotools/git-hooks/git_post_commit_hook" "$@"

into each <path to git clone>\.git\hooks\post-commit

NOTE: Starting with git 1.7.8, if <module name>/.git contains gitdir: ../.git/modules/<module name>, you need to put the submodule hooks in .git/modules/<module name>/hooks instead of <module name>/.git/hooks.

Configuring Git

We are developing in a heterogeneous environment with both Unix and Windows machines. Therefore it is imperative to have all files in the repository in the canonical LF-only format. Therefore, Windows users must run

  1.     $ git config --global core.autocrlf true

to automatically get CRLF line endings which are suitable for the native tools, and Unix users should use

  1.     $ git config --global core.autocrlf input

(this is a safety measure for the case where files with CRLF line endings get into the file system – this can happen when archives are unpacked, attachments saved, etc.).

To be able to create commits which can be pushed to the server, you need to set up your committer information correctly:

  1.     $ git config --global user.name "Your Name"
  2.     $ git config --global user.email "me@example.com"

Please do not use nicknames or pseudonyms instead of the real name unless you have really good reasons.
Gerrit will not accept your commits unless the committer information matches the email address(es) you registered.

To facilitate following the style guide for commit messages, it is recommended to install the Qt commit message template:

  1.     $ git config --global commit.template <path to qt5.git or qt.git>/.commit-template

A common mistake is forgetting to add new files to a commit. Therefore it is recommended to set up git to always show them in git stat and git commit, even if this is somewhat slower (especially on Windows):

  1.     $ git config --global status.showuntrackedfiles all

Git has a somewhat stupid default that git push will push all branches to the upstream repository, which is almost never what you want. To fix this, use:

  1.     $ git config --global push.default tracking

This is not relevant for mainline branches under Gerrit control, as all pushing happens with refs anyway, but it may be important for your private clones.

Sometimes it is necessary to resolve the same conflicts multiple times. Git has the ability to record and replay conflict resolutions automatically, but – surprise surprise – it is not enabled by default. To fix it, run:

  1.     $ git config --global rerere.enabled true
  2.     $ git config --global rerere.autoupdate true   # this saves you the git add, but you should verify the result with git diff --staged

git pull will show a nice diffstat, so you get an overview of the changes from upstream. git pull —rebase does not do that by default. But you want it:

  1.     $ git config --global rebase.stat true

To get nicely colored patches (from git diff, git log -p, git show, etc.), use this:

  1.     $ git config --global color.ui auto
  2.     $ git config --global core.pager "less -FRSX"

Git supports aliases which you can use to save yourself some typing. For example, these (any similarity with subversion command aliases is purely accidental ;)):

  1.     $ git config --global alias.di diff
  2.     $ git config --global alias.ci commit
  3.     $ git config --global alias.co checkout
  4.     $ git config --global alias.ann blame
  5.     $ git config --global alias.st status

Using Existing clones

Add a gerrit remote pointing to codereview.

  1.  $ git remote add gerrit ssh://codereview.qt-project.org/qt/<qt5 or the submodule name you have checked out>

If you are behind a SSH-blocking firewall, use the https protocol:

  1.  $ git remote add gerrit https://codereview.qt-project.org/p/qt/<qt5 or the submodule name you have checked out>

For Qt 4.8, use

  1.  $ git remote add gerrit ssh://codereview.qt-project.org/qt/qt

If you are behind a SSH-blocking firewall, use the https protocol:

  1.  $ git remote add gerrit https://codereview.qt-project.org/p/qt/qt

Cloning repositories

You should clone from the repositories hosted at qt.gitorious.org [qt.gitorious.org] or github.com/qtproject [github.com] and track changes from there in order to keep the load on Gerrit down.

Cloning Qt4

For qt.gitorious.org [qt.gitorious.org] :

  1.  $ git clone git://gitorious.org/qt/qt.git

For github.com/qtproject [github.com] :

  1.  $ git clone git://github.com/qtproject/qt.git

Note that Qt4 does not have a master branch (since no 4.9 is planned). So, you should push changes to the 4.8 branch.

Cloning Qt5

For qt.gitorious.org [qt.gitorious.org] :

  1.  $ git clone git://gitorious.org/qt/qt5.git

For github.com/qtproject [github.com] :

  1.  $ git clone git://github.com/qtproject/qt5.git
  2.  $ cd qt5
  3.  $ ./init-repository -f --no-webkit --mirror git://github.com/qtproject

It is recommended that, regardless of the server you use for the initial clone, you use the init-repository script in qt5 to set up the gerrit remote(s) pointing to codereview, and to clone the submodules.

Alternatively, individual Qt5 submodules can be manually cloned as well. Follow Using Existing Clones above after cloning.

Note that Qt 5 submodules have been changed from absolute to relative URLs (like “../qtbase.git”) in the .gitmodules file.
If you make a clone of git://gitorious.org/qt/qt5 in gitorious as git://gitorious.org/~<username>/qt/<cloned-repository-name>.git the init-repository script will not work.

A URL rewrite rule has to be added to the .gitconfig file:

  1. [url "git://gitorious.org/qt/"]
  2.          insteadOf = git://gitorious.org/~<username>/qt/

Cloning Qt Creator

For qt.gitorious.org [qt.gitorious.org] :

  1.  $ git clone git://gitorious.org/qt-creator/qt-creator.git

For github.com/qtproject [github.com] :

  1.  $ git clone git://github.com/qtproject/qt-creator.git

Pushing your local changes to gerrit

After you have committed your changes locally, you can push them to Gerrit like this (for example, stable branch):

  1.  $ git push gerrit HEAD:refs/for/stable

It is recommended you use the git-gpush script from the qtrepotools repository [qt.gitorious.org].

Categories: