Merge branch 'sb/submodule-unset-core-worktree-when-worktree-is-lost'
authorJunio C Hamano <gitster@pobox.com>
Fri, 18 Jan 2019 21:49:53 +0000 (13:49 -0800)
committerJunio C Hamano <gitster@pobox.com>
Fri, 18 Jan 2019 21:49:53 +0000 (13:49 -0800)
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

1  2 
builtin/submodule--helper.c
index 0c5b2eb5fc6bb7553b71dac5f16d04e312093ae0,672b74db8999e299f9cc1669a1e3462c6e3bbb84..6881b6a9cb0fa1cd44118663cd8d7c8eaef1c95a
@@@ -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/<name>)+/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,
                 * 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 <name> <path>");
+               BUG("submodule--helper ensure-core-worktree <path>");
  
        path = argv[1];