Skip to content

Commit d71f1a5

Browse files
committed
Add support for using tags for target branch overrides
1 parent a83b938 commit d71f1a5

File tree

1 file changed

+10
-26
lines changed

1 file changed

+10
-26
lines changed

pycheribuild/projects/repository.py

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,11 @@ def __init__(self, source_project: "type[Project]", *, subdirectory=".", do_upda
149149

150150
# Use git-worktree to handle per-target branches:
151151
class TargetBranchInfo:
152-
def __init__(self, branch: str, directory_name: str, url: "Optional[str]" = None):
152+
def __init__(self, branch: str, directory_name: str, url: "Optional[str]" = None, tag: "Optional[str]" = None):
153153
self.branch = branch
154154
self.directory_name = directory_name
155155
self.url = url
156+
self.tag = tag
156157

157158

158159
_PRETEND_RUN_GIT_COMMANDS = os.getenv("_TEST_SKIP_GIT_COMMANDS") is None
@@ -468,21 +469,15 @@ def ensure_cloned(
468469
if current_project.query_yes_no("Use this remote?"):
469470
break
470471
matching_remote = input("Please enter the correct remote: ")
471-
# TODO --track -B?
472+
git_worktree_add_cmd = ["git", "-C", base_project_source_dir, "worktree", "add"]
473+
if target_override.tag is not None:
474+
target_hash = target_override.tag + "^{tag}"
475+
else:
476+
target_hash = matching_remote + "/" + target_override.branch
477+
git_worktree_add_cmd.append("--track")
472478
try:
473479
current_project.run_cmd(
474-
[
475-
"git",
476-
"-C",
477-
base_project_source_dir,
478-
"worktree",
479-
"add",
480-
"--track",
481-
"-b",
482-
target_override.branch,
483-
src_dir,
484-
matching_remote + "/" + target_override.branch,
485-
],
480+
[*git_worktree_add_cmd, "-b", target_override.branch, src_dir, target_hash],
486481
print_verbose_only=False,
487482
)
488483
except subprocess.CalledProcessError:
@@ -493,18 +488,7 @@ def ensure_cloned(
493488
sep="",
494489
)
495490
current_project.run_cmd(
496-
[
497-
"git",
498-
"-C",
499-
base_project_source_dir,
500-
"worktree",
501-
"add",
502-
"--track",
503-
"-b",
504-
"worktree-fallback-" + target_override.branch,
505-
src_dir,
506-
matching_remote + "/" + target_override.branch,
507-
],
491+
[*git_worktree_add_cmd, "-b", "worktree-fallback-" + target_override.branch, src_dir, target_hash],
508492
print_verbose_only=False,
509493
)
510494

0 commit comments

Comments
 (0)