From: Junio C Hamano Date: Fri, 18 Jan 2019 21:49:53 +0000 (-0800) Subject: Merge branch 'sb/submodule-unset-core-worktree-when-worktree-is-lost' X-Git-Tag: v2.21.0-rc0~97 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/3942920966b4392c52c09f66dda391d9c330f0f7?ds=inline;hp=-c Merge branch 'sb/submodule-unset-core-worktree-when-worktree-is-lost' The core.worktree setting in a submodule repository should not be pointing at a directory when the submodule loses its working tree (e.g. getting deinit'ed), but the code did not properly maintain this invariant. * sb/submodule-unset-core-worktree-when-worktree-is-lost: submodule deinit: unset core.worktree submodule--helper: fix BUG message in ensure_core_worktree submodule: unset core.worktree if no working tree is present submodule update: add regression test with old style setups --- 3942920966b4392c52c09f66dda391d9c330f0f7 diff --combined builtin/submodule--helper.c index 0c5b2eb5fc,672b74db89..6881b6a9cb --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@@ -1131,6 -1131,8 +1131,8 @@@ static void deinit_submodule(const cha if (!(flags & OPT_QUIET)) printf(format, displaypath); + submodule_unset_core_worktree(sub); + strbuf_release(&sb_rm); } @@@ -1265,20 -1267,19 +1267,20 @@@ struct submodule_alternate_setup SUBMODULE_ALTERNATE_ERROR_IGNORE, NULL } static int add_possible_reference_from_superproject( - struct alternate_object_database *alt, void *sas_cb) + struct object_directory *odb, void *sas_cb) { struct submodule_alternate_setup *sas = sas_cb; + size_t len; /* * If the alternate object store is another repository, try the * standard layout with .git/(modules/)+/objects */ - if (ends_with(alt->path, "/objects")) { + if (strip_suffix(odb->path, "/objects", &len)) { char *sm_alternate; struct strbuf sb = STRBUF_INIT; struct strbuf err = STRBUF_INIT; - strbuf_add(&sb, alt->path, strlen(alt->path) - strlen("objects")); + strbuf_add(&sb, odb->path, len); /* * We need to end the new path with '/' to mark it as a dir, @@@ -1286,7 -1287,7 +1288,7 @@@ * as the last part of a missing submodule reference would * be taken as a file name. */ - strbuf_addf(&sb, "modules/%s/", sas->submodule_name); + strbuf_addf(&sb, "/modules/%s/", sas->submodule_name); sm_alternate = compute_alternate_path(sb.buf, &err); if (sm_alternate) { @@@ -1552,7 -1553,7 +1554,7 @@@ struct submodule_update_clone #define SUBMODULE_UPDATE_CLONE_INIT {0, MODULE_LIST_INIT, 0, \ SUBMODULE_UPDATE_STRATEGY_INIT, 0, 0, -1, STRING_LIST_INIT_DUP, 0, \ NULL, NULL, NULL, \ - NULL, 0, 0, 0, NULL, 0, 0, 0} + NULL, 0, 0, 0, NULL, 0, 0, 1} static void next_submodule_warn_missing(struct submodule_update_clone *suc, @@@ -2046,7 -2047,7 +2048,7 @@@ static int ensure_core_worktree(int arg struct repository subrepo; if (argc != 2) - BUG("submodule--helper connect-gitdir-workingtree "); + BUG("submodule--helper ensure-core-worktree "); path = argv[1];