Skip to content

Commit 42817e1

Browse files
committed
fix(run-task): avoid unnecessary 'git fetch' call
If the condition in the if statement is true, then we've already fetched ref from head_repo. There's no need to do so again.
1 parent 336bfaa commit 42817e1

File tree

1 file changed

+15
-24
lines changed

1 file changed

+15
-24
lines changed

src/taskgraph/run-task/run-task

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -686,33 +686,24 @@ def git_checkout(
686686

687687
retry_required_command(b"vcs", args, cwd=destination_path, extra_env=env)
688688

689-
# If a head_ref was provided, it might be tag, so we need to make sure we fetch
690-
# those. This is explicitly only done when base and head repo match,
691-
# because it is the only scenario where tags could be present. (PRs, for
692-
# example, always include an explicit rev.) Failure to do this could result
693-
# in not having a tag, or worse: having an outdated version of one.
694-
# `--force` is needed to be able to update an existing tag.
689+
# Fetch head_ref
690+
args = ["git", "fetch"]
695691
if head_ref and base_repo == head_repo:
696-
args = [
697-
"git",
698-
"fetch",
699-
"--tags",
700-
"--force",
701-
base_repo,
702-
head_ref,
703-
]
692+
# If a head_ref was provided, it might be tag, so we need to make sure we fetch
693+
# those. This is explicitly only done when base and head repo match,
694+
# because it is the only scenario where tags could be present. (PRs, for
695+
# example, always include an explicit rev.) Failure to do this could result
696+
# in not having a tag, or worse: having an outdated version of one.
697+
# `--force` is needed to be able to update an existing tag.
698+
args.extend(["--tags", "--force"])
704699

705-
retry_required_command(b"vcs", args, cwd=destination_path, extra_env=env)
706-
707-
# If a head_ref isn't provided, we fetch all refs from head_repo, which may be slow
708-
args = [
709-
"git",
710-
"fetch",
711-
"--no-tags",
712-
head_repo,
713-
head_ref if head_ref else "+refs/heads/*:refs/remotes/work/*",
714-
]
700+
else:
701+
args.append("--no-tags")
715702

703+
# If a head_ref isn't provided, we fetch all refs from head_repo, which may be slow.
704+
args.extend(
705+
[head_repo, head_ref if head_ref else "+refs/heads/*:refs/remotes/work/*"]
706+
)
716707
retry_required_command(b"vcs", args, cwd=destination_path, extra_env=env)
717708

718709
args = [

0 commit comments

Comments
 (0)