Downloading a patch from Gerrit
There are similarities between OpenStack’s review system, Gerrit and Git. However, there are a few differences that can be confusing. This piece helps you download a patch from Gerrit.
I’ve been contributing to OpenStack Horizon for a while now, and everyday I realize that there are so many depths left to explore.
I’ve written about unit testing, Angular directives, and even debugging devstack in the recent past.
Today, I want to pen something about OpenStack’s review system, named Gerrit. One of the things that you need to do as part of your ‘contribution setup’ is create and configure a Gerrit account.
The initial set up is quite straightforward, and you’re unlikely to run into any trouble. The problems begin when you need to get code from Gerrit into your local set up. The correct terminology in version control systems like Git it to ‘pull’ or ‘fetch’.
And this is where we’ll be spending some time today.
Downloading a patch
We are going to use ‘fetch’ so that we understand what I’m trying to explain. So if you want to fetch changes from Gerrit, you need to download a patch.
You access that functionality from the top right corner of the patch on gerrit.
When you click ‘download patch’, you get several options, HTTP and SSH, as you would on GitHub.
We’ll go with the first option,
git fetch https://review.opendev.org/openstack/horizon refs/changes/79/926379/28 && git checkout FETCH_HEA
D
This command will fetch the changes from the patch you want create a temporary reference, a ‘detached HEAD state’.
If you check your braches now, you’ll have an extra branch ‘'FETCH_HEAD’. You’ll however notice that its name is wrapped in parenthesis because it is not a real branch, just a temporary reference to the most recently fetched branch from a remote repository.
You can test your changes from the patch when you’re in detached state and even make more changes.
If you want to keep the changes, use the command git switch -c <new-branch-name>
and you’ll have your updated patch in a new branch.
Pushing Changes
When the patch was committed, a ‘Change_Id’ is automatically created. You don’t need to change this as you want to keep working on the same patch.
That’s why we use git commit --amend <file_changed>.
This command will add your changes to the patch, keep the same Change_Id, and not create a new commit.
Final Thoughts
There are similarities between OpenStack’s review system, Gerrit and Git. However, there are a few differences that can be confusing. I hope this piece clears the air for you and helps you work with Gerrit a bit faster.