Skip to content

The agent that grows with you

fix(update): only local git's own 'not a git repository' reads as a damaged checkout

Tekniume323c5381b88
diff --git a/hermes_cli/update_cmd_git.py b/hermes_cli/update_cmd_git.py
index c4b2e5c750a..3160ff7ede5 100644
--- a/hermes_cli/update_cmd_git.py
+++ b/hermes_cli/update_cmd_git.py
@@ -510,9 +510,12 @@ def _damaged_checkout_message() -> str:
# answered with HTTP 401 ("could not read Username") is GitHub during an outage (or a renamed/private
# repo), not a user credentials problem. A diagnosis may be a callable when it depends on the host.
_FETCH_FAILURE_RULES = (
- # The updater only fetches when .git exists, so this is a .git git rejects (empty dir, lost HEAD):
- # no retry can work and the ZIP fallback cannot tell user edits apart, but the installer can.
- (lambda s: "not a git repository" in s, _damaged_checkout_message),
+ # The updater only fetches when .git exists, so local git saying this about itself is a .git it
+ # rejects (empty dir, lost HEAD): no retry can work and the ZIP fallback cannot tell user edits
+ # apart, but the installer can. Line-anchored: a remote's own refusal arrives as "'<path>' does
+ # not appear to be a git repository" or relayed under "remote: ", and reinstalling cannot fix it.
+ (lambda s: any(line.startswith("fatal: not a git repository") for line in s.splitlines()),
+ _damaged_checkout_message),
(lambda s: _has_http_code(s, "429") or "rate limit" in s.lower(),
"✗ GitHub is rate limiting requests or having an outage (HTTP 429) — try again in 5 minutes."),
(lambda s: _has_http_code(s, "500", "502", "503", "504"),
diff --git a/tests/hermes_cli/test_update_fetch_failure_classifier.py b/tests/hermes_cli/test_update_fetch_failure_classifier.py
index a9ecdfd684d..b1c63b3325d 100644
--- a/tests/hermes_cli/test_update_fetch_failure_classifier.py
+++ b/tests/hermes_cli/test_update_fetch_failure_classifier.py
@@ -92,6 +92,16 @@ class TestClassifyFetchFailure:
assert "damaged" in msg
assert "hermes-agent.nousresearch.com/install." in msg
+ # A healthy checkout whose REMOTE is the broken one: reinstalling Hermes cannot fix that.
+ healthy = tmp_path / "healthy"
+ healthy.mkdir()
+ subprocess.run(["git", "init", "-q", str(healthy)], check=True)
+ remote = subprocess.run(["git", "fetch", str(tmp_path)], cwd=healthy, capture_output=True, check=False,
+ text=True, encoding="utf-8", errors="replace").stderr
+ for stderr in (remote, "remote: fatal: not a git repository (or any of the parent directories): .git\n"
+ "fatal: Could not read from remote repository."):
+ assert "damaged" not in update_cmd._classify_fetch_failure(stderr), stderr
+
def test_ssh_host_key_failure_reports_ssh_auth(self):
msg = update_cmd._classify_fetch_failure(
"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"