]> git.ipfire.org Git - thirdparty/git.git/blobdiff - submodule.c
path.c: move some code out of strbuf_git_path_submodule()
[thirdparty/git.git] / submodule.c
index 3200b7bb2b2360c7efab86b680ed5d0cafa5e9d3..a31f68812c598e8a29048022f36cc60c2ebd415d 100644 (file)
@@ -1596,3 +1596,34 @@ const char *get_superproject_working_tree(void)
 
        return ret;
 }
+
+int submodule_to_gitdir(struct strbuf *buf, const char *submodule)
+{
+       const struct submodule *sub;
+       const char *git_dir;
+       int ret = 0;
+
+       strbuf_reset(buf);
+       strbuf_addstr(buf, submodule);
+       strbuf_complete(buf, '/');
+       strbuf_addstr(buf, ".git");
+
+       git_dir = read_gitfile(buf->buf);
+       if (git_dir) {
+               strbuf_reset(buf);
+               strbuf_addstr(buf, git_dir);
+       }
+       if (!is_git_directory(buf->buf)) {
+               gitmodules_config();
+               sub = submodule_from_path(null_sha1, submodule);
+               if (!sub) {
+                       ret = -1;
+                       goto cleanup;
+               }
+               strbuf_reset(buf);
+               strbuf_git_path(buf, "%s/%s", "modules", sub->name);
+       }
+
+cleanup:
+       return ret;
+}