Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git post-receive hook loop though all commits

I am trying to do a post-receive hook on server side that will run some Python script once for each commit in push.

I have a loop:

while read oldrev newrev refname
do
    python /local/Git/util.py $newrev $oldrev $refname
done

But this runs script only for last commit that was given in push.

There is any way to run script for all commits pushed to the server in one push?

like image 275
Sarpens Avatar asked Dec 05 '14 14:12

Sarpens


1 Answers

In scripts, use git rev-list to obtain the SHA-1s of commits in a range. In this case you should loop over the output from git rev-list $oldrev..$newrev, e.g. like this:

git rev-list $oldrev..$newrev | while read rev ; do
    python /local/Git/util.py $rev $oldrev $refname
done
like image 82
Magnus Bäck Avatar answered Oct 04 '22 05:10

Magnus Bäck