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

[PATCHv3 1/5] submodule: prepare recursive path from non root directory

From
Stefan Beller <sbeller@google.com>
Date
Mar 25, 2016, 18:39 UTC
Message-ID
<1458931156-29125-2-git-send-email-sbeller@google.com>
In-Reply-To
<1458931156-29125-1-git-send-email-sbeller@google.com>
One of the first things that happens in most submodule sub commands is
    git submodule--helper list --prefix "$wt_prefix"

Currently the passed --prefix is used for doing path calculation as if we were in that path relative to the repository root, which is why we need to pass "$wt_prefix". A more common way in Git however would be to use

    git -C "$wt_prefix" submodule--helper list

which I want to change to later as it is easier to understand for readers of the code base. That way however does not just pass the prefix into the submodule command, but also changes into that directory. Say you have the following setup:

    repo/ # a superproject repository
    repo/untracked/ # an untracked dir in repo/
    repo/sub/ # a submodule
    repo/sub/subsub # a submodule of a submodule

When in repo/untracked/ and invoking "git submodule status --recursive", the recursed instance of the latter version for listing submodules would try to change into the directory repo/sub/untracked, which is a bug. This happens as we cd into the submodule in git-submodule.sh without clearing wt_prefix, which is the assumed relative path inside the working directory.

Most times that directory doesn't exist and we error out. Fix this potential bug by clearing wt_prefix, such that any recursive instances of will assume to operate from the root of the respective submodule.

When changing wt_prefix, we need to make sure the reported paths stay correct, as paths are reported relative to the wt_prefix. We can fix this by computing the relative path before changing the wt_prefix.

As we do not pass in filenames or pathspecs into submodules recursively, we do not need to care about filenames being relative to wt_prefix, so fixing the display path for error reporting is the only thing we need to do.

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 git-submodule.sh | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/git-submodule.sh b/git-submodule.sh
index 43c68de..d83608c 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -825,8 +825,9 @@ Maybe you want to use 'update --init'?")"
 		if test -n "$recursive"
 		then
 			(
-				prefix="$prefix$sm_path/"
+				prefix="$(relative_path $prefix$sm_path)/"
 				clear_local_git_env
+				wt_prefix=
 				cd "$sm_path" &&
 				eval cmd_update
 			)
@@ -1159,6 +1160,7 @@ cmd_status()
 			(
 				prefix="$displaypath/"
 				clear_local_git_env
+				wt_prefix=
 				cd "$sm_path" &&
 				eval cmd_status
 			) ||
@@ -1239,7 +1241,8 @@ cmd_sync()
 
 				if test -n "$recursive"
 				then
-					prefix="$prefix$sm_path/"
+					prefix=$(relative_path "$prefix$sm_path/")
+					wt_prefix=
 					eval cmd_sync
 				fi
 			)
-- 
2.8.0.rc4.10.g52f3f33.dirty
Previous: Stefan BellerNext: Junio C Hamano
Message 2 of 15 in “[PATCHv3 0/5] submodule helper: cleanup prefix passing”
  1. Stefan BellerMar 25, 2016
  2. 1/5 submodule: prepare recursive path from non root directoryStefan Beller, Mar 25, 2016
  3. Junio C HamanoMar 25, 2016
  4. 2/5 submodule--helper list: lose the extra prefix optionStefan Beller, Mar 25, 2016
  5. 3/5 submodule update: add test for recursive from non root dirStefan Beller, Mar 25, 2016
  6. 4/5 submodule sync: test syncing one submoduleStefan Beller, Mar 25, 2016
  7. 5/5 submodule--helper clone: lose the extra prefix optionStefan Beller, Mar 25, 2016
  8. Junio C HamanoMar 25, 2016
  9. Junio C HamanoMar 25, 2016
  10. Stefan BellerMar 25, 2016
  11. Junio C HamanoMar 25, 2016
  12. Stefan BellerMar 25, 2016
  13. Junio C HamanoMar 25, 2016
  14. Stefan BellerMar 25, 2016
  15. Junio C HamanoMar 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.