]> git.ipfire.org Git - thirdparty/git.git/commitdiff
submodule--helper: advise on fatal alternate error
authorJonathan Tan <jonathantanmy@google.com>
Mon, 2 Dec 2019 19:57:52 +0000 (11:57 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 3 Dec 2019 16:49:45 +0000 (08:49 -0800)
When recursively cloning a superproject with some shallow modules
defined in its .gitmodules, then recloning with "--reference=<path>", an
error occurs. For example:

  git clone --recurse-submodules --branch=master -j8 \
    https://android.googlesource.com/platform/superproject \
    master
  git clone --recurse-submodules --branch=master -j8 \
    https://android.googlesource.com/platform/superproject \
    --reference master master2

fails with:

  fatal: submodule '<snip>' cannot add alternate: reference repository
  '<snip>' is shallow

When a alternate computed from the superproject's alternate cannot be
added, whether in this case or another, advise about configuring the
"submodule.alternateErrorStrategy" configuration option and using
"--reference-if-able" instead of "--reference" when cloning.

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/config/advice.txt
advice.c
advice.h
builtin/submodule--helper.c

index 6aaa36020298f54f60cab1973b91641d684b9b18..d4e698cd3fe4aaee50df132ab237a8f35ad4c8d8 100644 (file)
@@ -107,4 +107,7 @@ advice.*::
                editor input from the user.
        nestedTag::
                Advice shown if a user attempts to recursively tag a tag object.
+       submoduleAlternateErrorStrategyDie:
+               Advice shown when a submodule.alternateErrorStrategy option
+               configured to "die" causes a fatal error.
 --
index 3ee0ee2d8fbb04dabcfc0152dc741c7d1f28b220..249c60dcf32e242b57316385fb31d52bec2a282a 100644 (file)
--- a/advice.c
+++ b/advice.c
@@ -30,6 +30,7 @@ int advice_waiting_for_editor = 1;
 int advice_graft_file_deprecated = 1;
 int advice_checkout_ambiguous_remote_branch_name = 1;
 int advice_nested_tag = 1;
+int advice_submodule_alternate_error_strategy_die = 1;
 
 static int advice_use_color = -1;
 static char advice_colors[][COLOR_MAXLEN] = {
@@ -89,6 +90,7 @@ static struct {
        { "graftFileDeprecated", &advice_graft_file_deprecated },
        { "checkoutAmbiguousRemoteBranchName", &advice_checkout_ambiguous_remote_branch_name },
        { "nestedTag", &advice_nested_tag },
+       { "submoduleAlternateErrorStrategyDie", &advice_submodule_alternate_error_strategy_die },
 
        /* make this an alias for backward compatibility */
        { "pushNonFastForward", &advice_push_update_rejected }
index d0154048431c773b9bf0ec450478a93d5ede06c0..b706780614dd3721b71b79feed9b3e0bdae3964c 100644 (file)
--- a/advice.h
+++ b/advice.h
@@ -30,6 +30,7 @@ extern int advice_waiting_for_editor;
 extern int advice_graft_file_deprecated;
 extern int advice_checkout_ambiguous_remote_branch_name;
 extern int advice_nested_tag;
+extern int advice_submodule_alternate_error_strategy_die;
 
 int git_default_advice_config(const char *var, const char *value);
 __attribute__((format (printf, 1, 2)))
index 2c2395a6201ae5bccd1b078a185bfa751ed23248..12d546dfbba5ee3d26a95b6eaea22a5a3aaf6bd3 100644 (file)
@@ -19,6 +19,7 @@
 #include "diffcore.h"
 #include "diff.h"
 #include "object-store.h"
+#include "advice.h"
 
 #define OPT_QUIET (1 << 0)
 #define OPT_CACHED (1 << 1)
@@ -1268,6 +1269,13 @@ struct submodule_alternate_setup {
 #define SUBMODULE_ALTERNATE_SETUP_INIT { NULL, \
        SUBMODULE_ALTERNATE_ERROR_IGNORE, NULL }
 
+static const char alternate_error_advice[] = N_(
+"An alternate computed from a superproject's alternate is invalid.\n"
+"To allow Git to clone without an alternate in such a case, set\n"
+"submodule.alternateErrorStrategy to 'info' or, equivalently, clone with\n"
+"'--reference-if-able' instead of '--reference'."
+);
+
 static int add_possible_reference_from_superproject(
                struct object_directory *odb, void *sas_cb)
 {
@@ -1299,6 +1307,8 @@ static int add_possible_reference_from_superproject(
                } else {
                        switch (sas->error_mode) {
                        case SUBMODULE_ALTERNATE_ERROR_DIE:
+                               if (advice_submodule_alternate_error_strategy_die)
+                                       advise(_(alternate_error_advice));
                                die(_("submodule '%s' cannot add alternate: %s"),
                                    sas->submodule_name, err.buf);
                        case SUBMODULE_ALTERNATE_ERROR_INFO: