| 2734 | } |
| 2735 | |
| 2736 | void submodule_name_to_gitdir(struct strbuf *buf, struct repository *r, |
| 2737 | const char *submodule_name) |
| 2738 | { |
| 2739 | if (!r->repository_format_submodule_path_cfg) { |
| 2740 | /* |
| 2741 | * If extensions.submodulePathConfig is disabled, |
| 2742 | * continue to use the plain path. |
| 2743 | */ |
| 2744 | repo_git_path_append(r, buf, "modules/%s", submodule_name); |
| 2745 | } else { |
| 2746 | const char *gitdir; |
| 2747 | char *key; |
| 2748 | int ret; |
| 2749 | |
| 2750 | /* Otherwise the extension is enabled, so use the gitdir config. */ |
| 2751 | key = xstrfmt("submodule.%s.gitdir", submodule_name); |
| 2752 | ret = repo_config_get_string_tmp(r, key, &gitdir); |
| 2753 | FREE_AND_NULL(key); |
| 2754 | |
| 2755 | if (ret) |
| 2756 | die(_("the 'submodule.%s.gitdir' config does not exist for module '%s'. " |
| 2757 | "Please ensure it is set, for example by running something like: " |
| 2758 | "'git config submodule.%s.gitdir .git/modules/%s'. For details " |
| 2759 | "see the extensions.submodulePathConfig documentation."), |
| 2760 | submodule_name, submodule_name, submodule_name, submodule_name); |
| 2761 | |
| 2762 | strbuf_addstr(buf, gitdir); |
| 2763 | } |
| 2764 | |
| 2765 | /* validate because users might have modified the config */ |
| 2766 | if (validate_submodule_git_dir(buf->buf, submodule_name)) { |
| 2767 | advise(_("enabling extensions.submodulePathConfig might fix the " |
| 2768 | "following error, if it's not already enabled.")); |
| 2769 | die(_("refusing to create/use '%s' in another submodule's " |
| 2770 | " git dir."), buf->buf); |
| 2771 | } |
| 2772 | } |
no test coverage detected