I am running vanilla git (git version 2.23.3) as origin master of a bare repository on an AWS instance.
I have created a file repo_dir/hooks/pre-receive with the following contents:
#!/bin/bash -p echo $1 > pre-receive-old-hash.txt echo $2 > pre-receive-new-hash.txt echo $3 > pre-receive-ref.txt exit 1
I make a test push from my remote. I can confirm that hook is run, as I get the push rejected.
However, while the pre-receive-x.txt files exist, they are empty. What am I doing wrong?
It takes no arguments, but for each ref to be updated it receives on standard input a line of the format:
<old-value> SP <new-value> SP <ref-name> LF
(Emphasize mine — phd)
Make your script this:
#!/bin/bash -p while read old new refname; do echo $old >> pre-receive-old-hash.txt echo $new >> pre-receive-new-hash.txt echo $refname >> pre-receive-ref.txt done exit 1