From b61d388162438d12df37aa3fcd40bc9d3344d5bd Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Fri, 23 Jan 2026 14:26:54 +0000 Subject: Add git prerequisite checks to migration scripts - 10-check-git-sync.sh: Check for git before running - run-migration-analysis.sh: Include git in prerequisite checks - Fixes script failures when git is not installed --- docs/how-to/migration-scripts/10-check-git-sync.sh | 15 +++++++++++---- docs/how-to/migration-scripts/run-migration-analysis.sh | 4 ++-- 2 files changed, 13 insertions(+), 6 deletions(-) (limited to 'docs') diff --git a/docs/how-to/migration-scripts/10-check-git-sync.sh b/docs/how-to/migration-scripts/10-check-git-sync.sh index 1f2ce04..b4536cb 100755 --- a/docs/how-to/migration-scripts/10-check-git-sync.sh +++ b/docs/how-to/migration-scripts/10-check-git-sync.sh @@ -118,6 +118,11 @@ usage() { check_prerequisites() { local missing=0 + if ! command -v git &> /dev/null; then + log_error "git not found. Install with your package manager." + missing=1 + fi + if ! command -v nak &> /dev/null; then log_error "nak not found. Install from: https://github.com/fiatjaf/nak" log_error "Or run: nix-shell -p nak jq --run \"$0 $*\"" @@ -161,13 +166,15 @@ count_git_refs() { return fi - # Use git show-ref to handle both packed and loose refs - # Fall back to counting loose refs if git show-ref fails - if git --git-dir="$git_dir" show-ref --heads 2>/dev/null | wc -l | tr -d ' '; then + # Try git show-ref first (handles packed refs correctly) + # Note: We capture output separately to avoid pipefail issues + local count + if count=$(git --git-dir="$git_dir" show-ref --heads 2>/dev/null | wc -l); then + echo "$count" | tr -d ' ' return fi - # Fallback: count loose refs + # Fallback: count loose refs (when git is not available or fails) if [[ -d "$git_dir/refs/heads" ]]; then find "$git_dir/refs/heads" -type f 2>/dev/null | wc -l | tr -d ' ' else diff --git a/docs/how-to/migration-scripts/run-migration-analysis.sh b/docs/how-to/migration-scripts/run-migration-analysis.sh index 84aec2a..65d9d17 100755 --- a/docs/how-to/migration-scripts/run-migration-analysis.sh +++ b/docs/how-to/migration-scripts/run-migration-analysis.sh @@ -155,7 +155,7 @@ FROM_PHASE="" declare -A PHASE_TIMES usage() { - head -80 "$0" | tail -n +3 | sed 's/^# //' | sed 's/^#//' + head -73 "$0" | tail -n +3 | sed 's/^# //' | sed 's/^#//' exit 0 } @@ -285,7 +285,7 @@ check_prerequisites() { log_info "Checking prerequisites..." # Required tools - for tool in nak jq awk sort; do + for tool in git nak jq awk sort; do if command -v "$tool" &> /dev/null; then log_step "$tool: found" else -- cgit v1.2.3