[XDA-University] nailyk:
Purposes of this guide​

This guide want to be a how-to use Gerrit, allowing everyone to contribute on AOSP like projects.

Divided in 3 parts:

Now few important stuff needs to be setup before proceeding- -> Minimal setup to use Gerrit.

How to setup & submit for recurent contributes

How to submit patches one time

Here we will setup clones, outside of the build tree. See faq for commit testing.

This mean you do not need build environement to contribute :cool:

Important: for projects using Gerrit, Github pull request will never be merged! This also mean you do not need to create a Github fork for every changed projects :victory:

So firstly, I'll explain few terms that are important for you to learn before going towards a bit tricky side. ;)​

Git

- To be precise, git is a code-sharing website/software that allows you to share your project resources you can 'Make Software, better, together'(That's what the tag line says :p )!

Now, before I go to gerrit, read this: Major Open Source Projects, like, CyanogenMod, AOKP, OmniROM etc. don't directly accept pull requests and in case you want to make a change in their source for a fix/feature or anything, you need to send them patches over gerrit which are then reviewed by the trusted members of the community and if they find it valuable enough, gets merged into the git repository!

Gerrit

(Copying the definition from Wiki) - Gerrit is a free, web-based team software code review tool. Software developers in a team can review each other's modifications on their source code using a Web browser and approve or reject those changes. It integrates closely with Git, a distributed version control system.

So, now, git and gerrit are so closely related, that a patch verified over gerrit can directly be merged on git without much hassel, also please note that your gerrit and git username must be same.

Pull Requests

- Pull requests are sent over Git after you fork a repository, make some changes into it and then want the owner to merge those changes into his repository, and that's how community development and Open Source works. :)

Patches

- In simple terms, any changes you make to repos of Open Source Projects like LineageOS, OmniRom or AOKP and send them over gerrit for code review are called Patches.

You can find the Gerrit URL of the project you are working on, on the contribute webpage of the project. Example: OmniRom gerrit is https://gerrit.omnirom.org/ , LineageOS is https://review.lineageos.org/

How GERRIT works?! :confused:​

Now, Gerrit is deployed in place of this central repository and adds an additional concept, a store of pending changes. Everyone still fetches from the authoritative repository but instead of pushing back to it, they push to this pending changes location. A change can only be submitted into the authoritative repository and become an accepted part of the project once the change has been reviewed and approved.

I found a nice diagram explaining this over the internet that will clear your doubts(if any :p) :) -

There is two different way to use gerrit:

With git , on your computer (useful for recurrent contribute)

Using the Gerrit WebUI (useful for punctual contribute)

Now few important stuff needs to be setup before proceeding-

​

Install up Git:

Debian/Ubuntu:

sudo apt-get install git

Fedora:

yum install git

ArchLinux:

pacman -S git

openSUSE:

zypper install git

Configuring git:

This step is very very important as those ID will be the one which identify you and you cannot change them later!

WARNING: You need to setup the same email as on github.com !

WARNING: email is case sensitive!

(For username I highly recommend to use the same as on your computer, but you could use any username you want)

git config --global user.email "your-email@domain.com"

git config --global user.name "your-username"

Setting up SSH Keys(Skip this if you have already set them up) -

ssh-keygen -t rsa -C "your-email@domain.com"

[IMG="ssh-keygen"]https://xdaforums.com/attachment.php?attachmentid=4363089[/IMG]​

Now this will create 2 files in ~/.ssh directory as follows:

[IMG="ll ~/.ssh"]https://xdaforums.com/attachment.php?attachmentid=4363090[/IMG]​

Adding SSH Keys to your Account :

cat /home/username_on_pc/.ssh/id_rsa.pub

This will show up few lines over terminal, copy those and add them into your Gerrit profile (Will not be detailed, there is a lot of guides on internet for this part) ;)

[IMG="cat ~/.ssh/id_rsa.pub"]https://xdaforums.com/attachment.php?attachmentid=4363077[/IMG]

[IMG="Gerrit ssh key setting"]https://xdaforums.com/attachment.php?attachmentid=4363078[/IMG]​

Important: you need to setup your username into gerrit UI, otherwise you will never be able to push changes (on the screenshot there is no option to modify username as it is already setup but you should see one):

[IMG="gerrit username setup"]https://xdaforums.com/attachment.php?attachmentid=4363097[/IMG]​

Test ssh is correctly working :

ssh -p 29418 <username>@<gerrit address>

If you see this message, then everything is setup and ready to propose changes :

[IMG="ssh test"]https://xdaforums.com/attachment.php?attachmentid=4363166[/IMG]​

If you get any errors, reread the howto to ensure you are not missing something.

You can also contact your team (there is probably an IRC channel for this) and ask for help.

Setting up the hook Change-ID :

WARNING: this need to be done in every repository or upload will fail!

gitdir=$(git rev-parse --git-dir); scp -p -P 29418 <username>@<gerrit address>:hooks/commit-msg ${gitdir}/hooks/

[IMG="gerrit hook"]https://xdaforums.com/attachment.php?attachmentid=4363186[/IMG]​