submodule: properly recurse for read-tree and checkout
[gitweb.git] / submodule.c
index cdbecfbeaf8c16af192845c95477985e659bcd20..b3ae642f29205655342b08343d440d7f333a39f9 100644 (file)
@@ -1329,7 +1329,7 @@ int bad_to_remove_submodule(const char *path, unsigned flags)
        cp.dir = path;
        if (start_command(&cp)) {
                if (flags & SUBMODULE_REMOVAL_DIE_ON_ERROR)
-                       die(_("could not start 'git status in submodule '%s'"),
+                       die(_("could not start 'git status' in submodule '%s'"),
                                path);
                ret = -1;
                goto out;
@@ -1342,7 +1342,7 @@ int bad_to_remove_submodule(const char *path, unsigned flags)
 
        if (finish_command(&cp)) {
                if (flags & SUBMODULE_REMOVAL_DIE_ON_ERROR)
-                       die(_("could not run 'git status in submodule '%s'"),
+                       die(_("could not run 'git status' in submodule '%s'"),
                                path);
                ret = -1;
        }
@@ -1363,7 +1363,7 @@ static int submodule_has_dirty_index(const struct submodule *sub)
 {
        struct child_process cp = CHILD_PROCESS_INIT;
 
-       prepare_submodule_repo_env_no_git_dir(&cp.env_array);
+       prepare_submodule_repo_env(&cp.env_array);
 
        cp.git_cmd = 1;
        argv_array_pushl(&cp.args, "diff-index", "--quiet",
@@ -1380,7 +1380,7 @@ static int submodule_has_dirty_index(const struct submodule *sub)
 static void submodule_reset_index(const char *path)
 {
        struct child_process cp = CHILD_PROCESS_INIT;
-       prepare_submodule_repo_env_no_git_dir(&cp.env_array);
+       prepare_submodule_repo_env(&cp.env_array);
 
        cp.git_cmd = 1;
        cp.no_stdin = 1;
@@ -1438,7 +1438,7 @@ int submodule_move_head(const char *path,
                }
        }
 
-       prepare_submodule_repo_env_no_git_dir(&cp.env_array);
+       prepare_submodule_repo_env(&cp.env_array);
 
        cp.git_cmd = 1;
        cp.no_stdin = 1;
@@ -1446,7 +1446,7 @@ int submodule_move_head(const char *path,
 
        argv_array_pushf(&cp.args, "--super-prefix=%s%s/",
                        get_super_prefix_or_empty(), path);
-       argv_array_pushl(&cp.args, "read-tree", NULL);
+       argv_array_pushl(&cp.args, "read-tree", "--recurse-submodules", NULL);
 
        if (flags & SUBMODULE_MOVE_HEAD_DRY_RUN)
                argv_array_push(&cp.args, "-n");
@@ -1468,16 +1468,16 @@ int submodule_move_head(const char *path,
 
        if (!(flags & SUBMODULE_MOVE_HEAD_DRY_RUN)) {
                if (new) {
-                       struct child_process cp1 = CHILD_PROCESS_INIT;
+                       child_process_init(&cp);
                        /* also set the HEAD accordingly */
-                       cp1.git_cmd = 1;
-                       cp1.no_stdin = 1;
-                       cp1.dir = path;
+                       cp.git_cmd = 1;
+                       cp.no_stdin = 1;
+                       cp.dir = path;
 
-                       argv_array_pushl(&cp1.args, "update-ref", "HEAD",
-                                        new ? new : EMPTY_TREE_SHA1_HEX, NULL);
+                       prepare_submodule_repo_env(&cp.env_array);
+                       argv_array_pushl(&cp.args, "update-ref", "HEAD", new, NULL);
 
-                       if (run_command(&cp1)) {
+                       if (run_command(&cp)) {
                                ret = -1;
                                goto out;
                        }
@@ -1866,3 +1866,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;
+}