Git post-receive hook loop though all commits
Asked Answered
S

1

7

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?

Spoofery answered 5/12, 2014 at 14:5 Comment(0)
G
6

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
Galactic answered 5/12, 2014 at 14:17 Comment(1)
Simply and clever! Thanks man a lot. Hope you will get tons of presents from Santa!Spoofery

© 2022 - 2024 — McMap. All rights reserved.