@@ -50,6 +50,8 @@ static int option_no_checkout, option_bare, option_mirror, option_single_branch
5050static int option_local = -1 , option_no_hardlinks , option_shared ;
5151static int option_no_tags ;
5252static int option_shallow_submodules ;
53+ static int option_reject_shallow = -1 ; /* unspecified */
54+ static int config_reject_shallow = -1 ; /* unspecified */
5355static int deepen ;
5456static char * option_template , * option_depth , * option_since ;
5557static char * option_origin = NULL ;
@@ -90,6 +92,8 @@ static struct option builtin_clone_options[] = {
9092 OPT__VERBOSITY (& option_verbosity ),
9193 OPT_BOOL (0 , "progress" , & option_progress ,
9294 N_ ("force progress reporting" )),
95+ OPT_BOOL (0 , "reject-shallow" , & option_reject_shallow ,
96+ N_ ("don't clone shallow repository" )),
9397 OPT_BOOL ('n' , "no-checkout" , & option_no_checkout ,
9498 N_ ("don't create a checkout" )),
9599 OPT_BOOL (0 , "bare" , & option_bare , N_ ("create a bare repository" )),
@@ -858,6 +862,9 @@ static int git_clone_config(const char *k, const char *v, void *cb)
858862 free (remote_name );
859863 remote_name = xstrdup (v );
860864 }
865+ if (!strcmp (k , "clone.rejectshallow" ))
866+ config_reject_shallow = git_config_bool (k , v );
867+
861868 return git_default_config (k , v , cb );
862869}
863870
@@ -963,6 +970,7 @@ static int path_exists(const char *path)
963970int cmd_clone (int argc , const char * * argv , const char * prefix )
964971{
965972 int is_bundle = 0 , is_local ;
973+ int reject_shallow = 0 ;
966974 const char * repo_name , * repo , * work_tree , * git_dir ;
967975 char * path = NULL , * dir , * display_repo = NULL ;
968976 int dest_exists , real_dest_exists = 0 ;
@@ -1157,6 +1165,15 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
11571165 */
11581166 git_config (git_clone_config , NULL );
11591167
1168+ /*
1169+ * If option_reject_shallow is specified from CLI option,
1170+ * ignore config_reject_shallow from git_clone_config.
1171+ */
1172+ if (config_reject_shallow != -1 )
1173+ reject_shallow = config_reject_shallow ;
1174+ if (option_reject_shallow != -1 )
1175+ reject_shallow = option_reject_shallow ;
1176+
11601177 /*
11611178 * apply the remote name provided by --origin only after this second
11621179 * call to git_config, to ensure it overrides all config-based values.
@@ -1217,6 +1234,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
12171234 if (filter_options .choice )
12181235 warning (_ ("--filter is ignored in local clones; use file:// instead." ));
12191236 if (!access (mkpath ("%s/shallow" , path ), F_OK )) {
1237+ if (reject_shallow )
1238+ die (_ ("source repository is shallow, reject to clone." ));
12201239 if (option_local > 0 )
12211240 warning (_ ("source repository is shallow, ignoring --local" ));
12221241 is_local = 0 ;
@@ -1228,6 +1247,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
12281247
12291248 transport_set_option (transport , TRANS_OPT_KEEP , "yes" );
12301249
1250+ if (reject_shallow )
1251+ transport_set_option (transport , TRANS_OPT_REJECT_SHALLOW , "1" );
12311252 if (option_depth )
12321253 transport_set_option (transport , TRANS_OPT_DEPTH ,
12331254 option_depth );
0 commit comments