@@ -441,6 +441,13 @@ static int parse_config(const char *var, const char *value, void *data)
me->gitmodules_oid,
name.buf);
+ /*
+ * FIXME me->overwrite=1 is only meant to overwrite existing submodule
+ * configurations when we're reading from another .gitmodules (e.g. from
+ * another commit), but it also unintentionally changes behavior when
+ * there are multiple configurations in a single .gitmodules - instead
+ * of respecting the first value, we now respect the last value.
+ */
if (!strcmp(item.buf, "path")) {
if (!value)
ret = config_error_nonbool(var);
@@ -29,11 +29,31 @@ int cmd__submodule_config(int argc, const char **argv)
my_argc--;
}
- if (my_argc % 2 != 0)
+ if (my_argc > 1 && my_argc % 2 != 0)
die_usage(argc, argv, "Wrong number of arguments.");
setup_git_directory();
+ if (my_argc == 1) {
+ const struct submodule *submodule;
+ const char *path_or_name;
+
+ path_or_name = arg[0];
+ if (lookup_name) {
+ submodule = submodule_from_name(the_repository,
+ null_oid(), path_or_name);
+ } else
+ submodule = submodule_from_path(the_repository,
+ null_oid(), path_or_name);
+ if (!submodule)
+ die_usage(argc, argv, "Submodule not found.");
+
+ printf("Submodule name: '%s' for path '%s'\n", submodule->name,
+ submodule->path);
+
+ return 0;
+ }
+
while (*arg) {
struct object_id commit_oid;
const struct submodule *submodule;
@@ -258,4 +258,26 @@ test_expect_success 'reading nested submodules config when .gitmodules is not in
)
'
+test_expect_success 'multiple config fields in .gitmodules' '
+ test_when_finished "rm -fr super-duplicate" &&
+ mkdir super-duplicate &&
+ (cd super-duplicate &&
+ git init &&
+ git submodule add ../submodule &&
+ git config --file .gitmodules --add submodule.submodule.path ignored &&
+ git config --file .gitmodules --add submodule.submodule.url ignored &&
+ git add .gitmodules &&
+ git commit -m "duplicate fields in .gitmodules" &&
+ test-tool submodule-config HEAD submodule >actual 2>warning &&
+ grep "Skipping second one" warning &&
+ echo "Submodule name: ${SQ}submodule${SQ} for path ${SQ}submodule${SQ}" >expect &&
+ test_cmp expect actual &&
+ # FIXME this should give the same result as "HEAD", but there is
+ # a bug where if we use null_oid() instead of the real commit
+ # id, the second .path gets respected instead of the first.
+ test_must_fail test-tool submodule-config submodule 2>null-oid-error &&
+ grep "Submodule not found" null-oid-error
+ )
+'
+
test_done