]> git.ipfire.org Git - thirdparty/git.git/commitdiff
submodule: fix 'submodule status' when called from a subdirectory
authorManish Goregaokar <manishsmail@gmail.com>
Mon, 25 Nov 2019 04:15:44 +0000 (04:15 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 25 Nov 2019 05:08:25 +0000 (14:08 +0900)
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>
builtin/submodule--helper.c
t/t7400-submodule-basic.sh

index 909e77e802d3302c2486aeb1646fe953d81a0a92..eeea8dfa977c4ce3cfd3c26c3e334c32cb6d0460 100644 (file)
@@ -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,
index a208cb26e1dfd4b1a147f620747c025600ce7181..7382f500a4fa5d2940256b7587bc83196ecd62fd 100755 (executable)
@@ -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 expect2 actual2 &&
+               ! 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" &&