static struct string_list config_ignore_for_name;
static int config_fetch_recurse_submodules = RECURSE_SUBMODULES_ON_DEMAND;
static struct string_list changed_submodule_paths;
+/*
+ * The following flag is set if the .gitmodules file is unmerged. We then
+ * disable recursion for all submodules where .git/config doesn't have a
+ * matching config entry because we can't guess what might be configured in
+ * .gitmodules unless the user resolves the conflict. When a command line
+ * option is given (which always overrides configuration) this flag will be
+ * ignored.
+ */
+static int gitmodules_is_unmerged;
static int add_submodule_odb(const char *path)
{
ignore_option = unsorted_string_list_lookup(&config_ignore_for_name, path_option->util);
if (ignore_option)
handle_ignore_submodules_arg(diffopt, ignore_option->util);
+ else if (gitmodules_is_unmerged)
+ DIFF_OPT_SET(diffopt, IGNORE_SUBMODULES);
}
}
const char *work_tree = get_git_work_tree();
if (work_tree) {
struct strbuf gitmodules_path = STRBUF_INIT;
+ int pos;
strbuf_addstr(&gitmodules_path, work_tree);
strbuf_addstr(&gitmodules_path, "/.gitmodules");
- git_config_from_file(submodule_config, gitmodules_path.buf, NULL);
+ if (read_cache() < 0)
+ die("index file corrupt");
+ pos = cache_name_pos(".gitmodules", 11);
+ if (pos < 0) { /* .gitmodules not found or isn't merged */
+ pos = -1 - pos;
+ if (active_nr > pos) { /* there is a .gitmodules */
+ const struct cache_entry *ce = active_cache[pos];
+ if (ce_namelen(ce) == 11 &&
+ !memcmp(ce->name, ".gitmodules", 11))
+ gitmodules_is_unmerged = 1;
+ }
+ }
+
+ if (!gitmodules_is_unmerged)
+ git_config_from_file(submodule_config, gitmodules_path.buf, NULL);
strbuf_release(&gitmodules_path);
}
}
while (parent) {
struct diff_options diff_opts;
diff_setup(&diff_opts);
+ DIFF_OPT_SET(&diff_opts, RECURSIVE);
diff_opts.output_format |= DIFF_FORMAT_CALLBACK;
diff_opts.format_callback = submodule_collect_changed_cb;
if (diff_setup_done(&diff_opts) < 0)
default_argv = "on-demand";
}
} else {
- if (config_fetch_recurse_submodules == RECURSE_SUBMODULES_OFF)
+ if ((config_fetch_recurse_submodules == RECURSE_SUBMODULES_OFF) ||
+ gitmodules_is_unmerged)
continue;
if (config_fetch_recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND) {
if (!unsorted_string_list_lookup(&changed_submodule_paths, ce->name))