Yegor Timoshenko | c2e4941 | 2018-10-07 01:58:27 +0000 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Alex Thiessen | d4a3d01 | 2018-01-04 20:31:29 +0000 | [diff] [blame] | 2 | ## |
Patrick Georgi | 7333a11 | 2020-05-08 20:48:04 +0200 | [diff] [blame] | 3 | ## SPDX-License-Identifier: GPL-2.0-only |
Alex Thiessen | d4a3d01 | 2018-01-04 20:31:29 +0000 | [diff] [blame] | 4 | |
Alex Thiessen | 7bcd6ec | 2018-01-04 15:16:23 +0000 | [diff] [blame] | 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. |
| 7 | MAKE="${1:-make}" |
| 8 | |
Alex Thiessen | fda071c | 2018-01-13 17:05:31 +0000 | [diff] [blame] | 9 | if ! { cdup="$(git rev-parse --show-cdup 2>/dev/null)" && [ -z "${cdup}" ]; } |
| 10 | then |
| 11 | echo "Error: Not in root of a git repository" |
Marc Jones | 9ab8ae6 | 2017-12-13 15:21:33 -0700 | [diff] [blame] | 12 | exit 1 |
| 13 | fi |
Alex Thiessen | fda071c | 2018-01-13 17:05:31 +0000 | [diff] [blame] | 14 | coreboot_hooks=$(git rev-parse --git-path hooks) |
| 15 | mkdir -p "${coreboot_hooks}" |
Marc Jones | 9ab8ae6 | 2017-12-13 15:21:33 -0700 | [diff] [blame] | 16 | for hook in commit-msg pre-commit ; do |
Alex Thiessen | fda071c | 2018-01-13 17:05:31 +0000 | [diff] [blame] | 17 | if [ util/gitconfig/${hook} -nt "${coreboot_hooks}/${hook}" ] \ |
| 18 | || [ ! -x "${coreboot_hooks}/${hook}" ] |
| 19 | then |
Alex Thiessen | 7bcd6ec | 2018-01-04 15:16:23 +0000 | [diff] [blame] | 20 | sed -e "s,%MAKE%,${MAKE},g" util/gitconfig/$hook \ |
Alex Thiessen | fda071c | 2018-01-13 17:05:31 +0000 | [diff] [blame] | 21 | > "${coreboot_hooks}/${hook}" |
| 22 | chmod +x "${coreboot_hooks}/${hook}" |
Marc Jones | 9ab8ae6 | 2017-12-13 15:21:33 -0700 | [diff] [blame] | 23 | fi |
| 24 | done |
| 25 | # Now set up the hooks for 3rdparty/ |
Alex Thiessen | fda071c | 2018-01-13 17:05:31 +0000 | [diff] [blame] | 26 | for 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 Thiessen | 7bcd6ec | 2018-01-04 15:16:23 +0000 | [diff] [blame] | 33 | sed -e "s,%MAKE%,${MAKE},g" util/gitconfig/commit-msg \ |
Alex Thiessen | fda071c | 2018-01-13 17:05:31 +0000 | [diff] [blame] | 34 | > "${hooks}/commit-msg" |
| 35 | chmod +x "${hooks}/commit-msg" |
Marc Jones | 9ab8ae6 | 2017-12-13 15:21:33 -0700 | [diff] [blame] | 36 | fi |
| 37 | fi |
| 38 | done |
| 39 | for d in 3rdparty/{blobs,libhwbase,libgfxinit}; do |
| 40 | if [ -d $d ]; then |
| 41 | (cd $d || exit 1 |
Stefan Reinauer | 16672ca | 2023-06-10 12:35:51 -0700 | [diff] [blame] | 42 | git config remote.origin.push HEAD:refs/for/main) |
Marc Jones | 9ab8ae6 | 2017-12-13 15:21:33 -0700 | [diff] [blame] | 43 | fi |
| 44 | done |
Alex Thiessen | 2ca4ca3 | 2018-01-13 18:48:38 +0000 | [diff] [blame] | 45 | |
Stefan Reinauer | 16672ca | 2023-06-10 12:35:51 -0700 | [diff] [blame] | 46 | git config remote.origin.push HEAD:refs/for/main |
Alex Thiessen | 2ca4ca3 | 2018-01-13 18:48:38 +0000 | [diff] [blame] | 47 | git config alias.sup "!git submodule update --remote --rebase && \ |
| 48 | git submodule update --init --checkout" |
| 49 | |
Alex Thiessen | 7459eeb | 2018-01-13 18:52:18 +0000 | [diff] [blame] | 50 | git config alias.sup-destroy "!git submodule deinit --all --force; \ |
| 51 | git submodule update --init --checkout" |
Alex Thiessen | 2ca4ca3 | 2018-01-13 18:48:38 +0000 | [diff] [blame] | 52 | |
Alex Thiessen | 7c7181f | 2018-01-13 19:27:45 +0000 | [diff] [blame] | 53 | { git config --includes user.name && \ |
| 54 | git config --includes user.email; } >/dev/null || \ |
Alex Thiessen | 101485c | 2018-01-13 19:49:33 +0000 | [diff] [blame] | 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 |
| 60 | EOMSG |
Alex Thiessen | 7c7181f | 2018-01-13 19:27:45 +0000 | [diff] [blame] | 61 | exit 1; } |