rejecting a change upload based on gerrit patchset-created hook?

533 views
Skip to first unread message

Janne Hellsten

unread,
Feb 23, 2011, 6:13:46 PM2/23/11
to repo-d...@googlegroups.com
Hi!

After playing with the patchset-created hook a bit today, it seems that a change upload will be accepted to Gerrit regardless of the hook error code.  It'd be useful to be able to return an error from the Gerrit hook to reject a change before it goes into Gerrit.

Is it possible to reject a "repo upload"/"git push refs/for" based on the exit code of patchset-created hook?

This would be useful for enforcing some types of commit message conventions.  Rather than automatically adding a comment to the change in Gerrit saying that a convention rule was broken, it'd be nicer for users if their "repo upload" was just rejected immediately.  The same hook under contrib/ runs similar heuristics but it looks to me like it only adds comments and modifies review scores based on rules.

Did I misunderstand something about the way hooks work or is this just not supported in Gerrit currently?

Thanks!

Janne

Shawn Pearce

unread,
Feb 23, 2011, 6:16:00 PM2/23/11
to Janne Hellsten, repo-d...@googlegroups.com
On Wed, Feb 23, 2011 at 15:13, Janne Hellsten <jjhe...@gmail.com> wrote:
> After playing with the patchset-created hook a bit today, it seems that a
> change upload will be accepted to Gerrit regardless of the hook error code.
>  It'd be useful to be able to return an error from the Gerrit hook to reject
> a change before it goes into Gerrit.
> Is it possible to reject a "repo upload"/"git push refs/for" based on the
> exit code of patchset-created hook?

Nope. Hooks run after-the-fact on a background thread.

Brad Larson

unread,
Feb 24, 2011, 2:40:25 PM2/24/11
to Repo and Gerrit Discussion


On Feb 23, 5:16 pm, Shawn Pearce <s...@google.com> wrote:
FWIW, I've implemented a patchset-created script which will give a -2
review for the change if the commit message isn't properly formatted.
Maybe not as good as rejecting the patch, but OTOH it has more of a
public shame aspect to it which might correct bad behavior faster ;)

You can find the script in Gerrit at contrib/check-valid-commit.py
(See https://review.source.android.com/#change,15177)
Reply all
Reply to author
Forward
0 new messages