Skip to content

Commit

Permalink
compare git hashes for submit
Browse files Browse the repository at this point in the history
  • Loading branch information
rkansal47 committed Mar 5, 2024
1 parent 624b840 commit b6237c0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
26 changes: 14 additions & 12 deletions src/HHbbVV/run_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import json
import os
import time
import subprocess
from pathlib import Path
from string import Template

Expand Down Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion src/condor/submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}/")
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/condor/submit_pp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand Down

0 comments on commit b6237c0

Please sign in to comment.