@@ -13,6 +13,24 @@ static git_config *_config;
1313 cl_assert_equal_p(r, NULL); \
1414 } while (0);
1515
16+ static int cl_git_config_section_count__foreach (const git_config_entry * entry , void * payload )
17+ {
18+ size_t * count = payload ;
19+
20+ GIT_UNUSED (entry );
21+ (* count )++ ;
22+
23+ return 0 ;
24+ }
25+
26+ static size_t cl_git_config_sections_count (git_config * cfg , const char * regex )
27+ {
28+ size_t count = 0 ;
29+
30+ cl_git_pass (git_config_foreach_match (cfg , regex , cl_git_config_section_count__foreach , & count ));
31+
32+ return count ;
33+ }
1634
1735void test_remote_create__initialize (void )
1836{
@@ -51,6 +69,9 @@ void test_remote_create__named(void)
5169 git_remote * remote ;
5270 git_config * cfg ;
5371 const char * cfg_val ;
72+
73+ size_t section_count = cl_git_config_sections_count (_config , "remote." );
74+
5475 cl_git_pass (git_remote_create (& remote , _repo , "valid-name" , TEST_URL ));
5576
5677 cl_assert_equal_s (git_remote_name (remote ), "valid-name" );
@@ -64,6 +85,8 @@ void test_remote_create__named(void)
6485 cl_git_pass (git_config_get_string (& cfg_val , cfg , "remote.valid-name.url" ));
6586 cl_assert_equal_s (cfg_val , TEST_URL );
6687
88+ cl_assert_equal_i (section_count + 2 , cl_git_config_sections_count (_config , "remote." ));
89+
6790 git_config_free (cfg );
6891 git_remote_free (remote );
6992}
@@ -93,11 +116,13 @@ void test_remote_create__with_fetchspec(void)
93116{
94117 git_remote * remote ;
95118 git_strarray array ;
119+ size_t section_count = cl_git_config_sections_count (_config , "remote." );
96120
97121 cl_git_pass (git_remote_create_with_fetchspec (& remote , _repo , "test-new" , "git://github.com/libgit2/libgit2" , "+refs/*:refs/*" ));
98122 cl_git_pass (git_remote_get_fetch_refspecs (& array , remote ));
99123 cl_assert_equal_s ("+refs/*:refs/*" , array .strings [0 ]);
100124 cl_assert_equal_i (1 , array .count );
125+ cl_assert_equal_i (section_count + 2 , cl_git_config_sections_count (_config , "remote." ));
101126
102127 git_strarray_free (& array );
103128 git_remote_free (remote );
@@ -107,10 +132,12 @@ void test_remote_create__with_empty_fetchspec(void)
107132{
108133 git_remote * remote ;
109134 git_strarray array ;
135+ size_t section_count = cl_git_config_sections_count (_config , "remote." );
110136
111137 cl_git_pass (git_remote_create_with_fetchspec (& remote , _repo , "test-new" , "git://github.com/libgit2/libgit2" , NULL ));
112138 cl_git_pass (git_remote_get_fetch_refspecs (& array , remote ));
113139 cl_assert_equal_i (0 , array .count );
140+ cl_assert_equal_i (section_count + 1 , cl_git_config_sections_count (_config , "remote." ));
114141
115142 git_strarray_free (& array );
116143 git_remote_free (remote );
@@ -130,13 +157,15 @@ void test_remote_create__anonymous(void)
130157{
131158 git_remote * remote ;
132159 git_strarray array ;
160+ size_t section_count = cl_git_config_sections_count (_config , "remote." );
133161
134162 cl_git_pass (git_remote_create_anonymous (& remote , _repo , TEST_URL ));
135163 cl_assert_equal_s (git_remote_name (remote ), NULL );
136164 cl_assert_equal_s (git_remote_url (remote ), TEST_URL );
137165
138166 cl_git_pass (git_remote_get_fetch_refspecs (& array , remote ));
139167 cl_assert_equal_i (0 , array .count );
168+ cl_assert_equal_i (section_count , cl_git_config_sections_count (_config , "remote." ));
140169
141170 git_strarray_free (& array );
142171 git_remote_free (remote );
0 commit comments