Skip to content

Instantly share code, notes, and snippets.

@yugoslavskiy
Last active September 26, 2016 08:51
Show Gist options
  • Save yugoslavskiy/76ff24a2280753d664d1d08ac9474599 to your computer and use it in GitHub Desktop.
Save yugoslavskiy/76ff24a2280753d664d1d08ac9474599 to your computer and use it in GitHub Desktop.
Post-commit hook script to make actual master branch archive in every commit
#!/bin/bash
#
# created date: 26.09.2016
# last update date: 26.09.2016
# author: @yugoslavskiy
#
# post-commit hook script to make actual master branch archive in every commit
# 1) save it as a .git/hooks/post-commit
# 2) create .git/hooks/last_hooked_commit — first time it has to be previous commit hash:
# $ git log -1 --format="%H" > .git/hooks/last_hooked_commit
# 3) profit.
#
last_hooked_commit=$( cat .git/hooks/last_hooked_commit )
last_manual_commit=$( cat .git/hooks/last_manual_commit )
preprevious_commit=$( git log -2 --format="%H" | tail -1 )
# if PREprevious commit was manual — we are on looped post-commit hook, break it.
if [ "${preprevious_commit}" == "${last_manual_commit}" ]; then
git rev-parse HEAD > .git/hooks/last_hooked_commit
exit 0
elif [ "${preprevious_commit}" == "${last_hooked_commit}" ]; then
git rev-parse HEAD > .git/hooks/last_manual_commit
git archive master --format=zip --output=master.zip
git add master.zip
git commit -a -m 'updated/added actual master branch archive'
else
echo "shit. i do not know wtf is going on" > .git/hooks/post_commit_errorlog
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment