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

[PATCHv4 1/6] submodule foreach: correct path display in recursive submodules

From
Stefan Beller <sbeller@google.com>
Date
Mar 30, 2016, 01:27 UTC
Message-ID
<1459301266-12403-2-git-send-email-sbeller@google.com>
In-Reply-To
<1459301266-12403-1-git-send-email-sbeller@google.com>

The `prefix` was put in front of the display path unconditionally. This is wrong as any relative path computation would need to be at the front, so include the prefix into the display path.

The new test replicates the previous test with the difference of executing from a sub directory. By executing from a sub directory all we would expect all displayed paths to be prefixed by '../'.

Prior to this patch the test would report
    Entering 'nested1/nested2/../nested3'
instead of the expected
    Entering '../nested1/nested2/nested3'
Signed-off-by: Stefan Beller <sbeller@google.com>
---
Notes:
    * reworded commit message
    * when writing the commit message I discovered a new way to fix the bug
      (fix the computation of the displaypath instead of its parameters
       wt_prefix and prefix.)
    
      The result is the same, but I am not yet sure if I like it more.
 git-submodule.sh             |  6 +++---
 t/t7407-submodule-foreach.sh | 20 ++++++++++++++++++++
 2 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/git-submodule.sh b/git-submodule.sh
index 43c68de..b3f248c 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -413,8 +413,8 @@ cmd_foreach()
 		die_if_unmatched "$mode"
 		if test -e "$sm_path"/.git
 		then
-			displaypath=$(relative_path "$sm_path")
-			say "$(eval_gettext "Entering '\$prefix\$displaypath'")"
+			displaypath=$(relative_path "$prefix$sm_path")
+			say "$(eval_gettext "Entering '\$displaypath'")"
 			name=$(git submodule--helper name "$sm_path")
 			(
 				prefix="$prefix$sm_path/"
@@ -434,7 +434,7 @@ cmd_foreach()
 					cmd_foreach "--recursive" "$@"
 				fi
 			) <&3 3<&- ||
-			die "$(eval_gettext "Stopping at '\$prefix\$displaypath'; script returned non-zero status.")"
+			die "$(eval_gettext "Stopping at '\$displaypath'; script returned non-zero status.")"
 		fi
 	done
 }
diff --git a/t/t7407-submodule-foreach.sh b/t/t7407-submodule-foreach.sh
index 7ca10b8..776b349 100755
--- a/t/t7407-submodule-foreach.sh
+++ b/t/t7407-submodule-foreach.sh
@@ -178,6 +178,26 @@ test_expect_success 'test messages from "foreach --recursive"' '
 '
 
 cat > expect <<EOF
+Entering '../nested1'
+Entering '../nested1/nested2'
+Entering '../nested1/nested2/nested3'
+Entering '../nested1/nested2/nested3/submodule'
+Entering '../sub1'
+Entering '../sub2'
+Entering '../sub3'
+EOF
+
+test_expect_success 'test messages from "foreach --recursive" from subdirectory' '
+	(
+		cd clone2 &&
+		mkdir untracked &&
+		cd untracked &&
+		git submodule foreach --recursive >../../actual
+	) &&
+	test_i18ncmp expect actual
+'
+
+cat > expect <<EOF
 nested1-nested1
 nested2-nested2
 nested3-nested3
-- 
2.8.0.2.gb331331
Previous: Stefan BellerNext: Junio C Hamano
Message 2 of 8 in “[PATCHv4 0/6] Fix path bugs in submodule commands executed from sub dir”
  1. Stefan BellerMar 30, 2016
  2. 1/6 submodule foreach: correct path display in recursive submodulesStefan Beller, Mar 30, 2016
  3. Junio C HamanoMar 30, 2016
  4. 2/6 submodule update --init: correct path handling in recursive submodulesStefan Beller, Mar 30, 2016
  5. 3/6 submodule status: correct path handling in recursive submodulesStefan Beller, Mar 30, 2016
  6. 4/6 submodule update: align reporting path for custom command executionStefan Beller, Mar 30, 2016
  7. 5/6 submodule update: test recursive path reporting from subdirectoryStefan Beller, Mar 30, 2016
  8. 6/6 t7407: make expectation as clear as possibleStefan Beller, Mar 30, 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.