mirror of
https://github.com/vgstation-coders/vgstation13.git
synced 2025-12-10 10:21:11 +00:00
* Added git hooks * Fixed hooks * Deleted old script file * Changed install-hooks to remove the symlink, generate script file to run over those in folder * Fixed slave script and removed test script * Added batch version of install-hooks * Fixed variable name typo that would cause script number to always be 1 * Added new hook install hooks Scripts will now install any new hooks after checkout, merge, or rebase. Fixed an issue with install-hooks.sh incorrectly assuming the working directory. Removed an unnecessary variable assign from install-hooks.bat
62 lines
1.7 KiB
Bash
Executable File
62 lines
1.7 KiB
Bash
Executable File
#!/bin/sh
|
|
#
|
|
#This script generates the hook script for any defined hook steps
|
|
#Scripts are kept in the [hook-name]-hooks folder
|
|
#The installer generates a master script which loops through the folder and
|
|
#executes any scripts it finds there
|
|
|
|
# List of client-sided Git hooks
|
|
GIT_HOOKS="applypatch-msg pre-applypatch post-applypatch pre-commit prepare-commit-msg commit-msg
|
|
post-commit pre-rebase post-checkout post-merge pre-auto-gc post-rewrite
|
|
pre-push"
|
|
|
|
REPO_ROOT=`git rev-parse --show-toplevel`
|
|
REPO_GIT_DIR=`git rev-parse --git-dir`
|
|
BASEDIR="$REPO_ROOT/tools/git-hooks"
|
|
|
|
for hook in $GIT_HOOKS; do
|
|
#Slave scripts are stored under this folder
|
|
HOOKS_FOLDERNAME="$hook-hooks"
|
|
#Where the hooks are currently stored
|
|
HOOKS_FOLDER="$BASEDIR/$HOOKS_FOLDERNAME"
|
|
#The target file for the hook master
|
|
GIT_HOOKS_FILE="$REPO_GIT_DIR/hooks/$hook"
|
|
|
|
if [ ! -d "$HOOKS_FOLDER" ]; then
|
|
continue;
|
|
fi
|
|
|
|
#The master script hasn't been created yet
|
|
if [ ! -e "$GIT_HOOKS_FILE" ]; then
|
|
TIMESTAMP="$(date +"%T %d-%m-%Y")"
|
|
cat > "$GIT_HOOKS_FILE" << SLAVE
|
|
#!/bin/sh
|
|
|
|
#Master script autogenerated by install-hooks.sh on $TIMESTAMP
|
|
#This script runs everything in $HOOKS_FOLDERNAME as part of the git $hook hook
|
|
#A non-zero exit indicates the script number which was failed on
|
|
|
|
SCRIPT_COUNTER=0
|
|
for SCRIPT in $HOOKS_FOLDER/*
|
|
do
|
|
echo "Running : \$SCRIPT"
|
|
SCRIPT_COUNTER=\$(expr \$SCRIPT_COUNTER + 1)
|
|
#If the script file exists and can be executed
|
|
if [ -f "\$SCRIPT" -a -x "\$SCRIPT" ]
|
|
then
|
|
\$SCRIPT
|
|
if [ ! \$? -eq 0 ]
|
|
then
|
|
echo "Failed : \$SCRIPT"
|
|
exit \$SCRIPT_COUNTER
|
|
fi
|
|
fi
|
|
done
|
|
SLAVE
|
|
|
|
echo -e "\033[32m$hook: installed correctly\033[0m"
|
|
else
|
|
echo -e "\033[31m$hook: existing hook found, skipping...\033[0m"
|
|
fi
|
|
done
|