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>
This commit is contained in:
committed by
Junio C Hamano
parent
10c64a0b3c
commit
4f3e57ef13
@ -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:
|
||||
|
||||
Reference in New Issue
Block a user