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 | |
| 3 | ## |
| 4 | ## This file is part of the coreboot project. |
| 5 | ## |
| 6 | ## Copyright (C) 2011 secunet Security Networks AG |
| 7 | ## |
| 8 | ## This program is free software; you can redistribute it and/or modify |
| 9 | ## it under the terms of the GNU General Public License as published by |
| 10 | ## the Free Software Foundation; version 2 of the License. |
| 11 | ## |
| 12 | ## This program is distributed in the hope that it will be useful, |
| 13 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | ## GNU General Public License for more details. |
| 16 | ## |
| 17 | |
Alex Thiessen | 7bcd6ec | 2018-01-04 15:16:23 +0000 | [diff] [blame] | 18 | # In the hooks, use the same `make` tool as used when running `make gitconfig`, |
| 19 | # e.g. `remake gitconfig` will set `remake` to be run by the hooks. |
| 20 | MAKE="${1:-make}" |
| 21 | |
Alex Thiessen | fda071c | 2018-01-13 17:05:31 +0000 | [diff] [blame] | 22 | if ! { cdup="$(git rev-parse --show-cdup 2>/dev/null)" && [ -z "${cdup}" ]; } |
| 23 | then |
| 24 | echo "Error: Not in root of a git repository" |
Marc Jones | 9ab8ae6 | 2017-12-13 15:21:33 -0700 | [diff] [blame] | 25 | exit 1 |
| 26 | fi |
Alex Thiessen | fda071c | 2018-01-13 17:05:31 +0000 | [diff] [blame] | 27 | coreboot_hooks=$(git rev-parse --git-path hooks) |
| 28 | mkdir -p "${coreboot_hooks}" |
Marc Jones | 9ab8ae6 | 2017-12-13 15:21:33 -0700 | [diff] [blame] | 29 | for hook in commit-msg pre-commit ; do |
Alex Thiessen | fda071c | 2018-01-13 17:05:31 +0000 | [diff] [blame] | 30 | if [ util/gitconfig/${hook} -nt "${coreboot_hooks}/${hook}" ] \ |
| 31 | || [ ! -x "${coreboot_hooks}/${hook}" ] |
| 32 | then |
Alex Thiessen | 7bcd6ec | 2018-01-04 15:16:23 +0000 | [diff] [blame] | 33 | sed -e "s,%MAKE%,${MAKE},g" util/gitconfig/$hook \ |
Alex Thiessen | fda071c | 2018-01-13 17:05:31 +0000 | [diff] [blame] | 34 | > "${coreboot_hooks}/${hook}" |
| 35 | chmod +x "${coreboot_hooks}/${hook}" |
Marc Jones | 9ab8ae6 | 2017-12-13 15:21:33 -0700 | [diff] [blame] | 36 | fi |
| 37 | done |
| 38 | # Now set up the hooks for 3rdparty/ |
Alex Thiessen | fda071c | 2018-01-13 17:05:31 +0000 | [diff] [blame] | 39 | for submodule in 3rdparty/blobs libhwbase libgfxinit; do |
| 40 | hooks=$(git -C "$(git config --file .gitmodules --get \ |
| 41 | submodule.${submodule}.path)" rev-parse --git-path hooks) |
| 42 | if [ -d "${hooks}" ]; then |
| 43 | if [ util/gitconfig/commit-msg -nt "${hooks}/commit-msg" ] \ |
| 44 | || [ ! -x "${hooks}/commit-msg" ] |
| 45 | then |
Alex Thiessen | 7bcd6ec | 2018-01-04 15:16:23 +0000 | [diff] [blame] | 46 | sed -e "s,%MAKE%,${MAKE},g" util/gitconfig/commit-msg \ |
Alex Thiessen | fda071c | 2018-01-13 17:05:31 +0000 | [diff] [blame] | 47 | > "${hooks}/commit-msg" |
| 48 | chmod +x "${hooks}/commit-msg" |
Marc Jones | 9ab8ae6 | 2017-12-13 15:21:33 -0700 | [diff] [blame] | 49 | fi |
| 50 | fi |
| 51 | done |
| 52 | for d in 3rdparty/{blobs,libhwbase,libgfxinit}; do |
| 53 | if [ -d $d ]; then |
| 54 | (cd $d || exit 1 |
| 55 | git config remote.origin.push HEAD:refs/for/master) |
| 56 | fi |
| 57 | done |
Alex Thiessen | 2ca4ca3 | 2018-01-13 18:48:38 +0000 | [diff] [blame] | 58 | |
Marc Jones | 9ab8ae6 | 2017-12-13 15:21:33 -0700 | [diff] [blame] | 59 | git config remote.origin.push HEAD:refs/for/master |
Alex Thiessen | 2ca4ca3 | 2018-01-13 18:48:38 +0000 | [diff] [blame] | 60 | git config alias.sup "!git submodule update --remote --rebase && \ |
| 61 | git submodule update --init --checkout" |
| 62 | |
Alex Thiessen | 7459eeb | 2018-01-13 18:52:18 +0000 | [diff] [blame] | 63 | git config alias.sup-destroy "!git submodule deinit --all --force; \ |
| 64 | git submodule update --init --checkout" |
Alex Thiessen | 2ca4ca3 | 2018-01-13 18:48:38 +0000 | [diff] [blame] | 65 | |
Alex Thiessen | 7c7181f | 2018-01-13 19:27:45 +0000 | [diff] [blame] | 66 | { git config --includes user.name && \ |
| 67 | git config --includes user.email; } >/dev/null || \ |
Alex Thiessen | 101485c | 2018-01-13 19:49:33 +0000 | [diff] [blame] | 68 | { cat <<-EOMSG |
| 69 | Please configure your name and email in git: |
| 70 | |
| 71 | git config --global user.name "Your Name Comes Here" |
| 72 | git config --global user.email your.email@example.com |
| 73 | EOMSG |
Alex Thiessen | 7c7181f | 2018-01-13 19:27:45 +0000 | [diff] [blame] | 74 | exit 1; } |