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

[PATCH v3 1/1] submodule: fix 'submodule status' when called from a subdirectory

From
Manish Goregaokar via GitGitGadget <gitgitgadget@gmail.com>
Date
Nov 25, 2019, 04:15 UTC
Message-ID
<8dcea6b399923e931625ef09d66661e93975b93a.1574655344.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.472.v3.git.1574655344.gitgitgadget@gmail.com>
From: Manish Goregaokar <manishsmail@gmail.com>

When calling `git submodule status` while in a subdirectory, we are incorrectly not detecting modified submodules and thus reporting that all of the submodules are unchanged.

This is because the submodule helper is calling `diff-index` with the submodule path assuming the path is relative to the current prefix directory, however the submodule path used is actually relative to the root.

Always pass NULL as the `prefix` when running diff-files on the submodule, to make sure the submodule's path is interpreted as relative to the superproject's repository root.

Signed-off-by: Manish Goregaokar <manishsmail@gmail.com>
---
 builtin/submodule--helper.c |  3 ++-
 t/t7400-submodule-basic.sh  | 22 ++++++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 909e77e802..eeea8dfa97 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -802,7 +802,8 @@ static void status_submodule(const char *path, const struct object_id *ce_oid,
 			 path, NULL);
 
 	git_config(git_diff_basic_config, NULL);
-	repo_init_revisions(the_repository, &rev, prefix);
+
+	repo_init_revisions(the_repository, &rev, NULL);
 	rev.abbrev = 0;
 	diff_files_args.argc = setup_revisions(diff_files_args.argc,
 					       diff_files_args.argv,
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index a208cb26e1..09d8408f88 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -356,6 +356,28 @@ test_expect_success 'status should only print one line' '
 	test_line_count = 1 lines
 '
 
+test_expect_success 'status from subdirectory should have the same SHA1' '
+	test_when_finished "rmdir addtest/subdir" &&
+	(
+		cd addtest &&
+		mkdir subdir &&
+		git submodule status >output &&
+		awk "{print \$1}" <output >expect &&
+		cd subdir &&
+		git submodule status >../output &&
+		awk "{print \$1}" <../output >../actual &&
+		test_cmp ../expect ../actual &&
+		git -C ../submod checkout HEAD^ &&
+		git submodule status >../output &&
+		awk "{print \$1}" <../output >../actual2 &&
+		cd .. &&
+		git submodule status >output &&
+		awk "{print \$1}" <output >expect2 &&
+		test_cmp actual2 expect2 &&
+		! test_cmp actual actual2
+	)
+'
+
 test_expect_success 'setup - fetch commit name from submodule' '
 	rev1=$(cd .subrepo && git rev-parse HEAD) &&
 	printf "rev1: %s\n" "$rev1" &&
-- 
gitgitgadget
Previous: Manish Goregaokar via GitGitGadgetNext: Junio C Hamano
Message 9 of 11 in “submodule: Fix 'submodule status' when called from a subdirectory”
  1. 0/1 submodule: Fix 'submodule status' when called from a subdirectoryManish Goregaokar via GitGitGadget, Nov 23, 2019
  2. 1/1 submodule: Fix 'submodule status' when called from a subdirectoryManish Goregaokar via GitGitGadget, Nov 23, 2019
  3. Junio C HamanoNov 24, 2019
  4. 0/1 submodule: Fix 'submodule status' when called from a subdirectoryManish Goregaokar via GitGitGadget, Nov 24, 2019
  5. 1/1 submodule: fix 'submodule status' when called from a subdirectoryManish Goregaokar via GitGitGadget, Nov 24, 2019
  6. Junio C HamanoNov 25, 2019
  7. Manish GoregaokarNov 25, 2019
  8. 0/1 submodule: Fix 'submodule status' when called from a subdirectoryManish Goregaokar via GitGitGadget, Nov 25, 2019
  9. 1/1 submodule: fix 'submodule status' when called from a subdirectoryManish Goregaokar via GitGitGadget, Nov 25, 2019
  10. Junio C HamanoNov 25, 2019
  11. Manish GoregaokarNov 25, 2019

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.