Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get gerrit patchsets via topic (for multiple repositories)

Tags:

git

patch

gerrit

We have a couple of submodules in our project. So let's say one developer implements a new feature that affects several of those submodules and uploades his changes to gerrit patchsets with all the same topic.

So when I want to download his changes I can get the download links from the gerrit webinterface. But I would have to do this for every submodule.

Is there an easy way to automagically fetch the patch sets via the topic name?
Something like git fetch origin refs/changes/*topicname* ?

Or will I have to use gerrit REST API?

like image 891
Roman Avatar asked Dec 08 '25 09:12

Roman


2 Answers

I wrote a little script for this - it was easier than I thought.
Here is what to do:

  • get the desired patch sets via gerrit query, like this:
    ssh -p 29418 myserver gerrit query --patch-sets topic:mytopic AND project:myproject
  • As gerrit will output a lot of data per patch set, we have to 'grep' and 'sed' it's output a little bit:
    grep ref: | sed s%\ \ \ \ ref:\ %%
    so we get a nice list of the refs to fetch
  • we can use this output with xargs xargs -r -n 1 get_n_tag_patchset.sh
  • where my get_n_tag_patchset.sh looks like this:
    git fetch --recurse-submodules=no origin $1
    git tag -f $1 FETCH_HEAD

I merged the first three points together in one command line:
ssh -p 29418 myserver gerrit query --patch-sets topic:mytopic AND project:myproject | grep ref: | sed s%\ \ \ \ ref:\ %% | xargs -r -n 1 get_n_tag_patchset.sh

So I end up with all the patch sets of the desired topic in my local repo, each with a tag on it.
Doing this for all of my submodules (where 'myproject' has to be replaced to match the submodule, of course) will do the rest. :-)

like image 64
Roman Avatar answered Dec 10 '25 00:12

Roman


The latest GitMinutes episode (July 2014) mentions that, and Luca Milanesio, a seasoned Gerrit contributor, details it in its blog post:

With the forthcoming support of multi-repositories atomic commits in Gerrit, it will be possible to merge multiple changes on multiple repositories at the same time for a single topic.
This feature is not ready yet but coming hopefully in the near future and Google Gerrit Team developers and contributors are working on it.

This is not there yet in Gerrit 2.9 though.

like image 28
VonC Avatar answered Dec 10 '25 01:12

VonC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!