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

[PATCH v4 4/4] submodule: record superproject gitdir during 'update'

From
Emily Shaffer <emilyshaffer@google.com>
Date
Oct 14, 2021, 20:34 UTC
Message-ID
<20211014203416.2802639-5-emilyshaffer@google.com>
In-Reply-To
<20211014203416.2802639-1-emilyshaffer@google.com>

A recorded hint path to the superproject's gitdir might be added during 'git submodule add', but in some cases - like submodules which were created before 'git submodule add' learned to record that info - it might be useful to update the hint. Let's do it during 'git submodule update', when we already have a handle to the superproject while calling operations on the submodules.

Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
---
 git-submodule.sh            | 14 ++++++++++++++
 t/t7406-submodule-update.sh | 12 ++++++++++++
 2 files changed, 26 insertions(+)
diff --git a/git-submodule.sh b/git-submodule.sh
index 652861aa66..ec02eb5971 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -449,6 +449,20 @@ cmd_update()
 			;;
 		esac
 
+		# Cache a pointer to the superproject's gitdir. This may have
+		# changed, unless it's a fresh clone. Writes it to worktree
+		# if applicable, otherwise to local.
+		if test -z "$just_cloned"
+		then
+			sm_gitdir="$(git -C "$sm_path" rev-parse --absolute-git-dir)"
+			relative_gitdir="$(git rev-parse --path-format=relative \
+							 --prefix "${sm_gitdir}" \
+							 --git-dir)"
+
+			git -C "$sm_path" config --worktree \
+				submodule.superprojectgitdir "$relative_gitdir"
+		fi
+
 		if test -n "$recursive"
 		then
 			(
diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
index 11cccbb333..7fd5741a5a 100755
--- a/t/t7406-submodule-update.sh
+++ b/t/t7406-submodule-update.sh
@@ -1061,4 +1061,16 @@ test_expect_success 'submodule update --quiet passes quietness to fetch with a s
 	)
 '
 
+test_expect_success 'submodule update adds superproject gitdir to older repos' '
+	(cd super &&
+	 git -C submodule config --unset submodule.superprojectGitdir &&
+	 git submodule update &&
+	 test-tool path-utils relative_path \
+		"$(git rev-parse --absolute-git-dir)" \
+		"$(git -C submodule rev-parse --absolute-git-dir)" >expect &&
+	 git -C submodule config submodule.superprojectGitdir >actual &&
+	 test_cmp expect actual
+	)
+'
+
 test_done
-- 
2.33.0.1079.g6e70778dc9-goog
Previous: Emily ShafferNext: Derrick Stolee
Message 10 of 31 in “cache parent project's gitdir in submodules”
  1. 0/4 cache parent project's gitdir in submodulesEmily Shaffer, Oct 14, 2021
  2. 1/4 t7400-submodule-basic: modernize inspect() helperEmily Shaffer, Oct 14, 2021
  3. 2/4 introduce submodule.superprojectGitDir recordEmily Shaffer, Oct 14, 2021
  4. 3/4 submodule: record superproject gitdir during absorbgitdirsEmily Shaffer, Oct 14, 2021
  5. Jonathan TanOct 18, 2021
  6. Derrick StoleeOct 25, 2021
  7. Emily ShafferNov 4, 2021
  8. Derrick StoleeNov 8, 2021
  9. Emily ShafferNov 4, 2021
  10. 4/4 submodule: record superproject gitdir during 'update'Emily Shaffer, Oct 14, 2021
  11. Derrick StoleeOct 25, 2021
  12. Derrick StoleeOct 25, 2021
  13. 0/4 cache parent project's gitdir in submodulesEmily Shaffer, Nov 4, 2021
  14. 1/4 t7400-submodule-basic: modernize inspect() helperEmily Shaffer, Nov 4, 2021
  15. 2/4 introduce submodule.superprojectGitDir recordEmily Shaffer, Nov 4, 2021
  16. Junio C HamanoNov 5, 2021
  17. Emily ShafferNov 8, 2021
  18. 3/4 submodule: record superproject gitdir during absorbgitdirsEmily Shaffer, Nov 4, 2021
  19. 4/4 submodule: record superproject gitdir during 'update'Emily Shaffer, Nov 4, 2021
  20. Junio C HamanoNov 5, 2021
  21. Ævar Arnfjörð BjarmasonNov 5, 2021
  22. Emily ShafferNov 8, 2021
  23. Ævar Arnfjörð BjarmasonNov 9, 2021
  24. Emily ShafferNov 9, 2021
  25. Emily ShafferNov 9, 2021
  26. Ævar Arnfjörð BjarmasonNov 5, 2021
  27. Emily ShafferNov 8, 2021
  28. Ævar Arnfjörð BjarmasonNov 9, 2021
  29. Derrick StoleeNov 8, 2021
  30. Emily ShafferNov 8, 2021
  31. Derrick StoleeNov 9, 2021

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.