File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed
Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -759,16 +759,34 @@ void test_config_read__bom(void)
759759 git_buf_dispose (& buf );
760760}
761761
762+ static int read_nosection_cb (const git_config_entry * entry , void * payload ) {
763+ int * seen = (int * )payload ;
764+ if (strcmp (entry -> name , "key" ) == 0 ) {
765+ (* seen )++ ;
766+ }
767+ return 0 ;
768+ }
769+
762770/* This would ideally issue a warning, if we had a way to do so. */
763771void test_config_read__nosection (void )
764772{
765773 git_config * cfg ;
766774 git_buf buf = GIT_BUF_INIT ;
775+ int seen = 0 ;
767776
768777 cl_git_pass (git_config_open_ondisk (& cfg , cl_fixture ("config/config-nosection" )));
769778
770- cl_git_pass (git_config_get_string_buf (& buf , cfg , "key" ));
771- cl_assert_equal_s (buf .ptr , "value" );
779+ /*
780+ * Given a key with no section, we do not allow reading it,
781+ * but we do include it in an iteration over the config
782+ * store. This appears to match how git's own APIs (and
783+ * git-config(1)) behave.
784+ */
785+
786+ cl_git_fail_with (git_config_get_string_buf (& buf , cfg , "key" ), GIT_EINVALIDSPEC );
787+
788+ cl_git_pass (git_config_foreach (cfg , read_nosection_cb , & seen ));
789+ cl_assert_equal_i (seen , 1 );
772790
773791 git_buf_dispose (& buf );
774792 git_config_free (cfg );
You can’t perform that action at this time.
0 commit comments