-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit
executable file
·32 lines (25 loc) · 935 Bytes
/
init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash
DIR=$(dirname "$(dirname "$(realpath "$0")")")
$($DIR/ghw git-config)
WRAPPERS_PATH="$DIR/hooks"
WRAPPERS_PATH_INSENS=$(echo $WRAPPERS_PATH | tr '[:upper:]' '[:lower:]')
HOOKS_PATH="${1:-git-hooks}"
echo -n "$HOOKS_PATH" > "$WRAPPERS_PATH/../hooks_dir"
CONFIGED=$(git config --get core.hooksPath | \
sed -e 's/^\([A-Z]\):/\/\1/' | \
tr '[:upper:]' '[:lower:]')
[ -z "$CONFIGED" ] || [ -z "$1" ] && [ "$CONFIGED" != "$WRAPPERS_PATH_INSENS" ] && \
cp -rnp "$CONFIGED" "$HOOKS_PATH"
git config --includes core.hooksPath "$WRAPPERS_PATH"
# Windows MINGW stuff
CONFIGED=$(git config --get core.hooksPath | \
sed -e 's/^\([A-Z]\):/\/\1/' | \
tr '[:upper:]' '[:lower:]')
if [ "$CONFIGED" == "$WRAPPERS_PATH_INSENS" ]
then
echo "Wrapped git hooks in folder '$HOOKS_PATH'"
exit 0
else
echo "hooksPathPath wasn't applied - received '$CONFIGED'.\nRun manually: git config core.hooksPath \"$WRAPPERS_PATH\""
exit 1
fi