/ util / gitconfig / gitconfig.sh
gitconfig.sh
 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.
 7  MAKE="${1:-make}"
 8  
 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"
12  	exit 1
13  fi
14  coreboot_hooks=$(git rev-parse --git-path hooks)
15  mkdir -p "${coreboot_hooks}"
16  for 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
24  done
25  # Now set up the hooks for 3rdparty/
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
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
38  done
39  for 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
44  done
45  
46  git config remote.origin.push HEAD:refs/for/main
47  git config alias.sup "!git submodule update --remote --rebase && \
48  git submodule update --init --checkout"
49  
50  git config alias.sup-destroy "!git submodule deinit --all --force; \
51  git 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
60  EOMSG
61  exit 1; }