diff --git a/.circleci/config.yml b/.circleci/config.yml index 27563c97503b4..0ebe24477ef5d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -218,6 +218,7 @@ step-gclient-sync: &step-gclient-sync "$CIRCLE_REPOSITORY_URL" if ! gclient sync --with_branch_heads --with_tags; then + python src/electron/script/reset_patched_repos.py if ELECTRON_USE_THREE_WAY_MERGE_FOR_PATCHES=1 gclient sync -f --with_branch_heads --with_tags; then # Re-export all the new patches now that they've been nicely 3-way # merged diff --git a/script/lib/git.py b/script/lib/git.py index bcf685ad67aaa..ad9cee9a85243 100644 --- a/script/lib/git.py +++ b/script/lib/git.py @@ -126,7 +126,7 @@ def reset(repo): def commit(repo, author, message): - """ Commit whatever in the index is now.""" + """Commit whatever in the index is now.""" # Let's setup committer info so git won't complain about it being missing. # TODO: Is there a better way to set committer's name and email? @@ -143,27 +143,33 @@ def commit(repo, author, message): committed_successfully = (return_code == 0) return committed_successfully +def get_upstream_head(repo): + args = [ + 'git', + '-C', + repo, + 'rev-parse', + '--verify', + 'refs/patches/upstream-head', + ] + return subprocess.check_output(args).strip() + +def get_commit_count(repo, commit_range): + args = [ + 'git', + '-C', + repo, + 'rev-list', + '--count', + commit_range + ] + return int(subprocess.check_output(args).strip()) + def guess_base_commit(repo): """Guess which commit the patches might be based on""" try: - args = [ - 'git', - '-C', - repo, - 'rev-parse', - '--verify', - 'refs/patches/upstream-head', - ] - upstream_head = subprocess.check_output(args).strip() - args = [ - 'git', - '-C', - repo, - 'rev-list', - '--count', - upstream_head + '..', - ] - num_commits = subprocess.check_output(args).strip() + upstream_head = get_upstream_head(repo) + num_commits = get_commit_count(repo, upstream_head + '..') return [upstream_head, num_commits] except subprocess.CalledProcessError: args = [ diff --git a/script/reset_patched_repos.py b/script/reset_patched_repos.py new file mode 100644 index 0000000000000..848264b6343e8 --- /dev/null +++ b/script/reset_patched_repos.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python + +import argparse +import json +import subprocess + + +def reset_patched_repos(dirs): + for patch_dir, repo in dirs.iteritems(): + args = ['git', '-C', repo, 'am', '--abort'] + subprocess.call(args) # ignore failure + args = ['git', '-C', repo, 'checkout', 'refs/patches/upstream-head'] + subprocess.call(args) # ignore failure + + +def parse_args(): + parser = argparse.ArgumentParser(description='Reset patched repos') + parser.add_argument('config', nargs='+', + type=argparse.FileType('r'), + help='patches\' config(s) in the JSON format') + return parser.parse_args() + + +def main(): + configs = parse_args().config + for config_json in configs: + reset_patched_repos(json.load(config_json)) + + +if __name__ == '__main__': + main()