Skip to content

Commit ddde8a9

Browse files
committed
fix(run-task)!: stop fetching / checking out 'base_ref'
BREAKING CHANGE: `base_ref` will no longer be fetched or checked out by run-task Taskgraph uses base_rev anyway for computing files changed, so there's no need to additionally fetch base_ref. Some tasks may need to be updated to not rely on base_ref being present in the local clone.
1 parent 42817e1 commit ddde8a9

File tree

2 files changed

+8
-27
lines changed

2 files changed

+8
-27
lines changed

src/taskgraph/run-task/run-task

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,6 @@ def git_checkout(
609609
destination_path: str,
610610
head_repo: str,
611611
base_repo: Optional[str],
612-
base_ref: Optional[str],
613612
base_rev: Optional[str],
614613
head_ref: Optional[str],
615614
head_rev: Optional[str],
@@ -664,23 +663,11 @@ def git_checkout(
664663

665664
retry_required_command(b"vcs", args, extra_env=env)
666665

667-
if base_ref:
668-
args = ["git", "fetch", "origin", base_ref]
669-
670-
retry_required_command(b"vcs", args, cwd=destination_path, extra_env=env)
671-
672-
# Create local branch so that taskgraph is able to compute differences
673-
# between the head branch and the base one, if needed
674-
args = ["git", "checkout", base_ref]
675-
676-
retry_required_command(b"vcs", args, cwd=destination_path, extra_env=env)
677-
678-
# When commits are force-pushed (like on a testing branch), base_rev doesn't
679-
# exist on base_ref. Fetching it allows taskgraph to compute differences
680-
# between the previous state before the force-push and the current state.
681-
#
682-
# Unlike base_ref just above, there is no need to checkout the revision:
683-
# it's immediately available after the fetch.
666+
# For Github based repos, base_rev often doesn't refer to an ancestor of
667+
# head_rev simply due to Github not providing that information in their
668+
# webhook events. Therefore we fetch it independently from `head_rev` so
669+
# that consumers can compute the merge-base or files modified between the
670+
# two as needed.
684671
if base_rev and base_rev != NULL_REVISION:
685672
args = ["git", "fetch", "origin", base_rev]
686673

@@ -900,7 +887,6 @@ def collect_vcs_options(args, project, name):
900887

901888
repo_type = os.environ.get(f"{env_prefix}_REPOSITORY_TYPE")
902889
base_repo = os.environ.get(f"{env_prefix}_BASE_REPOSITORY")
903-
base_ref = os.environ.get(f"{env_prefix}_BASE_REF")
904890
base_rev = os.environ.get(f"{env_prefix}_BASE_REV")
905891
head_repo = os.environ.get(f"{env_prefix}_HEAD_REPOSITORY")
906892
head_ref = os.environ.get(f"{env_prefix}_HEAD_REF")
@@ -933,7 +919,6 @@ def collect_vcs_options(args, project, name):
933919
"checkout": checkout,
934920
"sparse-profile": sparse_profile,
935921
"base-repo": base_repo,
936-
"base-ref": base_ref,
937922
"base-rev": base_rev,
938923
"head-repo": head_repo,
939924
"head-ref": head_ref,
@@ -984,7 +969,6 @@ def vcs_checkout_from_args(options):
984969
options["checkout"],
985970
options["head-repo"],
986971
options["base-repo"],
987-
options["base-ref"],
988972
options["base-rev"],
989973
head_ref,
990974
head_rev,

test/test_scripts_run_task.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ def test_collect_vcs_options(monkeypatch, run_task_mod, env, extra_expected):
183183

184184
expected = {
185185
"base-repo": env.get("BASE_REPOSITORY"),
186-
"base-ref": env.get("BASE_REF"),
187186
"base-rev": env.get("BASE_REV"),
188187
"checkout": os.path.join(os.getcwd(), "checkout"),
189188
"env-prefix": name.upper(),
@@ -354,7 +353,7 @@ def _commit_file(message, filename):
354353

355354

356355
@pytest.mark.parametrize(
357-
"base_ref,head_ref,files,hash_key",
356+
"base_rev,head_ref,files,hash_key",
358357
[
359358
(None, None, ["mainfile"], "main"),
360359
(None, "main", ["mainfile"], "main"),
@@ -367,7 +366,7 @@ def test_git_checkout(
367366
mock_stdin,
368367
run_task_mod,
369368
mock_git_repo,
370-
base_ref,
369+
base_rev,
371370
head_ref,
372371
files,
373372
hash_key,
@@ -378,8 +377,7 @@ def test_git_checkout(
378377
destination_path=destination,
379378
head_repo=mock_git_repo["path"],
380379
base_repo=mock_git_repo["path"],
381-
base_ref=base_ref,
382-
base_rev=None,
380+
base_rev=base_rev,
383381
head_ref=head_ref,
384382
head_rev=None,
385383
ssh_key_file=None,
@@ -414,7 +412,6 @@ def test_git_checkout_with_commit(
414412
destination_path=destination,
415413
head_repo=mock_git_repo["path"],
416414
base_repo=mock_git_repo["path"],
417-
base_ref="mybranch",
418415
base_rev=mock_git_repo["main"],
419416
head_ref=mock_git_repo["branch"],
420417
head_rev=mock_git_repo["branch"],

0 commit comments

Comments
 (0)