Skip to content

Commit c3f1a3c

Browse files
committed
refactor: rename script function to reflect usage only occurring in demo
1 parent 1b56f02 commit c3f1a3c

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

scripts/lint-from-demo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from util import git
2222
from util import FolderOption
2323
from util import in_new_demo
24-
from util import require_clean_and_up_to_date_repo
24+
from util import require_clean_and_up_to_date_demo_repo
2525

2626

2727
# These still may need linted, but retrocookie shouldn't be used on them
@@ -46,7 +46,7 @@ def lint_from_demo(
4646
add_rust_extension=add_rust_extension,
4747
no_cache=no_cache
4848
) as demo_path:
49-
require_clean_and_up_to_date_repo(demo_path=demo_path)
49+
require_clean_and_up_to_date_demo_repo(demo_path=demo_path)
5050
git("checkout", DEMO.develop_branch)
5151
git("branch", "-D", "temp/lint-from-demo", ignore_error=True)
5252
git("checkout", "-b", "temp/lint-from-demo", DEMO.develop_branch)

scripts/release-demo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from util import gh
2323
from util import git
2424
from util import nox
25-
from util import require_clean_and_up_to_date_repo
25+
from util import require_clean_and_up_to_date_demo_repo
2626
from util import FolderOption
2727
from util import DEMO
2828

@@ -40,7 +40,7 @@ def release_demo(
4040
demo_path: Path = demos_cache_folder / demo_name
4141

4242
with work_in(demo_path):
43-
require_clean_and_up_to_date_repo(demo_path)
43+
require_clean_and_up_to_date_demo_repo(demo_path)
4444
git("checkout", DEMO.develop_branch)
4545
try:
4646
nox("setup-release", "--", "MINOR")

scripts/update-demo.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
# ]
99
# ///
1010

11-
import sys
1211
from pathlib import Path
1312
from subprocess import CompletedProcess
1413
from typing import Annotated
@@ -20,14 +19,15 @@
2019

2120
from util import DEMO
2221
from util import is_ancestor
22+
from util import is_merge_commit
2323
from util import get_current_branch
2424
from util import get_current_commit
2525
from util import get_demo_name
2626
from util import get_last_cruft_update_commit
2727
from util import git
2828
from util import FolderOption
2929
from util import REPO_FOLDER
30-
from util import require_clean_and_up_to_date_repo
30+
from util import require_clean_and_up_to_date_demo_repo
3131
from util import TEMPLATE
3232
from util import uv
3333

@@ -48,9 +48,8 @@ def update_demo(
4848

4949
current_branch: str = get_current_branch()
5050
template_commit: str = get_current_commit()
51-
5251
_validate_template_main_not_checked_out(branch=current_branch)
53-
require_clean_and_up_to_date_repo(demo_path=demo_path)
52+
require_clean_and_up_to_date_demo_repo(demo_path=demo_path)
5453
_checkout_demo_develop_or_existing_branch(demo_path=demo_path, branch=current_branch)
5554
last_update_commit: str = get_last_cruft_update_commit(demo_path=demo_path)
5655

scripts/util.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def run_command(command: str, *args: str, ignore_error: bool = False) -> Optiona
126126
gh: partial[subprocess.CompletedProcess] = partial(run_command, "gh")
127127

128128

129-
def require_clean_and_up_to_date_repo(demo_path: Path) -> None:
129+
def require_clean_and_up_to_date_demo_repo(demo_path: Path) -> None:
130130
"""Checks if the repo is clean and up to date with any important branches."""
131131
try:
132132
with work_in(demo_path):
@@ -162,6 +162,16 @@ def is_ancestor(ancestor: str, descendent: str) -> bool:
162162
return False
163163

164164

165+
def is_merge_commit() -> bool:
166+
"""Returns whether the latest commit was a merge commit."""
167+
output: str = git("log", "--format=%P", "-n", "1", "HEAD").stdout.strip()
168+
if output == "":
169+
raise ValueError("No existing commit was found.")
170+
171+
parent_count: int = len(output.split(" "))
172+
return parent_count > 1
173+
174+
165175
def get_current_branch() -> str:
166176
"""Returns the current branch name."""
167177
return git("branch", "--show-current").stdout.strip()

0 commit comments

Comments
 (0)