Skip to content

Commit 5dd1d59

Browse files
committed
Merge branch 'jt/clone-recursesub-ref-advise'
The interaction between "git clone --recurse-submodules" and alternate object store was ill-designed. The documentation and code have been taught to make more clear recommendations when the users see failures. * jt/clone-recursesub-ref-advise: submodule--helper: advise on fatal alternate error Doc: explain submodule.alternateErrorStrategy
2 parents dac30e7 + 4f3e57e commit 5dd1d59

File tree

5 files changed

+19
-1
lines changed

5 files changed

+19
-1
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
--

Documentation/config/submodule.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,6 @@ submodule.alternateLocation::
7979
submodule.alternateErrorStrategy::
8080
Specifies how to treat errors with the alternates for a submodule
8181
as computed via `submodule.alternateLocation`. Possible values are
82-
`ignore`, `info`, `die`. Default is `die`.
82+
`ignore`, `info`, `die`. Default is `die`. Note that if set to `ignore`
83+
or `info`, and if there is an error with the computed alternate, the
84+
clone proceeds as if no alternate was specified.

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
@@ -20,6 +20,7 @@
2020
#include "diff.h"
2121
#include "object-store.h"
2222
#include "dir.h"
23+
#include "advice.h"
2324

2425
#define OPT_QUIET (1 << 0)
2526
#define OPT_CACHED (1 << 1)
@@ -1270,6 +1271,13 @@ struct submodule_alternate_setup {
12701271
#define SUBMODULE_ALTERNATE_SETUP_INIT { NULL, \
12711272
SUBMODULE_ALTERNATE_ERROR_IGNORE, NULL }
12721273

1274+
static const char alternate_error_advice[] = N_(
1275+
"An alternate computed from a superproject's alternate is invalid.\n"
1276+
"To allow Git to clone without an alternate in such a case, set\n"
1277+
"submodule.alternateErrorStrategy to 'info' or, equivalently, clone with\n"
1278+
"'--reference-if-able' instead of '--reference'."
1279+
);
1280+
12731281
static int add_possible_reference_from_superproject(
12741282
struct object_directory *odb, void *sas_cb)
12751283
{
@@ -1301,6 +1309,8 @@ static int add_possible_reference_from_superproject(
13011309
} else {
13021310
switch (sas->error_mode) {
13031311
case SUBMODULE_ALTERNATE_ERROR_DIE:
1312+
if (advice_submodule_alternate_error_strategy_die)
1313+
advise(_(alternate_error_advice));
13041314
die(_("submodule '%s' cannot add alternate: %s"),
13051315
sas->submodule_name, err.buf);
13061316
case SUBMODULE_ALTERNATE_ERROR_INFO:

0 commit comments

Comments
 (0)