At OsmoDevCon2016 we discussed problems with our past contribution / patch submission process using mails on the mailing list as well as patchwork. The result is that we want to give Gerrit a try for some time and see if it helps us to have a better process

first sign in on https://osmocom.org. Do this before logging in on gerrit (the redmine login process loses the gerrit login data and you'd have to do the same thing twice if not logged in on osmocom.org already).

careful: enter 'https' to ensure that your openid credentials are passed on encryptedly.pitfall: if you're logged in on 'projects.osmocom.org' (including the 'projects.' part), you should also use the openid provider: https://projects.osmocom.org/openid; the 'projects.' part may be omitted, what's important is that redmine login and OpenID URLs match. Also, decide for one of those URLs once, because when picking a different OpenID URL next time, you will create a new user instead of logging in as yourself.note: gerrit will create a distinct user for each openid URL you pass. If you logged in successfully but your user seems to have lost permissions, you may have created an evil twin user: contact us on the mailing list so we can fix it in the user database.

If you have no Osmocom redmine account, you can simply create one online at the "Register" link in the upper right corner.Even without an existing or new redmine account, you should also be able to use any other OpenID provider to authenticate against gerrit (untested).

After the initial sign-up you will need to:

Pick a username (can not be changed)

Add your public ssh key(s)

Add email addresses you intend to use as author/comitter

If you would like to push private branches to the Gerrit repository, you also need to be added to the "known users" group.Please send a short requesting email to openbsc@lists.osmocom.org.

Note: it is easiest to work with gerrit when gerrit is the only remote in your git clone.When you clone from git.osmocom.org and add the gerrit remote, git will have two remotes,so when you first checkout a branch you have to supply the remote explicitly (cumbersome).The gerrit repositories and git.osmocom.org are constantly synced, so it is sufficientto clone from gerrit only.

The commit-msg hook places a Change-Id tag in the footer, often above other tags like 'Depends:' or 'Related:'. Since the Change-Id is an implementation detail for Gerrit, I personally prefer it always placed right at the bottom. This simple edit changes the commit-msg hook to add Change-Id at the bottom unconditionally:

Your email address on gerrit and the email address git places in yourcommits must match, or you will get rejected with an error message like"invalid commiter". You can add email addresses on the gerrit web UI.

A patch can be merged when it has CR+2 and V+1 votes, and if, in case of aseries of patches pushed from a branch, when its ancestor patches can also bemerged.

Sometimes the reviewer that gives CR+2 also hits the "Submit" button right away to merge the patch to master. Sometimes it is left up to the owner of the patchto decide when to hit "Submit" (who needs to be in the "Known Users" group).

The CR+2 vote means "code reviewed and ready for merge to master branch".Accounts with the "Reviewer" role for a given project are allowed to give CR+2votes. Others are allowed to give CR+1 (and CR-1). CR votes don't add up.

Fixed by gerrit 2.12.6, see https://bugs.chromium.org/p/gerrit/issues/detail?id=4158:Sometimes hitting the "Submit" button results in an error message saying"Change is New", which is a bug related to a private branch with the samepatches being present. Can be fixed e.g. by an admin's manual push to master.

If you need to adjust and re-submit patches, it may be handy to create a throw-away branch ("R D" in magit-gerrit in emacs for example),make your changes/amendments and then send patch(es) back to gerrit while removing temporary branch automatically with "git review -f".

On a feature branch, one typically has numerous commits that depend on their preceding commits.Often, some of the branch commits need to be amended for fixes. You can re-submit changes topatches on your branch by pushing in the same way that you first submitted the branch.

Note: if you modify the Change-Ids in the commit logs, your push would open entirely newreview entries and you would have to abandon your previous submission. Comments on the firstsubmission are "lost" and you cannot diff between patch sets.

(There used to be a bug in gerrit that required editing the first patch to be able tore-submit a branch, but that's fixed.)

There are different merge strategies that Gerrit performs to accept patches.Each project can be configured to a specific merge strategy, but unfortunately you can'tdecide on a strategy per patch submission.

It seems that the "Merge if Necessary" strategy is best supported, but it creates non-linearhistory with numerous merge commits that are usually not at all necessary.

Instead, the "Cherry Pick" strategy puts each patch onto current master's HEAD to createlinear history. However, this will cause merge failures as soon as one patch depends onanother submitted patch, as typical for a feature branch submission.

So we prefer the "Rebase if Necessary" strategy, which always tries to apply your patches tothe current master HEAD, in sequence with the previous patches on the same branch.However, some problems still remain, including some bugs in "Rebase if Necessary".

There's a problem with "Rebase if Necessary": If your branch sits at master's HEAD, Gerritrefuses to accept the submission, because it thinks that no new changes are submitted.This is a bug in Gerrit, which holger has fixed manually in our Gerrit installation:

Say you have an extensive feature in development, and you want to keep it on theupstream git repository to a) keep it safe and b) collaborate with other devs on it.So, of course, you have regularly pushed to refs/heads/yoyodyne/feature.

Since you have the gerrit commit hook installed, your feature branch already hasChange-Id tags in all commit log messages.

Now your feature is complete and you would like to submit it to master.Alas, Gerrit refuses to accept your patch submission for master, because itknows the Change-Ids are also on a different branch.

Gerrit by default enforces that a Change-Id must be unique across all branches,so that each submission for review is separate for each branch. Instead, wewant to handle Change-Ids per-branch, so that you can have the same changesubmitted to different branches, as separate patch submissions, without havingto cosmetically adjust the Change-Id.

Solution: set the option Create a new change for every commit not in the target branch to TRUE

By default, gerrit compares patches only by the files' paths. If two paths are the same,it immediately shows them as conflicts (path conflicts).

In software development, a conflict usually means an actual content conflict, so if theedits are in two entirely separate places in the file, we don't consider this a conflict.

By setting Allow content merges to TRUE in the git project config, we tell Gerrit toperform text merges of the submitted patches and only complain about actual contentconflicts, in the usual software engineering sense.

Normally, the gerrit UI auto-completes a user name in the edit field. It has happenedthough that an existing user is not auto-completed, as if it didn't exist. In that case,find out the user ID (seven digit number like 1000123) and just enter that.

The user ID can be found on the user's "Settings" page, or in the database (s.b.).