@matheusbsbs / matheus-bagliano / commits / 4f3e57ef13
Fork 0

submodule--helper: advise on fatal alternate error

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>

Jonathan Tan committed Dec 2, 2019 at 11:57 UTC 4f3e57ef13d0ad4c00d0a87f0858cde81456a2e0
4 files changed +16
Documentation/config/advice.txt
+3
@@ -107,4 +107,7 @@ advice.*::
107 editor input from the user.
108 nestedTag::
109 Advice shown if a user attempts to recursively tag a tag object.
110 + submoduleAlternateErrorStrategyDie:
111 + Advice shown when a submodule.alternateErrorStrategy option
112 + configured to "die" causes a fatal error.
113 --
advice.c
+2
@@ -30,6 +30,7 @@ int advice_waiting_for_editor = 1;
30 int advice_graft_file_deprecated = 1;
31 int advice_checkout_ambiguous_remote_branch_name = 1;
32 int advice_nested_tag = 1;
33 +int advice_submodule_alternate_error_strategy_die = 1;
34
35 static int advice_use_color = -1;
36 static char advice_colors[][COLOR_MAXLEN] = {
@@ -89,6 +90,7 @@ static struct {
90 { "graftFileDeprecated", &advice_graft_file_deprecated },
91 { "checkoutAmbiguousRemoteBranchName", &advice_checkout_ambiguous_remote_branch_name },
92 { "nestedTag", &advice_nested_tag },
93 + { "submoduleAlternateErrorStrategyDie", &advice_submodule_alternate_error_strategy_die },
94
95 /* make this an alias for backward compatibility */
96 { "pushNonFastForward", &advice_push_update_rejected }
advice.h
+1
@@ -30,6 +30,7 @@ extern int advice_waiting_for_editor;
30 extern int advice_graft_file_deprecated;
31 extern int advice_checkout_ambiguous_remote_branch_name;
32 extern int advice_nested_tag;
33 +extern int advice_submodule_alternate_error_strategy_die;
34
35 int git_default_advice_config(const char *var, const char *value);
36 __attribute__((format (printf, 1, 2)))
builtin/submodule--helper.c
+10
@@ -19,6 +19,7 @@
19 #include "diffcore.h"
20 #include "diff.h"
21 #include "object-store.h"
22 +#include "advice.h"
23
24 #define OPT_QUIET (1 << 0)
25 #define OPT_CACHED (1 << 1)
@@ -1268,6 +1269,13 @@ struct submodule_alternate_setup {
1269 #define SUBMODULE_ALTERNATE_SETUP_INIT { NULL, \
1270 SUBMODULE_ALTERNATE_ERROR_IGNORE, NULL }
1271
1272 +static const char alternate_error_advice[] = N_(
1273 +"An alternate computed from a superproject's alternate is invalid.\n"
1274 +"To allow Git to clone without an alternate in such a case, set\n"
1275 +"submodule.alternateErrorStrategy to 'info' or, equivalently, clone with\n"
1276 +"'--reference-if-able' instead of '--reference'."
1277 +);
1278 +
1279 static int add_possible_reference_from_superproject(
1280 struct object_directory *odb, void *sas_cb)
1281 {
@@ -1299,6 +1307,8 @@ static int add_possible_reference_from_superproject(
1307 } else {
1308 switch (sas->error_mode) {
1309 case SUBMODULE_ALTERNATE_ERROR_DIE:
1310 + if (advice_submodule_alternate_error_strategy_die)
1311 + advise(_(alternate_error_advice));
1312 die(_("submodule '%s' cannot add alternate: %s"),
1313 sas->submodule_name, err.buf);
1314 case SUBMODULE_ALTERNATE_ERROR_INFO: