@@ -451,11 +451,12 @@ struct foreach_cb {
int quiet;
int recursive;
int active_only;
+ int populated_only;
};
#define FOREACH_BOOL_FILTER_NOT_SET -1
-#define FOREACH_CB_INIT { .active_only=FOREACH_BOOL_FILTER_NOT_SET }
+#define FOREACH_CB_INIT { .active_only = FOREACH_BOOL_FILTER_NOT_SET, .populated_only = 1 }
static void runcommand_in_submodule(const struct cache_entry *list_item,
struct foreach_cb *info)
@@ -475,9 +476,6 @@ static void runcommand_in_submodule(const struct cache_entry *list_item,
die(_("No url found for submodule path '%s' in .gitmodules"),
displaypath);
- if (!is_submodule_populated_gently(path, NULL))
- goto cleanup;
-
prepare_submodule_repo_env(&cp.env_array);
/*
@@ -554,7 +552,6 @@ static void runcommand_in_submodule(const struct cache_entry *list_item,
displaypath);
}
-cleanup:
free(displaypath);
}
@@ -571,6 +568,9 @@ static void runcommand_in_submodule_filtered_cb(const struct cache_entry *list_i
return;
}
+ if (info->populated_only != is_submodule_populated_gently(path, NULL))
+ return;
+
runcommand_in_submodule(list_item, info);
}
@@ -586,11 +586,13 @@ static int module_foreach(int argc, const char **argv, const char *prefix)
N_("Recurse into nested submodules")),
OPT_BOOL(0, "active", &info.active_only,
N_("Call command depending on submodule active state")),
+ OPT_BOOL(0, "populated", &info.populated_only,
+ N_("Call command depending on submodule populated state")),
OPT_END()
};
const char *const git_submodule_helper_usage[] = {
- N_("git submodule--helper foreach [--quiet] [--recursive] [--[no-]active] [--] <command>"),
+ N_("git submodule--helper foreach [--quiet] [--recursive] [--[no-]active] [--[no-]populated] [--] <command>"),
NULL
};
@@ -80,6 +80,21 @@ test_expect_success 'test basic "submodule foreach" usage' '
test_i18ncmp expect actual
'
+sub2sha1=$(cd super/sub2 && git rev-parse HEAD)
+
+cat > expect <<EOF
+Entering 'sub2'
+$pwd/clone-foo2-sub2-$sub2sha1
+EOF
+
+test_expect_success 'test "submodule--helper foreach --no-populated" usage' '
+ (
+ cd clone &&
+ git submodule--helper foreach --no-populated "echo \$toplevel-\$name-\$path-\$sha1" > ../actual
+ ) &&
+ test_i18ncmp expect actual
+'
+
cat > expect <<EOF
Entering 'sub3'
$pwd/clone-foo3-sub3-$sub3sha1