git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Sean Allred <allred.sean@gmail.com>
Date
Aug 9, 2023, 11:00 UTC
Message-ID
<m0wmy4lbd0.fsf@epic96565.epic.com>
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.
Show 27 quoted lines
> ----< 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

Previous: WesleyNext: Wesley
Message 2 of 3 in “git pre-push hook not getting the lines from STDIN”
  1. WesleyAug 8, 2023
  2. Sean AllredAug 9, 2023
  3. WesleyAug 9, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.