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
This commit is contained in:
DanConwayDev
2026-01-27 20:38:02 +00:00
parent 79d2d01923
commit b61d388162
2 changed files with 13 additions and 6 deletions
@@ -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
@@ -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