Closed
Description
repo.add_worktree
only has arguments of name and path so it is currently not possible to create a work tree on a specific reference (existing branches, tags ect) and it just creates a new branch name
repo.listall_branches()
>> ['master',
'develop',
'foo']
worktree_dir = tempfile.mkdtemp()
os.rmdir(worktree_dir)
worktree_name = 'foo'
worktree = repo.add_worktree(worktree_name, worktree_dir)
>> Traceback (most recent call last):
File "<ipython-input-134-cb34d9dc7f6a>", line 4, in <module>
worktree = repo.add_worktree(worktree_name, worktree_dir)
ValueError: failed to write reference 'refs/heads/foo': a reference with that name already exists.
my current workaround is to move the reference after the fact but this will still create the unwanted branch, and may leave files in the directory.
branch = repo.branches[name]
branch.set_target(repo.branches[the_branch_i_wanted].target)
# or
branch.set_target(repo.references[some reference].target)