Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions hermes_cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6425,11 +6425,22 @@ def _stash_local_changes_if_needed(git_cmd: list[str], cwd: Path) -> Optional[st
"hermes-update-autostash-%Y%m%d-%H%M%S"
)
print("→ Local changes detected — stashing before update...")
subprocess.run(
git_cmd + ["stash", "push", "--include-untracked", "-m", stash_name],
cwd=cwd,
check=True,
)
try:
subprocess.run(
git_cmd + ["stash", "push", "--include-untracked", "-m", stash_name],
cwd=cwd,
check=True,
timeout=120,
)
except subprocess.TimeoutExpired:
print(
" ⚠ git stash timed out after 120s — skipping auto-stash.\n"
" Your local changes are NOT stashed. The update will proceed\n"
" without stashing; if git complains, manually stash or reset:\n"
" git stash push --include-untracked\n"
" git reset --hard HEAD"
)
return None

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Returning None says no stash exists, but local changes remain after the timeout. If the subsequent pull is nonzero, current cmd_update falls back to git reset --hard origin/<branch> at hermes_cli/main.py:9900-9912 under the assumption changes were stashed. Please abort through a distinct safe path instead of continuing with this sentinel.

stash_ref = subprocess.run(
git_cmd + ["rev-parse", "--verify", "refs/stash"],
cwd=cwd,
Expand Down
20 changes: 20 additions & 0 deletions tests/hermes_cli/test_update_autostash.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,3 +901,23 @@ def git(*args):
["git", "status", "--porcelain"], cwd=tmp_path, capture_output=True, text=True
).stdout
assert ".hermes-bootstrap-complete" not in status


def test_stash_local_changes_if_needed_returns_none_on_timeout(monkeypatch, tmp_path):
"""When git stash hangs (TimeoutExpired), skip stashing and return None."""
import subprocess
from types import SimpleNamespace

def fake_run(cmd, **kwargs):
if cmd[-2:] == ["status", "--porcelain"]:
return SimpleNamespace(stdout=" M hermes_cli/main.py\n", returncode=0)
if cmd[-2:] == ["ls-files", "--unmerged"]:
return SimpleNamespace(stdout="", returncode=0)
if cmd[1:4] == ["stash", "push", "--include-untracked"]:
raise subprocess.TimeoutExpired(cmd=cmd, timeout=120)
raise AssertionError(f"unexpected command: {cmd}")

monkeypatch.setattr(hermes_main.subprocess, "run", fake_run)

result = hermes_main._stash_local_changes_if_needed(["git"], Path(tmp_path))
assert result is None
Loading