Commit 091c5155 authored by Michal Sojka's avatar Michal Sojka

Make the hook easier to test and document how

parent 030157b3
......@@ -2,9 +2,9 @@
# git post-receive hook to update BRUTE automatic evaluation (AE) git
# repository. After pushing to a course git repository, this script
# creates a subset of that repository containing only files for AE (by
# default directories */ae | */auto_evaluation) and pushes this subset
# to BRUTE's AE git repository.
# creates a subset of the course repository containing only files for
# AE (by default directories */ae | */auto_evaluation) and pushes this
# subset to BRUTE's AE git repository.
#
# For the script to work, you have to manually configure brutegit
# remote in the (server) repository, where this hook is installed,
......@@ -17,7 +17,18 @@
# git config brutegit.glob '*/ae'
# git config --add brutegit.glob '*/auto_eval'
# etc.
#
# You can test this script in your local repository by giving it a
# commit as an argument:
#
# brutegit-ae-sync HEAD~1
# brutegit-ae-sync HEAD
#
# This creates the branch ae with one or two commits (depending on
# whether the AE data were changed between HEAD~1 and HEAD). You can
# see the commit(s) with:
#
# git log ae
set -e
......@@ -60,23 +71,33 @@ handle_commit() {
[ "$ae" ] && parent="-p $ae"
new_commit=$(git commit-tree $new_tree $parent -m "$(git cat-file commit $commit|sed -e '0,/^$/d')")
git update-ref refs/heads/ae $new_commit $ae
echo "ae-sync: Created new commit ${new_commit:0:7} on branch ae ($(git log -1 --format=%s "$commit"))"
else
commit_hash=$(git rev-parse "$commit")
echo "ae-sync: No AE changes in commit ${commit_hash:0:7} ($(git log -1 --format=%s "$commit"))"
fi
}
while read oldrev newrev refname; do
if [ "$refname" = "refs/heads/master" ]; then
echo "Checking for AE updates"
ae=$(git rev-parse --verify --quiet refs/heads/ae) || :
for rev in $(git rev-list --reverse $oldrev..$newrev); do
handle_commit $rev
done
if [ "$ae" != $(git rev-parse --verify --quiet refs/heads/ae) ]; then
if git config remote.brutegit.url >/dev/null; then
echo "Pushing AE to BRUTE"
git push -f --quiet brutegit ae:master
else
echo "Not pushing AE to BRUTE because brutegit remote is not configured"
if [ "$1" ]; then
# local testing
handle_commit $1
else
# git hook
while read oldrev newrev refname; do
if [ "$refname" = "refs/heads/master" ]; then
echo "ae-sync: Checking for AE updates"
ae=$(git rev-parse --verify --quiet refs/heads/ae) || :
for rev in $(git rev-list --reverse $oldrev..$newrev); do
handle_commit $rev
done
if [ "$ae" != $(git rev-parse --verify --quiet refs/heads/ae) ]; then
if git config remote.brutegit.url >/dev/null; then
echo "ae-sync: Pushing AE to BRUTE"
git push -f --quiet brutegit ae:master
else
echo "ae-sync: Not pushing AE to BRUTE because brutegit remote is not configured"
fi
fi
fi
fi
done
done
fi
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment