This commit is contained in:
Shoner Shin 2026-04-24 18:23:39 -05:00 committed by GitHub
commit 12ba9cca29
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 30 additions and 1 deletions

View file

@ -4920,7 +4920,12 @@ def _restore_stashed_changes(
if input_fn is not None:
response = input_fn("Restore local changes now? [Y/n]", "y")
else:
response = input().strip().lower()
try:
response = input().strip().lower()
except (KeyboardInterrupt, EOFError):
print()
print("No interactive input available — skipping automatic restore.")
response = "n"
if response not in ("", "y", "yes"):
print("Skipped restoring local changes.")
print("Your changes are still preserved in git stash.")

View file

@ -116,6 +116,30 @@ def test_restore_stashed_changes_can_skip_restore_and_keep_stash(monkeypatch, tm
assert "git stash apply abc123" in out
def test_restore_stashed_changes_handles_eof_and_keeps_stash(monkeypatch, tmp_path, capsys):
calls = []
def fake_run(cmd, **kwargs):
calls.append((cmd, kwargs))
raise AssertionError(f"unexpected command: {cmd}")
monkeypatch.setattr(hermes_main.subprocess, "run", fake_run)
def _raise_eof():
raise EOFError
monkeypatch.setattr("builtins.input", _raise_eof)
restored = hermes_main._restore_stashed_changes(["git"], tmp_path, "abc123", prompt_user=True)
assert restored is False
assert calls == []
out = capsys.readouterr().out
assert "No interactive input available — skipping automatic restore." in out
assert "Your changes are still preserved in git stash." in out
assert "git stash apply abc123" in out
def test_restore_stashed_changes_applies_without_prompt_when_disabled(monkeypatch, tmp_path, capsys):
calls = []