-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BFB]
- Loading branch information
Showing
3 changed files
with
242 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env python | ||
|
||
""" | ||
A script to merge ESMCI's cime development and make it into a PR for ACME | ||
""" | ||
|
||
from standard_script_setup import * | ||
from acme_cime_mgmt import * | ||
|
||
import sys, os, argparse | ||
|
||
############################################################################### | ||
def parse_command_line(args, description): | ||
############################################################################### | ||
parser = argparse.ArgumentParser( | ||
usage="""\n{0} [--verbose] | ||
OR | ||
{0} --help | ||
""".format(os.path.basename(args[0])), | ||
|
||
description=description, | ||
|
||
formatter_class=argparse.ArgumentDefaultsHelpFormatter | ||
) | ||
|
||
CIME.utils.setup_standard_logging_options(parser) | ||
|
||
parser.add_argument("repo", nargs="?", | ||
help="Location of repo to use, default is based on current location") | ||
|
||
parser.add_argument("--resume", action="store_true", | ||
help="Resume merge after fixing conflicts") | ||
|
||
args = CIME.utils.parse_args_and_handle_standard_logging_options(args, parser) | ||
|
||
return args.repo, args.resume | ||
|
||
############################################################################### | ||
def _main_func(description): | ||
############################################################################### | ||
repo, resume = parse_command_line(sys.argv, description) | ||
|
||
if repo is not None: | ||
os.chdir(repo) | ||
|
||
acme_cime_merge(resume) | ||
|
||
############################################################################### | ||
|
||
if (__name__ == "__main__"): | ||
_main_func(__doc__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,15 +5,10 @@ A script to split-off ACME's cime development and make it into a PR for ESMCI | |
""" | ||
|
||
from standard_script_setup import * | ||
from CIME.utils import run_cmd, run_cmd_no_fail, expect, get_timestamp | ||
from acme_cime_mgmt import * | ||
from CIME.utils import expect | ||
|
||
import sys, os, argparse, getpass | ||
|
||
# Constants | ||
ESMCI_REMOTE_NAME = "esmci_remote_for_split" | ||
ESMCI_URL = "[email protected]:ESMCI/CIME.git" | ||
SPLIT_TAG_PREFIX = "acme-split-" | ||
MERGE_TAG_PREFIX = "to-acme-" | ||
import sys, os, argparse | ||
|
||
############################################################################### | ||
def parse_command_line(args, description): | ||
|
@@ -46,140 +41,6 @@ formatter_class=argparse.ArgumentDefaultsHelpFormatter | |
|
||
return args.repo, args.resume_one, args.resume_two | ||
|
||
############################################################################### | ||
def setup(): | ||
############################################################################### | ||
run_cmd_no_fail("git config merge.renameLimit 999999") | ||
run_cmd_no_fail("git checkout master && git pull && git submodule update --init") | ||
|
||
remotes = run_cmd_no_fail("git remote") | ||
if ESMCI_REMOTE_NAME not in remotes: | ||
run_cmd_no_fail("git remote add {} {}".format(ESMCI_REMOTE_NAME, ESMCI_URL)) | ||
|
||
run_cmd_no_fail("git fetch {}".format(ESMCI_REMOTE_NAME)) | ||
run_cmd_no_fail("git fetch {} --tags".format(ESMCI_REMOTE_NAME)) | ||
|
||
############################################################################### | ||
def get_old_tag(prefix, expected_num=1): | ||
############################################################################### | ||
tags = run_cmd_no_fail("git tag").split() | ||
old_tags = [tag for tag in tags if tag.startswith(prefix)] | ||
|
||
expect(len(old_tags) == expected_num, "Expected exactly {} old {} tag, found {}".format(expected_num, prefix, ", ".join(old_tags))) | ||
|
||
if expected_num == 1: | ||
return old_tags[0] | ||
else: | ||
return old_tags | ||
|
||
############################################################################### | ||
def get_old_split_tag(): | ||
############################################################################### | ||
return get_old_tag(SPLIT_TAG_PREFIX) | ||
|
||
############################################################################### | ||
def get_split_tags(): | ||
############################################################################### | ||
return get_old_tag(SPLIT_TAG_PREFIX, expected_num=2) | ||
|
||
############################################################################### | ||
def get_merge_tag(): | ||
############################################################################### | ||
return get_old_tag(MERGE_TAG_PREFIX) | ||
|
||
############################################################################### | ||
def make_new_tag(prefix, old_tag, remote="origin", commit="HEAD"): | ||
############################################################################### | ||
new_tag = "{}{}".format(prefix, get_timestamp(timestamp_format="%m-%d-%Y")) | ||
expect(old_tag != new_tag, "New tag must have different name than old tag") | ||
|
||
run_cmd_no_fail("git tag {} {}".format(new_tag, commit)) | ||
run_cmd_no_fail("git push {} {}".format(remote, new_tag)) | ||
|
||
return new_tag | ||
|
||
############################################################################### | ||
def make_new_split_tag(old_split_tag): | ||
############################################################################### | ||
return make_new_tag(SPLIT_TAG_PREFIX, old_split_tag) | ||
|
||
############################################################################### | ||
def do_subtree_split(old_split_tag, new_split_tag, merge_tag): | ||
############################################################################### | ||
subtree_branch = "{}/branch-for-{}".format(getpass.getuser(), new_split_tag) | ||
run_cmd_no_fail("git subtree split {}.. --prefix=cime --onto={} --ignore-joins -b {}".\ | ||
format(old_split_tag, merge_tag, subtree_branch)) | ||
return subtree_branch | ||
|
||
############################################################################### | ||
def make_pr_branch(subtree_branch, merge_tag): | ||
############################################################################### | ||
pr_branch = "{}-pr".format(subtree_branch) | ||
run_cmd_no_fail("git checkout -b {} {}".format(pr_branch, merge_tag)) | ||
|
||
return pr_branch | ||
|
||
############################################################################### | ||
def merge_branch(branch, resume_count): | ||
############################################################################### | ||
stat = run_cmd("git merge -m 'Merge {}' -X rename-threshold=25 {}".format(branch, branch))[0] | ||
if stat != 0: | ||
logging.info("There are merge conflicts. Please fix, commit, and re-run this tool with --resume-{}".format(resume_count)) | ||
sys.exit(1) | ||
|
||
############################################################################### | ||
def merge_pr_branch_1(subtree_branch): | ||
############################################################################### | ||
merge_branch(subtree_branch, "one") | ||
|
||
############################################################################### | ||
def merge_pr_branch_2(): | ||
############################################################################### | ||
merge_branch("{}/master".format(ESMCI_REMOTE_NAME), "two") | ||
|
||
############################################################################### | ||
def delete_tag(tag, remote="origin"): | ||
############################################################################### | ||
run_cmd_no_fail("git tag -d {}".format(tag)) | ||
run_cmd_no_fail("git push {} :refs/tags/{}".format(remote, tag)) | ||
|
||
############################################################################### | ||
def acme_cime_split(resume_one, resume_two): | ||
############################################################################### | ||
if not resume_one and not resume_two: | ||
setup() | ||
|
||
old_split_tag = get_old_split_tag() | ||
|
||
try: | ||
new_split_tag = make_new_split_tag(old_split_tag) | ||
|
||
merge_tag = get_merge_tag() | ||
|
||
subtree_branch = do_subtree_split(old_split_tag, new_split_tag, merge_tag) | ||
|
||
pr_branch = make_pr_branch(subtree_branch, merge_tag) | ||
except: | ||
# If unexpected failure happens, delete new split tag | ||
delete_tag(new_split_tag) | ||
raise | ||
|
||
merge_pr_branch_1(subtree_branch) | ||
else: | ||
old_split_tag, new_split_tag = get_split_tags() | ||
pr_branch = "{}/branch-for-{}-pr".format(getpass.getuser(), new_split_tag) | ||
|
||
if not resume_two: | ||
merge_pr_branch_2() | ||
|
||
try: | ||
run_cmd_no_fail("git push {} {}".format(ESMCI_REMOTE_NAME, pr_branch)) | ||
except: | ||
delete_tag(old_split_tag) | ||
raise | ||
|
||
delete_tag(old_split_tag) | ||
|
||
############################################################################### | ||
def _main_func(description): | ||
############################################################################### | ||
|
Oops, something went wrong.