Skip to content

Commit c46e5bd

Browse files
committed
submodule foreach: fix recursion of options
Calling git submodule foreach --recursive git reset --hard leads to an error stating that the option --hard is unknown to submodule--helper. Reasons: . Above call is internally translated into git submodule--helper foreach --recursive -- git reset --hard . After calling git reset --hard inside the first first level submodule, git --super-prefix <submodulepath> submodule--helper \ foreach --recursive git reset --hard is called. Note the missing --. . Due to the removal of PARSE_OPT_KEEP_UNKNOWN in commit a282f5a the option --hard is not passed to git reset anymore, but leads to git submodule--helper complaining about an unknown option. Fix: . Add -- before the command to execute, such that now correctly git --super-prefix <submodulepath> submodule--helper \ foreach --recursive -- git reset --hard is called. Signed-off-by: Morian Sonnet <[email protected]>
1 parent b697d92 commit c46e5bd

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
@@ -540,6 +540,7 @@ static void runcommand_in_submodule_cb(const struct cache_entry *list_item,
540540
if (info->quiet)
541541
argv_array_push(&cpr.args, "--quiet");
542542

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

545546
if (run_command(&cpr))

t/t7407-submodule-foreach.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,4 +421,11 @@ test_expect_success 'option-like arguments passed to foreach commands are not lo
421421
test_cmp expected actual
422422
'
423423

424+
test_expect_success 'option-like arguments passed to foreach recurse correctly' '
425+
(
426+
cd super &&
427+
git submodule foreach --recursive git reset --hard
428+
)
429+
'
430+
424431
test_done

0 commit comments

Comments
 (0)