Skip to content

Commit 1f3aea2

Browse files
Manishearthgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5fa0f52 commit 1f3aea2

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

builtin/submodule--helper.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,8 @@ static void status_submodule(const char *path, const struct object_id *ce_oid,
802802
path, NULL);
803803

804804
git_config(git_diff_basic_config, NULL);
805-
repo_init_revisions(the_repository, &rev, prefix);
805+
806+
repo_init_revisions(the_repository, &rev, NULL);
806807
rev.abbrev = 0;
807808
diff_files_args.argc = setup_revisions(diff_files_args.argc,
808809
diff_files_args.argv,

t/t7400-submodule-basic.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,28 @@ test_expect_success 'status should only print one line' '
356356
test_line_count = 1 lines
357357
'
358358

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+
359381
test_expect_success 'setup - fetch commit name from submodule' '
360382
rev1=$(cd .subrepo && git rev-parse HEAD) &&
361383
printf "rev1: %s\n" "$rev1" &&

0 commit comments

Comments
 (0)