Wiki source code of Commit Author Hook

Last modified by superadmin on 2020/04/18 20:53

Show last authors
1 = Commit Author Hook =
2
3 The following pre-commit hook will enable confirmation that a specific e-mail address was used in the author information in the commit message. To enable this you will need to copy this content into the {{code language="bash"}}.git/hooks/pre-commit{{/code}} file, remove the {{code language="bash"}}.git/hooks/pre-commit.sample{{/code}} file and set the hook to executable {{code language="bash"}}chmod +x .git/hooks/pre-commit{{/code}}.
4
5 {{code language="bash"}}
6 #!/bin/sh
7 AUTHORINFO=$(git var GIT_AUTHOR_IDENT) || exit 1
8
9 echo "$AUTHORINFO"
10
11 #(?<=@)([^.]+)(?=\.)
12
13 EMAIL_DOMAIN=$(printf '%s\n' "$AUTHORINFO" | grep -o '@codeaurora.org')
14 echo "$EMAIL_DOMAIN"
15 if [ "$EMAIL_DOMAIN" != "@codeaurora.org" ];
16 then
17 cat <<EOF >&2
18 Please commit with the correct codeaurora.org domain name.
19 Your author information was $AUTHORINFO
20 EOF
21 exit 1
22 fi
23 exit 0
24 {{/code}}