rubocop: install pre-commit hook in plugins
Change-Id: Ica5fdc2ea8306483e8597b9c4ea4f40f92b13c24 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/279017 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> QA-Review: Jeremy Stanley <jeremy@instructure.com> Reviewed-by: Jeremy Stanley <jeremy@instructure.com> Product-Review: Cody Cutrer <cody@instructure.com>
This commit is contained in:
parent
d37a8066b5
commit
7b0031a2fe
|
@ -2,26 +2,39 @@
|
|||
set -e
|
||||
|
||||
if [ -n "$1" ]; then
|
||||
PREPEND_PATH=$1
|
||||
CANVAS_ROOT=$1
|
||||
fi
|
||||
|
||||
if [ ! -d $PREPEND_PATH".git" ]; then
|
||||
if [ -z "$2" ]; then
|
||||
$0 "$CANVAS_ROOT" $CANVAS_ROOT".git" "."
|
||||
for plugin in $(find $CANVAS_ROOT"gems/plugins" -name .git | sort); do
|
||||
$0 "$CANVAS_ROOT" $plugin "../../.."
|
||||
done
|
||||
exit 0
|
||||
fi
|
||||
|
||||
GLOB_PATTERN=$PREPEND_PATH"hooks/*"
|
||||
GIT_DIR=$2
|
||||
HOOKS_PREFIX=$3
|
||||
|
||||
if [ ! -d "$GIT_DIR" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo running for git dir $GIT_DIR
|
||||
|
||||
GLOB_PATTERN=$CANVAS_ROOT"hooks/*"
|
||||
|
||||
for hook in $GLOB_PATTERN; do
|
||||
hook_name=${hook##*/}
|
||||
git_path="$PREPEND_PATH"".git/hooks/""$hook_name"
|
||||
git_path="$GIT_DIR/hooks/$hook_name"
|
||||
# make sure file exists
|
||||
touch "$git_path"
|
||||
# make sure it has a shebang prepending if necessary
|
||||
grep -qF -- "#!" "$git_path" || (echo "#!/bin/sh" | cat - $git_path > "$git_path""-temp" && mv "$git_path""-temp" $git_path)
|
||||
grep -qF -- "#!" "$git_path" || (echo "#!/bin/sh" | cat - $git_path > "$git_path-temp" && mv "$git_path-temp" $git_path)
|
||||
# make sure it is executable
|
||||
[ -x "$git_path" ] || chmod +x "$git_path"
|
||||
# # put in line to call this hook
|
||||
grep -qF -- "./hooks/$hook_name" "$git_path" || echo "./hooks/$hook_name" >> "$git_path"
|
||||
grep -qF -- "$HOOKS_PREFIX/hooks/$hook_name" "$git_path" || echo "$HOOKS_PREFIX/hooks/$hook_name" >> "$git_path"
|
||||
done
|
||||
|
||||
exit 0
|
||||
|
|
Loading…
Reference in New Issue