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
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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"]:
|
||||
|
||||
Reference in New Issue
Block a user