git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/7] submodule foreach: correct path computation in recursive submodules

From
Stefan Beller <sbeller@google.com>
Date
Mar 28, 2016, 23:28 UTC
Message-ID
<1459207703-1635-3-git-send-email-sbeller@google.com>
In-Reply-To
<1459207703-1635-1-git-send-email-sbeller@google.com>
The test which is fixed by this patch would report
    Entering 'nested1/nested2/../nested3'
instead of the expected
    Entering '../nested1/nested2/nested3'

because the prefix is put unconditionally in front and after that a computed display path with is affected by `wt_prefix`. This is wrong as any relative path computation would need to be at the front. By emptying the `wt_prefix` in recursive submodules and adding the information of any relative path into the `prefix` this is fixed.

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 git-submodule.sh             | 3 ++-
 t/t7407-submodule-foreach.sh | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/git-submodule.sh b/git-submodule.sh
index 43c68de..2838069 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -417,10 +417,11 @@ cmd_foreach()
 			say "$(eval_gettext "Entering '\$prefix\$displaypath'")"
 			name=$(git submodule--helper name "$sm_path")
 			(
-				prefix="$prefix$sm_path/"
+				prefix="$(relative_path $prefix$sm_path)/"
 				clear_local_git_env
 				cd "$sm_path" &&
 				sm_path=$(relative_path "$sm_path") &&
+				wt_prefix=
 				# we make $path available to scripts ...
 				path=$sm_path &&
 				if test $# -eq 1
diff --git a/t/t7407-submodule-foreach.sh b/t/t7407-submodule-foreach.sh
index f868636..776b349 100755
--- a/t/t7407-submodule-foreach.sh
+++ b/t/t7407-submodule-foreach.sh
@@ -187,7 +187,7 @@ Entering '../sub2'
 Entering '../sub3'
 EOF
 
-test_expect_failure 'test messages from "foreach --recursive" from subdirectory' '
+test_expect_success 'test messages from "foreach --recursive" from subdirectory' '
 	(
 		cd clone2 &&
 		mkdir untracked &&
-- 
2.8.0.rc4.23.gd22361a.dirty
Previous: Stefan BellerNext: Junio C Hamano
Message 3 of 17 in “Fix path bugs in submodule commands executed from sub dir [WAS: submodule--helper clone: lose the extra prefix option]”
  1. 0/7 Fix path bugs in submodule commands executed from sub dir [WAS: submodule--helper clone: lose the extra prefix option]Stefan Beller, Mar 28, 2016
  2. 1/7 submodule foreach: test path handling in recursive submodulesStefan Beller, Mar 28, 2016
  3. 2/7 submodule foreach: correct path computation in recursive submodulesStefan Beller, Mar 28, 2016
  4. Junio C HamanoMar 29, 2016
  5. Junio C HamanoMar 29, 2016
  6. Stefan BellerMar 29, 2016
  7. Stefan BellerMar 29, 2016
  8. 3/7 submodule update --init: test path handling in recursive submodulesStefan Beller, Mar 28, 2016
  9. Junio C HamanoMar 29, 2016
  10. 4/7 submodule update --init: correct path handling in recursive submodulesStefan Beller, Mar 28, 2016
  11. Junio C HamanoMar 29, 2016
  12. Junio C HamanoMar 29, 2016
  13. Stefan BellerMar 29, 2016
  14. 5/7 t7407: make expectation as clear as possibleStefan Beller, Mar 28, 2016
  15. Junio C HamanoMar 29, 2016
  16. 6/7 submodule status: test path handling in recursive submodulesStefan Beller, Mar 28, 2016
  17. 7/7 submodule status: fix path handling in recursive submodulesStefan Beller, Mar 28, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.