[pulseaudio-discuss] [PATCH] scripts: Add a pre-receive hook to catch invalid merge and WIP commits

Tanu Kaskinen tanuk at iki.fi
Fri Apr 14 13:08:23 UTC 2017


On Fri, 2017-04-07 at 14:09 +0530, Arun Raghavan wrote:
> This should make sure we avoid merge commits from branches outside of PA
> (we don't really have any, so this should avoid all merge commits). This
> also catches "WIP" and such in the title to prevent accidental pushing
> of those.
> ---
>  scripts/pre-receive.hook | 89 ++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 89 insertions(+)
>  create mode 100755 scripts/pre-receive.hook

I tested the script. The "wip" detection seems to work as advertised,
but I found a couple of other issues, see below.

> diff --git a/scripts/pre-receive.hook b/scripts/pre-receive.hook
> new file mode 100755
> index 0000000..7240c27
> --- /dev/null
> +++ b/scripts/pre-receive.hook
> @@ -0,0 +1,89 @@
> +#!/usr/bin/env python2
> +import sys
> +import os
> +import subprocess
> +
> +# Based on the same file in: https://cgit.freedesktop.org/gstreamer/common
> +# Manually deployed to /srv/git.freedesktop.org/git/pulseaudio/pulseaudio.git/hooks

This should mention that when deploying, the .hook suffix needs to be
dropped. Or maybe the suffix shouldn't be in the file name in the first
place?

> +
> +# checks whether the push contains merge commits and if so, makes sure that
> +# the merge is only between branches present on the repository.
> +def contains_valid_merge(old, new, ref):
> +    sub = subprocess.Popen(["git", "rev-list", "--parents", "%s..%s" % (old, new, )],
> +                           stdout=subprocess.PIPE)
> +    stdout, stderr = sub.communicate()
> +
> +    res = True
> +
> +    print "=> Checking for merge commits"
> +
> +    for line in stdout.split('\n'):
> +        if res == False:
> +            break
> +        splits = line.strip().split()
> +        if len(splits) > 2:
> +            # the commit has more than one parent => it's a merge
> +            commit = splits[0]
> +            for parent in splits[1:]:
> +                if not commit_in_valid_branch(parent):

remote: => Checking for merge commits
remote: Traceback (most recent call last):
remote:   File "hooks/pre-receive", line 71, in <module>
remote:     pushvalid = contains_valid_merge(old, new, ref)
remote:   File "hooks/pre-receive", line 28, in contains_valid_merge
remote:     if not commit_in_valid_branch(parent):
remote: NameError: global name 'commit_in_valid_branch' is not defined

-- 
Tanu

https://www.patreon.com/tanuk


More information about the pulseaudio-discuss mailing list