-
Notifications
You must be signed in to change notification settings - Fork 49
Allow extra refs to be marked as optional in run-task #935
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -574,6 +574,7 @@ def git_fetch( | |
| tags: bool = False, | ||
| shallow: bool = False, | ||
| env: Optional[Dict[str, str]] = None, | ||
| optional: bool = False, | ||
| ): | ||
| args = ["git", "fetch"] | ||
| if tags: | ||
|
|
@@ -584,6 +585,30 @@ def git_fetch( | |
| args.append("--depth=1") | ||
|
|
||
| args.extend([remote, *set(targets)]) | ||
| if not optional: | ||
| retry_required_command(b"vcs", args, cwd=destination_path, extra_env=env) | ||
| return | ||
|
|
||
| try: | ||
| retry_required_command( | ||
| b"vcs", args, cwd=destination_path, extra_env=env, retries=0 | ||
| ) | ||
| return | ||
| except SystemExit: | ||
| # Ignore the first failure to check if the ref even exists | ||
| pass | ||
|
|
||
| ref_names = [t.split(":", 1)[0] for t in targets] | ||
| ls = subprocess.run( | ||
| ["git", "ls-remote", "--exit-code", remote, *ref_names], | ||
| cwd=destination_path, | ||
| capture_output=True, | ||
| ) | ||
|
|
||
| if ls.returncode == 2: | ||
| print_line(b"vcs", b"optional refs %r not present on remote, skipping\n" % ref_names) | ||
| return | ||
|
|
||
| retry_required_command(b"vcs", args, cwd=destination_path, extra_env=env) | ||
|
|
||
|
|
||
|
|
@@ -735,11 +760,15 @@ def git_checkout( | |
| env=env, | ||
| ) | ||
|
|
||
| if extra_refs: | ||
| for ref in extra_refs or []: | ||
| optional = ref.startswith("?") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tbh, I think I'd rather these just never fail, and if there's some use case where we absolutely need the extra ref fetched, then we can deal with it then |
||
| if optional: | ||
| ref = ref[1:] | ||
| git_fetch( | ||
|
Comment on lines
+763
to
767
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we avoid calling git_fetch once per ref?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so? Cause we cannot extract what ref failed to fetch, so we'd have to check them all after the fact |
||
| destination_path, | ||
| *[f"{ref}:{ref}" for ref in extra_refs], | ||
| f"{ref}:{ref}", | ||
| remote=head_repo, | ||
| optional=optional, | ||
| env=env, | ||
| ) | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.