Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
741 views
in Technique[技术] by (71.8m points)

bash - git: empty arguments in post-receive hook

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)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...