Introduce the config "submodule.<name>.gitdirpath" which is used to
indicate where a submodule's gitdir is located inside of a repository's
"modules" directory.

Signed-off-by: Brandon Williams <bmw...@google.com>
---

Maybe something like this on top?  Do you think we should disallow "../"
in this config, even though it is a repository local configuration and
not shipped in .gitmodules?

 submodule.c                | 13 ++++++++++++-
 t/t7400-submodule-basic.sh | 10 ++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/submodule.c b/submodule.c
index 4854d88ce8..0cb00a9f24 100644
--- a/submodule.c
+++ b/submodule.c
@@ -1966,16 +1966,27 @@ void submodule_name_to_gitdir(struct strbuf *buf, 
struct repository *r,
                              const char *submodule_name)
 {
        size_t modules_len;
+       char *key;
+       char *gitdir_path;
 
        strbuf_git_common_path(buf, r, "modules/");
        modules_len = buf->len;
-       strbuf_addstr(buf, submodule_name);
+
+       key = xstrfmt("submodule.%s.gitdirpath", submodule_name);
+       if (!repo_config_get_string(r, key, &gitdir_path)) {
+               strbuf_addstr(buf, gitdir_path);
+               free(key);
+               free(gitdir_path);
+               return;
+       }
+       free(key);
 
        /*
         * If the submodule gitdir already exists using the old-fashioned
         * location (which uses the submodule name as-is, without munging it)
         * then return that.
         */
+       strbuf_addstr(buf, submodule_name);
        if (!access(buf->buf, F_OK))
                return;
 
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index 963693332c..1555329a2f 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -1351,6 +1351,16 @@ test_expect_success 'resolve submodule gitdir in 
superprojects modules directory
        $(git -C superproject rev-parse --git-common-dir)/modules/sub/module
        EOF
        git -C superproject submodule--helper gitdir "sub/module" >actual &&
+       test_cmp expect actual &&
+
+       # Test using "submodule.<name>.gitdirpath" config for where the 
submodules
+       # gitdir is located inside the superprojecs "modules" directory
+       mv superproject/.git/modules/sub/module 
superproject/.git/modules/submodule &&
+       cat >expect <<-EOF &&
+       $(git -C superproject rev-parse --git-common-dir)/modules/submodule
+       EOF
+       git -C superproject config "submodule.sub/module.gitdirpath" 
"submodule" &&
+       git -C superproject submodule--helper gitdir "sub/module" >actual &&
        test_cmp expect actual
 '
 
-- 
2.18.0.865.gffc8e1a3cd6-goog

Reply via email to