@@ -962,6 +962,48 @@ def test_empty_repo(self, rw_dir):
962962
963963 assert "BAD MESSAGE" not in contents , "log is corrupt"
964964
965+ @with_rw_directory
966+ def test_active_branch_raises_value_error_when_head_ref_is_invalid (self , rw_dir ):
967+ repo = Repo .init (rw_dir )
968+ with open (osp .join (rw_dir , ".git" , "HEAD" ), "w" ) as f :
969+ f .write ("ref: refs/heads/.invalid\n " )
970+
971+ self .assertRaisesRegex (
972+ ValueError ,
973+ r"refs/heads/\.invalid.*older clients" ,
974+ lambda : repo .active_branch ,
975+ )
976+
977+ @with_rw_directory
978+ def test_active_branch_raises_value_error_for_reftable_repo (self , rw_dir ):
979+ git = Git (rw_dir )
980+ try :
981+ git .init (ref_format = "reftable" )
982+ except GitCommandError as err :
983+ if err .status == 129 :
984+ pytest .skip ("git init --ref-format is not supported by this git version" )
985+ raise
986+
987+ with open (osp .join (rw_dir , ".git" , "HEAD" )) as f :
988+ self .assertEqual (f .read (), "ref: refs/heads/.invalid\n " )
989+
990+ repo = Repo (rw_dir )
991+ self .assertRaisesRegex (
992+ ValueError ,
993+ r"refs/heads/\.invalid.*older clients" ,
994+ lambda : repo .active_branch ,
995+ )
996+
997+ @with_rw_directory
998+ def test_active_branch_raises_type_error_when_head_is_detached (self , rw_dir ):
999+ repo = Repo .init (rw_dir )
1000+ with open (osp .join (rw_dir , "a.txt" ), "w" ) as f :
1001+ f .write ("a" )
1002+ repo .index .add (["a.txt" ])
1003+ repo .index .commit ("initial commit" )
1004+ repo .git .checkout (repo .head .commit .hexsha )
1005+ self .assertRaisesRegex (TypeError , "detached symbolic reference" , lambda : repo .active_branch )
1006+
9651007 def test_merge_base (self ):
9661008 repo = self .rorepo
9671009 c1 = "f6aa8d1"
0 commit comments