blob: 148d43778891327d84fc05d9acc198ff9481d984 [file] [log] [blame]
Yegor Timoshenkoc2e49412018-10-07 01:58:27 +00001#!/usr/bin/env bash
Alex Thiessend4a3d012018-01-04 20:31:29 +00002##
Patrick Georgi7333a112020-05-08 20:48:04 +02003## SPDX-License-Identifier: GPL-2.0-only
Alex Thiessend4a3d012018-01-04 20:31:29 +00004
Alex Thiessen7bcd6ec2018-01-04 15:16:23 +00005# 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
Alex Thiessenfda071c2018-01-13 17:05:31 +00009if ! { cdup="$(git rev-parse --show-cdup 2>/dev/null)" && [ -z "${cdup}" ]; }
10then
11 echo "Error: Not in root of a git repository"
Marc Jones9ab8ae62017-12-13 15:21:33 -070012 exit 1
13fi
Alex Thiessenfda071c2018-01-13 17:05:31 +000014coreboot_hooks=$(git rev-parse --git-path hooks)
15mkdir -p "${coreboot_hooks}"
Marc Jones9ab8ae62017-12-13 15:21:33 -070016for hook in commit-msg pre-commit ; do
Alex Thiessenfda071c2018-01-13 17:05:31 +000017 if [ util/gitconfig/${hook} -nt "${coreboot_hooks}/${hook}" ] \
18 || [ ! -x "${coreboot_hooks}/${hook}" ]
19 then
Alex Thiessen7bcd6ec2018-01-04 15:16:23 +000020 sed -e "s,%MAKE%,${MAKE},g" util/gitconfig/$hook \
Alex Thiessenfda071c2018-01-13 17:05:31 +000021 > "${coreboot_hooks}/${hook}"
22 chmod +x "${coreboot_hooks}/${hook}"
Marc Jones9ab8ae62017-12-13 15:21:33 -070023 fi
24done
25# Now set up the hooks for 3rdparty/
Alex Thiessenfda071c2018-01-13 17:05:31 +000026for 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
Alex Thiessen7bcd6ec2018-01-04 15:16:23 +000033 sed -e "s,%MAKE%,${MAKE},g" util/gitconfig/commit-msg \
Alex Thiessenfda071c2018-01-13 17:05:31 +000034 > "${hooks}/commit-msg"
35 chmod +x "${hooks}/commit-msg"
Marc Jones9ab8ae62017-12-13 15:21:33 -070036 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/master)
43 fi
44done
Alex Thiessen2ca4ca32018-01-13 18:48:38 +000045
Marc Jones9ab8ae62017-12-13 15:21:33 -070046git config remote.origin.push HEAD:refs/for/master
Alex Thiessen2ca4ca32018-01-13 18:48:38 +000047git config alias.sup "!git submodule update --remote --rebase && \
48git submodule update --init --checkout"
49
Alex Thiessen7459eeb2018-01-13 18:52:18 +000050git config alias.sup-destroy "!git submodule deinit --all --force; \
51git submodule update --init --checkout"
Alex Thiessen2ca4ca32018-01-13 18:48:38 +000052
Alex Thiessen7c7181f2018-01-13 19:27:45 +000053{ git config --includes user.name && \
54 git config --includes user.email; } >/dev/null || \
Alex Thiessen101485c2018-01-13 19:49:33 +000055 { 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
Alex Thiessen7c7181f2018-01-13 19:27:45 +000061exit 1; }