@@ -962,6 +962,46 @@ 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_empty_repo_reftable_active_branch (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+ repo = Repo (rw_dir )
988+ self .assertEqual (repo .head .reference .name , ".invalid" )
989+ self .assertRaisesRegex (
990+ ValueError ,
991+ r"refs/heads/\.invalid.*older clients" ,
992+ lambda : repo .active_branch ,
993+ )
994+
995+ @with_rw_directory
996+ def test_active_branch_raises_type_error_when_head_is_detached (self , rw_dir ):
997+ repo = Repo .init (rw_dir )
998+ with open (osp .join (rw_dir , "a.txt" ), "w" ) as f :
999+ f .write ("a" )
1000+ repo .index .add (["a.txt" ])
1001+ repo .index .commit ("initial commit" )
1002+ repo .git .checkout (repo .head .commit .hexsha )
1003+ self .assertRaisesRegex (TypeError , "detached symbolic reference" , lambda : repo .active_branch )
1004+
9651005 def test_merge_base (self ):
9661006 repo = self .rorepo
9671007 c1 = "f6aa8d1"
0 commit comments