@matheusbsbs / matheus-bagliano / commits / 1f3aea22c7
Fork 0

submodule: fix 'submodule status' when called from a subdirectory

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Manish Goregaokar committed Nov 25, 2019 at 04:15 UTC 1f3aea22c781d603d56ce794879a8fe8d8dd77d1
2 files changed +24 -1
builtin/submodule--helper.c
+2 -1
@@ -802,7 +802,8 @@ static void status_submodule(const char *path, const struct object_id *ce_oid,
802 path, NULL);
803
804 git_config(git_diff_basic_config, NULL);
805 - repo_init_revisions(the_repository, &rev, prefix);
805 +
806 + repo_init_revisions(the_repository, &rev, NULL);
807 rev.abbrev = 0;
808 diff_files_args.argc = setup_revisions(diff_files_args.argc,
809 diff_files_args.argv,
t/t7400-submodule-basic.sh
+22
@@ -356,6 +356,28 @@ test_expect_success 'status should only print one line' '
356 test_line_count = 1 lines
357 '
358
359 +test_expect_success 'status from subdirectory should have the same SHA1' '
360 + test_when_finished "rmdir addtest/subdir" &&
361 + (
362 + cd addtest &&
363 + mkdir subdir &&
364 + git submodule status >output &&
365 + awk "{print \$1}" <output >expect &&
366 + cd subdir &&
367 + git submodule status >../output &&
368 + awk "{print \$1}" <../output >../actual &&
369 + test_cmp ../expect ../actual &&
370 + git -C ../submod checkout HEAD^ &&
371 + git submodule status >../output &&
372 + awk "{print \$1}" <../output >../actual2 &&
373 + cd .. &&
374 + git submodule status >output &&
375 + awk "{print \$1}" <output >expect2 &&
376 + test_cmp expect2 actual2 &&
377 + ! test_cmp actual actual2
378 + )
379 +'
380 +
381 test_expect_success 'setup - fetch commit name from submodule' '
382 rev1=$(cd .subrepo && git rev-parse HEAD) &&
383 printf "rev1: %s\n" "$rev1" &&