Skip to content

Commit 9816734

Browse files
committed
refactor: break apart util function for validating branch history and state
1 parent 94fd2b5 commit 9816734

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

scripts/util.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,17 @@ def require_clean_and_up_to_date_repo() -> None:
103103

104104
git("fetch")
105105
git("status", "--porcelain")
106-
if not is_branch_synced_with_remote(develop_branch):
107-
raise ValueError(f"{develop_branch} is not synced with origin/{develop_branch}")
108-
if not is_branch_synced_with_remote(main_branch):
109-
raise ValueError(f"{main_branch} is not synced with origin/{main_branch}")
110-
if not is_ancestor(main_branch, develop_branch):
111-
raise ValueError(f"{main_branch} is not an ancestor of {develop_branch}")
106+
validate_is_synced_ancestor(ancestor=main_branch, descendent=develop_branch)
107+
108+
109+
def validate_is_synced_ancestor(ancestor: str, descendent: str) -> None:
110+
"""Returns whether the given ancestor is actually an up-to-date ancestor of the given descendent branch."""
111+
if not is_branch_synced_with_remote(branch=descendent):
112+
raise ValueError(f"{descendent} is not synced with origin/{descendent}")
113+
if not is_branch_synced_with_remote(branch=ancestor):
114+
raise ValueError(f"{ancestor} is not synced with origin/{ancestor}")
115+
if not is_ancestor(ancestor=ancestor, descendent=descendent):
116+
raise ValueError(f"{ancestor} is not an ancestor of {descendent}")
112117

113118

114119
def is_branch_synced_with_remote(branch: str) -> bool:

0 commit comments

Comments
 (0)