diff --git a/get.sh b/get.sh index b1ca910..97f37c5 100755 --- a/get.sh +++ b/get.sh @@ -79,16 +79,45 @@ echo " Dest: $DEST" # ── git ─────────────────────────────────────────────────────────────────────── step "Checking for git" -if ! command -v git >/dev/null 2>&1; then - warn "git not found — attempting to install" - if command -v apt-get >/dev/null 2>&1; then sudo apt-get install -y git >/dev/null 2>&1 - elif command -v pacman >/dev/null 2>&1; then sudo pacman -S --noconfirm git >/dev/null 2>&1 - elif command -v dnf >/dev/null 2>&1; then sudo dnf install -y git >/dev/null 2>&1 - elif command -v brew >/dev/null 2>&1; then brew install git >/dev/null 2>&1 - else die "git is required. Install it manually then re-run."; fi - command -v git >/dev/null 2>&1 || die "git install failed. Try: sudo apt install git" +HAS_GIT=0 +command -v git >/dev/null 2>&1 && HAS_GIT=1 + +if [[ $HAS_GIT -eq 0 ]]; then + if [[ $DRY_RUN -eq 1 ]]; then + warn "git not found — would need to install git before a real install" + else + warn "git not found — attempting to install" + if command -v apt-get >/dev/null 2>&1; then sudo apt-get install -y git >/dev/null 2>&1 + elif command -v pacman >/dev/null 2>&1; then sudo pacman -S --noconfirm git >/dev/null 2>&1 + elif command -v dnf >/dev/null 2>&1; then sudo dnf install -y git >/dev/null 2>&1 + elif command -v brew >/dev/null 2>&1; then brew install git >/dev/null 2>&1 + else die "git is required. Install it manually then re-run."; fi + command -v git >/dev/null 2>&1 || die "git install failed. Try: sudo apt install git" + HAS_GIT=1 + fi +fi +if [[ $HAS_GIT -eq 1 ]]; then + ok "git $(git --version | awk '{print $3}')" +elif [[ $DRY_RUN -eq 1 ]]; then + info "Would require: git" +else + die "git is required. Install it manually then re-run." +fi + +if [[ $DRY_RUN -eq 1 && $HAS_GIT -eq 0 ]]; then + step "Setting up $DEST" + if [[ -d "$DEST/.git" ]]; then + info "Would inspect existing git repo at $DEST" + info "Would update it only if its origin is $REPO" + elif [[ -d "$DEST" ]]; then + die "$DEST exists but git is unavailable, so dry-run cannot verify whether it is chopsticks. + Install git and re-run dry-run for the full safety check." + else + info "Would clone $REPO to $DEST" + fi + info "Would run: bash install.sh ${INSTALLER_ARGS[*]:-(no installer options)}" + exit 0 fi -ok "git $(git --version | awk '{print $3}')" # ── Clone or update ─────────────────────────────────────────────────────────── step "Setting up $DEST" diff --git a/scripts/test.sh b/scripts/test.sh index f6b70ba..d2287e4 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -94,6 +94,22 @@ check_bootstrap() { grep -q 'Would clone' "$TMP_ROOT/get-dry-run.txt" test ! -e "$TMP_ROOT/bootstrap" + mkdir -p "$TMP_ROOT/no-git-bin" + printf '%s\n' \ + '#!/usr/bin/env bash' \ + "echo \"brew was called\" >> \"\$BREW_LOG\"" \ + 'exit 42' > "$TMP_ROOT/no-git-bin/brew" + chmod +x "$TMP_ROOT/no-git-bin/brew" + BREW_LOG="$TMP_ROOT/no-git-brew.log" \ + PATH="$TMP_ROOT/no-git-bin" \ + CHOPSTICKS_DEST="$TMP_ROOT/no-git-bootstrap" \ + /bin/bash ./get.sh --dry-run --profile=full \ + | tee "$TMP_ROOT/get-no-git-dry-run.txt" + grep -q 'Would require: git' "$TMP_ROOT/get-no-git-dry-run.txt" + grep -q 'Would clone' "$TMP_ROOT/get-no-git-dry-run.txt" + test ! -e "$TMP_ROOT/no-git-brew.log" + test ! -e "$TMP_ROOT/no-git-bootstrap" + mkdir -p "$TMP_ROOT/not-chopsticks" git -c init.defaultBranch=main init "$TMP_ROOT/not-chopsticks" >/dev/null git -C "$TMP_ROOT/not-chopsticks" remote add origin https://github.com/example/not-chopsticks.git