From b6237c026a7cbf0f20507ba10d8dc574f1d2e8f9 Mon Sep 17 00:00:00 2001 From: rkansal47 Date: Tue, 5 Mar 2024 11:42:18 -0600 Subject: [PATCH] compare git hashes for submit --- src/HHbbVV/run_utils.py | 26 ++++++++++++++------------ src/condor/submit.py | 10 +++++++++- src/condor/submit_pp.py | 2 +- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/HHbbVV/run_utils.py b/src/HHbbVV/run_utils.py index e83fa845..ebde4160 100644 --- a/src/HHbbVV/run_utils.py +++ b/src/HHbbVV/run_utils.py @@ -3,7 +3,7 @@ import json import os -import time +import subprocess from pathlib import Path from string import Template @@ -51,23 +51,25 @@ def add_mixins(nanoevents): nanoevents.PFNanoAODSchema.mixins["SV"] = "PFCand" -def check_branch_exists(git_branch: str): - """Check that specified git branch exists in the repo""" +def check_branch(git_branch: str, allow_diff_local_repo: bool = False): + """Check that specified git branch exists in the repo, and local repo is up-to-date""" assert not bool( os.system( f'git ls-remote --exit-code --heads "https://github.com/rkansal47/HHbbVV" "{git_branch}"' ) ), f"Branch {git_branch} does not exist" - print(f"Using the {git_branch} branch.") - print_red("-----------Important!------------") - print_red("-----------Important!------------") - print_red("-----------Important!------------") - print_red("Did you push your changes to github?") - print_red("-----------Important!------------") - print_red("-----------Important!------------") - print_red("-----------Important!------------") - time.sleep(5) + remote_hash = subprocess.getoutput(f"git show origin/{git_branch} | head -n 1").split(" ")[1] + local_hash = subprocess.getoutput("git rev-parse HEAD") + + if remote_hash != local_hash: + print_red("Latest local and github commits do not match!") + print(f"Local commit hash: {local_hash}") + print(f"Remote commit hash: {remote_hash}") + if allow_diff_local_repo: + print("Proceeding anyway...") + else: + print_red("Exiting! Use the --allow-diff-local-repo option to override this.") # for Dask executor diff --git a/src/condor/submit.py b/src/condor/submit.py index bd2ec619..3c071ced 100755 --- a/src/condor/submit.py +++ b/src/condor/submit.py @@ -38,7 +38,7 @@ def get_site_vars(site): def main(args): - run_utils.check_branch_exists(args.git_branch) + run_utils.check_branch(args.git_branch, args.allow_diff_local_repo) username, t2_local_prefix, t2_prefix, proxy = get_site_vars(args.site) homedir = Path(f"store/user/{username}/bbVV/{args.processor}/") @@ -151,6 +151,14 @@ def parse_args(parser): parser, "submit", default=False, help="submit files as well as create them" ) + run_utils.add_bool_arg( + parser, + "allow-diff-local-repo", + default=False, + help="Allow the local repo to be different from the specified remote repo (not recommended!)." + "If false, submit script will exit if the latest commits locally and on Github are different.", + ) + if __name__ == "__main__": parser = argparse.ArgumentParser() diff --git a/src/condor/submit_pp.py b/src/condor/submit_pp.py index dfc1d380..069d552a 100755 --- a/src/condor/submit_pp.py +++ b/src/condor/submit_pp.py @@ -137,7 +137,7 @@ def main(args): username, t2_local_prefix, t2_prefix, proxy = submit.get_site_vars(args.site) - run_utils.check_branch_exists(args.git_branch) + run_utils.check_branch(args.git_branch, args.allow_diff_local_repo) local_dir = f"condor/postprocessing/{args.tag}" homedir = f"/store/user/{username}/bbVV/templates/"