Skip to content
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
33 changes: 31 additions & 2 deletions src/taskgraph/run-task/run-task
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Comment thread
Eijebong marked this conversation as resolved.
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)


Expand Down Expand Up @@ -735,11 +760,15 @@ def git_checkout(
env=env,
)

if extra_refs:
for ref in extra_refs or []:
optional = ref.startswith("?")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we avoid calling git_fetch once per ref?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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,
)

Expand Down
Loading