git hooks: address shellcheck issues

This commit is contained in:
William Ballenthin
2020-06-26 19:04:36 -06:00
parent d1dd997b7b
commit 918a47cfb7
3 changed files with 56 additions and 49 deletions

View File

@@ -1,23 +1,21 @@
#!/usr/bin/env bash
set -e
set -u
set -o pipefail
set -euo pipefail
GIT_DIR=`git rev-parse --show-toplevel`
cd $GIT_DIR
GIT_DIR=$(git rev-parse --show-toplevel);
cd "$GIT_DIR";
# hooks may exist already (e.g. git-lfs configuration)
# If the `.git/hooks/$arg` file doesn't exist it, initialize with `#!/bin/sh`
# After that append `scripts/hooks/$arg` and ensure they can be run
create_hook() {
if [[ ! -e .git/hooks/$1 ]]; then
echo "#!/bin/sh" > ".git/hooks/$1"
echo "#!/bin/sh" > ".git/hooks/$1";
fi
cat scripts/hooks/$1 >> ".git/hooks/$1"
chmod +x .git/hooks/$1
cat scripts/hooks/"$1" >> ".git/hooks/$1";
chmod +x .git/hooks/"$1";
}
echo '\n#### Copying hooks into .git/hooks'
create_hook 'post-commit'
create_hook 'pre-push'
printf '\n#### Copying hooks into .git/hooks';
create_hook 'post-commit';
create_hook 'pre-push';