Skip to content

Commit 4f3e57e

Browse files
jonathantanmygitster
authored andcommitted
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 <[email protected]> Acked-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 10c64a0 commit 4f3e57e

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

Documentation/config/advice.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,7 @@ advice.*::
107107
editor input from the user.
108108
nestedTag::
109109
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.
110113
--

advice.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ int advice_waiting_for_editor = 1;
3030
int advice_graft_file_deprecated = 1;
3131
int advice_checkout_ambiguous_remote_branch_name = 1;
3232
int advice_nested_tag = 1;
33+
int advice_submodule_alternate_error_strategy_die = 1;
3334

3435
static int advice_use_color = -1;
3536
static char advice_colors[][COLOR_MAXLEN] = {
@@ -89,6 +90,7 @@ static struct {
8990
{ "graftFileDeprecated", &advice_graft_file_deprecated },
9091
{ "checkoutAmbiguousRemoteBranchName", &advice_checkout_ambiguous_remote_branch_name },
9192
{ "nestedTag", &advice_nested_tag },
93+
{ "submoduleAlternateErrorStrategyDie", &advice_submodule_alternate_error_strategy_die },
9294

9395
/* make this an alias for backward compatibility */
9496
{ "pushNonFastForward", &advice_push_update_rejected }

advice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ extern int advice_waiting_for_editor;
3030
extern int advice_graft_file_deprecated;
3131
extern int advice_checkout_ambiguous_remote_branch_name;
3232
extern int advice_nested_tag;
33+
extern int advice_submodule_alternate_error_strategy_die;
3334

3435
int git_default_advice_config(const char *var, const char *value);
3536
__attribute__((format (printf, 1, 2)))

builtin/submodule--helper.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "diffcore.h"
2020
#include "diff.h"
2121
#include "object-store.h"
22+
#include "advice.h"
2223

2324
#define OPT_QUIET (1 << 0)
2425
#define OPT_CACHED (1 << 1)
@@ -1268,6 +1269,13 @@ struct submodule_alternate_setup {
12681269
#define SUBMODULE_ALTERNATE_SETUP_INIT { NULL, \
12691270
SUBMODULE_ALTERNATE_ERROR_IGNORE, NULL }
12701271

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+
12711279
static int add_possible_reference_from_superproject(
12721280
struct object_directory *odb, void *sas_cb)
12731281
{
@@ -1299,6 +1307,8 @@ static int add_possible_reference_from_superproject(
12991307
} else {
13001308
switch (sas->error_mode) {
13011309
case SUBMODULE_ALTERNATE_ERROR_DIE:
1310+
if (advice_submodule_alternate_error_strategy_die)
1311+
advise(_(alternate_error_advice));
13021312
die(_("submodule '%s' cannot add alternate: %s"),
13031313
sas->submodule_name, err.buf);
13041314
case SUBMODULE_ALTERNATE_ERROR_INFO:

0 commit comments

Comments
 (0)