@@ -68,7 +68,7 @@ cmd_init() {
6868 # Generate output (cached to ~/.cache/gtr/, auto-invalidates on shell integration changes)
6969 local cache_dir=" ${XDG_CACHE_HOME:- $HOME / .cache} /gtr"
7070 local cache_file=" $cache_dir /init-${func_name} .${shell} "
71- local cache_schema=" ${GTR_INIT_CACHE_VERSION:- 2 } "
71+ local cache_schema=" ${GTR_INIT_CACHE_VERSION:- 3 } "
7272 local cache_stamp=" # gtr-cache: version=${GTR_VERSION:- unknown} init=${cache_schema} func=$func_name shell=$shell "
7373
7474 # Return cached output if version matches
@@ -115,6 +115,14 @@ __FUNC___hooks_hash() {
115115 printf '%s\n' "$_gtr_hook_defs" | shasum -a 256 | cut -d' ' -f1
116116}
117117
118+ __FUNC___hooks_trust_key() {
119+ local _gtr_config_file="$1"
120+ local _gtr_hook_hash _gtr_repo_root
121+ _gtr_hook_hash="$(__FUNC___hooks_hash "$_gtr_config_file" 2>/dev/null)" || return 1
122+ _gtr_repo_root="$(cd "$(dirname "$_gtr_config_file")" 2>/dev/null && pwd -P)" || return 1
123+ printf '%s\n%s\n' "$_gtr_repo_root" "$_gtr_hook_hash" | shasum -a 256 | cut -d' ' -f1
124+ }
125+
118126__FUNC___run_post_cd_hooks() {
119127 local dir="$1"
120128 local _gtr_trust_dir="${XDG_CONFIG_HOME:-$HOME/.config}/gtr/trusted"
@@ -132,9 +140,9 @@ __FUNC___run_post_cd_hooks() {
132140 _gtr_file_hooks="$(git config -f "$_gtr_config_file" --get-all hooks.postCd 2>/dev/null)" || true
133141 if [ -n "$_gtr_file_hooks" ]; then
134142 # Verify trust before including .gtrconfig hooks
135- local _gtr_hook_hash
136- _gtr_hook_hash ="$(__FUNC___hooks_hash "$_gtr_config_file" 2>/dev/null)" || true
137- if [ -n "$_gtr_hook_hash " ] && [ -f "$_gtr_trust_dir/$_gtr_hook_hash " ]; then
143+ local _gtr_trust_key
144+ _gtr_trust_key ="$(__FUNC___hooks_trust_key "$_gtr_config_file" 2>/dev/null)" || true
145+ if [ -n "$_gtr_trust_key " ] && [ -f "$_gtr_trust_dir/$_gtr_trust_key " ]; then
138146 if [ -n "$_gtr_hooks" ]; then
139147 _gtr_hooks="$_gtr_hooks"$'\n'"$_gtr_file_hooks"
140148 else
@@ -321,6 +329,15 @@ __FUNC___hooks_hash() {
321329 printf '%s\n' "$_gtr_hook_defs" | shasum -a 256 | cut -d' ' -f1
322330}
323331
332+ __FUNC___hooks_trust_key() {
333+ emulate -L zsh
334+ local _gtr_config_file="$1"
335+ local _gtr_hook_hash _gtr_repo_root
336+ _gtr_hook_hash="$(__FUNC___hooks_hash "$_gtr_config_file" 2>/dev/null)" || return 1
337+ _gtr_repo_root="$(cd "$(dirname "$_gtr_config_file")" 2>/dev/null && pwd -P)" || return 1
338+ printf '%s\n%s\n' "$_gtr_repo_root" "$_gtr_hook_hash" | shasum -a 256 | cut -d' ' -f1
339+ }
340+
324341__FUNC___run_post_cd_hooks() {
325342 emulate -L zsh
326343 local dir="$1"
@@ -339,9 +356,9 @@ __FUNC___run_post_cd_hooks() {
339356 _gtr_file_hooks="$(git config -f "$_gtr_config_file" --get-all hooks.postCd 2>/dev/null)" || true
340357 if [ -n "$_gtr_file_hooks" ]; then
341358 # Verify trust before including .gtrconfig hooks
342- local _gtr_hook_hash
343- _gtr_hook_hash ="$(__FUNC___hooks_hash "$_gtr_config_file" 2>/dev/null)" || true
344- if [ -n "$_gtr_hook_hash " ] && [ -f "$_gtr_trust_dir/$_gtr_hook_hash " ]; then
359+ local _gtr_trust_key
360+ _gtr_trust_key ="$(__FUNC___hooks_trust_key "$_gtr_config_file" 2>/dev/null)" || true
361+ if [ -n "$_gtr_trust_key " ] && [ -f "$_gtr_trust_dir/$_gtr_trust_key " ]; then
345362 if [ -n "$_gtr_hooks" ]; then
346363 _gtr_hooks="$_gtr_hooks"$'\n'"$_gtr_file_hooks"
347364 else
@@ -528,6 +545,15 @@ function __FUNC___hooks_hash
528545 printf '%s\n' "$_gtr_hook_defs" | shasum -a 256 | cut -d' ' -f1
529546end
530547
548+ function __FUNC___hooks_trust_key
549+ set -l _gtr_config_file "$argv[1]"
550+ set -l _gtr_hook_hash (__FUNC___hooks_hash "$_gtr_config_file" 2>/dev/null)
551+ test -n "$_gtr_hook_hash"; or return 1
552+ set -l _gtr_repo_root (cd (dirname "$_gtr_config_file") 2>/dev/null; and pwd -P)
553+ test -n "$_gtr_repo_root"; or return 1
554+ printf '%s\n%s\n' "$_gtr_repo_root" "$_gtr_hook_hash" | shasum -a 256 | cut -d' ' -f1
555+ end
556+
531557function __FUNC___run_post_cd_hooks
532558 set -l dir "$argv[1]"
533559 set -l _gtr_trust_dir "$HOME/.config/gtr/trusted"
@@ -547,8 +573,8 @@ function __FUNC___run_post_cd_hooks
547573 set -l _gtr_candidate_hooks (git config -f "$_gtr_config_file" --get-all hooks.postCd 2>/dev/null)
548574 if test (count $_gtr_candidate_hooks) -gt 0
549575 # Verify trust before including .gtrconfig hooks
550- set -l _gtr_hook_hash (__FUNC___hooks_hash "$_gtr_config_file" 2>/dev/null)
551- if test -n "$_gtr_hook_hash "; and test -f "$_gtr_trust_dir/$_gtr_hook_hash "
576+ set -l _gtr_trust_key (__FUNC___hooks_trust_key "$_gtr_config_file" 2>/dev/null)
577+ if test -n "$_gtr_trust_key "; and test -f "$_gtr_trust_dir/$_gtr_trust_key "
552578 set _gtr_file_hooks $_gtr_candidate_hooks
553579 else
554580 echo "__FUNC__: Untrusted .gtrconfig hooks skipped — run 'git gtr trust' to approve" >&2
@@ -705,6 +731,7 @@ complete -f -c __FUNC__ -n '___FUNC___needs_subcommand' -a adapter -d 'List avai
705731complete -f -c __FUNC__ -n '___FUNC___needs_subcommand' -a config -d 'Manage configuration'
706732complete -f -c __FUNC__ -n '___FUNC___needs_subcommand' -a completion -d 'Generate shell completions'
707733complete -f -c __FUNC__ -n '___FUNC___needs_subcommand' -a init -d 'Generate shell integration'
734+ complete -f -c __FUNC__ -n '___FUNC___needs_subcommand' -a trust -d 'Trust .gtrconfig hooks'
708735complete -f -c __FUNC__ -n '___FUNC___needs_subcommand' -a version -d 'Show version'
709736complete -f -c __FUNC__ -n '___FUNC___needs_subcommand' -a help -d 'Show help'
710737
0 commit comments