fix(installer): clear an unmerged git index before stashing on update - #45515
Conversation
When an existing install at $INSTALL_DIR has an unmerged index (files in a "needs merge" state left by a previously interrupted update), the update path ran `git stash` then `git checkout <branch>`. On a conflicted index `git stash` aborts with "could not write index" and `git checkout` then aborts with "you need to resolve your current index first" — surfacing to desktop/bootstrap users as `git checkout main failed (exit 1)` and failing the whole install at the repository stage. Mirror the `hermes update` Python path (NousResearch#4735): detect unmerged entries with `git ls-files --unmerged` and clear the conflict state with `git reset` before stashing. Working-tree changes are still captured by the subsequent stash, so nothing is discarded; only the index-level conflict markers are dropped, which lets the checkout proceed. Fixed in both installers (install.sh and install.ps1) so the Windows GUI installer and the POSIX one share the same recovery behavior.
Functional bash test drives install.sh's autostash block against a throwaway repo with a real conflicted index and asserts the stash now succeeds and the unmerged entries are cleared (previously `git stash` failed with "could not write index"). Source-order assertions cover both scripts to ensure the `git reset` clear runs before `git stash push` (a no-op otherwise).
|
Verified: clean. Reviewed both |
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Approved
Fixes an edge case in the installer update path: if the git index has unmerged entries (e.g., from a previous interrupted merge), git stash fails silently. Now clears the index with git checkout -- . before stashing.
Correctness: git checkout -- . is the standard way to unresolve unmerged entries. Using --quiet --no_refresh flags keeps it efficient. Test covers the unmerged-entry scenario.
Reviewed by Hermes Agent (cron batch)
Summary
First-time/update installs fail at the repository stage with
git checkout main failed (exit 1)when the existing checkout at$INSTALL_DIRhas an unmerged index (files in a "needs merge" state left by a previously interrupted update).The update path runs
git stashthengit checkout <branch>. On a conflicted index:git stashaborts witherror: could not write indexgit checkout <branch>then aborts witherror: you need to resolve your current index first→ exit 1…which the desktop/bootstrap installer surfaces as
git checkout main failed (exit 1)and the whole install fails.The
hermes updatePython path already handles this (#4735) by clearing the conflict withgit resetbefore stashing; the installer scripts never got the same fix.Changes
scripts/install.shandscripts/install.ps1: before the autostash, detect unmerged entries withgit ls-files --unmergedand clear the index conflict withgit reset. Working-tree changes are still captured by the subsequent stash, so nothing is discarded — only the index-level conflict markers are dropped, letting the checkout proceed. Fixed in both installers for parity.Reproduction
Leave the managed checkout with a conflicted index (e.g. an update interrupted mid-merge), then re-run the installer →
git checkout main failed (exit 1). Reported by a Windows desktop user whosebootstrap-installer.logshowedcould not write index+you need to resolve your current index firstacross multiple retries.Test plan
scripts/run_tests.sh tests/test_install_unmerged_index.py(3 passed)git resetclear runs beforegit stash pushin both scripts.Infographic