Commit 9d4b3e5
fix: harden hermes update against diverged history, non-main branches, and gateway edge cases (salvage NousResearch#3489) (NousResearch#3492)
* fix: harden `hermes update` against diverged history, non-main branches, and gateway edge cases
The self-update command (`hermes update` / gateway `/update`) could fail
or silently corrupt state in several scenarios:
1. **Diverged history** — `git pull --ff-only` aborts with a cryptic
subprocess error when upstream has force-pushed or rebased. Now falls
back to `git reset --hard origin/main` since local changes are already
stashed.
2. **User on a feature branch / detached HEAD** — the old code would
either clobber the feature branch HEAD to point at origin/main, or
silently pull against a non-existent remote branch. Now auto-checkouts
main before pulling, with a clear warning.
3. **Fetch failures** — network or auth errors produced raw subprocess
tracebacks. Now shows user-friendly messages ("Network error",
"Authentication failed") with actionable hints.
4. **reset --hard failure** — if the fallback reset itself fails (disk
full, permissions), the old code would still attempt stash restore on
a broken working tree. Now skips restore and tells the user their
changes are safe in stash.
5. **Gateway /update stash conflicts** — non-interactive mode (Telegram
`/update`) called sys.exit(1) when stash restore had conflicts, making
the entire update report as failed even though the code update itself
succeeded. Now treats stash conflicts as non-fatal in non-interactive
mode (returns False instead of exiting).
* fix: restore stash and branch on 'already up to date' early return
The PR moved stash creation before the commit-count check (needed for
the branch-switching feature), but the 'already up to date' early return
didn't restore the stash or switch back to the original branch — leaving
the user stranded on main with changes trapped in a stash.
Now the early-return path restores the stash and checks out the original
branch when applicable.
---------
Co-authored-by: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com>1 parent 6ed9740 commit 9d4b3e5
2 files changed
Lines changed: 338 additions & 31 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2632 | 2632 | | |
2633 | 2633 | | |
2634 | 2634 | | |
2635 | | - | |
| 2635 | + | |
| 2636 | + | |
| 2637 | + | |
| 2638 | + | |
| 2639 | + | |
| 2640 | + | |
2636 | 2641 | | |
2637 | 2642 | | |
2638 | 2643 | | |
| |||
2706 | 2711 | | |
2707 | 2712 | | |
2708 | 2713 | | |
2709 | | - | |
2710 | 2714 | | |
2711 | 2715 | | |
2712 | 2716 | | |
2713 | | - | |
2714 | | - | |
2715 | | - | |
2716 | | - | |
| 2717 | + | |
| 2718 | + | |
| 2719 | + | |
| 2720 | + | |
| 2721 | + | |
| 2722 | + | |
| 2723 | + | |
| 2724 | + | |
| 2725 | + | |
| 2726 | + | |
| 2727 | + | |
| 2728 | + | |
| 2729 | + | |
| 2730 | + | |
| 2731 | + | |
| 2732 | + | |
| 2733 | + | |
| 2734 | + | |
| 2735 | + | |
| 2736 | + | |
| 2737 | + | |
| 2738 | + | |
2717 | 2739 | | |
2718 | 2740 | | |
2719 | 2741 | | |
2720 | 2742 | | |
2721 | 2743 | | |
2722 | | - | |
| 2744 | + | |
2723 | 2745 | | |
2724 | | - | |
| 2746 | + | |
2725 | 2747 | | |
2726 | | - | |
2727 | | - | |
2728 | | - | |
2729 | | - | |
2730 | | - | |
2731 | | - | |
2732 | | - | |
| 2748 | + | |
| 2749 | + | |
| 2750 | + | |
| 2751 | + | |
| 2752 | + | |
| 2753 | + | |
| 2754 | + | |
| 2755 | + | |
| 2756 | + | |
| 2757 | + | |
| 2758 | + | |
| 2759 | + | |
| 2760 | + | |
| 2761 | + | |
| 2762 | + | |
| 2763 | + | |
| 2764 | + | |
| 2765 | + | |
| 2766 | + | |
| 2767 | + | |
2733 | 2768 | | |
2734 | 2769 | | |
2735 | 2770 | | |
2736 | 2771 | | |
2737 | 2772 | | |
2738 | 2773 | | |
2739 | 2774 | | |
2740 | | - | |
| 2775 | + | |
2741 | 2776 | | |
2742 | 2777 | | |
2743 | | - | |
| 2778 | + | |
2744 | 2779 | | |
2745 | 2780 | | |
| 2781 | + | |
| 2782 | + | |
| 2783 | + | |
| 2784 | + | |
| 2785 | + | |
| 2786 | + | |
| 2787 | + | |
| 2788 | + | |
| 2789 | + | |
| 2790 | + | |
| 2791 | + | |
2746 | 2792 | | |
2747 | 2793 | | |
2748 | | - | |
2749 | | - | |
2750 | 2794 | | |
2751 | | - | |
2752 | | - | |
| 2795 | + | |
2753 | 2796 | | |
2754 | 2797 | | |
| 2798 | + | |
2755 | 2799 | | |
2756 | | - | |
| 2800 | + | |
| 2801 | + | |
| 2802 | + | |
| 2803 | + | |
| 2804 | + | |
| 2805 | + | |
| 2806 | + | |
| 2807 | + | |
| 2808 | + | |
| 2809 | + | |
| 2810 | + | |
| 2811 | + | |
| 2812 | + | |
| 2813 | + | |
| 2814 | + | |
| 2815 | + | |
| 2816 | + | |
| 2817 | + | |
| 2818 | + | |
| 2819 | + | |
| 2820 | + | |
| 2821 | + | |
| 2822 | + | |
| 2823 | + | |
2757 | 2824 | | |
2758 | 2825 | | |
2759 | | - | |
2760 | | - | |
2761 | | - | |
2762 | | - | |
2763 | | - | |
2764 | | - | |
| 2826 | + | |
| 2827 | + | |
| 2828 | + | |
| 2829 | + | |
| 2830 | + | |
| 2831 | + | |
| 2832 | + | |
| 2833 | + | |
| 2834 | + | |
| 2835 | + | |
| 2836 | + | |
| 2837 | + | |
2765 | 2838 | | |
2766 | 2839 | | |
2767 | 2840 | | |
| |||
0 commit comments