Skip to content

Commit 944e0ba

Browse files
authored
Merge pull request #4892 from aleksgapp/sr-2695-tag-checkout
2 parents b05d3c2 + ed865fc commit 944e0ba

File tree

1 file changed

+67
-31
lines changed

1 file changed

+67
-31
lines changed

utils/update-checkout

Lines changed: 67 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -82,42 +82,74 @@ def update_single_repository(repo_path, branch, reset_to_remote, should_clean,
8282
echo=True)
8383

8484

85-
def update_all_repositories(args, config, scheme_name, cross_repos_pr):
85+
def update_repository_to_tag(args, repo_name, repo_path, tag_name):
86+
with shell.pushd(repo_path, dry_run=False, echo=False):
87+
tag_exists = shell.capture(['git', 'ls-remote', '--tags',
88+
'origin', tag_name], echo=False)
89+
if not tag_exists:
90+
print("--- Skipping '" + repo_name + "' ---")
91+
return
92+
update_single_repository(repo_path,
93+
tag_name,
94+
args.reset_to_remote,
95+
args.clean,
96+
cross_repo=True)
97+
98+
99+
def update_repository_to_scheme(
100+
args, config, repo_name, repo_path, scheme_name, cross_repos_pr):
101+
cross_repo = False
86102
repo_branch = scheme_name
103+
# This loop is only correct, since we know that each alias set has
104+
# unique contents. This is checked by verify config. Thus the first
105+
# branch scheme data that has scheme_name as one of its aliases is
106+
# the only possible correct answer.
107+
for v in config['branch-schemes'].values():
108+
if scheme_name not in v['aliases']:
109+
continue
110+
repo_branch = v['repos'][repo_name]
111+
remote_repo_id = config['repos'][repo_name]['remote']['id']
112+
if remote_repo_id in cross_repos_pr:
113+
cross_repo = True
114+
pr_id = cross_repos_pr[remote_repo_id]
115+
repo_branch = "ci_pr_{0}".format(pr_id)
116+
with shell.pushd(repo_path, dry_run=False, echo=False):
117+
shell.call(["git", "checkout", v['repos'][repo_name]],
118+
echo=True)
119+
shell.capture(["git", "branch", "-D", repo_branch],
120+
echo=True, allow_non_zero_exit=True)
121+
shell.call(["git", "fetch", "origin",
122+
"pull/{0}/merge:{1}"
123+
.format(pr_id, repo_branch)], echo=True)
124+
break
125+
update_single_repository(repo_path,
126+
repo_branch,
127+
args.reset_to_remote,
128+
args.clean,
129+
cross_repo)
130+
131+
132+
def update_all_repositories(args, config, scheme_name, cross_repos_pr):
87133
for repo_name in config['repos'].keys():
88-
cross_repo = False
89134
if repo_name in args.skip_repository_list:
90135
print("--- Skipping '" + repo_name + "' ---")
91136
continue
92137
repo_path = os.path.join(SWIFT_SOURCE_ROOT, repo_name)
93-
if scheme_name:
94-
# This loop is only correct, since we know that each alias set has
95-
# unique contents. This is checked by verify config. Thus the first
96-
# branch scheme data that has scheme_name as one of its aliases is
97-
# the only possible correct answer.
98-
for v in config['branch-schemes'].values():
99-
if scheme_name not in v['aliases']:
100-
continue
101-
repo_branch = v['repos'][repo_name]
102-
remote_repo_id = config['repos'][repo_name]['remote']['id']
103-
if remote_repo_id in cross_repos_pr:
104-
cross_repo = True
105-
pr_id = cross_repos_pr[remote_repo_id]
106-
repo_branch = "ci_pr_{0}".format(pr_id)
107-
with shell.pushd(repo_path, dry_run=False, echo=False):
108-
shell.call(["git", "checkout", v['repos'][repo_name]],
109-
echo=True)
110-
shell.capture(["git", "branch", "-D", repo_branch],
111-
echo=True, allow_non_zero_exit=True)
112-
shell.call(["git", "fetch", "origin",
113-
"pull/{0}/merge:{1}"
114-
.format(pr_id, repo_branch)], echo=True)
115-
break
116-
update_single_repository(repo_path,
117-
repo_branch,
118-
args.reset_to_remote,
119-
args.clean,
120-
cross_repo)
138+
if args.tag:
139+
update_repository_to_tag(args, repo_name, repo_path, args.tag)
140+
elif scheme_name:
141+
update_repository_to_scheme(args,
142+
config,
143+
repo_name,
144+
repo_path,
145+
scheme_name,
146+
cross_repos_pr)
147+
else:
148+
update_single_repository(repo_path,
149+
branch=None,
150+
reset_to_remote=args.reset_to_remote,
151+
should_clean=args.clean,
152+
cross_repo=False)
121153

122154

123155
def obtain_additional_swift_sources(
@@ -255,11 +287,15 @@ By default, updates your checkouts of Swift, SourceKit, LLDB, and SwiftPM.""")
255287
help="""Check out related pull requests referenced in the given
256288
free-form GitHub-style comment.""",
257289
metavar='GITHUB-COMMENT',
258-
dest='github_comment'),
290+
dest='github_comment')
259291
parser.add_argument(
260292
'--dump-hashes',
261293
action='store_true',
262294
help='Dump the git hashes of all repositories being tracked')
295+
parser.add_argument(
296+
"--tag",
297+
help="""Check out each repository to the specified tag.""",
298+
metavar='TAG-NAME')
263299
args = parser.parse_args()
264300

265301
clone = args.clone

0 commit comments

Comments
 (0)