Skip to content

Commit 8a7b618

Browse files
committed
Merge branch 'rs/status-with-removed-submodule' into next
"git submodule status" misbehaved on a submodule that has been removed from the working tree. * rs/status-with-removed-submodule: submodule: check for NULL return of get_submodule_ref_store()
2 parents 86e2c4d + 74b6bda commit 8a7b618

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

builtin/submodule--helper.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,9 +654,13 @@ static void status_submodule(const char *path, const struct object_id *ce_oid,
654654
displaypath);
655655
} else if (!(flags & OPT_CACHED)) {
656656
struct object_id oid;
657+
struct ref_store *refs = get_submodule_ref_store(path);
657658

658-
if (refs_head_ref(get_submodule_ref_store(path),
659-
handle_submodule_head_ref, &oid))
659+
if (!refs) {
660+
print_status(flags, '-', path, ce_oid, displaypath);
661+
goto cleanup;
662+
}
663+
if (refs_head_ref(refs, handle_submodule_head_ref, &oid))
660664
die(_("could not resolve HEAD ref inside the "
661665
"submodule '%s'"), path);
662666

t/t7400-submodule-basic.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,21 @@ test_expect_success 'moving the superproject does not break submodules' '
821821
)
822822
'
823823

824+
test_expect_success 'moving the submodule does not break the superproject' '
825+
(
826+
cd addtest2 &&
827+
git submodule status
828+
) >actual &&
829+
sed -e "s/^ \([^ ]* repo\) .*/-\1/" <actual >expect &&
830+
mv addtest2/repo addtest2/repo.bak &&
831+
test_when_finished "mv addtest2/repo.bak addtest2/repo" &&
832+
(
833+
cd addtest2 &&
834+
git submodule status
835+
) >actual &&
836+
test_cmp expect actual
837+
'
838+
824839
test_expect_success 'submodule add --name allows to replace a submodule with another at the same path' '
825840
(
826841
cd addtest2 &&

0 commit comments

Comments
 (0)