@@ -233,6 +233,9 @@ static void setup_tracking(const char *new_ref, const char *orig_ref,
233233 struct string_list tracking_srcs = STRING_LIST_INIT_DUP ;
234234 int config_flags = quiet ? 0 : BRANCH_CONFIG_VERBOSE ;
235235
236+ if (!track )
237+ BUG ("asked to set up tracking, but tracking is disallowed" );
238+
236239 memset (& tracking , 0 , sizeof (tracking ));
237240 tracking .spec .dst = (char * )orig_ref ;
238241 tracking .srcs = & tracking_srcs ;
@@ -260,7 +263,7 @@ static void setup_tracking(const char *new_ref, const char *orig_ref,
260263 string_list_append (tracking .srcs , orig_ref );
261264 if (install_branch_config_multiple_remotes (config_flags , new_ref ,
262265 tracking .remote , tracking .srcs ) < 0 )
263- exit (- 1 );
266+ exit (1 );
264267
265268cleanup :
266269 string_list_clear (& tracking_srcs , 0 );
@@ -385,12 +388,10 @@ static void dwim_branch_start(struct repository *r, const char *start_name,
385388 real_ref = NULL ;
386389 if (get_oid_mb (start_name , & oid )) {
387390 if (explicit_tracking ) {
388- if (advice_enabled (ADVICE_SET_UPSTREAM_FAILURE )) {
389- error (_ (upstream_missing ), start_name );
390- advise (_ (upstream_advice ));
391- exit (1 );
392- }
393- die (_ (upstream_missing ), start_name );
391+ int code = die_message (_ (upstream_missing ), start_name );
392+ advise_if_enabled (ADVICE_SET_UPSTREAM_FAILURE ,
393+ _ (upstream_advice ));
394+ exit (code );
394395 }
395396 die (_ ("not a valid object name: '%s'" ), start_name );
396397 }
@@ -534,8 +535,27 @@ static int submodule_create_branch(struct repository *r,
534535 strvec_push (& child .args , "--quiet" );
535536 if (reflog )
536537 strvec_push (& child .args , "--create-reflog" );
537- if (track == BRANCH_TRACK_ALWAYS || track == BRANCH_TRACK_EXPLICIT )
538- strvec_push (& child .args , "--track" );
538+
539+ switch (track ) {
540+ case BRANCH_TRACK_NEVER :
541+ strvec_push (& child .args , "--no-track" );
542+ break ;
543+ case BRANCH_TRACK_ALWAYS :
544+ case BRANCH_TRACK_EXPLICIT :
545+ strvec_push (& child .args , "--track=direct" );
546+ break ;
547+ case BRANCH_TRACK_OVERRIDE :
548+ BUG ("BRANCH_TRACK_OVERRIDE cannot be used when creating a branch." );
549+ break ;
550+ case BRANCH_TRACK_INHERIT :
551+ strvec_push (& child .args , "--track=inherit" );
552+ break ;
553+ case BRANCH_TRACK_UNSPECIFIED :
554+ /* Default for "git checkout". Do not pass --track. */
555+ case BRANCH_TRACK_REMOTE :
556+ /* Default for "git branch". Do not pass --track. */
557+ break ;
558+ }
539559
540560 strvec_pushl (& child .args , name , start_oid , tracking_name , NULL );
541561
@@ -585,11 +605,13 @@ void create_branches_recursively(struct repository *r, const char *name,
585605 */
586606 for (i = 0 ; i < submodule_entry_list .entry_nr ; i ++ ) {
587607 if (submodule_entry_list .entries [i ].repo == NULL ) {
608+ int code = die_message (
609+ _ ("submodule '%s': unable to find submodule" ),
610+ submodule_entry_list .entries [i ].submodule -> name );
588611 if (advice_enabled (ADVICE_SUBMODULES_NOT_UPDATED ))
589612 advise (_ ("You may try updating the submodules using 'git checkout %s && git submodule update --init'" ),
590613 start_commitish );
591- die (_ ("submodule '%s': unable to find submodule" ),
592- submodule_entry_list .entries [i ].submodule -> name );
614+ exit (code );
593615 }
594616
595617 if (submodule_create_branch (
@@ -614,7 +636,8 @@ void create_branches_recursively(struct repository *r, const char *name,
614636 * tedious to determine whether or not tracking was set up in the
615637 * superproject.
616638 */
617- setup_tracking (name , tracking_name , track , quiet );
639+ if (track )
640+ setup_tracking (name , tracking_name , track , quiet );
618641
619642 for (i = 0 ; i < submodule_entry_list .entry_nr ; i ++ ) {
620643 if (submodule_create_branch (
0 commit comments