mirror of
https://oauth2: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@github.com/m1ngsama/chopsticks.git
synced 2026-05-13 20:41:04 +08:00
Make bootstrap dry-run avoid git installation (#19)
This commit is contained in:
parent
259744b5e3
commit
1c54077487
2 changed files with 54 additions and 9 deletions
33
get.sh
33
get.sh
|
|
@ -79,7 +79,13 @@ echo " Dest: $DEST"
|
|||
# ── git ───────────────────────────────────────────────────────────────────────
|
||||
step "Checking for git"
|
||||
|
||||
if ! command -v git >/dev/null 2>&1; then
|
||||
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
|
||||
|
|
@ -87,8 +93,31 @@ if ! command -v git >/dev/null 2>&1; then
|
|||
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"
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue