Skip to content

Commit

Permalink
Merge branch 'pk/status-of-uncloned-submodule'
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gitster committed Feb 14, 2020
2 parents 78e67cd + f38c924 commit f2dcfcc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
12 changes: 11 additions & 1 deletion builtin/submodule--helper.c
Expand Up @@ -782,6 +782,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'"),
Expand All @@ -794,10 +796,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", "--",
Expand Down
23 changes: 23 additions & 0 deletions t/t7400-submodule-basic.sh
Expand Up @@ -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 &&
(
Expand Down Expand Up @@ -412,6 +427,14 @@ test_expect_success 'init should register submodule url in .git/config' '
test_cmp expect url
'

test_expect_success '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
Expand Down

0 comments on commit f2dcfcc

Please sign in to comment.