submodule: check for NULL return of get_submodule_ref_store()
If we can't find a ref store for a submodule then assume the latter is not initialized (or was removed). Print a status line accordingly instead of causing a segmentation fault by passing NULL as the first parameter of refs_head_ref(). Reported-by: Jeremy Feusi <jeremy@feusi.co> Reviewed-by: Stefan Beller <sbeller@google.com> Initial-Test-By: Stefan Beller <sbeller@google.com> Helped-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Mar 28, 2018 at 23:14 UTC
74b6bda32f8350b2dc32f8d66f4046272168184e
2 files changed
+21
-2
builtin/submodule--helper.c
+6
-2
@@ -620,9 +620,13 @@ static void status_submodule(const char *path, const struct object_id *ce_oid,
620
displaypath);
621
} else if (!(flags & OPT_CACHED)) {
622
struct object_id oid;
623
+ struct ref_store *refs = get_submodule_ref_store(path);
624
624
- if (refs_head_ref(get_submodule_ref_store(path),
625
- handle_submodule_head_ref, &oid))
625
+ if (!refs) {
626
+ print_status(flags, '-', path, ce_oid, displaypath);
627
+ goto cleanup;
628
+ }
629
+ if (refs_head_ref(refs, handle_submodule_head_ref, &oid))
630
die(_("could not resolve HEAD ref inside the "
631
"submodule '%s'"), path);
632
t/t7400-submodule-basic.sh
+15
@@ -821,6 +821,21 @@ test_expect_success 'moving the superproject does not break submodules' '
821
)
822
'
823
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
+
839
test_expect_success 'submodule add --name allows to replace a submodule with another at the same path' '
840
(
841
cd addtest2 &&