Make bootstrap dry-run avoid git installation (#19)

This commit is contained in:
m1ngsama 2026-05-13 12:37:46 +08:00 committed by GitHub
parent 259744b5e3
commit 1c54077487
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 54 additions and 9 deletions

47
get.sh
View file

@ -79,16 +79,45 @@ echo " Dest: $DEST"
# ── git ─────────────────────────────────────────────────────────────────────── # ── git ───────────────────────────────────────────────────────────────────────
step "Checking for git" step "Checking for git"
if ! command -v git >/dev/null 2>&1; then HAS_GIT=0
warn "git not found — attempting to install" command -v git >/dev/null 2>&1 && HAS_GIT=1
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 if [[ $HAS_GIT -eq 0 ]]; then
elif command -v dnf >/dev/null 2>&1; then sudo dnf install -y git >/dev/null 2>&1 if [[ $DRY_RUN -eq 1 ]]; then
elif command -v brew >/dev/null 2>&1; then brew install git >/dev/null 2>&1 warn "git not found — would need to install git before a real install"
else die "git is required. Install it manually then re-run."; fi else
command -v git >/dev/null 2>&1 || die "git install failed. Try: sudo apt install git" 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 fi
ok "git $(git --version | awk '{print $3}')"
# ── Clone or update ─────────────────────────────────────────────────────────── # ── Clone or update ───────────────────────────────────────────────────────────
step "Setting up $DEST" step "Setting up $DEST"

View file

@ -94,6 +94,22 @@ check_bootstrap() {
grep -q 'Would clone' "$TMP_ROOT/get-dry-run.txt" grep -q 'Would clone' "$TMP_ROOT/get-dry-run.txt"
test ! -e "$TMP_ROOT/bootstrap" 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" mkdir -p "$TMP_ROOT/not-chopsticks"
git -c init.defaultBranch=main init "$TMP_ROOT/not-chopsticks" >/dev/null 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 git -C "$TMP_ROOT/not-chopsticks" remote add origin https://github.com/example/not-chopsticks.git