fix(install): move broken checkout aside instead of deleting it

Review feedback (#40998): `rm -rf` / `Remove-Item -Recurse -Force` on the
install dir is destructive -- a user might still want whatever is there.
Rename the broken checkout to a timestamped `<dir>.broken-<ts>` backup and
re-clone fresh, so nothing is ever deleted. Transient cleanup of a clone
attempt that fails within the same run is left as-is.
This commit is contained in:
xxxigm 2026-06-08 06:49:46 +07:00 committed by Teknium
parent 5d7abf9114
commit a5c12f5f59
3 changed files with 37 additions and 14 deletions

View file

@ -1094,11 +1094,14 @@ clone_repo() {
# An interrupted previous clone leaves a .git with no initial commit, where
# the update path's `git stash` / `git checkout` abort with "You do not
# have the initial commit yet" and fail the install (#40998). Drop such a
# partial checkout so the fresh-clone path below handles it cleanly.
# have the initial commit yet" and fail the install (#40998). Move such a
# partial checkout aside -- never delete it, in case it holds something the
# user wants -- so the fresh-clone path below can proceed.
if [ -d "$INSTALL_DIR/.git" ] && ! git -C "$INSTALL_DIR" rev-parse --verify HEAD >/dev/null 2>&1; then
log_warn "Existing checkout at $INSTALL_DIR has no commits (interrupted clone) -- replacing it."
rm -rf "$INSTALL_DIR"
backup_dir="${INSTALL_DIR}.broken-$(date -u +%Y%m%d-%H%M%S)"
log_warn "Existing checkout at $INSTALL_DIR has no commits (interrupted clone)."
log_warn "Moving it aside to $backup_dir before re-cloning."
mv "$INSTALL_DIR" "$backup_dir"
fi
if [ -d "$INSTALL_DIR" ]; then