Skip to content

[utils] Update checkout should skip remote reset for PR branch #4647

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
Sep 6, 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
14 changes: 9 additions & 5 deletions utils/update-checkout
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ from swift_build_support import shell # noqa (E402)


def update_single_repository(repo_path, branch, reset_to_remote, should_clean,
cross_repos_pr):
cross_repo):
if not os.path.isdir(repo_path):
return

Expand Down Expand Up @@ -68,15 +68,15 @@ def update_single_repository(repo_path, branch, reset_to_remote, should_clean,

# If we were asked to reset to the specified branch, do the hard
# reset and return.
if reset_to_remote:
if reset_to_remote and not cross_repo:
shell.call(['git', 'reset', '--hard', "origin/%s" % branch],
echo=True)
return

# Prior to Git 2.6, this is the way to do a "git pull
# --rebase" that respects rebase.autostash. See
# http://stackoverflow.com/a/30209750/125349
if not cross_repos_pr:
if not cross_repo:
shell.call(["git", "rebase", "FETCH_HEAD"], echo=True)
shell.call(["git", "submodule", "update", "--recursive"],
echo=True)
Expand All @@ -85,6 +85,7 @@ def update_single_repository(repo_path, branch, reset_to_remote, should_clean,
def update_all_repositories(args, config, scheme_name, cross_repos_pr):
repo_branch = scheme_name
for repo_name in config['repos'].keys():
cross_repo = False
if repo_name in args.skip_repository_list:
print("--- Skipping '" + repo_name + "' ---")
continue
Expand All @@ -100,9 +101,12 @@ def update_all_repositories(args, config, scheme_name, cross_repos_pr):
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",
Expand All @@ -113,7 +117,7 @@ def update_all_repositories(args, config, scheme_name, cross_repos_pr):
repo_branch,
args.reset_to_remote,
args.clean,
cross_repos_pr)
cross_repo)


def obtain_additional_swift_sources(
Expand Down Expand Up @@ -255,7 +259,7 @@ By default, updates your checkouts of Swift, SourceKit, LLDB, and SwiftPM.""")
regex_pr = r'(apple/[-a-zA-Z0-9_]+/pull/\d+|apple/[-a-zA-Z0-9_]+#\d+)'
repos_with_pr = re.findall(regex_pr, github_comment)
print("Found related pull requests:", str(repos_with_pr))
repos_with_pr = [pr.replace('/pull/','#')for pr in repos_with_pr]
repos_with_pr = [pr.replace('/pull/','#') for pr in repos_with_pr]
cross_repos_pr = dict(pr.split('#') for pr in repos_with_pr)

if clone or clone_with_ssh:
Expand Down