fix(cli): skip the gh lookups that make gh run git on the CLT stub
The review pane's PR refresh (`gh pr view`, on turn settle and focus) and the sidebar's PR badges (`gh repo view`) name no branch or repo, so gh finds them by running git from PATH. On a Mac with only the stub, that launch opened Apple's install dialog, although web_git._run now refuses the stub for Hermes's own git calls. Skip both lookups when git is the stub: the pane reports no PR and the badges report nothing to badge, as they do without a GitHub remote. `gh auth status` needs no repo and still runs, so ghReady stays true.
This commit is contained in:
@@ -514,7 +514,8 @@ def review_ship_info(cwd: str) -> dict:
|
||||
"""gh availability/auth + this branch's PR. ghReady false when gh missing/unauthed."""
|
||||
if not _is_dir(cwd) or not _gh(cwd, ["auth", "status"])[0]:
|
||||
return {"ghReady": False, "pr": None}
|
||||
pr = _gh_json(cwd, ["pr", "view", "--json", "url,state,number"])
|
||||
# gh finds this branch and its repo by running git, so the CLT-stub guard applies to it too.
|
||||
pr = None if _git_argv0_unusable(["git"]) else _gh_json(cwd, ["pr", "view", "--json", "url,state,number"])
|
||||
if pr and pr.get("url"):
|
||||
return {"ghReady": True, "pr": {"url": pr["url"], "state": pr.get("state"), "number": pr.get("number")}}
|
||||
return {"ghReady": True, "pr": None}
|
||||
@@ -565,7 +566,7 @@ def review_pr_list(cwd: str, branches: list[str], numbers: list[int] | None = No
|
||||
return not_ready
|
||||
wanted = list(dict.fromkeys(str(b) for b in (branches or []) if b))[:_PR_QUERY_BRANCH_CAP]
|
||||
by_number = list(dict.fromkeys(int(n) for n in (numbers or []) if n))[:_PR_QUERY_BRANCH_CAP]
|
||||
if not wanted and not by_number:
|
||||
if (not wanted and not by_number) or _git_argv0_unusable(["git"]): # gh reads the repo from git
|
||||
return not_ready
|
||||
repo_ok, repo_out, _repo_err = _gh(cwd, ["repo", "view", "--json", "nameWithOwner", "-q", ".nameWithOwner"])
|
||||
owner, _, name = repo_out.strip().partition("/")
|
||||
|
||||
@@ -339,6 +339,28 @@ def test_clt_stub_plugin_git_falls_back_to_no_git_not_to_the_stub(tmp_path, monk
|
||||
assert not spawn_log.exists(), f"git stub was spawned: {spawn_log.read_text()}"
|
||||
|
||||
|
||||
@pytest.mark.platforms("posix")
|
||||
def test_clt_stub_skips_gh_calls_that_make_gh_run_git(tmp_path, clt_stub_env):
|
||||
"""The review pane's PR refresh and the sidebar's PR badges ask gh about "this repo", which gh
|
||||
answers by running git; ``gh auth status`` needs no repo and still runs."""
|
||||
from hermes_cli import web_git
|
||||
|
||||
trap_bin, _trap_git, spawn_log = clt_stub_env
|
||||
gh_log = tmp_path / "gh.log"
|
||||
_make_exe(
|
||||
trap_bin / "gh",
|
||||
f"#!/usr/bin/env bash\nprintf '%s\\n' \"$*\" >> {str(gh_log)!r}\n"
|
||||
"[ \"$1\" = auth ] && exit 0\ngit rev-parse --abbrev-ref HEAD >/dev/null 2>&1\nexit 1\n",
|
||||
)
|
||||
repo = tmp_path / "repo"
|
||||
repo.mkdir()
|
||||
|
||||
assert web_git.review_ship_info(str(repo)) == {"ghReady": True, "pr": None}
|
||||
assert web_git.review_pr_list(str(repo), ["main"]) == {"ghReady": False, "prs": []}
|
||||
assert gh_log.read_text().splitlines() == ["auth status"]
|
||||
assert not spawn_log.exists(), f"git stub was spawned: {spawn_log.read_text()}"
|
||||
|
||||
|
||||
@pytest.mark.platforms("posix")
|
||||
def test_clt_stub_never_spawns_review_commit_identity_or_commit(tmp_path, clt_stub_env):
|
||||
"""The review pane's commit reads the identity with ``git var`` before any ``_git_in`` call."""
|
||||
|
||||
Reference in New Issue
Block a user