Merge branch 'sb/submodule-init'
authorJunio C Hamano <gitster@pobox.com>
Mon, 23 Jan 2017 23:59:21 +0000 (15:59 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 23 Jan 2017 23:59:21 +0000 (15:59 -0800)
Error message fix.

* sb/submodule-init:
submodule update --init: display correct path from submodule

1  2 
builtin/submodule--helper.c
git-submodule.sh
index df0d9c166f05b27469fbd6c1ddd208ac763667d7,7b3f9fc293edc2cb7d174275c916a073c0411a48..74614a951e8bb8aef4ed0ef07665f8ec0e43cc78
@@@ -317,8 -317,12 +317,12 @@@ static void init_submodule(const char *
        /* Only loads from .gitmodules, no overlay with .git/config */
        gitmodules_config();
  
-       if (prefix) {
-               strbuf_addf(&sb, "%s%s", prefix, path);
+       if (prefix && get_super_prefix())
+               die("BUG: cannot have prefix and superprefix");
+       else if (prefix)
+               displaypath = xstrdup(relative_path(path, prefix, &sb));
+       else if (get_super_prefix()) {
+               strbuf_addf(&sb, "%s%s", get_super_prefix(), path);
                displaypath = strbuf_detach(&sb, NULL);
        } else
                displaypath = xstrdup(path);
@@@ -403,9 -407,6 +407,6 @@@ static int module_init(int argc, const 
        int i;
  
        struct option module_init_options[] = {
-               OPT_STRING(0, "prefix", &prefix,
-                          N_("path"),
-                          N_("alternative anchor for relative paths")),
                OPT__QUIET(&quiet, N_("Suppress output for initializing a submodule")),
                OPT_END()
        };
@@@ -498,9 -499,9 +499,9 @@@ static int add_possible_reference_from_
  
        /*
         * If the alternate object store is another repository, try the
 -       * standard layout with .git/modules/<name>/objects
 +       * standard layout with .git/(modules/<name>)+/objects
         */
 -      if (ends_with(alt->path, ".git/objects")) {
 +      if (ends_with(alt->path, "/objects")) {
                char *sm_alternate;
                struct strbuf sb = STRBUF_INIT;
                struct strbuf err = STRBUF_INIT;
@@@ -583,7 -584,6 +584,7 @@@ static int module_clone(int argc, cons
        struct strbuf rel_path = STRBUF_INIT;
        struct strbuf sb = STRBUF_INIT;
        struct string_list reference = STRING_LIST_INIT_NODUP;
 +      char *sm_alternate = NULL, *error_strategy = NULL;
  
        struct option module_clone_options[] = {
                OPT_STRING(0, "prefix", &prefix,
                die(_("could not get submodule directory for '%s'"), path);
        git_config_set_in_file(p, "core.worktree",
                               relative_path(path, sm_gitdir, &rel_path));
 +
 +      /* setup alternateLocation and alternateErrorStrategy in the cloned submodule if needed */
 +      git_config_get_string("submodule.alternateLocation", &sm_alternate);
 +      if (sm_alternate)
 +              git_config_set_in_file(p, "submodule.alternateLocation",
 +                                         sm_alternate);
 +      git_config_get_string("submodule.alternateErrorStrategy", &error_strategy);
 +      if (error_strategy)
 +              git_config_set_in_file(p, "submodule.alternateErrorStrategy",
 +                                         error_strategy);
 +
 +      free(sm_alternate);
 +      free(error_strategy);
 +
        strbuf_release(&sb);
        strbuf_release(&rel_path);
        free(sm_gitdir);
@@@ -1144,7 -1130,7 +1145,7 @@@ static struct cmd_struct commands[] = 
        {"relative-path", resolve_relative_path, 0},
        {"resolve-relative-url", resolve_relative_url, 0},
        {"resolve-relative-url-test", resolve_relative_url_test, 0},
-       {"init", module_init, 0},
+       {"init", module_init, SUPPORT_SUPER_PREFIX},
        {"remote-branch", resolve_remote_submodule_branch, 0},
        {"absorb-git-dirs", absorb_git_dirs, SUPPORT_SUPER_PREFIX},
  };
diff --combined git-submodule.sh
index b43af1742c7c54b4681ff56292a04a715d09d5e0,4e47ff8ad81a5df0179b06d598e1969c23de1bb0..9788175979273f8748635e2f5078f3ca8d4b7500
@@@ -12,8 -12,7 +12,8 @@@ USAGE="[--quiet] add [-b <branch>] [-f|
     or: $dashless [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--[no-]recommend-shallow] [--reference <repository>] [--recursive] [--] [<path>...]
     or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
     or: $dashless [--quiet] foreach [--recursive] <command>
 -   or: $dashless [--quiet] sync [--recursive] [--] [<path>...]"
 +   or: $dashless [--quiet] sync [--recursive] [--] [<path>...]
 +   or: $dashless [--quiet] absorbgitdirs [--] [<path>...]"
  OPTIONS_SPEC=
  SUBDIRECTORY_OK=Yes
  . git-sh-setup
@@@ -22,10 -21,14 +22,10 @@@ require_work_tre
  wt_prefix=$(git rev-parse --show-prefix)
  cd_to_toplevel
  
 -# Restrict ourselves to a vanilla subset of protocols; the URLs
 -# we get are under control of a remote repository, and we do not
 -# want them kicking off arbitrary git-remote-* programs.
 -#
 -# If the user has already specified a set of allowed protocols,
 -# we assume they know what they're doing and use that instead.
 -: ${GIT_ALLOW_PROTOCOL=file:git:http:https:ssh}
 -export GIT_ALLOW_PROTOCOL
 +# Tell the rest of git that any URLs we get don't come
 +# directly from the user, so it can apply policy as appropriate.
 +GIT_PROTOCOL_FROM_USER=0
 +export GIT_PROTOCOL_FROM_USER
  
  command=
  branch=
@@@ -371,7 -374,7 +371,7 @@@ cmd_init(
                shift
        done
  
-       git ${wt_prefix:+-C "$wt_prefix"} submodule--helper init ${GIT_QUIET:+--quiet} ${prefix:+--prefix "$prefix"} "$@"
+       git ${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix "$prefix"} submodule--helper init ${GIT_QUIET:+--quiet}  "$@"
  }
  
  #