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/tests/test_workshop_workflow.py, packages/workshop/tests/test_workshop_without_docs.py, packages/workshop/tests/test_workshop_vocabulary.py, packages/workshop/tests/test_workshop_variables.py, packages/workshop/tests/test_workshop_update.py, packages/workshop/tests/test_workshop_tokens.py, packages/workshop/tests/test_workshop_sync_locked.py, packages/workshop/tests/test_workshop_sync_install.py, packages/workshop/tests/test_workshop_sync.py, packages/workshop/tests/test_workshop_sweep.py, packages/workshop/tests/test_workshop_submit.py, packages/workshop/tests/test_workshop_shells.py, packages/workshop/tests/test_workshop_scale.py, packages/workshop/tests/test_workshop_runs.py, packages/workshop/tests/test_workshop_repair.py, packages/workshop/tests/test_workshop_release_driver.py, packages/workshop/tests/test_workshop_registries.py, packages/workshop/tests/test_workshop_publish.py, packages/workshop/tests/test_workshop_public_names.py, packages/workshop/tests/test_workshop_proved_trees.py, packages/workshop/tests/test_workshop_proved.py, packages/workshop/tests/test_workshop_prose.py, packages/workshop/tests/test_workshop_points.py, packages/workshop/tests/test_workshop_new_project.py, packages/workshop/tests/test_workshop_metrics.py, packages/workshop/tests/test_workshop_lifecycle.py, packages/workshop/tests/test_workshop_layering.py, packages/workshop/tests/test_workshop_issue.py, packages/workshop/tests/test_workshop_governance.py, packages/workshop/tests/test_workshop_footprint.py, packages/workshop/tests/test_workshop_fallbacks.py, packages/workshop/tests/test_workshop_extension_mount.py, packages/workshop/tests/test_workshop_env.py, packages/workshop/tests/test_workshop_e2e.py, packages/workshop/tests/test_workshop_dispatch.py, packages/workshop/tests/test_workshop_dev_release.py, packages/workshop/tests/test_workshop_currency.py, packages/workshop/tests/test_workshop_credential_traces.py, packages/workshop/tests/test_workshop_ci_context.py, packages/workshop/tests/test_workshop_balance.py, packages/workshop/tests/test_tools_restub.py, packages/workshop/tests/test_tools_materialise.py, packages/workshop/tests/test_kind_tools.py, packages/extensions/python/tests/test_python_phases.py, packages/extensions/python/tests/test_extensions_python.py, packages/extensions/nanobind/tests/test_kind_publish.py, packages/extensions/nanobind/tests/test_extensions_nanobind.py, packages/extensions/docs/tests/test_task_links.py, packages/extensions/docs/tests/test_docs_verbs.py, packages/extensions/cpp/tests/test_extensions_cpp.py, packages/extensions/conan/tests/test_extensions_conan.py, packages/extensions/conan/tests/test_conan_releases.py, packages/extensions/changelog/tests/test_changelog.py, packages/extensions/agents/tests/test_agents.py 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
11
12from pathlib import Path
13
14from livery import git
15
16
17def stack(root: Path, branch: str) -> tuple[str, str]:
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:
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:
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}")