Skip to content

Commit 619b206

Browse files
committed
fix(run-task): normalize head_ref before checking it out
This fixes the case where head_ref is passed in with a `refs/heads` prefix.
1 parent 5dde3b9 commit 619b206

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/taskgraph/run-task/run-task

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,19 @@ def _clean_git_checkout(destination_path):
621621
print_line(b"vcs", b"successfully cleaned git checkout!\n")
622622

623623

624+
def shortref(ref: str) -> str:
625+
"""Normalize a git ref to its short form.
626+
627+
Returns the ref unchanged if it's already in short form.
628+
"""
629+
# Strip common ref prefixes
630+
for prefix in ("refs/heads/", "refs/tags/"):
631+
if ref.startswith(prefix):
632+
return ref[len(prefix) :]
633+
634+
return ref
635+
636+
624637
def git_checkout(
625638
destination_path: str,
626639
head_repo: str,
@@ -721,7 +734,7 @@ def git_checkout(
721734
]
722735

723736
if head_ref:
724-
args.extend(["-B", head_ref])
737+
args.extend(["-B", shortref(head_ref)])
725738

726739
# `git fetch` set `FETCH_HEAD` reference to the last commit of the desired branch
727740
args.append(head_rev if head_rev else "FETCH_HEAD")

0 commit comments

Comments
 (0)