@@ -168,11 +168,18 @@ int git_submodule_lookup(
168
168
return error ;
169
169
}
170
170
171
- /* If it's not configured, we need to check for the path */
171
+ /* If it's not configured or we're looking by path */
172
172
if (location == 0 || location == GIT_SUBMODULE_STATUS_IN_WD ) {
173
173
git_config_backend * mods ;
174
174
const char * pattern = "submodule\\..*\\.path" ;
175
- fbp_data data = { name , NULL };
175
+ git_buf path = GIT_BUF_INIT ;
176
+ fbp_data data = { NULL , NULL };
177
+
178
+ git_buf_puts (& path , name );
179
+ while (path .ptr [path .size - 1 ] == '/' ) {
180
+ path .ptr [-- path .size ] = '\0' ;
181
+ }
182
+ data .path = path .ptr ;
176
183
177
184
mods = open_gitmodules (repo , GITMODULES_EXISTING );
178
185
@@ -189,15 +196,16 @@ int git_submodule_lookup(
189
196
if (data .name ) {
190
197
git__free (sm -> name );
191
198
sm -> name = data .name ;
192
- sm -> path = git__strdup (name );
193
- GITERR_CHECK_ALLOC (sm -> path );
199
+ sm -> path = git_buf_detach (& path );
194
200
195
201
/* Try to load again with the right name */
196
202
if ((error = git_submodule_reload (sm , false)) < 0 ) {
197
203
git_submodule_free (sm );
198
204
return error ;
199
205
}
200
206
}
207
+
208
+ git_buf_free (& path );
201
209
}
202
210
203
211
if ((error = git_submodule_location (& location , sm )) < 0 ) {
@@ -1691,28 +1699,9 @@ static int submodule_load_from_config(
1691
1699
1692
1700
/* Deregister under name being replaced */
1693
1701
if (replaced ) {
1694
- git_submodule_free (sm );
1695
1702
git__free (replaced );
1696
1703
}
1697
1704
1698
- /* Insert under alternate key */
1699
- if (alternate ) {
1700
- void * old_sm = NULL ;
1701
-
1702
- if (error < 0 )
1703
- goto done ;
1704
- if (error > 0 )
1705
- error = 0 ;
1706
-
1707
- GIT_REFCOUNT_INC (sm ); /* increase refcount for new key */
1708
-
1709
- /* if we replaced an old module under this key, release the old one */
1710
- if (old_sm && ((git_submodule * )old_sm ) != sm ) {
1711
- git_submodule_free (old_sm );
1712
- /* TODO: log warning about multiple submodules with same path */
1713
- }
1714
- }
1715
-
1716
1705
/* TODO: Look up path in index and if it is present but not a GITLINK
1717
1706
* then this should be deleted (at least to match git's behavior)
1718
1707
*/
0 commit comments