From 53ec19be60388c481faeaf1c900225a7d4625184 Mon Sep 17 00:00:00 2001 From: Maximilian Held Date: Mon, 20 Jan 2025 19:40:41 +0100 Subject: [PATCH] fix hook --- README.md | 6 +++--- post-checkout.sample | 24 ------------------------ update_hook.sample | 21 +++++++++++++++++++++ 3 files changed, 24 insertions(+), 27 deletions(-) delete mode 100755 post-checkout.sample create mode 100755 update_hook.sample diff --git a/README.md b/README.md index a209409..7ac5a1a 100644 --- a/README.md +++ b/README.md @@ -7,11 +7,11 @@ devops package Run this once to set up the git hooks. ```sh -cp -f muggle/post-checkout.sample .git/modules/muggle/hooks/post-checkout +cp -f muggle/update_hook.sample .git/modules/muggle/hooks/post-checkout chmod +x .git/modules/muggle/hooks/post-checkout -cp -f muggle/post-checkout.sample .git/modules/muggle/hooks/post-merge +cp -f muggle/update_hook.sample .git/modules/muggle/hooks/post-merge chmod +x .git/modules/muggle/hooks/post-merge -cp -f muggle/post-checkout.sample .git/modules/muggle/hooks/post-rewrite +cp -f muggle/update_hook.sample .git/modules/muggle/hooks/post-rewrite chmod +x .git/modules/muggle/hooks/post-rewrite sh muggle/install.sh ``` diff --git a/post-checkout.sample b/post-checkout.sample deleted file mode 100755 index 0d4f05b..0000000 --- a/post-checkout.sample +++ /dev/null @@ -1,24 +0,0 @@ -#!bin/bash - -# Determine the directory of this hook -HOOK_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -# Check if we are in a submodule setup -if [ -f "$HOOK_DIR/gitmodules" ]; then - # We're in a superproject's .git/modules directory, so navigate up to the submodule's root - SUBMODULE_ROOT="$(dirname "$HOOK_DIR")/../../../$(basename "$HOOK_DIR")" -else - # We're in a normal repo, so just go up one level to the repo root - SUBMODULE_ROOT="$(dirname "$HOOK_DIR")/.." -fi - -# Path to install.sh relative to the repo/submodule root -INSTALL_SCRIPT="$SUBMODULE_ROOT/install.sh" - -# Check if install.sh exists and is executable -if [ -x "$INSTALL_SCRIPT" ]; then - # Run the install script with the arguments passed to the hook - "$INSTALL_SCRIPT" "$@" -else - echo "Warning: install.sh not found or not executable at $INSTALL_SCRIPT" >&2 -fi diff --git a/update_hook.sample b/update_hook.sample new file mode 100755 index 0000000..8471cf8 --- /dev/null +++ b/update_hook.sample @@ -0,0 +1,21 @@ +#!/bin/bash + +# Check if we are in a submodule +if git rev-parse --show-superproject-working-tree > /dev/null 2>&1; then + # We're in a submodule. Get the submodule's working directory + SUBMODULE_ROOT="$(git rev-parse --show-toplevel)" +else + # We're in a normal repo + SUBMODULE_ROOT="$(pwd)" +fi + +# Path to install.sh relative to the repo/submodule root +INSTALL_SCRIPT="$SUBMODULE_ROOT/install.sh" + +# Check if install.sh exists and is executable +if [ -x "$INSTALL_SCRIPT" ]; then + # Run the install script with the arguments passed to the hook + "$INSTALL_SCRIPT" "$@" +else + echo "Warning: install.sh not found or not executable at $INSTALL_SCRIPT" >&2 +fi