@@ -115,11 +115,12 @@ def tmp_worktree(repo: str | Path = ".", ref: str = "HEAD") -> Iterator[Path]:
115115 """
116116 assert_git_repo (repo )
117117 repo_name = Path (repo ).resolve ().name
118- normref = _normalize (ref )
118+ normref = _normalize (ref ) # Branch names can contain slashes.
119119 with TemporaryDirectory (prefix = f"{ _WORKTREE_PREFIX } { repo_name } -{ normref } -" ) as tmp_dir :
120120 location = os .path .join (tmp_dir , normref ) # noqa: PTH118
121+ tmp_branch = f"griffe-{ normref } " # Temporary branch name must not already exist.
121122 process = subprocess .run (
122- ["git" , "-C" , repo , "worktree" , "add" , "-b" , normref , location , ref ],
123+ ["git" , "-C" , repo , "worktree" , "add" , "-b" , tmp_branch , location , ref ],
123124 capture_output = True ,
124125 check = False ,
125126 )
@@ -129,6 +130,6 @@ def tmp_worktree(repo: str | Path = ".", ref: str = "HEAD") -> Iterator[Path]:
129130 try :
130131 yield Path (location )
131132 finally :
132- subprocess .run (["git" , "-C" , repo , "worktree" , "remove" , normref ], stdout = subprocess .DEVNULL , check = False )
133+ subprocess .run (["git" , "-C" , repo , "worktree" , "remove" , location ], stdout = subprocess .DEVNULL , check = False )
133134 subprocess .run (["git" , "-C" , repo , "worktree" , "prune" ], stdout = subprocess .DEVNULL , check = False )
134- subprocess .run (["git" , "-C" , repo , "branch" , "-D" , normref ], stdout = subprocess .DEVNULL , check = False )
135+ subprocess .run (["git" , "-C" , repo , "branch" , "-D" , tmp_branch ], stdout = subprocess .DEVNULL , check = False )
0 commit comments