Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git: empty arguments in post-receive hook

Tags:

git

bash

githooks

I'm writing post-receive hook basing on the post-receive-email script from the contrib dir, but it seems that the oldrev and newrev arguments are empty.

The script looks like this:

#!/bin/bash

oldrev=$(git rev-parse $1)
newrev=$(git rev-parse $2)

The script runs on push, but all $1, $2, $oldrev and $newrev are empty. Should I configure something to get it running?

(The repository was created by gitolite if it does matter)

like image 222
takeshin Avatar asked Sep 21 '10 15:09

takeshin


2 Answers

I stumbled into this problem while setting up a continuous integration server. Since the arguments are not passed to post-receive via the command line, but are passed over STDIN, you have to use the read command to fetch them. Here is how I did it:

#!/bin/sh
read oldrev newrev refname
BRANCH=${refname#refs/heads/} 
curl --request POST "http://my.ci.server/hooks/build/myproject_$BRANCH"
like image 77
François Avatar answered Oct 23 '22 10:10

François


There are no arguments though the information is passed over STDIN. To read that information from bash simply do this:

read oldrev newrev refname
echo "Old revision: $oldrev"
echo "New revision: $newrev"
echo "Reference name: $refname"

I'm just summarizing the answers already posted.

like image 44
estani Avatar answered Oct 23 '22 09:10

estani