Skip to content

Commit f2dcfcc

Browse files
committed
Merge branch 'pk/status-of-uncloned-submodule'
The way "git submodule status" reports an initialized but not yet populated submodule has not been reimplemented correctly when a part of the "git submodule" command was rewritten in C, which has been corrected. * pk/status-of-uncloned-submodule: t7400: testcase for submodule status on unregistered inner git repos submodule: fix status of initialized but not cloned submodules t7400: add a testcase for submodule status on empty dirs
2 parents 78e67cd + f38c924 commit f2dcfcc

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

builtin/submodule--helper.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,8 @@ static void status_submodule(const char *path, const struct object_id *ce_oid,
782782
struct argv_array diff_files_args = ARGV_ARRAY_INIT;
783783
struct rev_info rev;
784784
int diff_files_result;
785+
struct strbuf buf = STRBUF_INIT;
786+
const char *git_dir;
785787

786788
if (!submodule_from_path(the_repository, &null_oid, path))
787789
die(_("no submodule mapping found in .gitmodules for path '%s'"),
@@ -794,10 +796,18 @@ static void status_submodule(const char *path, const struct object_id *ce_oid,
794796
goto cleanup;
795797
}
796798

797-
if (!is_submodule_active(the_repository, path)) {
799+
strbuf_addf(&buf, "%s/.git", path);
800+
git_dir = read_gitfile(buf.buf);
801+
if (!git_dir)
802+
git_dir = buf.buf;
803+
804+
if (!is_submodule_active(the_repository, path) ||
805+
!is_git_directory(git_dir)) {
798806
print_status(flags, '-', path, ce_oid, displaypath);
807+
strbuf_release(&buf);
799808
goto cleanup;
800809
}
810+
strbuf_release(&buf);
801811

802812
argv_array_pushl(&diff_files_args, "diff-files",
803813
"--ignore-submodules=dirty", "--quiet", "--",

t/t7400-submodule-basic.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,21 @@ test_expect_success 'add aborts on repository with no commits' '
5555
test_i18ncmp expect actual
5656
'
5757

58+
test_expect_success 'status should ignore inner git repo when not added' '
59+
rm -fr inner &&
60+
mkdir inner &&
61+
(
62+
cd inner &&
63+
git init &&
64+
>t &&
65+
git add t &&
66+
git commit -m "initial"
67+
) &&
68+
test_must_fail git submodule status inner 2>output.err &&
69+
rm -fr inner &&
70+
test_i18ngrep "^error: .*did not match any file(s) known to git" output.err
71+
'
72+
5873
test_expect_success 'setup - repository in init subdirectory' '
5974
mkdir init &&
6075
(
@@ -412,6 +427,14 @@ test_expect_success 'init should register submodule url in .git/config' '
412427
test_cmp expect url
413428
'
414429

430+
test_expect_success 'status should still be "missing" after initializing' '
431+
rm -fr init &&
432+
mkdir init &&
433+
git submodule status >lines &&
434+
rm -fr init &&
435+
grep "^-$rev1" lines
436+
'
437+
415438
test_failure_with_unknown_submodule () {
416439
test_must_fail git submodule $1 no-such-submodule 2>output.err &&
417440
test_i18ngrep "^error: .*no-such-submodule" output.err

0 commit comments

Comments
 (0)