Skip to content

[update-checkout] Skip fetching tags when --skip-tags is passed #79814

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
18 changes: 10 additions & 8 deletions utils/update_checkout/update_checkout/update_checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def find_rev_by_timestamp(timestamp, repo_name, refspec):


def get_branch_for_repo(config, repo_name, scheme_name, scheme_map,
cross_repos_pr):
cross_repos_pr, skip_tags):
"""Infer, fetch, and return a branch corresponding to a given PR, otherwise
return a branch found in the config for this repository name.

Expand Down Expand Up @@ -142,13 +142,13 @@ def get_branch_for_repo(config, repo_name, scheme_name, scheme_map,
echo=True, allow_non_zero_exit=True)
shell.run(["git", "fetch", "origin",
"pull/{0}/merge:{1}"
.format(pr_id, repo_branch), "--tags"], echo=True)
.format(pr_id, repo_branch)] + (['--tags'] if not skip_tags else []), echo=True)
return repo_branch, cross_repo


def update_single_repository(pool_args):
source_root, config, repo_name, scheme_name, scheme_map, tag, timestamp, \
reset_to_remote, should_clean, should_stash, cross_repos_pr = pool_args
reset_to_remote, should_clean, should_stash, cross_repos_pr, skip_tags = pool_args
repo_path = os.path.join(source_root, repo_name)
if not os.path.isdir(repo_path) or os.path.islink(repo_path):
return
Expand All @@ -164,7 +164,7 @@ def update_single_repository(pool_args):
checkout_target = confirm_tag_in_repo(tag, repo_name)
elif scheme_name:
checkout_target, cross_repo = get_branch_for_repo(
config, repo_name, scheme_name, scheme_map, cross_repos_pr)
config, repo_name, scheme_name, scheme_map, cross_repos_pr, skip_tags)
if timestamp:
checkout_target = find_rev_by_timestamp(timestamp,
repo_name,
Expand Down Expand Up @@ -217,7 +217,7 @@ def run_for_repo_and_each_submodule_rec(cmd):
shell.run(['git', 'rev-parse', '--verify', checkout_target])
except Exception:
shell.run(["git", "fetch", "--recurse-submodules=yes",
"--tags"],
f"{checkout_target}:{checkout_target}"],
echo=True, prefix=prefix)
Comment on lines 219 to 221
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The refspec will not work with hashes or tags, and I believe it is better not to proactively create local branches if the target is a branch. I also think we still want to respect skip_tags here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm yeah, this bit turned out to be trickier than I expected... The method for fetching a single tag is different from fetching a single branch, but it doesn't seem like the script knows whether checkout_target is a tag or a branch. Since this fetch is explicitly done because checkout_target wasn't found locally, it seems like simply skipping --tags here when --skip-tags is passed will lead to more errors than not. So it'd be good if we could fetch a just a single tag when needed.


try:
Expand All @@ -235,7 +235,7 @@ def run_for_repo_and_each_submodule_rec(cmd):
# It's important that we checkout, fetch, and rebase, in order.
# .git/FETCH_HEAD updates the not-for-merge attributes based on
# which branch was checked out during the fetch.
shell.run(["git", "fetch", "--recurse-submodules=yes", "--tags"],
shell.run(["git", "fetch", "--recurse-submodules=yes"] + (["--tags"] if not skip_tags else []),
echo=True, prefix=prefix)

# If we were asked to reset to the specified branch, do the hard
Expand Down Expand Up @@ -360,7 +360,8 @@ def update_all_repositories(args, config, scheme_name, scheme_map, cross_repos_p
args.reset_to_remote,
args.clean,
args.stash,
cross_repos_pr]
cross_repos_pr,
args.skip_tags]
pool_args.append(my_args)

return run_parallel(update_single_repository, pool_args, args.n_processes)
Expand Down Expand Up @@ -735,7 +736,8 @@ def main():
branch_name, cross_repo = get_branch_for_repo(config, 'swift',
scheme_name,
scheme_map,
cross_repos_pr)
cross_repos_pr,
skip_tags)

if cross_repo:
shell.run(['git', 'checkout', branch_name], echo=True,
Expand Down