Answer product-owner round 1: 0 🔴, 4 🟡 (0 misread); move through the open status, refuse open-epic without a branch, tell a conflict from git's other failures

This commit is contained in:
Lilleman
2026-11-20 20:15:33 +01:00
parent 9f367e90ca
commit ce2e9dc0e5
9 changed files with 143 additions and 21 deletions
+21 -4
View File
@@ -1,12 +1,14 @@
"""Keep an epic's working branch on origin: made off the default branch by the epic's first chunk, and level with it before each chunk starts and before the epic's own pull request opens (docs/decisions.md → `epic-branch: an epic's chunks branch off and merge into a working branch …`)."""
import re
from failure import Failure
from git_cli.git_repo import Git, git
def levelled(branch: str, default: str, cwd: str | None = None, timeout: float | None = None, run: Git = git) -> str | Failure:
def levelled(branch: str, default: str, cwd: str | None = None, timeout: float | None = None, run: Git = git, again: bool = True) -> str | Failure:
"""Brings origin's branch level with default, the default branch's ref, such as `origin/main`, and fetches it: what it did, as a sentence. Where origin has no such branch, it makes one at default.
It merges with a merge commit, never a rebase, since several chunks share the branch, and without a checkout, since no worktree has the branch checked out. A Failure where the two don't merge cleanly: a person resolves that, never the loop. A call to origin still running after timeout seconds fails."""
It merges with a merge commit, never a rebase, since several chunks share the branch, and without a checkout, since no worktree has the branch checked out. A Failure where the two don't merge cleanly: a person resolves that, never the loop. A call to origin still running after timeout seconds fails. Where the merge's push fails, as when another chunk pushed its own merge first, it fetches and levels once more, unless again is False."""
fetched = run("fetch", "--quiet", "origin", cwd=cwd, timeout=timeout)
if isinstance(fetched, Failure):
return fetched
@@ -21,11 +23,26 @@ def levelled(branch: str, default: str, cwd: str | None = None, timeout: float |
# git 2.38 or later: merges two commits into a tree without a checkout.
tree = run("merge-tree", "--write-tree", ours, default, cwd=cwd)
if isinstance(tree, Failure):
return Failure(f"{default} doesn't merge into {ours} cleanly, so a person merges it: check {branch} out, run `git merge {default}`, resolve the conflicts and push")
return unmerged(tree, branch, default)
commit = run("commit-tree", tree.strip(), "-p", ours, "-p", default, "-m", f"Merge remote-tracking branch '{default}' into {branch}", cwd=cwd)
if isinstance(commit, Failure):
return commit
return pushed(commit.strip(), branch, cwd, timeout, run) or f"Merged {default} into {ours}."
failed = pushed(commit.strip(), branch, cwd, timeout, run)
if failed and again:
return levelled(branch, default, cwd, timeout, run, again=False)
return failed or f"Merged {default} into {ours}."
def unmerged(failed: Failure, branch: str, default: str) -> Failure:
"""Why `git merge-tree --write-tree` didn't merge default into origin's branch, from its Failure.
A conflict prints nothing on stderr, so its reason ends at `git <command>:`, or, from a runner that shows stdout in place of an empty stderr, goes on with the merged tree's id. Git older than 2.38 reads --write-tree as a commit, which it doesn't find. Any other Failure is git's own."""
ours = f"origin/{branch}"
if re.fullmatch(r"git merge-tree [^:]*:\s*(?:[0-9a-f]{40,64}\b.*)?", failed.reason, re.DOTALL):
return Failure(f"{default} doesn't merge into {ours} cleanly, so a person merges it: check {branch} out, run `git merge {default}`, resolve the conflicts and push")
if "unknown rev --write-tree" in failed.reason:
return Failure(f"levelling {ours} with {default} needs git 2.38 or later: {failed.reason}")
return failed
def pushed(commit: str, branch: str, cwd: str | None, timeout: float | None, run: Git) -> Failure | None: