Skip to content

[utils][SR-2695] Tag checkout support for all repositories. #4892

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 12, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 67 additions & 31 deletions utils/update-checkout
Original file line number Diff line number Diff line change
Expand Up @@ -82,42 +82,74 @@ def update_single_repository(repo_path, branch, reset_to_remote, should_clean,
echo=True)


def update_all_repositories(args, config, scheme_name, cross_repos_pr):
def update_repository_to_tag(args, repo_name, repo_path, tag_name):
with shell.pushd(repo_path, dry_run=False, echo=False):
tag_exists = shell.capture(['git', 'ls-remote', '--tags',
'origin', tag_name], echo=False)
if not tag_exists:
print("--- Skipping '" + repo_name + "' ---")
return
update_single_repository(repo_path,
tag_name,
args.reset_to_remote,
args.clean,
cross_repo=True)


def update_repository_to_scheme(
args, config, repo_name, repo_path, scheme_name, cross_repos_pr):
cross_repo = False
repo_branch = scheme_name
# This loop is only correct, since we know that each alias set has
# unique contents. This is checked by verify config. Thus the first
# branch scheme data that has scheme_name as one of its aliases is
# the only possible correct answer.
for v in config['branch-schemes'].values():
if scheme_name not in v['aliases']:
continue
repo_branch = v['repos'][repo_name]
remote_repo_id = config['repos'][repo_name]['remote']['id']
if remote_repo_id in cross_repos_pr:
cross_repo = True
pr_id = cross_repos_pr[remote_repo_id]
repo_branch = "ci_pr_{0}".format(pr_id)
with shell.pushd(repo_path, dry_run=False, echo=False):
shell.call(["git", "checkout", v['repos'][repo_name]],
echo=True)
shell.capture(["git", "branch", "-D", repo_branch],
echo=True, allow_non_zero_exit=True)
shell.call(["git", "fetch", "origin",
"pull/{0}/merge:{1}"
.format(pr_id, repo_branch)], echo=True)
break
update_single_repository(repo_path,
repo_branch,
args.reset_to_remote,
args.clean,
cross_repo)


def update_all_repositories(args, config, scheme_name, cross_repos_pr):
for repo_name in config['repos'].keys():
cross_repo = False
if repo_name in args.skip_repository_list:
print("--- Skipping '" + repo_name + "' ---")
continue
repo_path = os.path.join(SWIFT_SOURCE_ROOT, repo_name)
if scheme_name:
# This loop is only correct, since we know that each alias set has
# unique contents. This is checked by verify config. Thus the first
# branch scheme data that has scheme_name as one of its aliases is
# the only possible correct answer.
for v in config['branch-schemes'].values():
if scheme_name not in v['aliases']:
continue
repo_branch = v['repos'][repo_name]
remote_repo_id = config['repos'][repo_name]['remote']['id']
if remote_repo_id in cross_repos_pr:
cross_repo = True
pr_id = cross_repos_pr[remote_repo_id]
repo_branch = "ci_pr_{0}".format(pr_id)
with shell.pushd(repo_path, dry_run=False, echo=False):
shell.call(["git", "checkout", v['repos'][repo_name]],
echo=True)
shell.capture(["git", "branch", "-D", repo_branch],
echo=True, allow_non_zero_exit=True)
shell.call(["git", "fetch", "origin",
"pull/{0}/merge:{1}"
.format(pr_id, repo_branch)], echo=True)
break
update_single_repository(repo_path,
repo_branch,
args.reset_to_remote,
args.clean,
cross_repo)
if args.tag:
update_repository_to_tag(args, repo_name, repo_path, args.tag)
elif scheme_name:
update_repository_to_scheme(args,
config,
repo_name,
repo_path,
scheme_name,
cross_repos_pr)
else:
update_single_repository(repo_path,
branch=None,
reset_to_remote=args.reset_to_remote,
should_clean=args.clean,
cross_repo=False)


def obtain_additional_swift_sources(
Expand Down Expand Up @@ -255,11 +287,15 @@ By default, updates your checkouts of Swift, SourceKit, LLDB, and SwiftPM.""")
help="""Check out related pull requests referenced in the given
free-form GitHub-style comment.""",
metavar='GITHUB-COMMENT',
dest='github_comment'),
dest='github_comment')
parser.add_argument(
'--dump-hashes',
action='store_true',
help='Dump the git hashes of all repositories being tracked')
parser.add_argument(
"--tag",
help="""Check out each repository to the specified tag.""",
metavar='TAG-NAME')
args = parser.parse_args()

clone = args.clone
Expand Down