-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathbootstrap
executable file
·55 lines (48 loc) · 1.79 KB
/
bootstrap
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env bash
#
# Bootstraps the developer tools and development environment. This includes
# copying project-standard git commit hooks that do things like ensure DCO
# signoff is present during commit.
pushd "$(bazel info workspace)"
if [ ! "$PWD" == "$(git rev-parse --show-toplevel)" ]; then
cat >&2 <<__EOF__
ERROR: couldn't detect git checkout
__EOF__
exit 1
fi
# Helper functions that calculate `abspath` and `relpath`. Taken from Mesos
# commit 82b040a60561cf94dec3197ea88ae15e57bcaa97, which also carries the Apache
# V2 license, and has deployed this code successfully for some time.
abspath() {
cd "$(dirname "${1}")"
echo "${PWD}"/"$(basename "${1}")"
cd "${OLDPWD}"
}
relpath() {
local FROM TO UP
FROM="$(abspath "${1%/}")" TO="$(abspath "${2%/}"/)"
while test "${TO}" = "${TO#"${FROM}"/}" \
-a "${TO}" != "${FROM}"; do
FROM="${FROM%/*}" UP="../${UP}"
done
TO="${UP%/}${TO#${FROM}}"
echo "${TO:-.}"
}
# Try to find the `.git` directory, even if it's not in Nighthawk project root (as
# it wouldn't be if, say, this were in a submodule). The "blessed" but fairly
# new way to do this is to use `--git-common-dir`.
DOT_GIT_DIR=$(git rev-parse --git-common-dir)
if test ! -d "${DOT_GIT_DIR}"; then
# If `--git-common-dir` is not available, fall back to older way of doing it.
DOT_GIT_DIR=$(git rev-parse --git-dir)
fi
HOOKS_DIR="${DOT_GIT_DIR}/hooks"
HOOKS_DIR_RELPATH=$(relpath "${HOOKS_DIR}" "$(dirname $0)")
if [ ! -e "${HOOKS_DIR}/prepare-commit-msg" ]; then
echo "Installing hook 'prepare-commit-msg'"
ln -sf "${HOOKS_DIR_RELPATH}/hooks/prepare-commit-msg" "${HOOKS_DIR}/prepare-commit-msg"
fi
if [ ! -e "${HOOKS_DIR}/pre-push" ]; then
echo "Installing hook 'pre-push'"
ln -sf "${HOOKS_DIR_RELPATH}/hooks/pre-push" "${HOOKS_DIR}/pre-push"
fi