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 <alex.thiessen.de+coreboot@gmail.com>
Reviewed-on: https://review.coreboot.org/23253
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
This commit is contained in:
Alex Thiessen 2018-01-13 17:05:31 +00:00 committed by Stefan Reinauer
parent f73914d1aa
commit fda071ca7a
1 changed files with 21 additions and 14 deletions

View File

@ -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