diff --git a/hermes_cli/main.py b/hermes_cli/main.py index e8f643e90..67f711b35 100644 --- a/hermes_cli/main.py +++ b/hermes_cli/main.py @@ -2032,6 +2032,16 @@ def _resolve_stash_selector(git_cmd: list[str], cwd: Path, stash_ref: str) -> Op +def _print_stash_cleanup_guidance(stash_ref: str, stash_selector: Optional[str] = None) -> None: + print(" Check `git status` first so you don't accidentally reapply the same change twice.") + print(" Find the saved entry with: git stash list --format='%gd %H %s'") + if stash_selector: + print(f" Remove it with: git stash drop {stash_selector}") + else: + print(f" Look for commit {stash_ref}, then drop its selector with: git stash drop stash@{{N}}") + + + def _restore_stashed_changes( git_cmd: list[str], cwd: Path, @@ -2072,7 +2082,7 @@ def _restore_stashed_changes( if stash_selector is None: print("⚠ Local changes were restored, but Hermes couldn't find the stash entry to drop.") print(" The stash was left in place. You can remove it manually after checking the result.") - print(f" Look for commit {stash_ref} in `git stash list --format='%gd %H'` and drop that selector.") + _print_stash_cleanup_guidance(stash_ref) else: drop = subprocess.run( git_cmd + ["stash", "drop", stash_selector], @@ -2087,7 +2097,7 @@ def _restore_stashed_changes( if drop.stderr.strip(): print(drop.stderr.strip()) print(" The stash was left in place. You can remove it manually after checking the result.") - print(f" If needed: git stash drop {stash_selector}") + _print_stash_cleanup_guidance(stash_ref, stash_selector) print("⚠ Local changes were restored on top of the updated codebase.") print(" Review `git diff` / `git status` if Hermes behaves unexpectedly.") diff --git a/tests/hermes_cli/test_update_autostash.py b/tests/hermes_cli/test_update_autostash.py index f5a25e971..85523e8df 100644 --- a/tests/hermes_cli/test_update_autostash.py +++ b/tests/hermes_cli/test_update_autostash.py @@ -134,6 +134,16 @@ def test_restore_stashed_changes_applies_without_prompt_when_disabled(monkeypatc +def test_print_stash_cleanup_guidance_with_selector(capsys): + hermes_main._print_stash_cleanup_guidance("abc123", "stash@{2}") + + out = capsys.readouterr().out + assert "Check `git status` first" in out + assert "git stash list --format='%gd %H %s'" in out + assert "git stash drop stash@{2}" in out + + + def test_restore_stashed_changes_keeps_going_when_stash_entry_cannot_be_resolved(monkeypatch, tmp_path, capsys): calls = [] @@ -157,6 +167,8 @@ def test_restore_stashed_changes_keeps_going_when_stash_entry_cannot_be_resolved out = capsys.readouterr().out assert "couldn't find the stash entry to drop" in out assert "stash was left in place" in out + assert "Check `git status` first" in out + assert "git stash list --format='%gd %H %s'" in out assert "Look for commit abc123" in out @@ -183,6 +195,8 @@ def test_restore_stashed_changes_keeps_going_when_drop_fails(monkeypatch, tmp_pa out = capsys.readouterr().out assert "couldn't drop the saved stash entry" in out assert "drop failed" in out + assert "Check `git status` first" in out + assert "git stash list --format='%gd %H %s'" in out assert "git stash drop stash@{0}" in out