Pushing a branch as one commit to gerrit

2,747 views
Skip to first unread message

Thomas Koch

unread,
Sep 22, 2011, 11:34:02 AM9/22/11
to Repo and Gerrit Discussion
Hi,

currently, gerrit encourages me to commit --amend all my work and to keep
rewriting the same commit over and over, until a change gets reviewed.
I'd however like to keep my local history of changes, until the change gets
approved. So now I'm doing:

git checkout -b feature_branch
make several commits
git checkout -b x
git rebase -i master (squash everything in the first commit)
git push gerrit
git checkout feature_branch
git branch -D x

Does anybody have an idea, how I could pack the above workflow in one command?

Furthermore, I'd actually like to also push my feature_branch to gerrit for
backup, but without triggering Jenkins on it or having Gerrit generate review
requests. Is this possible or should I set up a separate Git server for this
purpose?

Thank you,

Thomas Koch, http://www.koch.ro

Shawn Pearce

unread,
Sep 22, 2011, 12:46:53 PM9/22/11
to tho...@koch.ro, Repo and Gerrit Discussion
On Thu, Sep 22, 2011 at 08:34, Thomas Koch <tho...@koch.ro> wrote:
> currently, gerrit encourages me to commit --amend all my work and to keep
> rewriting the same commit over and over, until a change gets reviewed.
> I'd however like to keep my local history of changes, until the change gets
> approved. So now I'm doing:
>
> git checkout -b feature_branch
> make several commits
> git checkout -b x
> git rebase -i master (squash everything in the first commit)
> git push gerrit
> git checkout feature_branch
> git branch -D x
>
> Does anybody have an idea, how I could pack the above workflow in one command?

Maybe you can instead do:

git checkout -b feature_branch
make several commits

git reset --soft $(git merge-base master HEAD)
git commit -m "New message for the entire topic"
git push gerrit

Since Git supports aliases, you may be able to write:

git config --global alias.squash '! git reset --soft $(git
merge-base $0 HEAD)'

and now your flow is:

git squash master
git commit -m 'New message'
git push

> Furthermore, I'd actually like to also push my feature_branch to gerrit for
> backup, but without triggering Jenkins on it or having Gerrit generate review
> requests. Is this possible or should I set up a separate Git server for this
> purpose?

Grant yourself push access to a namespace, such as
refs/backup/${username}/* in the project access tab. Then you can push
branches to the server at refs/backup/$USER/foo and have it not
trigger a review, nor be shown as a real branch. But its there and can
be fetched with Git fetch just like a change.

Thomas Koch

unread,
Sep 27, 2011, 5:23:52 AM9/27/11
to repo-d...@googlegroups.com, Shawn Pearce
Shawn Pearce:

> Since Git supports aliases, you may be able to write:
>
> git config --global alias.squash '! git reset --soft $(git
> merge-base $0 HEAD)'
>
> and now your flow is:
>
> git squash master
> git commit -m 'New message'
> git push
Thank you for the idea! I had to hack the alias however to make it work. There
are a couple of discussions on Stackoverflow about the problems of passing
arguments to aliases.

squash = "!f() { git checkout -B gerrit_temp && git reset --soft $1; }; f `git
merge-base \"$1\" HEAD`"

When I have time I should add the following features:
- Get the changeId from the first commit on my current branch that's not in
the merge base
- generate a better name instead of gerrit_temp, maybe containing the ChangeId
- prepare a commit message from the first commit on this feature branch
- automatically set up the tracking for the new branch pointing to
gerrit:/refs/for/$1
- go the whole road, make an additional wrapper command to also call git
commit and git push

Regards,

Thomas Koch, http://www.koch.ro

Thomas Koch

unread,
Sep 28, 2011, 3:45:49 AM9/28/11
to repo-d...@googlegroups.com, Shawn Pearce
Shawn Pearce:

> > Furthermore, I'd actually like to also push my feature_branch to gerrit
> > for backup, but without triggering Jenkins on it or having Gerrit
> > generate review requests. Is this possible or should I set up a separate
> > Git server for this purpose?
>
> Grant yourself push access to a namespace, such as
> refs/backup/${username}/* in the project access tab. Then you can push
> branches to the server at refs/backup/$USER/foo and have it not
> trigger a review, nor be shown as a real branch. But its there and can
> be fetched with Git fetch just like a change.
I had to experiment a bit with the permissions:

1. Give only Push (with force push selected) right:
[remote rejected] HEAD -> refs/backup/thkoch/xxx (prohibited by Gerrit)

2. add Create Reference right:
(...as above...) (you are not allowed to upload merges)

3. add Push Merge Commit, no chance in behaviour
4. add Push Merge Commit right for refs/* as a workaround to this bug:
http://code.google.com/p/gerrit/issues/detail?id=1072

success.

I was a bit puzzled when you wrote "Grant yourself", since I can only grant
rights to groups. I must of course grant the rights to a kind of "developers"
group, but since the right is parameterized with the username, it applies to
different namespaces for different users.

Reply all
Reply to author
Forward
0 new messages