From ace912bfb8e0cf85e29cc2d81fd847a96637be36 Mon Sep 17 00:00:00 2001 From: Peter Kaestle Date: Fri, 24 Jan 2020 11:34:03 +0100 Subject: t7400: add a testcase for submodule status on empty dirs We have test coverage for "git submodule status" output in various cases, i.e. 1) not-init, not-cloned: status should initially be "missing" 2) init, not-cloned: status should be "missing" 3) not-init, cloned: 4) init, cloned: status should be "up-to-date" after update 4.1) + modified: status should be "modified" after submodule commit 4.2) + modified, committed: status should be "up-to-date" after update but the cases 2) and 3) are not covered. Test that submodule status reports initialized but not cloned submodules as missing to fill the gap in test coverage; this covers case (2) above, but case (3) remains uncovered. Signed-off-by: Peter Kaestle Signed-off-by: Junio C Hamano diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index a208cb2..5c9acb8 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -377,6 +377,14 @@ test_expect_success 'init should register submodule url in .git/config' ' test_cmp expect url ' +test_expect_failure 'status should still be "missing" after initializing' ' + rm -fr init && + mkdir init && + git submodule status >lines && + rm -fr init && + grep "^-$rev1" lines +' + test_failure_with_unknown_submodule () { test_must_fail git submodule $1 no-such-submodule 2>output.err && test_i18ngrep "^error: .*no-such-submodule" output.err -- cgit v0.10.2-6-g49f6 From 3b2885ec9ba0b1328858231c9f5095e7f85d9f23 Mon Sep 17 00:00:00 2001 From: Peter Kaestle Date: Fri, 24 Jan 2020 11:34:04 +0100 Subject: 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 Signed-off-by: Junio C Hamano diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index ad8df0d..ecec937 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -781,6 +781,8 @@ static void status_submodule(const char *path, const struct object_id *ce_oid, struct argv_array diff_files_args = ARGV_ARRAY_INIT; struct rev_info rev; int diff_files_result; + struct strbuf buf = STRBUF_INIT; + const char *git_dir; if (!submodule_from_path(the_repository, &null_oid, path)) 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, goto cleanup; } - if (!is_submodule_active(the_repository, path)) { + strbuf_addf(&buf, "%s/.git", path); + git_dir = read_gitfile(buf.buf); + if (!git_dir) + git_dir = buf.buf; + + if (!is_submodule_active(the_repository, path) || + !is_git_directory(git_dir)) { print_status(flags, '-', path, ce_oid, displaypath); + strbuf_release(&buf); goto cleanup; } + strbuf_release(&buf); argv_array_pushl(&diff_files_args, "diff-files", "--ignore-submodules=dirty", "--quiet", "--", diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index 5c9acb8..86b424f 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -377,7 +377,7 @@ test_expect_success 'init should register submodule url in .git/config' ' test_cmp expect url ' -test_expect_failure 'status should still be "missing" after initializing' ' +test_expect_success 'status should still be "missing" after initializing' ' rm -fr init && mkdir init && git submodule status >lines && -- cgit v0.10.2-6-g49f6 From f38c92452d0ad75b1c5c5cfdd04223ad7a9a08a9 Mon Sep 17 00:00:00 2001 From: Peter Kaestle Date: Mon, 3 Feb 2020 00:32:44 +0100 Subject: t7400: testcase for submodule status on unregistered inner git repos We have test coverage for "git submodule status" output in various cases, i.e. 1) not-init, not-cloned: status should initially be "missing" 2) init, not-cloned: status should be "missing" 3) not-init, cloned: status should ignore the inner git-repo 4) init, cloned: status should be "up-to-date" after update 4.1) + modified: status should be "modified" after submodule commit 4.2) + modified, committed: status should be "up-to-date" after update the case 3) is not covered yet. Test that submodule status reports an inner git repo as unknown, while it is not added to the superproject. This covers case (3). Signed-off-by: Peter Kaestle Signed-off-by: Junio C Hamano diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index 86b424f..e07afe9 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -55,6 +55,21 @@ test_expect_success 'add aborts on repository with no commits' ' test_i18ncmp expect actual ' +test_expect_success 'status should ignore inner git repo when not added' ' + rm -fr inner && + mkdir inner && + ( + cd inner && + git init && + >t && + git add t && + git commit -m "initial" + ) && + test_must_fail git submodule status inner 2>output.err && + rm -fr inner && + test_i18ngrep "^error: .*did not match any file(s) known to git" output.err +' + test_expect_success 'setup - repository in init subdirectory' ' mkdir init && ( -- cgit v0.10.2-6-g49f6