# generated by git-team, do not modify

#!/bin/sh

activation_scope=$(git config --global team.config.activation-scope)

gitconfig_scope_flag=
if [ "${activation_scope}" = "global" ]; then
        gitconfig_scope_flag=--global
fi

status=$(git config ${gitconfig_scope_flag} team.state.status)

if [ "${status}" != "enabled" ]; then
        exit 0
fi

template=$1
commit_source=$2
commit_hash=$3

# see: https://git-scm.com/docs/githooks#_prepare_commit_msg
# message  - git commit -m|-F
# merge    - git merge (unless ff)
# squash   - git merge --squash
# none     - git commit
# commit   - git commit -c|-C|--amend
# template - git commit -t or if commit.template is set

case "${commit_source}" in
"message" | "merge" | "squash")
        if grep "Co-authored-by:" ${template}; then
                exit 0
        fi

        printf "\n\n" >> $template
        git config ${gitconfig_scope_flag} --get-all team.state.active-coauthors | while read coauthor; do
                printf "Co-authored-by: $coauthor\n" >> $template
        done
        ;;
*)
        exit 0
esac

exit 0
