mirror of
https://github.com/kuhyx/todo-app.git
synced 2026-11-10 19:27:01 +01:00
install_hooks: resolve hooks dir via common git dir
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WzxdWY1k4muZfdVJfb7YGJ
This commit is contained in:
parent
2a9332094a
commit
d14b7e03e3
@ -26,9 +26,10 @@
|
|||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
REPO_ROOT="$(git rev-parse --show-toplevel)"
|
# The common git dir, not <toplevel>/.git: in a worktree .git is a file.
|
||||||
readonly REPO_ROOT
|
HOOKS_DIR="$(git rev-parse --path-format=absolute --git-common-dir)/hooks"
|
||||||
readonly HOOK="$REPO_ROOT/.git/hooks/pre-commit"
|
readonly HOOKS_DIR
|
||||||
|
readonly HOOK="$HOOKS_DIR/pre-commit"
|
||||||
readonly LEGACY_MARKER='bump_patch_version.sh'
|
readonly LEGACY_MARKER='bump_patch_version.sh'
|
||||||
|
|
||||||
# The old hand-written hook has to go before pre-commit will install over it;
|
# The old hand-written hook has to go before pre-commit will install over it;
|
||||||
@ -57,7 +58,7 @@ ensure_pre_commit() {
|
|||||||
# and only on success. pre-commit install --hook-type pre-commit writes the
|
# and only on success. pre-commit install --hook-type pre-commit writes the
|
||||||
# generated script; we move it aside and call it from ours.
|
# generated script; we move it aside and call it from ours.
|
||||||
install_wrapper() {
|
install_wrapper() {
|
||||||
local generated="$REPO_ROOT/.git/hooks/pre-commit.pre-commit-generated"
|
local generated="$HOOKS_DIR/pre-commit.pre-commit-generated"
|
||||||
mv "$HOOK" "$generated"
|
mv "$HOOK" "$generated"
|
||||||
cat > "$HOOK" <<'HOOK_BODY'
|
cat > "$HOOK" <<'HOOK_BODY'
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
@ -66,10 +67,13 @@ install_wrapper() {
|
|||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
ROOT="$(git rev-parse --show-toplevel)"
|
ROOT="$(git rev-parse --show-toplevel)"
|
||||||
readonly ROOT
|
readonly ROOT
|
||||||
|
# The common git dir, not $ROOT/.git: in a worktree .git is a file.
|
||||||
|
HOOKS_DIR="$(git rev-parse --path-format=absolute --git-common-dir)/hooks"
|
||||||
|
readonly HOOKS_DIR
|
||||||
|
|
||||||
# The read-only gates. A non-zero exit here rejects the commit, and the bump
|
# The read-only gates. A non-zero exit here rejects the commit, and the bump
|
||||||
# below never runs, so a rejected attempt leaves no stray version change.
|
# below never runs, so a rejected attempt leaves no stray version change.
|
||||||
"$(dirname "${BASH_SOURCE[0]}")/pre-commit.pre-commit-generated" "$@"
|
"$HOOKS_DIR/pre-commit.pre-commit-generated" "$@"
|
||||||
|
|
||||||
exec bash "$ROOT/scripts/bump_patch_version.sh"
|
exec bash "$ROOT/scripts/bump_patch_version.sh"
|
||||||
HOOK_BODY
|
HOOK_BODY
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user