Answer architecture round 2: split record into its two commands, accept a dated first line only with a Mean line alone, read a default branch without a plan table as empty, and fetch where an answer needs origin as it is

This commit is contained in:
2026-10-09 01:24:48 +02:00
parent 05efbb1d8a
commit 9c2f982741
6 changed files with 108 additions and 57 deletions
+10 -8
View File
@@ -1,6 +1,5 @@
import re
import subprocess
import sys
from failure import Failure
from larv_review.history import HistoryChange
@@ -21,19 +20,22 @@ def top() -> str | Failure:
return found if isinstance(found, Failure) else found.strip()
def default_branch() -> str | Failure:
"""The default branch's ref: `origin/<branch>` after a fetch, with that remote, else the local main or master."""
def default_branch(fetched: bool) -> tuple[str, str | None] | Failure:
"""The default branch's ref, `origin/<branch>` after a fetch with that remote, else the local main or master, and a note for stderr. Unless fetched, a failed fetch reads origin as last fetched, and the note says so."""
remotes = git("remote")
if isinstance(remotes, Failure):
return remotes
if "origin" in remotes.split():
if isinstance(fetched := git("fetch", "--quiet", "origin"), Failure):
print(f"reading origin as last fetched: {fetched.reason}", file=sys.stderr)
fetch = git("fetch", "--quiet", "origin")
if isinstance(fetch, Failure) and fetched:
return fetch
note = f"reading origin as last fetched: {fetch.reason}" if isinstance(fetch, Failure) else None
default = git("symbolic-ref", "--short", "refs/remotes/origin/HEAD")
return default.strip() if not isinstance(default, Failure) else origin_head()
named = default.strip() if not isinstance(default, Failure) else origin_head()
return named if isinstance(named, Failure) else (named, note)
for branch in ("main", "master"):
if not isinstance(git("rev-parse", "--quiet", "--verify", f"refs/heads/{branch}"), Failure):
return branch
return branch, None
return Failure("no origin remote, and no main or master branch to take as the default branch")
@@ -44,7 +46,7 @@ def origin_head() -> str | Failure:
return listed
if named := re.match(r"ref: refs/heads/(\S+)\tHEAD", listed):
return f"origin/{named.group(1)}"
return Failure("origin names no default branch")
return Failure("origin names no default branch; set it with `git remote set-head origin --auto`")
def commit_exists(commit: str) -> bool: