@@ -149,10 +149,11 @@ def __init__(self, source_project: "type[Project]", *, subdirectory=".", do_upda
149
149
150
150
# Use git-worktree to handle per-target branches:
151
151
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 ):
153
153
self .branch = branch
154
154
self .directory_name = directory_name
155
155
self .url = url
156
+ self .tag = tag
156
157
157
158
158
159
_PRETEND_RUN_GIT_COMMANDS = os .getenv ("_TEST_SKIP_GIT_COMMANDS" ) is None
@@ -468,21 +469,15 @@ def ensure_cloned(
468
469
if current_project .query_yes_no ("Use this remote?" ):
469
470
break
470
471
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" )
472
478
try :
473
479
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 ],
486
481
print_verbose_only = False ,
487
482
)
488
483
except subprocess .CalledProcessError :
@@ -493,18 +488,7 @@ def ensure_cloned(
493
488
sep = "" ,
494
489
)
495
490
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 ],
508
492
print_verbose_only = False ,
509
493
)
510
494
0 commit comments