Tested version: Gerrit 2.7
Source code peeked: at googlecode gerrit master branch plus jgit on github
Git command for pushing:
git push review new_branch:refs/for/new_branch
ref-update hook:
-----
#!/bin/sh
pname=$2
shift
shift
echo Project name: $pname, refname: $2, uploader: $4, newrev: $8
branch=`echo $2 | sed -E 's?.*/(.*)$?\1?'`
base=`git merge-base PRD $8`
git branch $branch $base
exit 0
-----
This hook will always try to create a new branch so that the trouble to "register" a branch in our (all bug fixes and changes are dedicated to a new branch) git branching model can be saved from this overhead.
However, it seems that the new branch reference is not visible to parseMagicBranch() as I got the "branch xxxx not found" error. Re-executing the push command would have the single commit being pushed as change.
Would it be feasible for Gerrit to refresh the advertised refs after executing the ref-update hook somehow? (this sounds like having a global impact to every triggering of the ref-update hook so I understand that this may not be the appropriate way)
Alternately, if adding a configurable variable to project.config to allow the automatic branch registration would definitely remove the need of the hook but I'm afraid it may need to have some UI checkbox and I'm not sure if this change will be easier and cleaner than refreshing the advertised refs since in order to do this, the commit id of the parent branch off point must be known in advance just like the ref-update hook written above.
I'm willing to do the change to ease my life, if you have any idea to minimize the impact of the change.