@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; \
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
=============
(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).
# 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)
(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).
# 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)
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)
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)
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
: "${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 ---
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 </dev/null | "bash" "$INSTALLER" >.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"
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"
# 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)
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."