Skip to content

Commit 30db18b

Browse files
Morian Sonnetgitster
authored andcommitted
submodule foreach: fix recursion of options
Calling git submodule foreach --recursive <subcommand> --<option> leads to an error stating that the option --<option> is unknown to submodule--helper. That is of course only, when <option> is not a valid option for git submodule foreach. The reason for this is, that above call is internally translated into a call to submodule--helper: git submodule--helper foreach --recursive \ -- <subcommand> --<option> This call starts by executing the subcommand with its option inside the first level submodule and continues by calling the next iteration of the submodule foreach call git --super-prefix <submodulepath> submodule--helper \ foreach --recursive <subcommand> --<option> inside the first level submodule. Note that the double dash in front of the subcommand is missing. This problem starts to arise only recently, as the PARSE_OPT_KEEP_UNKNOWN flag for the argument parsing of git submodule foreach was removed in commit a282f5a. Hence, the unknown option is complained about now, as the argument parsing is not properly ended by the double dash. This commit fixes the problem by adding the double dash in front of the subcommand during the recursion. Signed-off-by: Morian Sonnet <[email protected]> Acked-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0d0ac38 commit 30db18b

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

builtin/submodule--helper.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,7 @@ static void runcommand_in_submodule_cb(const struct cache_entry *list_item,
539539
if (info->quiet)
540540
argv_array_push(&cpr.args, "--quiet");
541541

542+
argv_array_push(&cpr.args, "--");
542543
argv_array_pushv(&cpr.args, info->argv);
543544

544545
if (run_command(&cpr))

t/t7407-submodule-foreach.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,4 +411,11 @@ test_expect_success 'multi-argument command passed to foreach is not shell-evalu
411411
test_cmp expected actual
412412
'
413413

414+
test_expect_success 'option-like arguments passed to foreach recurse correctly' '
415+
git -C clone2 submodule foreach --recursive "echo be --an-option" >expect &&
416+
git -C clone2 submodule foreach --recursive echo be --an-option >actual &&
417+
grep -e "--an-option" expect &&
418+
test_cmp expect actual
419+
'
420+
414421
test_done

0 commit comments

Comments
 (0)