From: Junio C Hamano Date: Mon, 23 Jan 2017 23:59:21 +0000 (-0800) Subject: Merge branch 'sb/submodule-init' X-Git-Tag: v2.12.0-rc0~51 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/e801be066cc12799cd053a5b4eb792d9007133fc?hp=-c Merge branch 'sb/submodule-init' Error message fix. * sb/submodule-init: submodule update --init: display correct path from submodule --- e801be066cc12799cd053a5b4eb792d9007133fc diff --combined builtin/submodule--helper.c index df0d9c166f,7b3f9fc293..74614a951e --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@@ -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//objects + * standard layout with .git/(modules/)+/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, @@@ -673,20 -673,6 +674,20 @@@ 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 b43af1742c,4e47ff8ad8..9788175979 --- a/git-submodule.sh +++ b/git-submodule.sh @@@ -12,8 -12,7 +12,8 @@@ USAGE="[--quiet] add [-b ] [-f| or: $dashless [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--[no-]recommend-shallow] [--reference ] [--recursive] [--] [...] or: $dashless [--quiet] summary [--cached|--files] [--summary-limit ] [commit] [--] [...] or: $dashless [--quiet] foreach [--recursive] - or: $dashless [--quiet] sync [--recursive] [--] [...]" + or: $dashless [--quiet] sync [--recursive] [--] [...] + or: $dashless [--quiet] absorbgitdirs [--] [...]" 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} "$@" } #