๐Ÿ”ง Where my dotfiles lives in harmony and peace, most of the time

๐Ÿ”ง Refactor pull-all-dirs to track parallel jobs and propagate errors

- Replace custom concurrency counter with PID tracking and strict wait to capture failures
- Improve messaging with printf and consistent quoting; return non-zero on remote update/pull failures
- Only list updated repositories when changes occur and exit with aggregated status

+19 -27
+19 -27
scripts/pull-all-dirs
··· 1 1 #!/usr/bin/env bash 2 - 3 2 # pull-all-dirs - Pull git repositories in all subdirectories that are behind upstream 4 3 # Usage: pull-all-dirs [directory] 5 4 6 5 set -euo pipefail 7 6 8 7 target_dir="${1:-.}" 9 - concurrency="${PULL_CONCURRENCY:-4}" 10 - concurrency=${concurrency:-4} 11 - (( concurrency < 1 )) && concurrency=1 12 8 13 9 if [[ ! -d "$target_dir" ]]; then 14 - echo "Error: Directory '$target_dir' does not exist" >&2 10 + printf 'Error: Directory "%s" does not exist\n' "$target_dir" >&2 15 11 exit 1 16 12 fi 17 13 ··· 26 22 [[ -d "$dir/.git" ]] || return 0 27 23 28 24 if ! git -C "$dir" remote update >/dev/null 2>&1; then 29 - echo "Warning: Could not update remotes for '$dir'" >&2 30 - return 0 25 + printf 'Warning: could not update remotes for "%s"\n' "$dir" >&2 26 + return 1 31 27 fi 32 28 33 29 if git -C "$dir" status -uno | grep -q "Your branch is behind"; then 34 - echo "Pulling updates for: $dir" 30 + printf 'Pulling updates for: %s\n' "$dir" 35 31 if git -C "$dir" pull --ff-only; then 36 32 printf '%s\n' "$dir" >>"$updated_file" 37 33 else 38 - echo "Error: Failed to pull updates for '$dir'" >&2 34 + printf 'Error: failed to pull updates for "%s"\n' "$dir" >&2 35 + return 1 39 36 fi 40 37 fi 41 38 } 42 39 43 - running_jobs=0 44 - 45 - wait_for_slot() { 46 - while (( running_jobs >= concurrency )); do 47 - wait -n || true 48 - ((running_jobs--)) 49 - done 50 - } 40 + pids=() 51 41 52 42 for dir in */; do 53 43 [[ -d "$dir" ]] || continue 54 - 55 - wait_for_slot 44 + dir=${dir%/} 56 45 process_repo "$dir" & 57 - ((++running_jobs)) 46 + pids+=("$!") 58 47 done 59 48 60 - while (( running_jobs > 0 )); do 61 - wait -n || true 62 - ((running_jobs--)) 49 + exit_status=0 50 + 51 + for pid in "${pids[@]}"; do 52 + if ! wait "$pid"; then 53 + exit_status=1 54 + fi 63 55 done 64 56 65 57 if [[ ! -s "$updated_file" ]]; then 66 58 echo "All repositories are up to date." 67 - exit 0 59 + else 60 + echo "Updated repositories:" 61 + sort -u "$updated_file" | sed 's/^/ - /' 68 62 fi 69 63 70 - mapfile -t updated_repos <"$updated_file" 71 - echo "Updated ${#updated_repos[@]} repository/repositories:" 72 - printf " - %s\n" "${updated_repos[@]}" 64 + exit "$exit_status"