From: Prathamesh Chavan Date: Fri, 02 Jun 2017 11:24:27 GMT Subject: [GSoC][PATCH v6 1/2] submodule: fix buggy $path and $sm_path variable's value Message-ID: <20170602112428.11131-1-pc44800@gmail.com> In-Reply-To: <48149a4a-c7e3-d70e-7894-369681587372@ramsayjones.plus.com> According to the documentation about git-submodule foreach subcommand's $path variable: $path is the name of the submodule directory relative to the superproject But it was observed when the value of the $path value deviates from this for the nested submodules when the is run from a subdirectory. This patch aims for its correction. Additional test cases added to the submodule-foreach test suite in t7407, to check the submodule foreach --recursive behavior from a subdirectory as this was missing from the test suite. Helped-by: Brandon Williams Mentored-by: Christian Couder Mentored-by: Stefan Beller Signed-off-by: Prathamesh Chavan --- git-submodule.sh | 2 +- t/t7407-submodule-foreach.sh | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/git-submodule.sh b/git-submodule.sh index c0d0e9a4c..ea6f56337 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -344,9 +344,9 @@ cmd_foreach() prefix="$prefix$sm_path/" sanitize_submodule_env cd "$sm_path" && - sm_path=$(git submodule--helper relative-path "$sm_path" "$wt_prefix") && # we make $path available to scripts ... path=$sm_path && + sm_path=$displaypath && if test $# -eq 1 then eval "$1" diff --git a/t/t7407-submodule-foreach.sh b/t/t7407-submodule-foreach.sh index 6ba5daf42..f4e07eee3 100755 --- a/t/t7407-submodule-foreach.sh +++ b/t/t7407-submodule-foreach.sh @@ -197,6 +197,39 @@ test_expect_success 'test messages from "foreach --recursive" from subdirectory' test_i18ncmp expect actual ' +sub1sha1=$(cd clone2/sub1 && git rev-parse HEAD) +sub2sha1=$(cd clone2/sub2 && git rev-parse HEAD) +sub3sha1=$(cd clone2/sub3 && git rev-parse HEAD) +nested1sha1=$(cd clone2/nested1 && git rev-parse HEAD) +nested2sha1=$(cd clone2/nested1/nested2 && git rev-parse HEAD) +nested3sha1=$(cd clone2/nested1/nested2/nested3 && git rev-parse HEAD) +submodulesha1=$(cd clone2/nested1/nested2/nested3/submodule && git rev-parse HEAD) + +cat >expect <../../actual + ) && + test_i18ncmp expect actual +' + cat > expect <