(
target: Path,
kind: str | None,
base_revision: str | None,
head_revision: str | None,
content_digest: str | None,
)
| 798 | |
| 799 | |
| 800 | def require_diff_target( |
| 801 | target: Path, |
| 802 | kind: str | None, |
| 803 | base_revision: str | None, |
| 804 | head_revision: str | None, |
| 805 | content_digest: str | None, |
| 806 | ) -> dict[str, str]: |
| 807 | current_head = require_review_changes_target(target) |
| 808 | if kind not in DIFF_TARGET_KINDS: |
| 809 | raise SystemExit("Choose which Git changes to review before starting a diff scan.") |
| 810 | if kind == "working_tree": |
| 811 | base = resolve_git_commit(target, base_revision or "HEAD", "Working-tree base") |
| 812 | head = resolve_git_commit(target, head_revision or current_head, "Working-tree HEAD") |
| 813 | current_digest = worktree_content_digest(target) |
| 814 | if base != current_head or head != current_head: |
| 815 | raise SystemExit( |
| 816 | "Repository HEAD changed after these working-tree changes were selected. " |
| 817 | "Select Uncommitted changes again." |
| 818 | ) |
| 819 | if content_digest and content_digest != current_digest: |
| 820 | raise SystemExit( |
| 821 | "Working-tree contents changed after they were selected. " |
| 822 | "Select Uncommitted changes again." |
| 823 | ) |
| 824 | return { |
| 825 | "kind": kind, |
| 826 | "baseRevision": current_head, |
| 827 | "headRevision": current_head, |
| 828 | "contentDigest": current_digest, |
| 829 | } |
| 830 | if kind == "commit": |
| 831 | head = resolve_git_commit(target, head_revision or "", "Commit") |
| 832 | commit = git_output(target, "cat-file", "-p", head) |
| 833 | if commit is None: |
| 834 | raise SystemExit(f"Commit is not available in the local checkout: {head}") |
| 835 | parent_line = next( |
| 836 | (line for line in commit.splitlines() if line.startswith("parent ")), |
| 837 | None, |
| 838 | ) |
| 839 | if parent_line is None: |
| 840 | parent = EMPTY_GIT_TREE |
| 841 | else: |
| 842 | parent = resolve_git_commit( |
| 843 | target, |
| 844 | parent_line.removeprefix("parent ").strip(), |
| 845 | "Commit parent", |
| 846 | ) |
| 847 | if base_revision and base_revision != parent: |
| 848 | supplied_base = ( |
| 849 | base_revision |
| 850 | if base_revision == EMPTY_GIT_TREE |
| 851 | else resolve_git_commit(target, base_revision, "Commit base") |
| 852 | ) |
| 853 | if supplied_base != parent: |
| 854 | raise SystemExit("Commit base revision must match the selected commit's parent.") |
| 855 | return {"kind": kind, "baseRevision": parent, "headRevision": head} |
| 856 | base = resolve_git_commit(target, base_revision or "", "Base revision") |
| 857 | head = resolve_git_commit(target, head_revision or "", "Head revision") |
no test coverage detected