What is Gerrit?
Pushing commits to gerrit
gitdir=$(git rev-parse --git-dir); scp -p -P <GERRIT_PORT> <GERRIT_SSH>:hooks/commit-msg ${gitdir}/hooks/
git push origin HEAD:refs/for/<BRANCH_NAME>
[alias] ... push-for-review = push origin HEAD:refs/for/master ...
To execute it just type:
git push-for-review
If I want to push as review to another branch then I use another alias:
[alias] ... push-for-review-branch = !git push origin HEAD:refs/for/$1 ...
and branch name could be pass as argument from command line:
git push-for-review-branch <BRANCH_NAME>
Pushing drafts
git push origin HEAD:refs/drafts/<BRANCH_NAME>
[alias] ... push-as-draft = push origin HEAD:refs/drafts/master push-as-draft-branch = !git push origin HEAD:refs/drafts/$1 ...
Invite for review
[alias] ... gerrit-remote = "!sh -c \"git remote -v | grep push | grep ssh | grep gerrit | head -1 | awk '{print $2}' | cut -d'/' -f3\"" gerrit-host = "!sh -c \"git gerrit-remote | cut -d':' -f1\"" gerrit-port = "!sh -c \"git gerrit-remote | cut -d':' -f2\"" gerrit-invite = "!sh -c \"ssh -pgit gerrit-port
git gerrit-host
'gerrit set-reviewers --add' $1git log | grep Change-Id | head -1 | tr -d ' ' | cut -d':' -f2
\"" ...
First alias selects remote repository which contains gerrit in name or url, could be used to push via ssh and extracts url to this repository.
Second and third alias uses the first to extract host and port from repository url. It is necessary for executing remote command via ssh.
The last alias extract Change-Id from HEAD and add user or group given form command line. Example usage:
git gerrit-invite <USER_OR_GROUP>