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

[PATCH 2/6] submodule update --init: correct path handling in recursive submodules

From
Stefan Beller <sbeller@google.com>
Date
Mar 29, 2016, 23:02 UTC
Message-ID
<1459292558-5840-3-git-send-email-sbeller@google.com>
In-Reply-To
<1459292558-5840-1-git-send-email-sbeller@google.com>
The new test demonstrates a failure in the code prior to this patch.
Instead of getting the expected
    Submodule 'submodule' (${pwd}/submodule) registered for path '../super/submodule'
the `super` directory is omitted and you get
    Submodule 'submodule' (${pwd}/submodule) registered for path '../submodule'
instead.

That happens because the prefix is ignored in `git submodule add`, probably because that function itself cannot recurse; it may however called by recursive instances of `git submodule update`, so we need to respect the `prefix`.

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 git-submodule.sh            |  2 +-
 t/t7406-submodule-update.sh | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 1 deletion(-)
diff --git a/git-submodule.sh b/git-submodule.sh
index 2838069..fdb5fbd 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -474,7 +474,7 @@ cmd_init()
 		die_if_unmatched "$mode"
 		name=$(git submodule--helper name "$sm_path") || exit
 
-		displaypath=$(relative_path "$sm_path")
+		displaypath=$(relative_path "$prefix$sm_path")
 
 		# Copy url setting when it is not set yet
 		if test -z "$(git config "submodule.$name.url")"
diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
index 68ea31d..9a4ba41 100755
--- a/t/t7406-submodule-update.sh
+++ b/t/t7406-submodule-update.sh
@@ -63,6 +63,10 @@ test_expect_success 'setup a submodule tree' '
 	 git submodule add ../none none &&
 	 test_tick &&
 	 git commit -m "none"
+	) &&
+	git clone . recursivesuper &&
+	( cd recursivesuper
+	 git submodule add ../super super
 	)
 '
 
@@ -95,6 +99,35 @@ test_expect_success 'submodule update from subdirectory' '
 	)
 '
 
+supersha1=$(cd super && git rev-parse HEAD)
+mergingsha1=$(cd super/merging && git rev-parse HEAD)
+nonesha1=$(cd super/none && git rev-parse HEAD)
+rebasingsha1=$(cd super/rebasing && git rev-parse HEAD)
+submodulesha1=$(cd super/submodule && git rev-parse HEAD)
+pwd=$(pwd)
+
+cat <<EOF >expect
+Submodule path '../super': checked out '$supersha1'
+Submodule 'merging' ($pwd/merging) registered for path '../super/merging'
+Submodule 'none' ($pwd/none) registered for path '../super/none'
+Submodule 'rebasing' ($pwd/rebasing) registered for path '../super/rebasing'
+Submodule 'submodule' ($pwd/submodule) registered for path '../super/submodule'
+Submodule path '../super/merging': checked out '$mergingsha1'
+Submodule path '../super/none': checked out '$nonesha1'
+Submodule path '../super/rebasing': checked out '$rebasingsha1'
+Submodule path '../super/submodule': checked out '$submodulesha1'
+EOF
+
+test_expect_success 'submodule update --init --recursive from subdirectory' '
+	git -C recursivesuper/super reset --hard HEAD^ &&
+	(cd recursivesuper &&
+	 mkdir tmp &&
+	 cd tmp &&
+	 git submodule update --init --recursive ../super >../../actual
+	) &&
+	test_cmp expect actual
+'
+
 apos="'";
 test_expect_success 'submodule update does not fetch already present commits' '
 	(cd submodule &&
-- 
2.8.0.6.g3d0b0ba
Previous: Junio C HamanoNext: Junio C Hamano
Message 4 of 12 in “[PATCHv3 0/6] Fix path bugs in submodule commands executed from sub dir”
  1. Stefan BellerMar 29, 2016
  2. 1/6 submodule foreach: correct path display in recursive submodulesStefan Beller, Mar 29, 2016
  3. Junio C HamanoMar 29, 2016
  4. 2/6 submodule update --init: correct path handling in recursive submodulesStefan Beller, Mar 29, 2016
  5. Junio C HamanoMar 29, 2016
  6. Stefan BellerMar 30, 2016
  7. 3/6 submodule status: correct path handling in recursive submodulesStefan Beller, Mar 29, 2016
  8. Junio C HamanoMar 29, 2016
  9. 4/6 submodule update: align reporting path for custom command executionStefan Beller, Mar 29, 2016
  10. Junio C HamanoMar 29, 2016
  11. 5/6 submodule update: test recursive path reporting from subdirectoryStefan Beller, Mar 29, 2016
  12. 6/6 t7407: make expectation as clear as possibleStefan Beller, Mar 29, 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.