Skip to content

Instantly share code, notes, and snippets.

@EthraZa
Created July 26, 2020 00:38
Show Gist options
  • Save EthraZa/01b6db497f12343dc1a9bbbc53041a0f to your computer and use it in GitHub Desktop.
Save EthraZa/01b6db497f12343dc1a9bbbc53041a0f to your computer and use it in GitHub Desktop.
One Git hooks script to rule them all
#!/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}
@EthraZa
Copy link
Author

EthraZa commented Jul 26, 2020

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.

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