submodule: fix status of initialized but not cloned submodules
Original bash helper for "submodule status" was doing a check for initialized but not cloned submodules and prefixed the status with a minus sign in case no .git file or folder was found inside the submodule directory. This check was missed when the original port of the functionality from bash to C was done. Signed-off-by: Peter Kaestle <peter.kaestle@nokia.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Peter Kaestle committed
Jan 24, 2020 at 11:34 UTC
3b2885ec9ba0b1328858231c9f5095e7f85d9f23
2 files changed
+12
-2
builtin/submodule--helper.c
+11
-1
@@ -781,6 +781,8 @@ static void status_submodule(const char *path, const struct object_id *ce_oid,
781
struct argv_array diff_files_args = ARGV_ARRAY_INIT;
782
struct rev_info rev;
783
int diff_files_result;
784
+ struct strbuf buf = STRBUF_INIT;
785
+ const char *git_dir;
786
787
if (!submodule_from_path(the_repository, &null_oid, path))
788
die(_("no submodule mapping found in .gitmodules for path '%s'"),
@@ -793,10 +795,18 @@ static void status_submodule(const char *path, const struct object_id *ce_oid,
795
goto cleanup;
796
}
797
796
- if (!is_submodule_active(the_repository, path)) {
798
+ strbuf_addf(&buf, "%s/.git", path);
799
+ git_dir = read_gitfile(buf.buf);
800
+ if (!git_dir)
801
+ git_dir = buf.buf;
802
+
803
+ if (!is_submodule_active(the_repository, path) ||
804
+ !is_git_directory(git_dir)) {
805
print_status(flags, '-', path, ce_oid, displaypath);
806
+ strbuf_release(&buf);
807
goto cleanup;
808
}
809
+ strbuf_release(&buf);
810
811
argv_array_pushl(&diff_files_args, "diff-files",
812
"--ignore-submodules=dirty", "--quiet", "--",
t/t7400-submodule-basic.sh
+1
-1
@@ -377,7 +377,7 @@ test_expect_success 'init should register submodule url in .git/config' '
377
test_cmp expect url
378
'
379
380
-test_expect_failure 'status should still be "missing" after initializing' '
380
+test_expect_success 'status should still be "missing" after initializing' '
381
rm -fr init &&
382
mkdir init &&
383
git submodule status >lines &&