Skip to content

Commit 35b918b

Browse files
committed
feat: add a check to the setup-release script in generated project along with light refactors
1 parent 6b02056 commit 35b918b

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

{{cookiecutter.project_name}}/scripts/setup-release.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import subprocess
55
from typing import Optional
66

7+
from scripts.util import require_clean_and_up_to_date_repo
78
from util import REPO_FOLDER
89
from util import bump_version
910
from util import check_dependencies
@@ -42,6 +43,7 @@ def setup_release(increment: Optional[str] = None) -> None:
4243
release or push any changes.
4344
"""
4445
check_dependencies(path=REPO_FOLDER, dependencies=["git"])
46+
require_clean_and_up_to_date_repo()
4547

4648
current_version: str = get_package_version()
4749
new_version: str = get_bumped_package_version(increment=increment)

{{cookiecutter.project_name}}/scripts/util.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111

1212
REPO_FOLDER: Path = Path(__file__).resolve().parent.parent
13+
MAIN_BRANCH: str = "main"
14+
DEVELOP_BRANCH: str = "develop"
1315

1416

1517
class MissingDependencyError(Exception):
@@ -34,6 +36,22 @@ def check_dependencies(path: Path, dependencies: list[str]) -> None:
3436
raise MissingDependencyError(path, dependency) from e
3537

3638

39+
def require_clean_and_up_to_date_repo() -> None:
40+
"""Checks if the repo is clean and up to date with any important branches."""
41+
commands: list[list[str]] = [
42+
["git", "fetch"],
43+
["git", "merge-base", "--is-ancestor", MAIN_BRANCH, f"origin/{MAIN_BRANCH}"],
44+
["git", "merge-base", "--is-ancestor", f"origin/{MAIN_BRANCH}", MAIN_BRANCH],
45+
["git", "merge-base", "--is-ancestor", DEVELOP_BRANCH, f"origin/{DEVELOP_BRANCH}"],
46+
["git", "merge-base", "--is-ancestor", f"origin/{DEVELOP_BRANCH}", DEVELOP_BRANCH],
47+
["git", "merge-base", "--is-ancestor", MAIN_BRANCH, DEVELOP_BRANCH],
48+
["git", "status", "--porcelain"],
49+
]
50+
51+
for command in commands:
52+
subprocess.run(command, cwd=REPO_FOLDER, check=True)
53+
54+
3755
def existing_dir(value: str) -> Path:
3856
"""Responsible for validating argparse inputs and returning them as pathlib Path's if they meet criteria."""
3957
path = Path(value).expanduser().resolve()

0 commit comments

Comments
 (0)