@@ -917,6 +917,39 @@ def test_implicit_boolean_round_trip(self, rw_dir):
917917 self .assertIs (config .getboolean ("flag" , "empty" ), False )
918918 self .assertEqual (dict (config .items_all ("flag" ))["multiple" ], ["false" , None , "" , None ])
919919
920+ @with_rw_directory
921+ def test_implicit_boolean_rejects_comments_like_git (self , rw_dir ):
922+ config_path = osp .join (rw_dir , "config" )
923+ comments = (
924+ " # comment" ,
925+ " ; comment" ,
926+ "# comment = value" ,
927+ "; comment = value" ,
928+ "\t # comment: value" ,
929+ "\t ; comment: value" ,
930+ )
931+ for comment in comments :
932+ with self .subTest (comment = comment ):
933+ content = ("[flag]\n \t enabled%s\n " % comment ).encode (defenc )
934+ with open (config_path , "wb" ) as config_file :
935+ config_file .write (content )
936+
937+ result = subprocess .run (
938+ ["git" , "config" , "--file" , config_path , "--bool" , "flag.enabled" ],
939+ stdout = subprocess .PIPE ,
940+ stderr = subprocess .PIPE ,
941+ )
942+ self .assertEqual (result .returncode , 128 , result .stderr )
943+ with GitConfigParser (config_path ) as config :
944+ with self .assertRaises (cp .ParsingError ):
945+ config .getboolean ("flag" , "enabled" )
946+ with GitConfigParser (config_path , read_only = False ) as config :
947+ with self .assertRaises (cp .ParsingError ):
948+ config .set_value ("other" , "value" , "updated" )
949+
950+ with open (config_path , "rb" ) as config_file :
951+ self .assertEqual (config_file .read (), content )
952+
920953 def test_config_with_quotes (self ):
921954 cr = GitConfigParser (fixture_path ("git_config_with_quotes" ), read_only = True )
922955
0 commit comments