@@ -1369,6 +1369,46 @@ class Repo:
13691369 osp .join (Repo .working_tree_dir + "-other" , "module" ),
13701370 )
13711371
1372+ @with_rw_directory
1373+ def test_update_rejects_checkout_path_outside_parent (self , rwdir ):
1374+ parent = git .Repo .init (osp .join (rwdir , "parent" ))
1375+ submodule = Submodule (
1376+ parent ,
1377+ Submodule .NULL_BIN_SHA ,
1378+ name = "module" ,
1379+ path = osp .join (".." , "outside" ),
1380+ url = "unused" ,
1381+ )
1382+
1383+ with mock .patch .object (Submodule , "_clone_repo" , side_effect = AssertionError ("clone attempted" )):
1384+ with pytest .raises (ValueError , match = "is not in repository" ):
1385+ submodule .update (init = True )
1386+
1387+ @with_rw_directory
1388+ def test_update_rejects_checkout_path_through_symlink (self , rwdir ):
1389+ parent = git .Repo .init (osp .join (rwdir , "parent" ))
1390+ os .mkdir (osp .join (parent .working_tree_dir , "target" ))
1391+ os .symlink ("target" , osp .join (parent .working_tree_dir , "link" ))
1392+ submodule = Submodule (
1393+ parent ,
1394+ Submodule .NULL_BIN_SHA ,
1395+ name = "module" ,
1396+ path = osp .join ("link" , "module" ),
1397+ url = "unused" ,
1398+ )
1399+
1400+ with mock .patch .object (Submodule , "_clone_repo" , side_effect = AssertionError ("clone attempted" )):
1401+ with pytest .raises (ValueError , match = "contains a symbolic link" ):
1402+ submodule .update (init = True )
1403+
1404+ @with_rw_directory
1405+ def test_update_rejects_checkout_path_at_parent_root (self , rwdir ):
1406+ parent = git .Repo .init (osp .join (rwdir , "parent" ))
1407+ submodule = Submodule (parent , Submodule .NULL_BIN_SHA , name = "module" , path = "." , url = "unused" )
1408+
1409+ with pytest .raises (ValueError , match = "must not be the repository root" ):
1410+ submodule .update (init = True )
1411+
13721412 @skipUnless (sys .platform == "win32" , "Specifically for Windows." )
13731413 @with_rw_directory
13741414 def test_to_relative_path_windows_path_kinds (self , rwdir ):
0 commit comments