log: add exhaustive tests for pattern style options & config
[gitweb.git] / submodule.c
index 620504d3251df806e49882b6483b7c764dcae93d..d3299e29c0855b8503f444f659e2b24bba8ecb1f 100644 (file)
@@ -1474,8 +1474,7 @@ int submodule_move_head(const char *path,
                        cp1.no_stdin = 1;
                        cp1.dir = path;
 
-                       argv_array_pushl(&cp1.args, "update-ref", "HEAD",
-                                        new ? new : EMPTY_TREE_SHA1_HEX, NULL);
+                       argv_array_pushl(&cp1.args, "update-ref", "HEAD", new, NULL);
 
                        if (run_command(&cp1)) {
                                ret = -1;
@@ -1866,3 +1865,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;
+}