Coverage for packages/workshop/src/livery/workshop/_stack.py: 100%

Measured by coverage.py 7.16.2 on CPython 3.14 while the suites of tests, packages/workshop, packages/extensions/ty, packages/extensions/ruff, packages/extensions/python, packages/extensions/pytest, packages/extensions/pyrefly, packages/extensions/nanobind, packages/extensions/mypy, packages/extensions/mkdocstrings, packages/extensions/lfs, packages/extensions/docs, packages/extensions/cpp, packages/extensions/coverage, packages/extensions/conan, packages/extensions/cmake, packages/extensions/claude, packages/extensions/clang-tidy, packages/extensions/clang-format, packages/extensions/changelog, packages/extensions/basedpyright ran.

1"""The stack a branch was started on, recorded in the checkout's git config.
2
3``fm start --from`` records a branch's parent and the parent's tip at
4the start as ``branch.<name>.workshop-parent`` and
5``branch.<name>.workshop-parent-tip``; a sync, a submit and the
6issue verbs read them back here. A branch standing on main has
7neither key.
8"""
9
10from __future__ import annotations(empty)
11
12from pathlib import Path(empty)
13
14from livery import git(empty)
15
16
17def stack(root: Path, branch: str) -> tuple[str, str]:(empty)
18 """The parent *branch* was started on, and the commit it started from.
19
20 Both are empty for a branch started on main; the commit is empty
21 for a branch started before it was recorded. One process for both
22 keys: a flow reads the stack several times.
23 """
24 prefix = f"branch.{branch}.workshop-parent"
25 found = git.config_regexp(root, f"^{prefix}(-tip)?$")
26 parent = found.get(prefix, "")
27 return parent, found.get(f"{prefix}-tip", "") if parent else ""
28
29
30def record_stack(root: Path, branch: str, parent: str, tip: str) -> None:(empty)
31 """Record *branch* as stacked on *parent*, its own commits after *tip*."""
32 git.config_set(root, f"branch.{branch}.workshop-parent", parent)
33 git.config_set(root, f"branch.{branch}.workshop-parent-tip", tip)
34
35
36def forget_stack(root: Path, branch: str) -> None:(empty)
37 """Drop the stack record: *branch* stands on main now."""
38 for key in ("workshop-parent", "workshop-parent-tip"):
39 git.config_unset(root, f"branch.{branch}.{key}")