1#!/usr/bin/env bash 2## 3## SPDX-License-Identifier: GPL-2.0-only 4 5# In the hooks, use the same `make` tool as used when running `make gitconfig`, 6# e.g. `remake gitconfig` will set `remake` to be run by the hooks. 7MAKE="${1:-make}" 8 9if ! { cdup="$(git rev-parse --show-cdup 2>/dev/null)" && [ -z "${cdup}" ]; } 10then 11 echo "Error: Not in root of a git repository" 12 exit 1 13fi 14coreboot_hooks=$(git rev-parse --git-path hooks) 15mkdir -p "${coreboot_hooks}" 16for hook in commit-msg pre-commit ; do 17 if [ util/gitconfig/${hook} -nt "${coreboot_hooks}/${hook}" ] \ 18 || [ ! -x "${coreboot_hooks}/${hook}" ] 19 then 20 sed -e "s,%MAKE%,${MAKE},g" util/gitconfig/$hook \ 21 > "${coreboot_hooks}/${hook}" 22 chmod +x "${coreboot_hooks}/${hook}" 23 fi 24done 25# Now set up the hooks for 3rdparty/ 26for submodule in 3rdparty/blobs libhwbase libgfxinit; do 27 hooks=$(git -C "$(git config --file .gitmodules --get \ 28 submodule.${submodule}.path)" rev-parse --git-path hooks) 29 if [ -d "${hooks}" ]; then 30 if [ util/gitconfig/commit-msg -nt "${hooks}/commit-msg" ] \ 31 || [ ! -x "${hooks}/commit-msg" ] 32 then 33 sed -e "s,%MAKE%,${MAKE},g" util/gitconfig/commit-msg \ 34 > "${hooks}/commit-msg" 35 chmod +x "${hooks}/commit-msg" 36 fi 37 fi 38done 39for d in 3rdparty/{blobs,libhwbase,libgfxinit}; do 40 if [ -d $d ]; then 41 (cd $d || exit 1 42 git config remote.origin.push HEAD:refs/for/main) 43 fi 44done 45 46git config remote.origin.push HEAD:refs/for/main 47git config alias.sup "!git submodule update --remote --rebase && \ 48git submodule update --init --checkout" 49 50git config alias.sup-destroy "!git submodule deinit --all --force; \ 51git submodule update --init --checkout" 52 53{ git config --includes user.name && \ 54 git config --includes user.email; } >/dev/null || \ 55 { cat <<-EOMSG 56 Please configure your name and email in git: 57 58 git config --global user.name "Your Name Comes Here" 59 git config --global user.email your.email@example.com 60EOMSG 61exit 1; } 62