Setting up Gerrit: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
(fixed markup and made code.qt.io official)
(fixed markup even more)
Line 1: Line 1:
[[Category:Developing_Qt::Instructions]]
[[Category:Developing_Qt::Instructions]]


All projects under the Qt Open Governance umbrella are hosted at [http://codereview.qt.io]. These repositories are mirrored on [http://code.qt.io].
All projects under the Qt Open Governance umbrella are hosted on our [http://codereview.qt.io Gerrit Instance]. There is an [http://code.qt.io official mirror and browser] of these repositories.


== How to get started - Gerrit registration ==
== How to get started - Gerrit registration ==
Line 23: Line 23:
Configure SSH properly (the URLs below rely on this). Add this to your <tt>~/.ssh/config</tt> (Windows: <tt>C:USERNAME%sh\config</tt>):  
Configure SSH properly (the URLs below rely on this). Add this to your <tt>~/.ssh/config</tt> (Windows: <tt>C:USERNAME%sh\config</tt>):  


<code>
<pre>
Host codereview.qt.io
Host codereview.qt.io
Port 29418
Port 29418
User <Gerrit/Jira username>
User <Gerrit/Jira username>
</code>
</pre>


'''NOTE:''' The following steps need to be applied to every clone:
'''NOTE:''' The following steps need to be applied to every clone:
Line 33: Line 33:
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
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


<code>
<pre>
$ scp -p codereview.qt.io:hooks/commit-msg .git/hooks
$ scp -p codereview.qt.io:hooks/commit-msg .git/hooks
</code>
</pre>


or by downloading the file via browser: "commit-msg":http://codereview.qt.io/tools/hooks/commit-msg and putting it into the <tt>.git/hooks</tt> directory (make sure it is executable).
or by downloading the file via browser: "commit-msg":http://codereview.qt.io/tools/hooks/commit-msg and putting it into the <tt>.git/hooks</tt> directory (make sure it is executable).


It is recommended to install the git_post_commit_hook from the "qtrepotools":https://qt.gitorious.org/qt/qtrepotools repository. This gives you the checks of the [[Early-Warning-System|Sanity Bot]] locally. To do this, save the script
It is recommended to install the git_post_commit_hook from the "qtrepotools":https://qt.gitorious.org/qt/qtrepotools repository. This gives you the checks of the [[Early-Warning-System|Sanity Bot]] locally. To do this, save the script
<code>
<pre>
#! /bin/sh
#! /bin/sh
exec "<path to git clone>/qtrepotools/git-hooks/git_post_commit_hook" "$@"
exec "<path to git clone>/qtrepotools/git-hooks/git_post_commit_hook" "$@"
</code>
</pre>
into each <path to git clone>/.git/hooks/post-commit
into each <path to git clone>/.git/hooks/post-commit


Line 52: Line 52:
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
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


<code>
<pre>
$ git config —global core.autocrlf true
$ git config —global core.autocrlf true
</code>
</pre>


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


<code>
<pre>
$ git config —global core.autocrlf input
$ git config —global core.autocrlf input
</code>
</pre>


(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.).
(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.).
Line 66: Line 66:
To be able to create commits which can be pushed to the server, you need to set up your committer information correctly:
To be able to create commits which can be pushed to the server, you need to set up your committer information correctly:


<code>
<pre>
$ git config —global user.name "Your Name"
$ git config —global user.name "Your Name"
$ git config —global user.email "me@example.com"
$ git config —global user.email "me@example.com"
</code>
</pre>


Please do not use nicknames or pseudonyms instead of the real name unless you have really good reasons.
Please do not use nicknames or pseudonyms instead of the real name unless you have really good reasons.
Line 76: Line 76:
To facilitate following the style guide for commit messages, it is recommended to install the Qt commit message template:
To facilitate following the style guide for commit messages, it is recommended to install the Qt commit message template:


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


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 <tt>git stat</tt> and <tt>git commit</tt>, even if this is somewhat slower (especially on Windows):
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 <tt>git stat</tt> and <tt>git commit</tt>, even if this is somewhat slower (especially on Windows):


<code>
<pre>
$ git config —global status.showuntrackedfiles all
$ git config —global status.showuntrackedfiles all
</code>
</pre>


Git has a somewhat stupid default that <tt>git push</tt> will push ''all'' branches to the upstream repository, which is almost never what you want. To fix this, use:
Pre-2.0 git has a somewhat stupid default that <tt>git push</tt> will push ''all'' branches to the upstream repository, which is almost never what you want. To fix this, use:


<code>
<pre>
$ git config —global push.default tracking
$ git config —global push.default tracking
</code>
</pre>


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.
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.
Line 96: Line 96:
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:
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:


<code>
<pre>
$ git config —global rerere.enabled true
$ git config —global rerere.enabled true
$ git config —global rerere.autoupdate true # this saves you the git add, but you should verify the result with git diff —staged
$ git config —global rerere.autoupdate true # this saves you the git add, but you should verify the result with git diff —staged
</code>
</pre>


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


<code>
<pre>
$ git config —global rebase.stat true
$ git config —global rebase.stat true
</code>
</pre>


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


<code>
<pre>
$ git config —global color.ui auto
$ git config —global color.ui auto
$ git config —global core.pager "less -FRSX"
$ git config —global core.pager "less -FRSX"
</code>
</pre>


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


<code>
<pre>
$ git config —global alias.di diff
$ git config —global alias.di diff
$ git config —global alias.ci commit
$ git config —global alias.ci commit
$ git config —global alias.co checkout
$ git config —global alias.co checkout
$ git config —global alias.ann blame
$ git config —global alias.ann blame
$ git config —global alias.st status
$ git config —global alias.st status
</code>
</pre>


=== Using Existing clones ===
=== Using Existing clones ===
Line 128: Line 128:
Add a <tt>gerrit</tt> remote pointing to codereview.
Add a <tt>gerrit</tt> remote pointing to codereview.


<code>
<pre>
$ git remote add gerrit ssh://codereview.qt.io/qt/<qt5 or the submodule name you have checked out>
$ git remote add gerrit ssh://codereview.qt.io/qt/<qt5 or the submodule name you have checked out>
</code>
</pre>


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


<code>
<pre>
$ git remote add gerrit https://codereview.qt.io/p/qt/<qt5 or the submodule name you have checked out>
$ git remote add gerrit https://codereview.qt.io/p/qt/<qt5 or the submodule name you have checked out>
</code>
</pre>


For Qt 4.8, use
For Qt 4.8, use


<code>
<pre>
$ git remote add gerrit ssh://codereview.qt.io/qt/qt
$ git remote add gerrit ssh://codereview.qt.io/qt/qt
</code>
</pre>


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


<code>
<pre>
$ git remote add gerrit https://codereview.qt.io/p/qt/qt
$ git remote add gerrit https://codereview.qt.io/p/qt/qt
</code>
</pre>


=== Cloning repositories ===
=== Cloning repositories ===


You should clone from the repositories hosted at [http://code.qt.io/] and track changes from there in order to keep the load on Gerrit down.
You should clone from the [http://code.qt.io/ official mirror] and track changes from there in order to keep the load on Gerrit down.


==== Cloning Qt5 ====
==== Cloning Qt5 ====
Line 159: Line 159:
The canonical way to obtain a Qt 5 clone is cloning the super repo from a mirror, and running the init-repository script in qt5 to set up the gerrit remote(s) pointing to codereview, and to clone the submodules:
The canonical way to obtain a Qt 5 clone is cloning the super repo from a mirror, and running the init-repository script in qt5 to set up the gerrit remote(s) pointing to codereview, and to clone the submodules:


<code>
<pre>
$ git clone git://code.qt.io/qt/qt5.git
$ git clone git://code.qt.io/qt/qt5.git
$ cd qt5
$ cd qt5
$ ./init-repository -f —no-webkit
$ ./init-repository -f —no-webkit
</code>
</pre>


Note that Qt 5 submodules have been changed from absolute to relative URLs (like "../qtbase.git") in the .gitmodules file.
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 to make it work:
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 to make it work:
<code>
<pre>
[url "git://gitorious.org/qt/"]
[url "git://gitorious.org/qt/"]
         insteadOf = git://gitorious.org/~<username>/qt/
         insteadOf = git://gitorious.org/~<username>/qt/
</code>
</pre>


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


==== Cloning Qt4 ====
==== Cloning Qt4 ====


<code>
<pre>
$ git clone git://code.qt.io/qt/qt.git
$ git clone git://code.qt.io/qt/qt.git
</code>
</pre>


Note that Qt4 does not have a <tt>master</tt> branch (since no 4.9 is planned). So, you should push changes to the <tt>4.8</tt> branch.
Note that Qt4 does not have a <tt>master</tt> branch (since no 4.9 is planned). So, you should push changes to the <tt>4.8</tt> branch.
Line 184: Line 184:
==== Cloning Qt Creator ====
==== Cloning Qt Creator ====


<code>
<pre>
$ git clone git://code.qt.io/qt-creator/qt-creator.git
$ git clone git://code.qt.io/qt-creator/qt-creator.git
</code>
</pre>


=== Pushing your local changes to gerrit ===
=== Pushing your local changes to gerrit ===


You can't push directly to a branch, so you need to create a review. See [[Gerrit Introduction]].
See [[Gerrit Introduction]].

Revision as of 17:40, 27 February 2015


All projects under the Qt Open Governance umbrella are hosted on our Gerrit Instance. There is an official mirror and browser of these repositories.

How to get started - Gerrit registration

  1. Create an account in the "Qt bug tracker":https://bugreports.qt.io/ (also known as JIRA)
  2. Go to https://codereview.qt.io and log in with your Qt bug tracker credentials
    • 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.
  3. Go to the Settings page: https://codereview.qt.io/settings/
  4. Go to "Settings" -> "Contact Information" and register your email address.
    • You will receive a confirmation email; click on the link inside to finalize your registration.
      • When you use Outlook, manually copy the link including any trailing equal signs into the browser.
    • Note: Your username and e-mail address will be visible to the public. Use an alias + a custom e-mail address if you want to stay anonymous (this is discouraged)
  5. Go to "Settings"-> "SSH Public Keys" and upload your "public SSH Key":https://help.github.com/articles/generating-ssh-keys
  6. If you are behind a firewall that blocks SSH access:
    1. Go to "Settings" -> "HTTP Password"
    2. Click "Generate Password"
    3. Add the following line to your ~/.netrc (Windows: ​%USERPROFILE%netrc):
      machine codereview.qt.io login <Gerrit username> password <Generated password>

Local Setup

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

Host codereview.qt.io
Port 29418
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

$ scp -p codereview.qt.io:hooks/commit-msg .git/hooks

or by downloading the file via browser: "commit-msg":http://codereview.qt.io/tools/hooks/commit-msg 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":https://qt.gitorious.org/qt/qtrepotools repository. This gives you the checks of the Sanity Bot locally. To do this, save the script

#! /bin/sh
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

$ git config —global core.autocrlf true

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

$ 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:

$ git config —global user.name "Your Name"
$ 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:

$ 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):

$ git config —global status.showuntrackedfiles all

Pre-2.0 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:

$ 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:

$ git config —global rerere.enabled true
$ 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:

$ git config —global rebase.stat true

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

$ git config —global color.ui auto
$ 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 ;)):

$ git config —global alias.di diff
$ git config —global alias.ci commit
$ git config —global alias.co checkout
$ git config —global alias.ann blame
$ git config —global alias.st status

Using Existing clones

Add a gerrit remote pointing to codereview.

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

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

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

For Qt 4.8, use

$ git remote add gerrit ssh://codereview.qt.io/qt/qt

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

$ git remote add gerrit https://codereview.qt.io/p/qt/qt

Cloning repositories

You should clone from the official mirror and track changes from there in order to keep the load on Gerrit down.

Cloning Qt5

Qt 5 is modularized into several repositories which are aggregated by the qt5 super repo. The canonical way to obtain a Qt 5 clone is cloning the super repo from a mirror, and running the init-repository script in qt5 to set up the gerrit remote(s) pointing to codereview, and to clone the submodules:

$ git clone git://code.qt.io/qt/qt5.git
$ cd qt5
$ ./init-repository -f —no-webkit

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 to make it work:

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

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

Cloning Qt4

$ git clone git://code.qt.io/qt/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 Qt Creator

$ git clone git://code.qt.io/qt-creator/qt-creator.git

Pushing your local changes to gerrit

See Gerrit Introduction.