From 67ae7a79df0feaae6bbe395a6005b2e7218d7259 Mon Sep 17 00:00:00 2001 From: Teknium Date: Fri, 3 Apr 2026 01:37:44 -0700 Subject: [PATCH] fix: use get_hermes_home(), consolidate git_cmd, update tests Follow-up for salvaged PR #2352: - Replace hardcoded Path(os.getenv('HERMES_HOME', ...)) with get_hermes_home() from hermes_constants (2 places) - Consolidate redundant git_cmd_base into the existing git_cmd variable, constructed once before fork detection - Update autostash tests for the unmerged index check added in the previous commit --- hermes_cli/main.py | 20 +++++++++----------- tests/hermes_cli/test_update_autostash.py | 9 +++++++-- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/hermes_cli/main.py b/hermes_cli/main.py index a53694bb8..52c12c104 100644 --- a/hermes_cli/main.py +++ b/hermes_cli/main.py @@ -2942,15 +2942,15 @@ def _count_commits_between(git_cmd: list[str], cwd: Path, base: str, head: str) def _should_skip_upstream_prompt() -> bool: """Check if user previously declined to add upstream.""" - hermes_home = Path(os.getenv("HERMES_HOME", Path.home() / ".hermes")) - return (hermes_home / SKIP_UPSTREAM_PROMPT_FILE).exists() + from hermes_constants import get_hermes_home + return (get_hermes_home() / SKIP_UPSTREAM_PROMPT_FILE).exists() def _mark_skip_upstream_prompt(): """Create marker file to skip future upstream prompts.""" try: - hermes_home = Path(os.getenv("HERMES_HOME", Path.home() / ".hermes")) - (hermes_home / SKIP_UPSTREAM_PROMPT_FILE).touch() + from hermes_constants import get_hermes_home + (get_hermes_home() / SKIP_UPSTREAM_PROMPT_FILE).touch() except Exception: pass @@ -3210,12 +3210,13 @@ def cmd_update(args): cwd=PROJECT_ROOT, check=False, capture_output=True ) - # Detect if we're updating from a fork (before any branch logic) - git_cmd_base = ["git"] + # Build git command once — reused for fork detection and the update itself. + git_cmd = ["git"] if sys.platform == "win32": - git_cmd_base = ["git", "-c", "windows.appendAtomically=false"] + git_cmd = ["git", "-c", "windows.appendAtomically=false"] - origin_url = _get_origin_url(git_cmd_base, PROJECT_ROOT) + # Detect if we're updating from a fork (before any branch logic) + origin_url = _get_origin_url(git_cmd, PROJECT_ROOT) is_fork = _is_fork(origin_url) if is_fork: @@ -3230,9 +3231,6 @@ def cmd_update(args): # Fetch and pull try: - git_cmd = ["git"] - if sys.platform == "win32": - git_cmd = ["git", "-c", "windows.appendAtomically=false"] print("→ Fetching updates...") fetch_result = subprocess.run( diff --git a/tests/hermes_cli/test_update_autostash.py b/tests/hermes_cli/test_update_autostash.py index 66a444de8..f97c6c35f 100644 --- a/tests/hermes_cli/test_update_autostash.py +++ b/tests/hermes_cli/test_update_autostash.py @@ -32,6 +32,8 @@ def test_stash_local_changes_if_needed_returns_specific_stash_commit(monkeypatch calls.append((cmd, kwargs)) if cmd[-2:] == ["status", "--porcelain"]: return SimpleNamespace(stdout=" M hermes_cli/main.py\n?? notes.txt\n", returncode=0) + if cmd[-2:] == ["ls-files", "--unmerged"]: + return SimpleNamespace(stdout="", returncode=0) if cmd[1:4] == ["stash", "push", "--include-untracked"]: return SimpleNamespace(stdout="Saved working directory\n", returncode=0) if cmd[-3:] == ["rev-parse", "--verify", "refs/stash"]: @@ -43,8 +45,9 @@ def test_stash_local_changes_if_needed_returns_specific_stash_commit(monkeypatch stash_ref = hermes_main._stash_local_changes_if_needed(["git"], tmp_path) assert stash_ref == "abc123" - assert calls[1][0][1:4] == ["stash", "push", "--include-untracked"] - assert calls[2][0][-3:] == ["rev-parse", "--verify", "refs/stash"] + assert calls[1][0][-2:] == ["ls-files", "--unmerged"] + assert calls[2][0][1:4] == ["stash", "push", "--include-untracked"] + assert calls[3][0][-3:] == ["rev-parse", "--verify", "refs/stash"] def test_resolve_stash_selector_returns_matching_entry(monkeypatch, tmp_path): @@ -296,6 +299,8 @@ def test_stash_local_changes_if_needed_raises_when_stash_ref_missing(monkeypatch 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"]: return SimpleNamespace(stdout="Saved working directory\n", returncode=0) if cmd[-3:] == ["rev-parse", "--verify", "refs/stash"]: