Gerrit

Avantus team use Gerrit for handling the repository commits. **Gerrit* is a tool that allows to software developers in a team 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. This article describe the basic things you can do in **Gerrit**.

# Add SSH keys

The first thing developers MUST to do before using Gerrit is to add a SSH Public Key to the system. This action can be performed in the settings. Check the next steps:

  • Click in your name on top right corner. Clickup statuses

  • On the menu open, click on Settings

  • On the left part you can find the menu with all possible submenus. Click in the SSH Keys Clickup statuses

  • After click in SSH Keys you will be able to add new one. The form is similar to the next pic. Clickup statuses

  • Once you paste your public key in the form, click on the blue button ADD NEW SSH KEY Clickup statuses

# Hook for task ID

Git has a way to fire off custom scripts when certain important actions occur. This has the name of hooks. In Avantus we use one specific custom hook for automatically add the label TaskId when you execute any commit, can be first commit or ammend commit.

# Configuring the hook prepare-commit-msg

The hook we are going to configure, add automatically the text TaskId:#YOUR_TASK_ID_HERE[READY FOR TEST] to the commit message. You only need to replace the text YOUR_TASK_ID_HERE for the taskId number that you get from Clickup.

The next steps assume you have a terminal ready and are under Unix system. If you have another Operation System, please find out how to do it. We also assume that the folder of your project is avantus.

  1. Go into the avantus folder and be sure the git is initialized
  • cd avantus
  • git status
  1. Once you confirm that git is initialized in avantus, go to the hooks folder.
  • cd .git/hooks
  1. Check if prepare-commit-msg exists, in that case edit it, otherwise create a file with that name.
  • ls
  • sudo nano prepare-commit-msg
  1. Paste the next code into the file and save it. Be sure there is not line space after the fi

#!/bin/sh

COMMIT_MSG_FILE=$1

SEARCH_MSG="TaskId"

MY_MSG="TaskId:#YOUR_TASK_ID_HERE[READY FOR TEST]"

if grep -q "TaskId" $1; then

echo '';

else

sed -i.old "3s/^/$MY_MSG \n\n /" "$COMMIT_MSG_FILE"

fi

  1. After that, any time you execute git commit -a or git commit --amend the text for TaskId will be added automatically. If you find any bug, please let the team know asap.

# How to donwload

  1. Download first time First time you want to download the project, and after you added your SSH KEY on Gerrit, you can do the next steps.
  • Go to BROWSE on Gerrit menu on top.
  • Click in Repositories
  • Click in the project that you want to download on the list. test project can be used by developers to practice everything about Gerrit.
  • You will see download section with the details for downloading, just click in COPY button. The section looks like below: Clickup statuses
  • Copy and paste into your terminal and execute the command.

# How to push the code

After you work in the project and need to submit the code to Gerrit follow the next steps.

  1. Verify the classes you changed
  • git status
  1. Add specific classes to the commit or just all the changes
  • git add .
  1. When is your first commit about this task to Gerrit and the commit is not a new patch set
  • git commit -a
  1. Add the comment according with the principles described in the Code compatibility article.
  2. Add the taskID to thecommit.
  3. Save the changes. Control+O in nano.
  4. Submit your commit
  • git push origin HEAD:refs/for/master
  1. Go to *Gerrit and verify that your commit is there.
  2. Wait for the reviewers team.

# How to pull

Developers MUST to has the habit to update regulary your code in order to get the last changes from repo made by others developers. You can perform that with:

  • git pull -q -r origin master

Also verify always the logs in order to check the commit on top

  • git log

# How to resubmit after -1

Always after -1 if you have that commit on top in your git log. Only fix the code and execute

  • git add .
  • git commmit --amend
  • Only save without change anything.
  • git push origin HEAD:refs/for/master
  • Go to Gerrit and verify there is new path set for your commit.
Last Updated: 4/8/2021, 8:49:55 AM