Skip to content

Commit fc9d9f2

Browse files
committed
[utils] Update checkout should skip remote reset for PR branch (#4647)
1 parent f3f453e commit fc9d9f2

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

utils/update-checkout

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ from swift_build_support import shell # noqa (E402)
3535

3636

3737
def update_single_repository(repo_path, branch, reset_to_remote, should_clean,
38-
cross_repos_pr):
38+
cross_repo):
3939
if not os.path.isdir(repo_path):
4040
return
4141

@@ -68,15 +68,15 @@ def update_single_repository(repo_path, branch, reset_to_remote, should_clean,
6868

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

7676
# Prior to Git 2.6, this is the way to do a "git pull
7777
# --rebase" that respects rebase.autostash. See
7878
# http://stackoverflow.com/a/30209750/125349
79-
if not cross_repos_pr:
79+
if not cross_repo:
8080
shell.call(["git", "rebase", "FETCH_HEAD"], echo=True)
8181
shell.call(["git", "submodule", "update", "--recursive"],
8282
echo=True)
@@ -85,6 +85,7 @@ def update_single_repository(repo_path, branch, reset_to_remote, should_clean,
8585
def update_all_repositories(args, config, scheme_name, cross_repos_pr):
8686
repo_branch = scheme_name
8787
for repo_name in config['repos'].keys():
88+
cross_repo = False
8889
if repo_name in args.skip_repository_list:
8990
print("--- Skipping '" + repo_name + "' ---")
9091
continue
@@ -100,9 +101,12 @@ def update_all_repositories(args, config, scheme_name, cross_repos_pr):
100101
repo_branch = v['repos'][repo_name]
101102
remote_repo_id = config['repos'][repo_name]['remote']['id']
102103
if remote_repo_id in cross_repos_pr:
104+
cross_repo = True
103105
pr_id = cross_repos_pr[remote_repo_id]
104106
repo_branch = "ci_pr_{0}".format(pr_id)
105107
with shell.pushd(repo_path, dry_run=False, echo=False):
108+
shell.call(["git", "checkout", v['repos'][repo_name]],
109+
echo=True)
106110
shell.capture(["git", "branch", "-D", repo_branch],
107111
echo=True, allow_non_zero_exit=True)
108112
shell.call(["git", "fetch", "origin",
@@ -113,7 +117,7 @@ def update_all_repositories(args, config, scheme_name, cross_repos_pr):
113117
repo_branch,
114118
args.reset_to_remote,
115119
args.clean,
116-
cross_repos_pr)
120+
cross_repo)
117121

118122

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

261265
if clone or clone_with_ssh:

0 commit comments

Comments
 (0)