From fda071ca7a17614a58c0812c28b14a417471b915 Mon Sep 17 00:00:00 2001 From: Alex Thiessen Date: Sat, 13 Jan 2018 17:05:31 +0000 Subject: util/gitconfig: Make gitconfig.sh support gitfile The `gitconfig.sh` script installs hooks to the according directories (for coreboot and its submodules). It has the `hooks` directory hard-coded to be `.git/hooks`, which makes the installation fail when coreboot itself is a submodule because then `.git` becomes a gitfile. Replace hard-coded path handling using the according `git rev-parse` calls. Change-Id: I778e20be24bb27d0081c9e1c12883117d6d50347 Signed-off-by: Alex Thiessen Reviewed-on: https://review.coreboot.org/23253 Tested-by: build bot (Jenkins) Reviewed-by: Paul Menzel Reviewed-by: Stefan Reinauer --- util/gitconfig/gitconfig.sh | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) (limited to 'util/gitconfig') diff --git a/util/gitconfig/gitconfig.sh b/util/gitconfig/gitconfig.sh index 2f96fd41f2..f456069f3f 100755 --- a/util/gitconfig/gitconfig.sh +++ b/util/gitconfig/gitconfig.sh @@ -15,26 +15,33 @@ ## GNU General Public License for more details. ## -if [ ! -d .git ]; then - echo "Error: Not in a git repository" +if ! { cdup="$(git rev-parse --show-cdup 2>/dev/null)" && [ -z "${cdup}" ]; } +then + echo "Error: Not in root of a git repository" exit 1 fi -mkdir -p .git/hooks +coreboot_hooks=$(git rev-parse --git-path hooks) +mkdir -p "${coreboot_hooks}" for hook in commit-msg pre-commit ; do - if [ util/gitconfig/$hook -nt .git/hooks/$hook ] || \ - [ ! -x .git/hooks/$hook ]; then - sed -e "s,%MAKE%,remake,g" util/gitconfig/$hook > .git/hooks/$hook - chmod +x .git/hooks/$hook + if [ util/gitconfig/${hook} -nt "${coreboot_hooks}/${hook}" ] \ + || [ ! -x "${coreboot_hooks}/${hook}" ] + then + sed -e "s,%MAKE%,remake,g" util/gitconfig/$hook \ + > "${coreboot_hooks}/${hook}" + chmod +x "${coreboot_hooks}/${hook}" fi done # Now set up the hooks for 3rdparty/ -for hooks in .git/modules/{3rdparty/blobs,libhwbase,libgfxinit}/hooks; do - if [ -d $hooks ]; then - if [ util/gitconfig/commit-msg -nt $hooks/commit-msg ] || \ - [ ! -x $hooks/commit-msg ]; then - sed -e "s,%MAKE%,remake,g" \ - util/gitconfig/commit-msg > $hooks/commit-msg - chmod +x $hooks/commit-msg +for submodule in 3rdparty/blobs libhwbase libgfxinit; do + hooks=$(git -C "$(git config --file .gitmodules --get \ + submodule.${submodule}.path)" rev-parse --git-path hooks) + if [ -d "${hooks}" ]; then + if [ util/gitconfig/commit-msg -nt "${hooks}/commit-msg" ] \ + || [ ! -x "${hooks}/commit-msg" ] + then + sed -e "s,%MAKE%,remake,g" util/gitconfig/commit-msg \ + > "${hooks}/commit-msg" + chmod +x "${hooks}/commit-msg" fi fi done -- cgit v1.2.3