* Encoded gitdir validation, only used when extensions.submodulePathConfig is enabled. * This does not print errors like the non-encoded version, because encoding is supposed * to mitigate / fix all these. */
| 2364 | * to mitigate / fix all these. |
| 2365 | */ |
| 2366 | static int validate_submodule_encoded_git_dir(char *git_dir, const char *submodule_name) |
| 2367 | { |
| 2368 | const char *modules_marker = "/modules/"; |
| 2369 | char *p = git_dir, *last_submodule_name = NULL; |
| 2370 | int config_ignorecase = 0; |
| 2371 | |
| 2372 | if (!the_repository->repository_format_submodule_path_cfg) |
| 2373 | BUG("validate_submodule_encoded_git_dir() must be called with " |
| 2374 | "extensions.submodulePathConfig enabled."); |
| 2375 | |
| 2376 | /* Find the last submodule name in the gitdir path (modules can be nested). */ |
| 2377 | while ((p = strstr(p, modules_marker))) { |
| 2378 | last_submodule_name = p + strlen(modules_marker); |
| 2379 | p++; |
| 2380 | } |
| 2381 | |
| 2382 | /* Prevent the use of '/' in encoded names */ |
| 2383 | if (!last_submodule_name || strchr(last_submodule_name, '/')) |
| 2384 | return -1; |
| 2385 | |
| 2386 | /* Prevent conflicts with existing submodule gitdirs */ |
| 2387 | if (is_git_directory(git_dir) && |
| 2388 | submodule_conflicts_with_existing(git_dir, submodule_name)) |
| 2389 | return -1; |
| 2390 | |
| 2391 | /* Prevent conflicts on case-folding filesystems */ |
| 2392 | repo_config_get_bool(the_repository, "core.ignorecase", &config_ignorecase); |
| 2393 | if (ignore_case || config_ignorecase) { |
| 2394 | bool suffixes_match = !strcmp(last_submodule_name, submodule_name); |
| 2395 | return check_casefolding_conflict(git_dir, submodule_name, |
| 2396 | suffixes_match); |
| 2397 | } |
| 2398 | |
| 2399 | return 0; |
| 2400 | } |
| 2401 | |
| 2402 | static int validate_submodule_legacy_git_dir(char *git_dir, const char *submodule_name) |
| 2403 | { |
no test coverage detected