Skip to content

Instantly share code, notes, and snippets.

@aslakhellesoy
Created January 4, 2018 22:14
Show Gist options
  • Save aslakhellesoy/ae557e7bd992648defaa1fe53a9233b3 to your computer and use it in GitHub Desktop.
Save aslakhellesoy/ae557e7bd992648defaa1fe53a9233b3 to your computer and use it in GitHub Desktop.
post-receive
#!/bin/sh
# This isn't really a git hook, but it's manually called it after every fetch run.
# This script essentially wraps the actual post-receive hook.
# Build the standard input for the post-receive hook
touch CPRO_HEAD
cat refs/heads/* | paste CPRO_HEAD - > post-fetch.tmp
find refs/heads/* | paste post-fetch.tmp - | awk '{print $1, $2, $3}' > post-fetch.stdin
# Call the post-receive hook just like the commits were pushed
cat post-fetch.stdin | hooks/post-receive
# Cleanup
rm post-fetch.tmp
rm post-fetch.stdin
#!/bin/sh
#
# Reads and notifies Cucumber Pro of only new commits that have not yet been dealt with.
#
# The "post-receive" script is run after receive-pack has accepted a pack
# and the repository has been updated. It is passed arguments in through
# stdin in the form
# <oldrev> <newrev> <refname>
# For example:
# aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master
#
LOCKFILE=post-receive.lock
# Check for the existence of the lock file and then schedule for later
if [ -e ${LOCKFILE} ] && kill -0 `cat ${LOCKFILE}`; then
at "now +5 minutes" hooks/post-fetch
exit
fi
# Make sure the lockfile is removed when we exit and then claim it
trap "rm -f ${LOCKFILE}; exit" INT TERM EXIT
echo $$ > ${LOCKFILE}
touch CPRO_HEAD
# Read the standard input
while read oldrev newrev refname ; do
echo "Processing branch: $refname"
# Read the last revisions for each branch from CPRO_HEAD
exclusions=$(cat CPRO_HEAD | uniq | sed -e 's/^/^/' -e 's/ / ^/g' | xargs echo)
git rev-list --reverse $newrev $exclusions | while read rev ; do
echo "Processed: $rev"
done
echo $newrev >> CPRO_HEAD
done
# Update the CPRO_HEAD file
cat refs/heads/* > CPRO_HEAD
# Clear the lock file
rm -f ${LOCKFILE}
@aslakhellesoy
Copy link
Author

This is a variant of https://gist.github.com/kenaniah/5471280 with the following changes:

  • Removed call to trac-admin
  • Renamed TRAC_HEAD file to CPRO_HEAD
  • touch CPRO_HEAD in case it doesn't exist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment