Skip to content

Commit

Permalink
Fix CURRENT_GIT_DIR setting in reference-transaction during git init 💚 💚
Browse files Browse the repository at this point in the history
  • Loading branch information
rycus86 committed Oct 7, 2024
1 parent 89f5359 commit 5f312c0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions base-template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ set_main_variables() {
ACCEPT_CHANGES=

CURRENT_GIT_DIR=$(git rev-parse --git-common-dir 2>/dev/null)
if [ -z "${CURRENT_GIT_DIR}" ] && [ -n "${GIT_DIR}" ]; then
# Patch up the current git dir when the above did not find it yet, perhaps during git init
CURRENT_GIT_DIR="${GIT_DIR}"
fi
if [ ! -d "${CURRENT_GIT_DIR}" ]; then
echo "! Hook not run inside a git repository" >&2
return 1
Expand Down Expand Up @@ -405,12 +409,10 @@ is_trusted_repo() {
fi
fi
fi

return 1
}



#####################################################
# Performs checks for new and changed hooks,
# and prompts the user for approval if needed.
Expand Down
4 changes: 2 additions & 2 deletions tests/step-061.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ mkdir -p /tmp/shared/first-shared.git/.githooks/pre-commit &&
git config --global githooks.shared 'file:///tmp/shared/first-shared.git' || exit 1

mkdir -p /tmp/test061/.githooks &&
echo '/tmp/shared/second-shared.git' >/tmp/test061/.githooks/.shared &&
cd /tmp/test061 &&
git init ||
git init &&
echo '/tmp/shared/second-shared.git' >/tmp/test061/.githooks/.shared ||
exit 1

if git hooks list | grep -q "sample-one"; then
Expand Down

0 comments on commit 5f312c0

Please sign in to comment.