30 lines
1.2 KiB
Python
30 lines
1.2 KiB
Python
from chunk_pick import default_plan, unreleased_changes
|
|
from failure import Failure
|
|
from git_repo import file_at, full_history, git
|
|
from comprehension_history import HISTORY, HistoryChange
|
|
|
|
|
|
def history_changes(default: str) -> list[HistoryChange] | Failure:
|
|
"""Each merged change on the default branch that touched the history, newest first; a merge commit counts as one change against its first parent."""
|
|
if partial := full_history():
|
|
return partial
|
|
commits = git("log", "--first-parent", "--format=%H", default, "--", HISTORY)
|
|
if isinstance(commits, Failure):
|
|
return commits
|
|
changes = []
|
|
for commit in commits.split():
|
|
before = file_at(f"{commit}^1", HISTORY)
|
|
if isinstance(before, Failure):
|
|
return before
|
|
after = file_at(commit, HISTORY)
|
|
if isinstance(after, Failure):
|
|
return after
|
|
changes.append(HistoryChange(commit, before, after))
|
|
return changes
|
|
|
|
|
|
def changes_unreleased(root: str, default: str) -> bool | Failure:
|
|
"""Whether the default branch holds a change after its last release, counted as chunk-preflight counts it: `chunk_pick.unreleased_changes`. root is the checkout the git commands run in."""
|
|
changes = unreleased_changes(default_plan(root, default).cut)
|
|
return changes if isinstance(changes, Failure) else changes > 0
|