xref: /aosp_15_r20/external/shflags/init_githooks.sh (revision 63d4e48fb639f6414be0db9d718e3be2667e4fed)
1#! /bin/sh
2#
3# Initialize the local git hooks this repository.
4# https://git-scm.com/docs/githooks
5
6topLevel=$(git rev-parse --show-toplevel)
7if ! cd "${topLevel}"; then
8  echo "filed to cd into topLevel directory '${topLevel}'"
9  exit 1
10fi
11
12hooksDir="${topLevel}/.githooks"
13if ! hooksPath=$(git config core.hooksPath); then
14  hooksPath="${topLevel}/.git/hooks"
15fi
16
17src="${hooksDir}/generic"
18echo "linking hooks..."
19for hook in \
20  applypatch-msg \
21  pre-applypatch \
22  post-applypatch \
23  pre-commit \
24  pre-merge-commit \
25  prepare-commit-msg \
26  commit-msg \
27  post-commit \
28  pre-rebase \
29  post-checkout \
30  post-merge \
31  pre-push \
32  pre-receive \
33  update \
34  post-receive \
35  post-update \
36  push-to-checkout \
37  pre-auto-gc \
38  post-rewrite \
39  sendemail-validate \
40  fsmonitor-watchman \
41  p4-pre-submit \
42  post-index-change
43do
44  echo "  ${hook}"
45  dest="${hooksPath}/${hook}"
46  ln -sf "${src}" "${dest}"
47done
48