@@ -327,13 +327,29 @@ def test_daemon_export(self):
327327
328328 def test_alternates (self ):
329329 cur_alternates = self .rorepo .alternates
330- # empty alternates
331- self .rorepo .alternates = []
332- self .assertEqual (self .rorepo .alternates , [])
330+ try :
331+ # Empty alternates.
332+ self .rorepo .alternates = []
333+ self .assertEqual (self .rorepo .alternates , [])
334+ alts = ["other/location" , "this/location" ]
335+ self .rorepo .alternates = alts
336+ self .assertEqual (alts , self .rorepo .alternates )
337+ finally :
338+ self .rorepo .alternates = cur_alternates
339+
340+ @with_rw_directory
341+ def test_alternates_use_common_dir (self , rw_dir ):
342+ common_dir = osp .join (rw_dir , "common" )
343+ git_dir = osp .join (rw_dir , "worktrees" , "linked" )
344+ os .makedirs (osp .join (common_dir , "objects" , "info" ))
345+ os .makedirs (osp .join (git_dir , "objects" , "info" ))
346+ repo = mock .Mock (common_dir = common_dir , git_dir = git_dir )
347+
333348 alts = ["other/location" , "this/location" ]
334- self .rorepo .alternates = alts
335- self .assertEqual (alts , self .rorepo .alternates )
336- self .rorepo .alternates = cur_alternates
349+ Repo ._set_alternates (repo , alts )
350+
351+ self .assertEqual (Repo ._get_alternates (repo ), alts )
352+ self .assertFalse (osp .exists (osp .join (git_dir , "objects" , "info" , "alternates" )))
337353
338354 def test_repr (self ):
339355 assert repr (self .rorepo ).startswith ("<git.repo.base.Repo " )
0 commit comments