Skip to content

Commit 17572a9

Browse files
hathachclaude
andcommitted
metrics_compare_base: use git worktree add --detach
`git worktree add <path> <branch>` fails if <branch> is already checked out elsewhere (main repo, another worktree). --detach checks out the ref at a detached HEAD instead of claiming the branch, making the script work regardless of what is currently checked out. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 6ba8aef commit 17572a9

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

tools/metrics_compare_base.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,11 @@ def main():
215215
print(f'[1/5] Setting up {args.base_branch} worktree...')
216216
if os.path.isdir(worktree_dir):
217217
run(['git', '-C', TINYUSB_ROOT, 'worktree', 'remove', '--force', worktree_dir])
218-
ret = run(['git', '-C', TINYUSB_ROOT, 'worktree', 'add', worktree_dir, args.base_branch])
218+
# --detach: check out the ref at a detached HEAD instead of trying to claim the
219+
# branch. Lets us add a worktree of `master` even if master is already checked
220+
# out elsewhere (main repo, another worktree).
221+
ret = run(['git', '-C', TINYUSB_ROOT, 'worktree', 'add', '--detach',
222+
worktree_dir, args.base_branch])
219223
if ret.returncode != 0:
220224
print(f'Error creating worktree: {ret.stderr}')
221225
sys.exit(1)

0 commit comments

Comments
 (0)