@@ -28,12 +28,6 @@ enum {
2828 TAGS_SET = 2
2929};
3030
31- enum {
32- RECURSE_SUBMODULES_OFF = 0 ,
33- RECURSE_SUBMODULES_DEFAULT = 1 ,
34- RECURSE_SUBMODULES_ON = 2
35- };
36-
3731static int all , append , dry_run , force , keep , multiple , prune , update_head_ok , verbosity ;
3832static int progress , recurse_submodules = RECURSE_SUBMODULES_DEFAULT ;
3933static int tags = TAGS_DEFAULT ;
@@ -42,6 +36,21 @@ static const char *upload_pack;
4236static struct strbuf default_rla = STRBUF_INIT ;
4337static struct transport * transport ;
4438static const char * submodule_prefix = "" ;
39+ static const char * recurse_submodules_default ;
40+
41+ static int option_parse_recurse_submodules (const struct option * opt ,
42+ const char * arg , int unset )
43+ {
44+ if (unset ) {
45+ recurse_submodules = RECURSE_SUBMODULES_OFF ;
46+ } else {
47+ if (arg )
48+ recurse_submodules = parse_fetch_recurse_submodules_arg (opt -> long_name , arg );
49+ else
50+ recurse_submodules = RECURSE_SUBMODULES_ON ;
51+ }
52+ return 0 ;
53+ }
4554
4655static struct option builtin_fetch_options [] = {
4756 OPT__VERBOSITY (& verbosity ),
@@ -60,9 +69,9 @@ static struct option builtin_fetch_options[] = {
6069 "do not fetch all tags (--no-tags)" , TAGS_UNSET ),
6170 OPT_BOOLEAN ('p' , "prune" , & prune ,
6271 "prune remote-tracking branches no longer on remote" ),
63- OPT_SET_INT ( 0 , "recurse-submodules" , & recurse_submodules ,
72+ { OPTION_CALLBACK , 0 , "recurse-submodules" , NULL , "on-demand" ,
6473 "control recursive fetching of submodules" ,
65- RECURSE_SUBMODULES_ON ) ,
74+ PARSE_OPT_OPTARG , option_parse_recurse_submodules } ,
6675 OPT_BOOLEAN (0 , "dry-run" , & dry_run ,
6776 "dry run" ),
6877 OPT_BOOLEAN ('k' , "keep" , & keep , "keep downloaded pack" ),
@@ -73,6 +82,9 @@ static struct option builtin_fetch_options[] = {
7382 "deepen history of shallow clone" ),
7483 { OPTION_STRING , 0 , "submodule-prefix" , & submodule_prefix , "dir" ,
7584 "prepend this to submodule path output" , PARSE_OPT_HIDDEN },
85+ { OPTION_STRING , 0 , "recurse-submodules-default" ,
86+ & recurse_submodules_default , NULL ,
87+ "default mode for recursion" , PARSE_OPT_HIDDEN },
7688 OPT_END ()
7789};
7890
@@ -284,6 +296,9 @@ static int update_local_ref(struct ref *ref,
284296 else {
285297 msg = "storing head" ;
286298 what = _ ("[new branch]" );
299+ if ((recurse_submodules != RECURSE_SUBMODULES_OFF ) &&
300+ (recurse_submodules != RECURSE_SUBMODULES_ON ))
301+ check_for_new_submodule_commits (ref -> new_sha1 );
287302 }
288303
289304 r = s_update_ref (msg , ref , 0 );
@@ -299,6 +314,9 @@ static int update_local_ref(struct ref *ref,
299314 strcpy (quickref , find_unique_abbrev (current -> object .sha1 , DEFAULT_ABBREV ));
300315 strcat (quickref , ".." );
301316 strcat (quickref , find_unique_abbrev (ref -> new_sha1 , DEFAULT_ABBREV ));
317+ if ((recurse_submodules != RECURSE_SUBMODULES_OFF ) &&
318+ (recurse_submodules != RECURSE_SUBMODULES_ON ))
319+ check_for_new_submodule_commits (ref -> new_sha1 );
302320 r = s_update_ref ("fast-forward" , ref , 1 );
303321 sprintf (display , "%c %-*s %-*s -> %s%s" , r ? '!' : ' ' ,
304322 TRANSPORT_SUMMARY_WIDTH , quickref , REFCOL_WIDTH , remote ,
@@ -310,6 +328,9 @@ static int update_local_ref(struct ref *ref,
310328 strcpy (quickref , find_unique_abbrev (current -> object .sha1 , DEFAULT_ABBREV ));
311329 strcat (quickref , "..." );
312330 strcat (quickref , find_unique_abbrev (ref -> new_sha1 , DEFAULT_ABBREV ));
331+ if ((recurse_submodules != RECURSE_SUBMODULES_OFF ) &&
332+ (recurse_submodules != RECURSE_SUBMODULES_ON ))
333+ check_for_new_submodule_commits (ref -> new_sha1 );
313334 r = s_update_ref ("forced-update" , ref , 1 );
314335 sprintf (display , "%c %-*s %-*s -> %s (%s)" , r ? '!' : '+' ,
315336 TRANSPORT_SUMMARY_WIDTH , quickref , REFCOL_WIDTH , remote ,
@@ -810,6 +831,8 @@ static void add_options_to_argv(int *argc, const char **argv)
810831 argv [(* argc )++ ] = "--keep" ;
811832 if (recurse_submodules == RECURSE_SUBMODULES_ON )
812833 argv [(* argc )++ ] = "--recurse-submodules" ;
834+ else if (recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND )
835+ argv [(* argc )++ ] = "--recurse-submodules=on-demand" ;
813836 if (verbosity >= 2 )
814837 argv [(* argc )++ ] = "-v" ;
815838 if (verbosity >= 1 )
@@ -951,15 +974,16 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
951974 if (!result && (recurse_submodules != RECURSE_SUBMODULES_OFF )) {
952975 const char * options [10 ];
953976 int num_options = 0 ;
954- /* Set recursion as default when we already are recursing */
955- if (submodule_prefix [0 ])
956- set_config_fetch_recurse_submodules (1 );
977+ if (recurse_submodules_default ) {
978+ int arg = parse_fetch_recurse_submodules_arg ("--recurse-submodules-default" , recurse_submodules_default );
979+ set_config_fetch_recurse_submodules (arg );
980+ }
957981 gitmodules_config ();
958982 git_config (submodule_config , NULL );
959983 add_options_to_argv (& num_options , options );
960984 result = fetch_populated_submodules (num_options , options ,
961985 submodule_prefix ,
962- recurse_submodules == RECURSE_SUBMODULES_ON ,
986+ recurse_submodules ,
963987 verbosity < 0 );
964988 }
965989
0 commit comments