From dfee0824d61788aaab3519acf8460c7e617d121c Mon Sep 17 00:00:00 2001 From: Raphael Fakhri <153192858+RaphaelFakhri@users.noreply.github.com> Date: Tue, 20 Oct 2026 09:16:41 +0000 Subject: [PATCH 1/5] fix(hooks): fall back to sha256sum when shasum is not installed --- lib/commands/init.sh | 29 +++++++++++++++++++++++++---- lib/hooks.sh | 18 ++++++++++++++++-- tests/hooks.bats | 26 +++++++++++++++++++++++++- tests/init.bats | 27 +++++++++++++++++++++++++++ tests/test_helper.bash | 20 ++++++++++++++++++++ 5 files changed, 113 insertions(+), 7 deletions(-) diff --git a/lib/commands/init.sh b/lib/commands/init.sh index 9ce061b..ee9821f 100644 --- a/lib/commands/init.sh +++ b/lib/commands/init.sh @@ -354,6 +354,17 @@ _init_emit_posix_trust_helpers() { # Keep case patterns balanced inside this substitution for Bash 3.2's parser. template=$(cat <<'EOF' +__FUNC___sha256() { +__SHELL_PRELUDE__ + if command -v shasum >/dev/null 2>&1; then + shasum -a 256 | cut -d' ' -f1 + elif command -v sha256sum >/dev/null 2>&1; then + sha256sum | cut -d' ' -f1 + else + return 1 + fi +} + __FUNC___gtrconfig_path() { __SHELL_PRELUDE__ local _gtr_git_common_dir _gtr_repo_root @@ -376,7 +387,7 @@ __SHELL_PRELUDE__ _gtr_hook_defs="$(__FUNC___hooks_read_definitions "$_gtr_config_file")" || return 1 fi [ -n "$_gtr_hook_defs" ] || return 1 - printf '%s\n' "$_gtr_hook_defs" | shasum -a 256 | cut -d' ' -f1 + printf '%s\n' "$_gtr_hook_defs" | __FUNC___sha256 } __FUNC___hooks_repo_root() { @@ -404,7 +415,7 @@ __SHELL_PRELUDE__ _gtr_hook_hash="$(__FUNC___hooks_current_content_hash "$_gtr_config_file" "$_gtr_definitions" 2>/dev/null)" || return 1 _gtr_repo_root="$(__FUNC___hooks_repo_root "$_gtr_config_file" 2>/dev/null)" || return 1 _gtr_repo_identity="$(__FUNC___hooks_repo_identity "$_gtr_repo_root" 2>/dev/null)" || return 1 - printf 'v4\n%s\n%s\n%s\n' "$_gtr_repo_root" "$_gtr_repo_identity" "$_gtr_hook_hash" | shasum -a 256 | cut -d' ' -f1 + printf 'v4\n%s\n%s\n%s\n' "$_gtr_repo_root" "$_gtr_repo_identity" "$_gtr_hook_hash" | __FUNC___sha256 } __FUNC___hooks_marker_matches_config() { @@ -455,6 +466,16 @@ _init_emit_fish_trust_helpers() { sed -e 's/\\/\\\\/g' -e "s/'/\\\\'/g") printf "function __FUNC___hooks_repo_identity\n command bash -c '%s\n_hooks_repo_identity \"\$1\"' bash \"\$argv[1]\"\nend\n" "$identity_helper" cat <<'FISH' +function __FUNC___sha256 + if command -q shasum + shasum -a 256 | cut -d' ' -f1 + else if command -q sha256sum + sha256sum | cut -d' ' -f1 + else + return 1 + end +end + function __FUNC___gtrconfig_path set -l _gtr_git_common_dir (git rev-parse --git-common-dir 2>/dev/null) test -n "$_gtr_git_common_dir"; or return 1 @@ -475,7 +496,7 @@ function __FUNC___hooks_current_content_hash set _gtr_hook_defs (__FUNC___hooks_read_definitions "$_gtr_config_file") end test -n "$_gtr_hook_defs"; or return 1 - printf '%s\n' "$_gtr_hook_defs" | shasum -a 256 | cut -d' ' -f1 + printf '%s\n' "$_gtr_hook_defs" | __FUNC___sha256 end function __FUNC___hooks_repo_root @@ -503,7 +524,7 @@ function __FUNC___hooks_current_trust_key set -l _gtr_repo_identity (__FUNC___hooks_repo_identity "$_gtr_repo_root" 2>/dev/null | string collect) test $pipestatus[1] -eq 0; or return 1 test -n "$_gtr_repo_identity"; or return 1 - printf 'v4\n%s\n%s\n%s\n' "$_gtr_repo_root" "$_gtr_repo_identity" "$_gtr_hook_hash" | shasum -a 256 | cut -d' ' -f1 + printf 'v4\n%s\n%s\n%s\n' "$_gtr_repo_root" "$_gtr_repo_identity" "$_gtr_hook_hash" | __FUNC___sha256 end function __FUNC___hooks_marker_matches_config diff --git a/lib/hooks.sh b/lib/hooks.sh index 4523846..67bb91e 100644 --- a/lib/hooks.sh +++ b/lib/hooks.sh @@ -173,12 +173,26 @@ _hooks_snapshot_is_trusted() { _hooks_marker_matches_config "$trust_path" "$config_file" } +# Print the SHA-256 hex digest of stdin. +# Falls back to sha256sum where Perl's shasum is not installed +# (for example Alpine or minimal Fedora/RHEL images). +# Usage: printf '%s' "$data" | _hooks_sha256 +_hooks_sha256() { + if command -v shasum >/dev/null 2>&1; then + shasum -a 256 | cut -d' ' -f1 + elif command -v sha256sum >/dev/null 2>&1; then + sha256sum | cut -d' ' -f1 + else + return 1 + fi +} + # Compute a content hash for trusted command definitions. # Usage: _hooks_content_hash _hooks_content_hash() { local hook_content="$1" [ -n "$hook_content" ] || return 1 - printf '%s\n' "$hook_content" | shasum -a 256 | cut -d' ' -f1 + printf '%s\n' "$hook_content" | _hooks_sha256 } # Compute a content hash of all current trusted command entries in a .gtrconfig file. @@ -226,7 +240,7 @@ _hooks_reviewed_trust_key() { if [ -z "$repo_identity" ]; then repo_identity=$(_hooks_repo_identity "$repo_root") || return 1 fi - printf 'v4\n%s\n%s\n%s\n' "$repo_root" "$repo_identity" "$hash" | shasum -a 256 | cut -d' ' -f1 + printf 'v4\n%s\n%s\n%s\n' "$repo_root" "$repo_identity" "$hash" | _hooks_sha256 } # Compute the repo-scoped trust key for the current trusted command content diff --git a/tests/hooks.bats b/tests/hooks.bats index ae8019b..f593a70 100644 --- a/tests/hooks.bats +++ b/tests/hooks.bats @@ -10,7 +10,7 @@ setup() { } teardown() { - rm -rf "$XDG_CONFIG_HOME" + rm -rf "$XDG_CONFIG_HOME" "$BATS_TMPDIR/no-shasum-bin-$$" teardown_integration_repo } @@ -69,6 +69,30 @@ EOF [ "$(_hooks_file_hash "$TEST_REPO/.gtrconfig")" = "$expected" ] } +@test "trust markers work when shasum is not installed" { + cat > "$TEST_REPO/.gtrconfig" <<'EOF' +[hooks] + postCd = echo hi +EOF + + local expected + expected="$(_hooks_file_hash "$TEST_REPO/.gtrconfig")" + + local no_shasum_path + no_shasum_path="$(path_without_command "$BATS_TMPDIR/no-shasum-bin-$$" shasum)" + + ( + PATH="$no_shasum_path" + if command -v shasum >/dev/null 2>&1; then + exit 1 + fi + + [ "$(_hooks_file_hash "$TEST_REPO/.gtrconfig")" = "$expected" ] + _hooks_mark_trusted "$TEST_REPO/.gtrconfig" + _hooks_are_trusted "$TEST_REPO/.gtrconfig" + ) +} + @test "_hooks_mark_trusted creates a marker recognized by _hooks_are_trusted" { cat > "$TEST_REPO/.gtrconfig" <<'EOF' [hooks] diff --git a/tests/init.bats b/tests/init.bats index d0b3068..a3fecdf 100644 --- a/tests/init.bats +++ b/tests/init.bats @@ -550,6 +550,33 @@ run_generated_v2_trust_upgrade() ( [[ "$output" == *"git gtr list --porcelain"* ]] } +@test "generated bash wrapper recognizes trust markers when shasum is not installed" { + local root repo xdg no_shasum_path + root=$(mktemp -d) + repo="$root/repo" + xdg="$root/xdg" + + git init --quiet "$repo" + cat > "$repo/.gtrconfig" <<'CFG' +[hooks] + postCd = echo hi +CFG + + ( + export XDG_CONFIG_HOME="$xdg" + # shellcheck disable=SC1091 + . "$PROJECT_ROOT/lib/hooks.sh" + _hooks_mark_trusted "$repo/.gtrconfig" + ) + + no_shasum_path=$(path_without_command "$root/bin" shasum) + run env PATH="$no_shasum_path" bash -c 'eval "$1" && gtr_hooks_are_trusted "$2" "$3"' \ + _ "$(cmd_init bash)" "$repo/.gtrconfig" "$xdg/gtr/trusted" + rm -rf "$root" + + [ "$status" -eq 0 ] +} + @test "zsh output validates trust marker contents" { run cmd_init zsh [ "$status" -eq 0 ] diff --git a/tests/test_helper.bash b/tests/test_helper.bash index 1489782..f162b92 100644 --- a/tests/test_helper.bash +++ b/tests/test_helper.bash @@ -124,3 +124,23 @@ SCRIPT chmod +x "$MOCK_BIN_DIR/$name" export PATH="$MOCK_BIN_DIR:$PATH" } + +# Mirror every command on PATH into a new directory, leaving out one command, +# so tests can simulate systems where that command is not installed. +# Usage: path_without_command +# Prints: the directory to use as PATH +path_without_command() { + local bin_dir="$1" omitted="$2" dir entry name + mkdir -p "$bin_dir" + local IFS=: + for dir in $PATH; do + [ -d "$dir" ] || continue + for entry in "$dir"/*; do + [ -e "$entry" ] || continue + name="${entry##*/}" + [ "$name" = "$omitted" ] && continue + [ -e "$bin_dir/$name" ] || ln -s "$entry" "$bin_dir/$name" + done + done + printf "%s" "$bin_dir" +} From 107c1cfb52798dc3bc0c84f5fffd9b6e5a902c83 Mon Sep 17 00:00:00 2001 From: Raphael Fakhri <153192858+RaphaelFakhri@users.noreply.github.com> Date: Wed, 21 Oct 2026 12:43:51 +0000 Subject: [PATCH 2/5] fix(init): bump the shell integration cache schema and test the fish fallback The generated helpers now hash with the sha256sum fallback, but an existing cache stamped `init=15` still serves helpers that call shasum directly. Bump the schema to 16 in `cmd_init` and in the cache invalidation tests. Add a fish regression test that runs the generated postCd helper with shasum removed from PATH and sha256sum still available, and a changelog entry. --- CHANGELOG.md | 1 + lib/commands/init.sh | 4 ++-- tests/init.bats | 32 +++++++++++++++++++++++++------- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 79e2781..b552c15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this ### Fixed - Command approval now binds to the object database directory and shared commit history, so replacing Git contents while preserving `.git` requires new approval. CLI and Bash/Zsh/Fish helpers ignore replace refs, grafts, and commit-graph caches when checking history. Upgrading requires fresh `git gtr trust` approval and reloading shell integration. +- `.gtrconfig` trust works on systems that have `sha256sum` but not `shasum`, such as Alpine and Fedora/RHEL with only `git-core`. Hashing falls back to `sha256sum`, so `git gtr trust` no longer fails and the generated `gtr cd` helpers recognize trusted hooks. The shell-integration cache schema is now `init=18`, so caches generated by older versions are regenerated. - The integration test helper now canonicalizes its temporary repository path. On macOS `mktemp -d` returns a `/var` path while git records the resolved `/private/var` one, so `cmd_clean --merged uses nested registered worktree path` compared two spellings of the same directory and failed locally while passing in CI. ## [2.11.1] - 2026-09-14 diff --git a/lib/commands/init.sh b/lib/commands/init.sh index ee9821f..d3e312f 100644 --- a/lib/commands/init.sh +++ b/lib/commands/init.sh @@ -155,8 +155,8 @@ cmd_init() { case "$cache_dir" in /*) ;; *) cache_dir="$(pwd -P)/$cache_dir" ;; esac local cache_file="$cache_dir/init-${func_name}.${shell}" # Bump when generated helpers change, even if GTR_VERSION is unchanged. - # Schema 17 checks continuity with approved repository history (trust v4). - local cache_schema="${GTR_INIT_CACHE_VERSION:-17}" + # Schema 18 hashes trusted hooks with sha256sum when shasum is not installed. + local cache_schema="${GTR_INIT_CACHE_VERSION:-18}" local cache_stamp="# gtr-cache: version=${GTR_VERSION:-unknown} init=${cache_schema} func=$func_name shell=$shell" # A matching public stamp alone does not make executable cache data trusted. diff --git a/tests/init.bats b/tests/init.bats index a3fecdf..05c2c8c 100644 --- a/tests/init.bats +++ b/tests/init.bats @@ -144,13 +144,15 @@ SCRIPT # Exercise generated Fish hooks against a trusted or untrusted shared config. run_generated_fish_gtrconfig_post_cd_hooks() { local trust_state="$1" - local root repo wt xdg init_file + local without_shasum="${2:-0}" + local root repo wt xdg init_file fish_path root=$(cd -P "$(mktemp -d)" && pwd) repo="$root/repo" wt="$root/wt" xdg="$root/xdg" init_file="$root/gtr.fish" + fish_path="$PATH" git init --quiet "$repo" git -C "$repo" config user.name "Test User" @@ -177,7 +179,11 @@ CFG ) fi - XDG_CONFIG_HOME="$xdg" fish -c ' + if [ "$without_shasum" -eq 1 ]; then + fish_path=$(path_without_command "$root/bin" shasum) + fi + + PATH="$fish_path" XDG_CONFIG_HOME="$xdg" fish -c ' source "$argv[1]" set -l wt "$argv[2]" set -l root "$argv[3]" @@ -661,6 +667,18 @@ CFG [ "$hook_pwd_line" = "$wt_line" ] } +@test "fish generated postCd trusts gtrconfig hooks when shasum is unavailable" { + require_runtime_shell fish + command -v sha256sum >/dev/null 2>&1 || skip "sha256sum is not installed" + + run run_generated_fish_gtrconfig_post_cd_hooks trusted 1 + + [ "$status" -eq 0 ] + [[ "$output" == *"RC=0"* ]] + [[ "$output" == *"HOOK_ORDER=second"* ]] + [[ "$output" == *"STDERR="* ]] +} + # ── new/pr --cd wrapper support ───────────────────────────────────────────── @test "bash output intercepts new/pr --cd and strips flag before delegating" { @@ -1196,14 +1214,14 @@ CFG mkdir -p "$XDG_CACHE_HOME/gtr" for shell_name in bash zsh fish; do for func_name in gtr gwtr; do - for schema in 16 15 14 13 12 11 10 9 8 7 6; do + for schema in 17 16 15 14 13 12 11 10 9 8 7 6; do cache_file="$XDG_CACHE_HOME/gtr/init-$func_name.$shell_name" printf '# gtr-cache: version=test init=%s func=%s shell=%s\nold-cache\n' \ "$schema" "$func_name" "$shell_name" > "$cache_file" run cmd_init "$shell_name" --as "$func_name" [ "$status" -eq 0 ] [[ "$output" != *old-cache* ]] - [[ "$(head -1 "$cache_file")" == *"init=17"* ]] + [[ "$(head -1 "$cache_file")" == *"init=18"* ]] done done done @@ -1232,15 +1250,15 @@ run_documented_init_upgrade() ( if [ "$shell_name" = zsh ]; then snippet='compdef() { :; }'$'\n'"$snippet" fi - for schema in 6 7 8 9 10 11 12 13 14 15 16 17; do + for schema in 6 7 8 9 10 11 12 13 14 15 16 17 18; do version="$cli_version" - [ "$schema" != 17 ] || version=old-version + [ "$schema" != 18 ] || version=old-version printf '# gtr-cache: version=%s init=%s func=gtr shell=%s\n' \ "$version" "$schema" "$shell_name" > "$cache_file" printf '%s\n' 'echo stale > "$STALE_CACHE_MARKER"' >> "$cache_file" "$shell_name" -c "$snippet" [ ! -f "$STALE_CACHE_MARKER" ] - [[ "$(head -1 "$cache_file")" == *"version=$cli_version init=17 "* ]] + [[ "$(head -1 "$cache_file")" == *"version=$cli_version init=18 "* ]] done done ) From c3f95a49a584629ffb234722ea8af3775686bcfe Mon Sep 17 00:00:00 2001 From: Raphael Fakhri <153192858+RaphaelFakhri@users.noreply.github.com> Date: Sat, 31 Oct 2026 12:00:48 +0000 Subject: [PATCH 3/5] test: skip the bash no-shasum trust test without sha256sum --- tests/init.bats | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/init.bats b/tests/init.bats index 05c2c8c..ea45049 100644 --- a/tests/init.bats +++ b/tests/init.bats @@ -558,6 +558,7 @@ run_generated_v2_trust_upgrade() ( @test "generated bash wrapper recognizes trust markers when shasum is not installed" { local root repo xdg no_shasum_path + command -v sha256sum >/dev/null 2>&1 || skip "sha256sum is not installed" root=$(mktemp -d) repo="$root/repo" xdg="$root/xdg" From db3e26224f08ec8985fcc65acebc27a3d7afa716 Mon Sep 17 00:00:00 2001 From: Raphael Fakhri <153192858+RaphaelFakhri@users.noreply.github.com> Date: Wed, 28 Oct 2026 15:30:22 +0000 Subject: [PATCH 4/5] test(init): pass hook definitions to the generated trust check --- tests/init.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/init.bats b/tests/init.bats index ea45049..07c894c 100644 --- a/tests/init.bats +++ b/tests/init.bats @@ -577,7 +577,7 @@ CFG ) no_shasum_path=$(path_without_command "$root/bin" shasum) - run env PATH="$no_shasum_path" bash -c 'eval "$1" && gtr_hooks_are_trusted "$2" "$3"' \ + run env PATH="$no_shasum_path" bash -c 'eval "$1" && gtr_hooks_are_trusted "$2" "$3" "$(gtr_hooks_read_definitions "$2")"' \ _ "$(cmd_init bash)" "$repo/.gtrconfig" "$xdg/gtr/trusted" rm -rf "$root" From 0be49b626450408ba016d2caa9fce7d470285b67 Mon Sep 17 00:00:00 2001 From: RaphaelFakhri <153192858+RaphaelFakhri@users.noreply.github.com> Date: Thu, 12 Nov 2026 14:34:38 +0000 Subject: [PATCH 5/5] fix(hooks): retry with sha256sum when shasum is installed but fails --- lib/commands/init.sh | 34 +++++++++++++++++++++++----------- lib/hooks.sh | 20 +++++++++++++------- tests/hooks.bats | 23 +++++++++++++++++++++++ tests/init.bats | 36 ++++++++++++++++++++++++++++++++++++ tests/test_helper.bash | 1 + 5 files changed, 96 insertions(+), 18 deletions(-) diff --git a/lib/commands/init.sh b/lib/commands/init.sh index d3e312f..1a87eee 100644 --- a/lib/commands/init.sh +++ b/lib/commands/init.sh @@ -356,13 +356,19 @@ _init_emit_posix_trust_helpers() { template=$(cat <<'EOF' __FUNC___sha256() { __SHELL_PRELUDE__ - if command -v shasum >/dev/null 2>&1; then - shasum -a 256 | cut -d' ' -f1 - elif command -v sha256sum >/dev/null 2>&1; then - sha256sum | cut -d' ' -f1 - else - return 1 + local _gtr_input _gtr_digest + _gtr_input="$(cat; printf '.')" + _gtr_input="${_gtr_input%.}" + if command -v shasum >/dev/null 2>&1 && + _gtr_digest="$(printf '%s' "$_gtr_input" | shasum -a 256 2>/dev/null)" && + [ -n "$_gtr_digest" ]; then + printf '%s\n' "${_gtr_digest%% *}" + return 0 fi + command -v sha256sum >/dev/null 2>&1 || return 1 + _gtr_digest="$(printf '%s' "$_gtr_input" | sha256sum)" || return 1 + [ -n "$_gtr_digest" ] || return 1 + printf '%s\n' "${_gtr_digest%% *}" } __FUNC___gtrconfig_path() { @@ -467,13 +473,19 @@ _init_emit_fish_trust_helpers() { printf "function __FUNC___hooks_repo_identity\n command bash -c '%s\n_hooks_repo_identity \"\$1\"' bash \"\$argv[1]\"\nend\n" "$identity_helper" cat <<'FISH' function __FUNC___sha256 + set -l _gtr_input (string collect -N) if command -q shasum - shasum -a 256 | cut -d' ' -f1 - else if command -q sha256sum - sha256sum | cut -d' ' -f1 - else - return 1 + set -l _gtr_digest (printf '%s' "$_gtr_input" | shasum -a 256 2>/dev/null | cut -d' ' -f1) + if test $pipestatus[2] -eq 0; and test -n "$_gtr_digest" + printf '%s\n' $_gtr_digest + return 0 + end end + command -q sha256sum; or return 1 + set -l _gtr_digest (printf '%s' "$_gtr_input" | sha256sum | cut -d' ' -f1) + test $pipestatus[2] -eq 0; or return 1 + test -n "$_gtr_digest"; or return 1 + printf '%s\n' $_gtr_digest end function __FUNC___gtrconfig_path diff --git a/lib/hooks.sh b/lib/hooks.sh index 67bb91e..6d71e80 100644 --- a/lib/hooks.sh +++ b/lib/hooks.sh @@ -174,17 +174,23 @@ _hooks_snapshot_is_trusted() { } # Print the SHA-256 hex digest of stdin. -# Falls back to sha256sum where Perl's shasum is not installed +# Falls back to sha256sum where Perl's shasum is not installed or cannot run # (for example Alpine or minimal Fedora/RHEL images). # Usage: printf '%s' "$data" | _hooks_sha256 _hooks_sha256() { - if command -v shasum >/dev/null 2>&1; then - shasum -a 256 | cut -d' ' -f1 - elif command -v sha256sum >/dev/null 2>&1; then - sha256sum | cut -d' ' -f1 - else - return 1 + local input digest + input=$(cat; printf '.') + input=${input%.} + if command -v shasum >/dev/null 2>&1 && + digest=$(printf '%s' "$input" | shasum -a 256 2>/dev/null) && + [ -n "$digest" ]; then + printf '%s\n' "${digest%% *}" + return 0 fi + command -v sha256sum >/dev/null 2>&1 || return 1 + digest=$(printf '%s' "$input" | sha256sum) || return 1 + [ -n "$digest" ] || return 1 + printf '%s\n' "${digest%% *}" } # Compute a content hash for trusted command definitions. diff --git a/tests/hooks.bats b/tests/hooks.bats index f593a70..d6ed573 100644 --- a/tests/hooks.bats +++ b/tests/hooks.bats @@ -93,6 +93,29 @@ EOF ) } +@test "trust markers work when shasum is installed but cannot run" { + command -v sha256sum >/dev/null 2>&1 || skip "sha256sum is not installed" + cat > "$TEST_REPO/.gtrconfig" <<'EOF' +[hooks] + postCd = echo hi +EOF + + local expected + expected="$(_hooks_file_hash "$TEST_REPO/.gtrconfig")" + + local broken_shasum_path + broken_shasum_path="$(path_without_command "$BATS_TMPDIR/no-shasum-bin-$$" shasum)" + printf '#!/bin/sh\nexit 127\n' > "$broken_shasum_path/shasum" + chmod +x "$broken_shasum_path/shasum" + + ( + PATH="$broken_shasum_path" + [ "$(_hooks_file_hash "$TEST_REPO/.gtrconfig")" = "$expected" ] + _hooks_mark_trusted "$TEST_REPO/.gtrconfig" + _hooks_are_trusted "$TEST_REPO/.gtrconfig" + ) +} + @test "_hooks_mark_trusted creates a marker recognized by _hooks_are_trusted" { cat > "$TEST_REPO/.gtrconfig" <<'EOF' [hooks] diff --git a/tests/init.bats b/tests/init.bats index 07c894c..60ee9fa 100644 --- a/tests/init.bats +++ b/tests/init.bats @@ -564,6 +564,9 @@ run_generated_v2_trust_upgrade() ( xdg="$root/xdg" git init --quiet "$repo" + git -C "$repo" config user.name "Test User" + git -C "$repo" config user.email "test@example.com" + git -C "$repo" -c commit.gpgsign=false commit --allow-empty -m "init" --quiet cat > "$repo/.gtrconfig" <<'CFG' [hooks] postCd = echo hi @@ -584,6 +587,39 @@ CFG [ "$status" -eq 0 ] } +@test "generated bash wrapper recognizes trust markers when shasum cannot run" { + local root repo xdg broken_shasum_path + command -v sha256sum >/dev/null 2>&1 || skip "sha256sum is not installed" + root=$(mktemp -d) + repo="$root/repo" + xdg="$root/xdg" + + git init --quiet "$repo" + git -C "$repo" config user.name "Test User" + git -C "$repo" config user.email "test@example.com" + git -C "$repo" -c commit.gpgsign=false commit --allow-empty -m "init" --quiet + cat > "$repo/.gtrconfig" <<'CFG' +[hooks] + postCd = echo hi +CFG + + ( + export XDG_CONFIG_HOME="$xdg" + # shellcheck disable=SC1091 + . "$PROJECT_ROOT/lib/hooks.sh" + _hooks_mark_trusted "$repo/.gtrconfig" + ) + + broken_shasum_path=$(path_without_command "$root/bin" shasum) + printf '#!/bin/sh\nexit 127\n' > "$broken_shasum_path/shasum" + chmod +x "$broken_shasum_path/shasum" + run env PATH="$broken_shasum_path" bash -c 'eval "$1" && gtr_hooks_are_trusted "$2" "$3" "$(gtr_hooks_read_definitions "$2")"' \ + _ "$(cmd_init bash)" "$repo/.gtrconfig" "$xdg/gtr/trusted" + rm -rf "$root" + + [ "$status" -eq 0 ] +} + @test "zsh output validates trust marker contents" { run cmd_init zsh [ "$status" -eq 0 ] diff --git a/tests/test_helper.bash b/tests/test_helper.bash index f162b92..9cb9799 100644 --- a/tests/test_helper.bash +++ b/tests/test_helper.bash @@ -139,6 +139,7 @@ path_without_command() { [ -e "$entry" ] || continue name="${entry##*/}" [ "$name" = "$omitted" ] && continue + case "$entry" in /*) ;; *) entry="$PWD/$entry" ;; esac [ -e "$bin_dir/$name" ] || ln -s "$entry" "$bin_dir/$name" done done