@@ -112,12 +112,14 @@ static int show_ignored_in_status, have_option_m;
112112static const char * only_include_assumed ;
113113static struct strbuf message = STRBUF_INIT ;
114114
115- static enum {
115+ static enum status_format {
116116 STATUS_FORMAT_NONE = 0 ,
117117 STATUS_FORMAT_LONG ,
118118 STATUS_FORMAT_SHORT ,
119- STATUS_FORMAT_PORCELAIN
120- } status_format ;
119+ STATUS_FORMAT_PORCELAIN ,
120+
121+ STATUS_FORMAT_UNSPECIFIED
122+ } status_format = STATUS_FORMAT_UNSPECIFIED ;
121123
122124static int opt_parse_m (const struct option * opt , const char * arg , int unset )
123125{
@@ -460,6 +462,9 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int
460462 case STATUS_FORMAT_PORCELAIN :
461463 wt_porcelain_print (s );
462464 break ;
465+ case STATUS_FORMAT_UNSPECIFIED :
466+ die ("BUG: finalize_deferred_config() should have been called" );
467+ break ;
463468 case STATUS_FORMAT_NONE :
464469 case STATUS_FORMAT_LONG :
465470 wt_status_print (s );
@@ -961,6 +966,42 @@ static const char *read_commit_message(const char *name)
961966 return logmsg_reencode (commit , NULL , out_enc );
962967}
963968
969+ /*
970+ * Enumerate what needs to be propagated when --porcelain
971+ * is not in effect here.
972+ */
973+ static struct status_deferred_config {
974+ enum status_format status_format ;
975+ int show_branch ;
976+ } status_deferred_config = {
977+ STATUS_FORMAT_UNSPECIFIED ,
978+ -1 /* unspecified */
979+ };
980+
981+ static void finalize_deferred_config (struct wt_status * s )
982+ {
983+ int use_deferred_config = (status_format != STATUS_FORMAT_PORCELAIN &&
984+ !s -> null_termination );
985+
986+ if (s -> null_termination ) {
987+ if (status_format == STATUS_FORMAT_NONE ||
988+ status_format == STATUS_FORMAT_UNSPECIFIED )
989+ status_format = STATUS_FORMAT_PORCELAIN ;
990+ else if (status_format == STATUS_FORMAT_LONG )
991+ die (_ ("--long and -z are incompatible" ));
992+ }
993+
994+ if (use_deferred_config && status_format == STATUS_FORMAT_UNSPECIFIED )
995+ status_format = status_deferred_config .status_format ;
996+ if (status_format == STATUS_FORMAT_UNSPECIFIED )
997+ status_format = STATUS_FORMAT_NONE ;
998+
999+ if (use_deferred_config && s -> show_branch < 0 )
1000+ s -> show_branch = status_deferred_config .show_branch ;
1001+ if (s -> show_branch < 0 )
1002+ s -> show_branch = 0 ;
1003+ }
1004+
9641005static int parse_and_validate_options (int argc , const char * argv [],
9651006 const struct option * options ,
9661007 const char * const usage [],
@@ -971,6 +1012,7 @@ static int parse_and_validate_options(int argc, const char *argv[],
9711012 int f = 0 ;
9721013
9731014 argc = parse_options (argc , argv , prefix , options , usage , 0 );
1015+ finalize_deferred_config (s );
9741016
9751017 if (force_author && !strchr (force_author , '>' ))
9761018 force_author = find_author_by_nickname (force_author );
@@ -1055,12 +1097,6 @@ static int parse_and_validate_options(int argc, const char *argv[],
10551097 if (all && argc > 0 )
10561098 die (_ ("Paths with -a does not make sense." ));
10571099
1058- if (s -> null_termination ) {
1059- if (status_format == STATUS_FORMAT_NONE )
1060- status_format = STATUS_FORMAT_PORCELAIN ;
1061- else if (status_format == STATUS_FORMAT_LONG )
1062- die (_ ("--long and -z are incompatible" ));
1063- }
10641100 if (status_format != STATUS_FORMAT_NONE )
10651101 dry_run = 1 ;
10661102
@@ -1113,6 +1149,17 @@ static int git_status_config(const char *k, const char *v, void *cb)
11131149 s -> submodule_summary = -1 ;
11141150 return 0 ;
11151151 }
1152+ if (!strcmp (k , "status.short" )) {
1153+ if (git_config_bool (k , v ))
1154+ status_deferred_config .status_format = STATUS_FORMAT_SHORT ;
1155+ else
1156+ status_deferred_config .status_format = STATUS_FORMAT_NONE ;
1157+ return 0 ;
1158+ }
1159+ if (!strcmp (k , "status.branch" )) {
1160+ status_deferred_config .show_branch = git_config_bool (k , v );
1161+ return 0 ;
1162+ }
11161163 if (!strcmp (k , "status.color" ) || !strcmp (k , "color.status" )) {
11171164 s -> use_color = git_config_colorbool (k , v );
11181165 return 0 ;
@@ -1155,8 +1202,8 @@ int cmd_status(int argc, const char **argv, const char *prefix)
11551202 OPT__VERBOSE (& verbose , N_ ("be verbose" )),
11561203 OPT_SET_INT ('s' , "short" , & status_format ,
11571204 N_ ("show status concisely" ), STATUS_FORMAT_SHORT ),
1158- OPT_BOOLEAN ('b' , "branch" , & s .show_branch ,
1159- N_ ("show branch information" )),
1205+ OPT_BOOL ('b' , "branch" , & s .show_branch ,
1206+ N_ ("show branch information" )),
11601207 OPT_SET_INT (0 , "porcelain" , & status_format ,
11611208 N_ ("machine-readable output" ),
11621209 STATUS_FORMAT_PORCELAIN ),
@@ -1189,13 +1236,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
11891236 builtin_status_options ,
11901237 builtin_status_usage , 0 );
11911238 finalize_colopts (& s .colopts , -1 );
1192-
1193- if (s .null_termination ) {
1194- if (status_format == STATUS_FORMAT_NONE )
1195- status_format = STATUS_FORMAT_PORCELAIN ;
1196- else if (status_format == STATUS_FORMAT_LONG )
1197- die (_ ("--long and -z are incompatible" ));
1198- }
1239+ finalize_deferred_config (& s );
11991240
12001241 handle_untracked_files_arg (& s );
12011242 if (show_ignored_in_status )
@@ -1224,6 +1265,9 @@ int cmd_status(int argc, const char **argv, const char *prefix)
12241265 case STATUS_FORMAT_PORCELAIN :
12251266 wt_porcelain_print (& s );
12261267 break ;
1268+ case STATUS_FORMAT_UNSPECIFIED :
1269+ die ("BUG: finalize_deferred_config() should have been called" );
1270+ break ;
12271271 case STATUS_FORMAT_NONE :
12281272 case STATUS_FORMAT_LONG :
12291273 s .verbose = verbose ;
@@ -1392,7 +1436,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
13921436 OPT_BOOLEAN (0 , "dry-run" , & dry_run , N_ ("show what would be committed" )),
13931437 OPT_SET_INT (0 , "short" , & status_format , N_ ("show status concisely" ),
13941438 STATUS_FORMAT_SHORT ),
1395- OPT_BOOLEAN (0 , "branch" , & s .show_branch , N_ ("show branch information" )),
1439+ OPT_BOOL (0 , "branch" , & s .show_branch , N_ ("show branch information" )),
13961440 OPT_SET_INT (0 , "porcelain" , & status_format ,
13971441 N_ ("machine-readable output" ), STATUS_FORMAT_PORCELAIN ),
13981442 OPT_SET_INT (0 , "long" , & status_format ,
@@ -1433,6 +1477,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
14331477 wt_status_prepare (& s );
14341478 gitmodules_config ();
14351479 git_config (git_commit_config , & s );
1480+ status_format = STATUS_FORMAT_NONE ; /* Ignore status.short */
14361481 determine_whence (& s );
14371482 s .colopts = 0 ;
14381483
0 commit comments