Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to understand Git/Gerrit command (fetch & push)

Tags:

git

gerrit

I am following an example from our IT department, and I would like to understand what this command is doing exactly:

git fetch origin +refs/changes/*:refs/remotes/origin/changes/*

To give some frame of reference, this is part of a continuous integration (CI) tool, and this is part of the step to checkout the code to test. The CI build is triggered by pushing to Gerrit with:

git push origin HEAD:refs/for/master

I secondary question, is if I wanted to push the change into a development branch could I use:

git push origin HEAD:refs/for/development
like image 776
Plazgoth Avatar asked Nov 02 '22 19:11

Plazgoth


2 Answers

I don't know anything about gerrit. But I can say something about the first git command you mention.

The last parts of the commands you mention are called the refspecs. You can read about what they do in the Refspec chapter of the Pro Git book. In short:

git fetch origin +refs/changes/*:refs/remotes/origin/changes/*

This says that, for the origin remote, fetch the commits of the branches that, in the origin repository, are in the refs/changes directory in the git directory (i.e. .git/refs/changes/ in a standard repository and refs/changes in a normal bare repository). It will copy those branches to the local directory .git/refs/remotes/origin/changes/. Lastly, as per normal fetch behavior, it will copy the commits belonging to those branches to the .git/object directory.

The standard refspec is +refs/heads/*:refs/remotes/origin/* so the refs/changes looks a bit strange to me. That is not a standard Git directory, but perhaps it is a Gerrit thing. The structure refs/remotes/origin/changes looks like changes is a branch in your local repository.

like image 143
Klas Mellbourn Avatar answered Nov 15 '22 03:11

Klas Mellbourn


A typical pull of a patch would look like this: git pull ssh://www.example/com:29418/project refs/changes/24/24/2

This would pull your project plus the second patch set of change 24. So when you pull all the changes that can be a lot.

I would recommend that you use Jenkins (CI) plus the Gerrit plugin and that make sure you specify the choosing strategy as Gerrit Trigger. This will then make sure that you build will test the appropriate change set.

Yes, you can push to a development branch. Of course you need to make sure you have the correct rights. Best is to create the branch in Gerrit first, this way you do not have to give the "create reference" right and prevent creating branches by mistake by spelling mistake for example.

like image 38
uncletall Avatar answered Nov 15 '22 05:11

uncletall