Git development
 help / color / mirror / Atom feed
From: Sean Allred <allred.sean@gmail.com>
To: Wesley <wesleys@opperschaap.net>
Cc: git@vger.kernel.org
Subject: Re: git pre-push hook not getting the lines from STDIN
Date: Wed, 09 Aug 2023 06:00:32 -0500	[thread overview]
Message-ID: <m0wmy4lbd0.fsf@epic96565.epic.com> (raw)
In-Reply-To: <676330b6-720a-e262-d583-9012e549bba7@opperschaap.net>


Wesley <wesleys@opperschaap.net> 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

  reply	other threads:[~2023-08-09 11:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-08 22:24 git pre-push hook not getting the lines from STDIN Wesley
2023-08-09 11:00 ` Sean Allred [this message]
2023-08-09 12:38   ` Wesley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m0wmy4lbd0.fsf@epic96565.epic.com \
    --to=allred.sean@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=wesleys@opperschaap.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox