@@ -111,12 +111,14 @@ static int show_ignored_in_status;
111111static const char * only_include_assumed ;
112112static struct strbuf message = STRBUF_INIT ;
113113
114- static enum {
114+ static enum status_format {
115115 STATUS_FORMAT_NONE = 0 ,
116116 STATUS_FORMAT_LONG ,
117117 STATUS_FORMAT_SHORT ,
118- STATUS_FORMAT_PORCELAIN
119- } status_format ;
118+ STATUS_FORMAT_PORCELAIN ,
119+
120+ STATUS_FORMAT_UNSPECIFIED
121+ } status_format = STATUS_FORMAT_UNSPECIFIED ;
120122
121123static int opt_parse_m (const struct option * opt , const char * arg , int unset )
122124{
@@ -457,6 +459,9 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int
457459 case STATUS_FORMAT_PORCELAIN :
458460 wt_porcelain_print (s );
459461 break ;
462+ case STATUS_FORMAT_UNSPECIFIED :
463+ die ("BUG: finalize_deferred_config() should have been called" );
464+ break ;
460465 case STATUS_FORMAT_NONE :
461466 case STATUS_FORMAT_LONG :
462467 wt_status_print (s );
@@ -958,6 +963,42 @@ static const char *read_commit_message(const char *name)
958963 return logmsg_reencode (commit , NULL , out_enc );
959964}
960965
966+ /*
967+ * Enumerate what needs to be propagated when --porcelain
968+ * is not in effect here.
969+ */
970+ static struct status_deferred_config {
971+ enum status_format status_format ;
972+ int show_branch ;
973+ } status_deferred_config = {
974+ STATUS_FORMAT_UNSPECIFIED ,
975+ -1 /* unspecified */
976+ };
977+
978+ static void finalize_deferred_config (struct wt_status * s )
979+ {
980+ int use_deferred_config = (status_format != STATUS_FORMAT_PORCELAIN &&
981+ !s -> null_termination );
982+
983+ if (s -> null_termination ) {
984+ if (status_format == STATUS_FORMAT_NONE ||
985+ status_format == STATUS_FORMAT_UNSPECIFIED )
986+ status_format = STATUS_FORMAT_PORCELAIN ;
987+ else if (status_format == STATUS_FORMAT_LONG )
988+ die (_ ("--long and -z are incompatible" ));
989+ }
990+
991+ if (use_deferred_config && status_format == STATUS_FORMAT_UNSPECIFIED )
992+ status_format = status_deferred_config .status_format ;
993+ if (status_format == STATUS_FORMAT_UNSPECIFIED )
994+ status_format = STATUS_FORMAT_NONE ;
995+
996+ if (use_deferred_config && s -> show_branch < 0 )
997+ s -> show_branch = status_deferred_config .show_branch ;
998+ if (s -> show_branch < 0 )
999+ s -> show_branch = 0 ;
1000+ }
1001+
9611002static int parse_and_validate_options (int argc , const char * argv [],
9621003 const struct option * options ,
9631004 const char * const usage [],
@@ -968,6 +1009,7 @@ static int parse_and_validate_options(int argc, const char *argv[],
9681009 int f = 0 ;
9691010
9701011 argc = parse_options (argc , argv , prefix , options , usage , 0 );
1012+ finalize_deferred_config (s );
9711013
9721014 if (force_author && !strchr (force_author , '>' ))
9731015 force_author = find_author_by_nickname (force_author );
@@ -1052,12 +1094,6 @@ static int parse_and_validate_options(int argc, const char *argv[],
10521094 if (all && argc > 0 )
10531095 die (_ ("Paths with -a does not make sense." ));
10541096
1055- if (s -> null_termination ) {
1056- if (status_format == STATUS_FORMAT_NONE )
1057- status_format = STATUS_FORMAT_PORCELAIN ;
1058- else if (status_format == STATUS_FORMAT_LONG )
1059- die (_ ("--long and -z are incompatible" ));
1060- }
10611097 if (status_format != STATUS_FORMAT_NONE )
10621098 dry_run = 1 ;
10631099
@@ -1112,13 +1148,13 @@ static int git_status_config(const char *k, const char *v, void *cb)
11121148 }
11131149 if (!strcmp (k , "status.short" )) {
11141150 if (git_config_bool (k , v ))
1115- status_format = STATUS_FORMAT_SHORT ;
1151+ status_deferred_config . status_format = STATUS_FORMAT_SHORT ;
11161152 else
1117- status_format = STATUS_FORMAT_NONE ;
1153+ status_deferred_config . status_format = STATUS_FORMAT_NONE ;
11181154 return 0 ;
11191155 }
11201156 if (!strcmp (k , "status.branch" )) {
1121- s -> show_branch = git_config_bool (k , v );
1157+ status_deferred_config . show_branch = git_config_bool (k , v );
11221158 return 0 ;
11231159 }
11241160 if (!strcmp (k , "status.color" ) || !strcmp (k , "color.status" )) {
@@ -1163,8 +1199,8 @@ int cmd_status(int argc, const char **argv, const char *prefix)
11631199 OPT__VERBOSE (& verbose , N_ ("be verbose" )),
11641200 OPT_SET_INT ('s' , "short" , & status_format ,
11651201 N_ ("show status concisely" ), STATUS_FORMAT_SHORT ),
1166- OPT_BOOLEAN ('b' , "branch" , & s .show_branch ,
1167- N_ ("show branch information" )),
1202+ OPT_BOOL ('b' , "branch" , & s .show_branch ,
1203+ N_ ("show branch information" )),
11681204 OPT_SET_INT (0 , "porcelain" , & status_format ,
11691205 N_ ("machine-readable output" ),
11701206 STATUS_FORMAT_PORCELAIN ),
@@ -1197,13 +1233,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
11971233 builtin_status_options ,
11981234 builtin_status_usage , 0 );
11991235 finalize_colopts (& s .colopts , -1 );
1200-
1201- if (s .null_termination ) {
1202- if (status_format == STATUS_FORMAT_NONE )
1203- status_format = STATUS_FORMAT_PORCELAIN ;
1204- else if (status_format == STATUS_FORMAT_LONG )
1205- die (_ ("--long and -z are incompatible" ));
1206- }
1236+ finalize_deferred_config (& s );
12071237
12081238 handle_untracked_files_arg (& s );
12091239 if (show_ignored_in_status )
@@ -1232,6 +1262,9 @@ int cmd_status(int argc, const char **argv, const char *prefix)
12321262 case STATUS_FORMAT_PORCELAIN :
12331263 wt_porcelain_print (& s );
12341264 break ;
1265+ case STATUS_FORMAT_UNSPECIFIED :
1266+ die ("BUG: finalize_deferred_config() should have been called" );
1267+ break ;
12351268 case STATUS_FORMAT_NONE :
12361269 case STATUS_FORMAT_LONG :
12371270 s .verbose = verbose ;
@@ -1400,7 +1433,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
14001433 OPT_BOOLEAN (0 , "dry-run" , & dry_run , N_ ("show what would be committed" )),
14011434 OPT_SET_INT (0 , "short" , & status_format , N_ ("show status concisely" ),
14021435 STATUS_FORMAT_SHORT ),
1403- OPT_BOOLEAN (0 , "branch" , & s .show_branch , N_ ("show branch information" )),
1436+ OPT_BOOL (0 , "branch" , & s .show_branch , N_ ("show branch information" )),
14041437 OPT_SET_INT (0 , "porcelain" , & status_format ,
14051438 N_ ("machine-readable output" ), STATUS_FORMAT_PORCELAIN ),
14061439 OPT_SET_INT (0 , "long" , & status_format ,
0 commit comments