Merge branch 'ms/submodule-foreach-fix' into maint
authorJunio C Hamano <gitster@pobox.com>
Mon, 29 Jul 2019 19:38:18 +0000 (12:38 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 29 Jul 2019 19:38:18 +0000 (12:38 -0700)
"git submodule foreach" did not protect command line options passed
to the command to be run in each submodule correctly, when the
"--recursive" option was in use.

* ms/submodule-foreach-fix:
submodule foreach: fix recursion of options

builtin/submodule--helper.c
t/t7407-submodule-foreach.sh
index 0bf4aa088e0ca4bf6378d121cfc23e0f42ac3af4..afaf0819c981ff896bf6f0b843b594a660d85a97 100644 (file)
@@ -540,6 +540,7 @@ static void runcommand_in_submodule_cb(const struct cache_entry *list_item,
                if (info->quiet)
                        argv_array_push(&cpr.args, "--quiet");
 
+               argv_array_push(&cpr.args, "--");
                argv_array_pushv(&cpr.args, info->argv);
 
                if (run_command(&cpr))
index 706ae762e0ec2fd0103f7f6788eff13ec86ebd67..6b2aa917e11871eb403c8c79725b1e1944f8d29f 100755 (executable)
@@ -421,4 +421,11 @@ test_expect_success 'option-like arguments passed to foreach commands are not lo
        test_cmp expected actual
 '
 
+test_expect_success 'option-like arguments passed to foreach recurse correctly' '
+       git -C clone2 submodule foreach --recursive "echo be --an-option" >expect &&
+       git -C clone2 submodule foreach --recursive echo be --an-option >actual &&
+       grep -e "--an-option" expect &&
+       test_cmp expect actual
+'
+
 test_done