diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2026-01-23 14:26:54 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2026-01-27 20:38:02 +0000 |
| commit | b61d388162438d12df37aa3fcd40bc9d3344d5bd (patch) | |
| tree | deb76a13e3f4bc7098301d0194db1c3ca6672039 /docs/how-to/migration-scripts/10-check-git-sync.sh | |
| parent | 79d2d01923cf66217fd5aa3a0be5ee9ea2000872 (diff) | |
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
Diffstat (limited to 'docs/how-to/migration-scripts/10-check-git-sync.sh')
| -rwxr-xr-x | docs/how-to/migration-scripts/10-check-git-sync.sh | 15 |
1 files changed, 11 insertions, 4 deletions
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() { | |||
| 118 | check_prerequisites() { | 118 | check_prerequisites() { |
| 119 | local missing=0 | 119 | local missing=0 |
| 120 | 120 | ||
| 121 | if ! command -v git &> /dev/null; then | ||
| 122 | log_error "git not found. Install with your package manager." | ||
| 123 | missing=1 | ||
| 124 | fi | ||
| 125 | |||
| 121 | if ! command -v nak &> /dev/null; then | 126 | if ! command -v nak &> /dev/null; then |
| 122 | log_error "nak not found. Install from: https://github.com/fiatjaf/nak" | 127 | log_error "nak not found. Install from: https://github.com/fiatjaf/nak" |
| 123 | log_error "Or run: nix-shell -p nak jq --run \"$0 $*\"" | 128 | log_error "Or run: nix-shell -p nak jq --run \"$0 $*\"" |
| @@ -161,13 +166,15 @@ count_git_refs() { | |||
| 161 | return | 166 | return |
| 162 | fi | 167 | fi |
| 163 | 168 | ||
| 164 | # Use git show-ref to handle both packed and loose refs | 169 | # Try git show-ref first (handles packed refs correctly) |
| 165 | # Fall back to counting loose refs if git show-ref fails | 170 | # Note: We capture output separately to avoid pipefail issues |
| 166 | if git --git-dir="$git_dir" show-ref --heads 2>/dev/null | wc -l | tr -d ' '; then | 171 | local count |
| 172 | if count=$(git --git-dir="$git_dir" show-ref --heads 2>/dev/null | wc -l); then | ||
| 173 | echo "$count" | tr -d ' ' | ||
| 167 | return | 174 | return |
| 168 | fi | 175 | fi |
| 169 | 176 | ||
| 170 | # Fallback: count loose refs | 177 | # Fallback: count loose refs (when git is not available or fails) |
| 171 | if [[ -d "$git_dir/refs/heads" ]]; then | 178 | if [[ -d "$git_dir/refs/heads" ]]; then |
| 172 | find "$git_dir/refs/heads" -type f 2>/dev/null | wc -l | tr -d ' ' | 179 | find "$git_dir/refs/heads" -type f 2>/dev/null | wc -l | tr -d ' ' |
| 173 | else | 180 | else |