Skip to content

fix(update): switch to main before pulling local-only branches#3467

Closed
SollanSystems wants to merge 1 commit intoNousResearch:mainfrom
SollanSystems:fix/update-local-only-branch-fallback
Closed

fix(update): switch to main before pulling local-only branches#3467
SollanSystems wants to merge 1 commit intoNousResearch:mainfrom
SollanSystems:fix/update-local-only-branch-fallback

Conversation

@SollanSystems
Copy link
Copy Markdown

Summary

  • keep current_branch separate from the update target branch in cmd_update
  • when the current branch does not exist on origin, explicitly git checkout main before git pull --ff-only origin main
  • restore any autostashed local changes even if the fallback checkout fails
  • add regression coverage for checkout-before-pull and stash restore on checkout failure

Problem

Updating from a local-only branch could fall back to main logically, but still attempt to fast-forward from the local branch context. That leads to update failures like:

fatal: Not possible to fast-forward, aborting.

Test Plan

  • uv run --extra dev pytest -o addopts= tests/hermes_cli/test_cmd_update.py tests/hermes_cli/test_update_autostash.py tests/hermes_cli/test_update_gateway_restart.py tests/hermes_cli/test_update_check.py -q

Copilot AI review requested due to automatic review settings March 27, 2026 23:59
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes hermes update failures when run from a local-only git branch by ensuring the update pull happens from the correct checked-out branch, and adds regression tests around branch switching and autostash restoration behavior.

Changes:

  • Track current_branch separately from the update target branch in cmd_update.
  • When the current branch is not present on origin, checkout main before git pull --ff-only origin main.
  • Ensure autostashed changes are restored even if the fallback checkout fails; add regression tests for these behaviors.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
hermes_cli/main.py Separates current vs target branch and checks out the target branch (e.g., main) before pulling to avoid FF-only failures from local-only branches.
tests/hermes_cli/test_cmd_update.py Adds regression tests verifying checkout happens before pull on fallback, and that stashed changes are restored even when checkout fails.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +121 to +126
mock_restore.assert_called_once_with(
["git"],
PROJECT_ROOT,
"stash123",
prompt_user=False,
)
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assertion hard-codes git_cmd as ["git"], but cmd_update uses a platform-dependent git_cmd (on Windows it becomes ["git", "-c", "windows.appendAtomically=false"]). Consider asserting the git_cmd argument more flexibly (e.g., match the prefix, or derive the expected value from sys.platform) so the test remains portable if run on Windows.

Copilot uses AI. Check for mistakes.
@teknium1
Copy link
Copy Markdown
Contributor

Thanks for the fix! This was independently addressed in PR #3492 (merged March 27), which did a broader hardening of hermes update — it now unconditionally targets main and switches branches before pulling, with stash/restore handling. Your fix is correct but already covered.

@teknium1 teknium1 closed this Mar 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants