Re: git pre-push hook not getting the lines from STDIN

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Wesley <wesleys@xxxxxxxxxxxxxxx> writes:

> Hello list,
>
> I'm trying to figure out how I can check which branches are used in a
> git push action while using the pre-push hook.

> ----< The pre-push script
>
> #!/usr/bin/env zsh
> #
> set -x
>
> remote="$1"
> url="$2"
>
> success=128
>
> z40=0000000000000000000000000000000000000000
> IFS=' '
>
> read LOCAL_REF LOCAL_SHA REMOTE_REF REMOTE_SHA
>
> echo $LOCAL_REF
> echo $LOCAL_SHA
> echo $REMOTE_REF
> echo $REMOTE_SHA
>
> # deletion of remote branch
> [ "$LOCAL_REF" = $z40 ] && exit $success
> # git 2.40 at least does not have $z40 as a delete
> [ "$LOCAL_REF" = '(delete)' ] && exit $success
>
> exit $success

Have you looked at simplifying this script to the bare minimum to
identify the issue? I might suggest starting by just slurping stdin and
writing that to a file:

    #!/bin/sh
    echo "$@" >pre-push.$$.args
    cat >>pre-push.$$.stdin
    exit 1

(The 'exit 1' here is to unconditionally prevent the push from actually
going through during testing. Likely similar to your '128' value, since
actual success of course should be exit code '0'.)

>From here, you can test your pre-push hook by using that file as stdin:

    ./my-hook $(cat pre-push.$$.args) <pre-push.12345.stdin

I'm not familiar with the particulars of Zsh scripting, but I suspect
there is a bug in your script. Zsh works with my script, too, so it
doesn't appear to be a problem with Zsh itself.

--
Sean Allred



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux