From: Sean Allred Date: Wed, 09 Aug 2023 11:00:32 GMT Subject: Re: git pre-push hook not getting the lines from STDIN Message-ID: In-Reply-To: <676330b6-720a-e262-d583-9012e549bba7@opperschaap.net> Wesley 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)