1010
1111
1212REPO_FOLDER : Path = Path (__file__ ).resolve ().parent .parent
13+ MAIN_BRANCH : str = "main"
14+ DEVELOP_BRANCH : str = "develop"
1315
1416
1517class 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+
3755def 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