mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-06-09 08:21:50 +00:00
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:
parent
5d7abf9114
commit
a5c12f5f59
3 changed files with 37 additions and 14 deletions
|
|
@ -1209,16 +1209,19 @@ function Install-Repository {
|
|||
}
|
||||
$didUpdate = $true
|
||||
} else {
|
||||
# Directory exists but isn't a usable git repo. Wipe it and
|
||||
# fall through to a fresh clone. A leftover ``.git`` stub from
|
||||
# a partial uninstall used to lock the installer into the
|
||||
# "update" branch forever, emitting three ``fatal: not a git
|
||||
# repository`` errors and failing with "not in a git directory".
|
||||
Write-Warn "Existing directory at $InstallDir is not a valid git repo -- replacing it."
|
||||
# Directory exists but isn't a usable git repo -- e.g. an
|
||||
# interrupted clone with no initial commit (#40998), or a leftover
|
||||
# ``.git`` stub from a partial uninstall that used to lock the
|
||||
# installer into the "update" branch forever. Move it aside rather
|
||||
# than deleting it -- never destroy a directory the user might still
|
||||
# want -- and fall through to a fresh clone.
|
||||
$backupDir = "$InstallDir.broken-" + (Get-Date -Format "yyyyMMdd-HHmmss")
|
||||
Write-Warn "Existing directory at $InstallDir is not a valid git repo."
|
||||
Write-Warn "Moving it aside to $backupDir before re-cloning."
|
||||
try {
|
||||
Remove-Item -Recurse -Force $InstallDir -ErrorAction Stop
|
||||
Move-Item -LiteralPath $InstallDir -Destination $backupDir -ErrorAction Stop
|
||||
} catch {
|
||||
Write-Err "Could not remove $InstallDir : $_"
|
||||
Write-Err "Could not move $InstallDir aside : $_"
|
||||
Write-Info "Close any programs that might be using files in $InstallDir (editors,"
|
||||
Write-Info "terminals, running hermes processes) and try again."
|
||||
throw
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue