blob: 4df93cf2c5a7f7a12bdb48f3a333f850541a9475 [file] [log] [blame]
Yegor Timoshenkoc2e49412018-10-07 01:58:27 +00001#!/usr/bin/env bash
Alex Thiessend4a3d012018-01-04 20:31:29 +00002
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 Thiessen7bcd6ec2018-01-04 15:16:23 +000018# 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.
20MAKE="${1:-make}"
21
Alex Thiessenfda071c2018-01-13 17:05:31 +000022if ! { cdup="$(git rev-parse --show-cdup 2>/dev/null)" && [ -z "${cdup}" ]; }
23then
24 echo "Error: Not in root of a git repository"
Marc Jones9ab8ae62017-12-13 15:21:33 -070025 exit 1
26fi
Alex Thiessenfda071c2018-01-13 17:05:31 +000027coreboot_hooks=$(git rev-parse --git-path hooks)
28mkdir -p "${coreboot_hooks}"
Marc Jones9ab8ae62017-12-13 15:21:33 -070029for hook in commit-msg pre-commit ; do
Alex Thiessenfda071c2018-01-13 17:05:31 +000030 if [ util/gitconfig/${hook} -nt "${coreboot_hooks}/${hook}" ] \
31 || [ ! -x "${coreboot_hooks}/${hook}" ]
32 then
Alex Thiessen7bcd6ec2018-01-04 15:16:23 +000033 sed -e "s,%MAKE%,${MAKE},g" util/gitconfig/$hook \
Alex Thiessenfda071c2018-01-13 17:05:31 +000034 > "${coreboot_hooks}/${hook}"
35 chmod +x "${coreboot_hooks}/${hook}"
Marc Jones9ab8ae62017-12-13 15:21:33 -070036 fi
37done
38# Now set up the hooks for 3rdparty/
Alex Thiessenfda071c2018-01-13 17:05:31 +000039for 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 Thiessen7bcd6ec2018-01-04 15:16:23 +000046 sed -e "s,%MAKE%,${MAKE},g" util/gitconfig/commit-msg \
Alex Thiessenfda071c2018-01-13 17:05:31 +000047 > "${hooks}/commit-msg"
48 chmod +x "${hooks}/commit-msg"
Marc Jones9ab8ae62017-12-13 15:21:33 -070049 fi
50 fi
51done
52for 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
57done
Alex Thiessen2ca4ca32018-01-13 18:48:38 +000058
Marc Jones9ab8ae62017-12-13 15:21:33 -070059git config remote.origin.push HEAD:refs/for/master
Alex Thiessen2ca4ca32018-01-13 18:48:38 +000060git config alias.sup "!git submodule update --remote --rebase && \
61git submodule update --init --checkout"
62
Alex Thiessen7459eeb2018-01-13 18:52:18 +000063git config alias.sup-destroy "!git submodule deinit --all --force; \
64git submodule update --init --checkout"
Alex Thiessen2ca4ca32018-01-13 18:48:38 +000065
Alex Thiessen7c7181f2018-01-13 19:27:45 +000066{ git config --includes user.name && \
67 git config --includes user.email; } >/dev/null || \
Alex Thiessen101485c2018-01-13 19:49:33 +000068 { 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
73EOMSG
Alex Thiessen7c7181f2018-01-13 19:27:45 +000074exit 1; }