From: Shane Jaroch Date: Thu, 15 Jan 2026 06:24:12 +0000 (-0500) Subject: more fixes X-Git-Url: https://git.nutra.tk/v2?a=commitdiff_plain;h=aa76b1b76919529d24721c6fd8c66371c01ebab3;p=gamesguru%2Fgit-remote-gcrypt.git more fixes --- diff --git a/Makefile b/Makefile index f060776..af7a8d1 100644 --- a/Makefile +++ b/Makefile @@ -133,7 +133,7 @@ test/system: ##H Run logic tests (with bash & coverage) @rm -rf $(COV_SYSTEM) @mkdir -p $(COV_SYSTEM) @export GPG_TTY=$$(tty); \ - [ -n "$(DEBUG)$(V)" ] && export GCRYPT_DEBUG=1 && printf "\033[1;33mDebug mode enabled\033[0m\n"; \ + [ -n "$(DEBUG)$(V)" ] && export GCRYPT_DEBUG=1 && $(call print_warn,Debug mode enabled); \ export GIT_CONFIG_PARAMETERS="'gcrypt.gpg-args=--pinentry-mode loopback --no-tty'"; \ sed -i 's|^#!/bin/sh|#!/bin/bash|' git-remote-gcrypt; \ trap "sed -i 's|^#!/bin/bash|#!/bin/sh|' git-remote-gcrypt" EXIT; \ diff --git a/README.rst b/README.rst index 4f798e3..ca4fed9 100644 --- a/README.rst +++ b/README.rst @@ -72,8 +72,6 @@ Command Reference Environment Variables: GCRYPT_DEBUG=1 Enable verbose debug logging to stderr GCRYPT_TRACE=1 Enable shell tracing (set -x) for rsync/curl commands - GCRYPT_FULL_REPACK=1 Force full repack when pushing - Configuration ============= @@ -289,7 +287,7 @@ To detect if a git url is a gcrypt repo, use:: (Legacy syntax ``--check`` is also supported). -Exit status is 0 +Exit status is 0 if the repository exists and uses gcrypt, 1 if it uses gcrypt but could not be decrypted, and 100 if the repo is not encrypted with gcrypt (or could not be accessed). diff --git a/completions/bash/git-remote-gcrypt b/completions/bash/git-remote-gcrypt index baf0715..3479aa5 100644 --- a/completions/bash/git-remote-gcrypt +++ b/completions/bash/git-remote-gcrypt @@ -21,13 +21,13 @@ _git_remote_gcrypt() { # 2. Handle subcommands case "${COMP_WORDS[1]}" in clean) - local remotes=$(git remote -v 2>/dev/null | grep 'gcrypt::' | awk '{print $1}' | sort -u || :) - COMPREPLY=($(compgen -W " $remotes" -- "$cur")) + local remotes=$( git remote -v 2>/dev/null | grep 'gcrypt::' | awk '{print $1}' | sort -u || : ) + COMPREPLY=( $( compgen -W " $remotes" -- "$cur" ) ) return 0 ;; check) - local remotes=$(git remote 2>/dev/null || :) - COMPREPLY=($(compgen -W "$remotes" -- "$cur")) + local remotes=$( git remote 2>/dev/null || : ) + COMPREPLY=( $( compgen -W "$remotes" -- "$cur" ) ) return 0 ;; capabilities|fetch|list|push) diff --git a/completions/templates/README.rst.in b/completions/templates/README.rst.in index a31a7fb..67b6ef8 100644 --- a/completions/templates/README.rst.in +++ b/completions/templates/README.rst.in @@ -271,7 +271,7 @@ To detect if a git url is a gcrypt repo, use:: (Legacy syntax ``--check`` is also supported). -Exit status is 0 +Exit status is 0 if the repository exists and uses gcrypt, 1 if it uses gcrypt but could not be decrypted, and 100 if the repo is not encrypted with gcrypt (or could not be accessed). diff --git a/completions/templates/bash.in b/completions/templates/bash.in index 32956ad..dcfe0cb 100644 --- a/completions/templates/bash.in +++ b/completions/templates/bash.in @@ -21,13 +21,13 @@ _git_remote_gcrypt() { # 2. Handle subcommands case "${COMP_WORDS[1]}" in clean) - local remotes=$(git remote -v 2>/dev/null | grep 'gcrypt::' | awk '{print $1}' | sort -u || :) - COMPREPLY=($(compgen -W "{clean_flags_bash} $remotes" -- "$cur")) + local remotes=$( git remote -v 2>/dev/null | grep 'gcrypt::' | awk '{print $1}' | sort -u || : ) + COMPREPLY=( $( compgen -W "{clean_flags_bash} $remotes" -- "$cur" ) ) return 0 ;; check) - local remotes=$(git remote 2>/dev/null || :) - COMPREPLY=($(compgen -W "$remotes" -- "$cur")) + local remotes=$( git remote 2>/dev/null || : ) + COMPREPLY=( $( compgen -W "$remotes" -- "$cur" ) ) return 0 ;; capabilities|fetch|list|push) diff --git a/completions/templates/zsh.in b/completions/templates/zsh.in index 329bdb1..60641e3 100644 --- a/completions/templates/zsh.in +++ b/completions/templates/zsh.in @@ -14,7 +14,7 @@ _git_remote_gcrypt() { case $line[1] in clean) - _arguments \ + _arguments {clean_flags_zsh} \ '*:gcrypt URL: _alternative "remotes:gcrypt remote:($(git remote -v 2>/dev/null | grep "gcrypt::" | awk "{print \$1}" | sort -u))" "files:file:_files"' ;; check) diff --git a/completions/zsh/_git-remote-gcrypt b/completions/zsh/_git-remote-gcrypt index ceb5ae5..14a8400 100644 --- a/completions/zsh/_git-remote-gcrypt +++ b/completions/zsh/_git-remote-gcrypt @@ -14,7 +14,7 @@ _git_remote_gcrypt() { case $line[1] in clean) - _arguments \ + _arguments \ '*:gcrypt URL: _alternative "remotes:gcrypt remote:($(git remote -v 2>/dev/null | grep "gcrypt::" | awk "{print \$1}" | sort -u))" "files:file:_files"' ;; check) diff --git a/git-remote-gcrypt b/git-remote-gcrypt index 4a9213c..c33dbec 100755 --- a/git-remote-gcrypt +++ b/git-remote-gcrypt @@ -1419,10 +1419,10 @@ get_remote_file_list() return 1 } git update-ref -d "refs/gcrypt/list-files" - else # Could not fetch, or remote is empty. # If checking, this might be fine, but for clean it's an issue if we expected files. # Returning 1 is safer. + git update-ref -d "refs/gcrypt/list-files" 2>/dev/null || true return 1 fi fi diff --git a/install.sh b/install.sh index ef42ede..1eb0c58 100755 --- a/install.sh +++ b/install.sh @@ -4,12 +4,19 @@ set -e : "${prefix:=/usr/local}" : "${DESTDIR:=}" +log() { printf "\033[1;36m[INSTALL] %s\033[0m\n" "$1"; } verbose() { echo "$@" >&2 && "$@"; } install_v() { # Install $1 into $2/ with mode $3 - verbose install -d "$2" \ - && verbose install -m "$3" "$1" "$2" + if ! verbose install -d "$2"; then + echo "Error: Failed to create directory $2" >&2 + exit 1 + fi + if ! verbose install -m "$3" "$1" "$2"; then + echo "Error: Failed to install $1 into $2" >&2 + exit 1 + fi } # --- VERSION DETECTION --- diff --git a/tests/test-install-logic.sh b/tests/test-install-logic.sh index 1b843f8..c160ae1 100755 --- a/tests/test-install-logic.sh +++ b/tests/test-install-logic.sh @@ -37,11 +37,13 @@ assert_version() { export prefix="$PREFIX" unset DESTDIR - # Run the installer - "bash" "$INSTALLER" >/dev/null 2>&1 || { - echo "Installer failed unexpectedly" - return 1 + # Run the installer and capture output + cat .install_log 2>&1 || { + print_err "Installer failed unexpectedly. Output:" + cat .install_log + exit 1 } + rm -f .install_log INSTALLED_BIN="$PREFIX/bin/git-remote-gcrypt" chmod +x "$INSTALLED_BIN" @@ -89,11 +91,29 @@ EXPECTED_TAG="5.5.5-1 ($OS_IDENTIFIER)" assert_version "$EXPECTED_TAG" -# --- TEST 3: DESTDIR Support --- -echo "--- Test 3: DESTDIR Support ---" +# --- TEST 3: Prefix Support (Mac-idiomatic) --- +echo "--- Test 3: Prefix Support ---" rm -rf "${SANDBOX:?}/usr" -export DESTDIR="$SANDBOX/pkg_root" +export prefix="$SANDBOX/usr" +unset DESTDIR + +"bash" "$INSTALLER" >/dev/null 2>&1 || { + print_err "Installer FAILED" + exit 1 +} + +if [ -f "$SANDBOX/usr/bin/git-remote-gcrypt" ]; then + printf " ✓ %s\n" "Prefix honored" +else + print_err "FAILED: Binary not found in expected prefix location" + exit 1 +fi + +# --- TEST 4: DESTDIR Support (Linux-idiomatic) --- +echo "--- Test 4: DESTDIR Support ---" +rm -rf "${SANDBOX:?}/pkg_root" export prefix="/usr" +export DESTDIR="$SANDBOX/pkg_root" "bash" "$INSTALLER" >/dev/null 2>&1 || { print_err "Installer FAILED" diff --git a/utils/gen_docs.sh b/utils/gen_docs.sh index b95bbaf..b054510 100755 --- a/utils/gen_docs.sh +++ b/utils/gen_docs.sh @@ -29,7 +29,7 @@ RAW_HELP=$(sed -n "/^$SCRIPT_KEY=\"/,/\"$/p" "$SRC" | sed "s/^$SCRIPT_KEY=\"//;s # 1. Prepare {commands_help} for README (Indented for RST) # We want the Options and Git Protocol Commands sections -COMMANDS_HELP=$(echo "$RAW_HELP" | sed -n '/^Options:/,$p' | sed 's/^/ /') +COMMANDS_HELP=$(echo "$RAW_HELP" | sed -n '/^Options:/,$p' | sed 's/^/ /' | sed '$d') # 2. Parse Commands and Flags for Completions # Extract command names (first word after 2 spaces) @@ -71,34 +71,38 @@ for line in $CLEAN_FLAGS_RAW; do done unset IFS +# Helper for template substitution using awk +# Usage: replace_template "TEMPLATE_FILE" "OUT_FILE" "KEY1=VALUE1" "KEY2=VALUE2" ... +replace_template() { + _tmpl="$1" + _out="$2" + shift 2 + _awk_script="" + for _kv in "$@"; do + _key="${_kv%%=*}" + _val="${_kv#*=}" + # Export the value so awk can access it via ENVIRON + export "REPLACE_$_key"="$_val" + _awk_script="${_awk_script} gsub(/\{${_key}\}/, ENVIRON[\"REPLACE_$_key\"]);" + done + awk "{ $_awk_script print }" "$_tmpl" >"$_out" +} + # 3. Generate README echo "Generating $README_OUT..." -sed "s/{commands_help}/$(echo "$COMMANDS_HELP" | sed 's/[\/&]/\\&/g' | awk 'NR>1{printf "\\n"} {printf "%s", $0}')/" "$README_TMPL" >"$README_OUT" +replace_template "$README_TMPL" "$README_OUT" "commands_help=$COMMANDS_HELP" # 4. Generate Bash echo "Generating Bash completions..." -sed "s/{commands}/$COMMANDS_LIST/; s/{clean_flags_bash}/$CLEAN_FLAGS_BASH/" "$BASH_TMPL" >"$BASH_OUT" +replace_template "$BASH_TMPL" "$BASH_OUT" "commands=$COMMANDS_LIST" "clean_flags_bash=$CLEAN_FLAGS_BASH" # 5. Generate Zsh echo "Generating Zsh completions..." -# Zsh substitution is tricky with the complex string. -# We'll stick to replacing {commands} and {clean_flags_zsh} -# Need to escape special chars for sed -# safe_cmds removed as unused -# For clean_flags_zsh, since it contains quotes and braces, we need care. -# We'll read the template line by line? No, sed is standard. -# We use a temp file for the replacement string to avoid sed escaping hell for large blocks? -# Or just keep it simple. -sed "s/{commands}/$COMMANDS_LIST/" "$ZSH_TMPL" \ - | sed "s|{clean_flags_zsh}|$CLEAN_FLAGS_ZSH|" >"$ZSH_OUT" +replace_template "$ZSH_TMPL" "$ZSH_OUT" "commands=$COMMANDS_LIST" "clean_flags_zsh=$CLEAN_FLAGS_ZSH" # 6. Generate Fish echo "Generating Fish completions..." # Fish needs {not_sc_list} which matches {commands} (space separated) -sed "s/{not_sc_list}/$COMMANDS_LIST/g" "$FISH_TMPL" \ - | - # Multi-line replacement in sed is hard. Use awk? - # Or just injecting the string with escaped newlines. - sed "s|{clean_flags_fish}|$CLEAN_FLAGS_FISH|" >"$FISH_OUT" +replace_template "$FISH_TMPL" "$FISH_OUT" "not_sc_list=$COMMANDS_LIST" "clean_flags_fish=$CLEAN_FLAGS_FISH" echo "Done."