Created
July 26, 2020 00:38
-
-
Save EthraZa/01b6db497f12343dc1a9bbbc53041a0f to your computer and use it in GitHub Desktop.
One Git hooks script to rule them all
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Config | |
APPDIR="/tmp" | |
# Setup | |
HOOKS=$(basename "$0") | |
HOOKSDIR=$(dirname $(dirname "$0")) | |
HOOKSLOG="${HOOKSDIR}/${HOOKS}.log" | |
HOOKSDT=$(date --rfc-3339=seconds) | |
HOOKSOUT="" | |
if [ $(git rev-parse --is-bare-repository) = true ]; then | |
HOOKSGDIR=$(basename "${PWD}") | |
else | |
HOOKSGDIR=$(basename $(readlink -nf "${PWD}"/..)) | |
fi | |
HOOKSREPO="${HOOKSGDIR%.*}" | |
# Repo update | |
git --work-tree=${APPDIR}/${HOOKSREPO} --git-dir=$HOOKSDIR checkout -f | |
# POST update | |
case ${HOOKSREPO} in | |
git-hello-world) | |
HOOKSOUT=$(echo "git-hello-world \n") | |
;; | |
esac | |
HOOKSOUT="${HOOKSOUT}${HOOKSDT} ${HOOKS} ${APPDIR}/${HOOKSREPO}" | |
echo -e ${HOOKSOUT} >> ${HOOKSLOG} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
One Git hooks script to rule them all.
This GIT hooks script will update (checkout) the master branch of a bare repository named "REPO-NAME.git" into the work tree APPDIR/REPO-NAME on push commits into it.