Skip to content

Commit e29497d

Browse files
committed
Merge branch 'jg/status-config'
"git status" learned status.branch and status.short configuration variables to use --branch and --short options by default (override with --no-branch and --no-short options from the command line). * jg/status-config: status/commit: make sure --porcelain is not affected by user-facing config commit: make it work with status.short status: introduce status.branch to enable --branch by default status: introduce status.short to enable --short by default
2 parents 04ce893 + 84b4202 commit e29497d

File tree

4 files changed

+135
-19
lines changed

4 files changed

+135
-19
lines changed

Documentation/config.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2112,6 +2112,14 @@ status.relativePaths::
21122112
relative to the repository root (this was the default for Git
21132113
prior to v1.5.4).
21142114

2115+
status.short::
2116+
Set to true to enable --short by default in linkgit:git-status[1].
2117+
The option --no-short takes precedence over this variable.
2118+
2119+
status.branch::
2120+
Set to true to enable --branch by default in linkgit:git-status[1].
2121+
The option --no-branch takes precedence over this variable.
2122+
21152123
status.showUntrackedFiles::
21162124
By default, linkgit:git-status[1] and linkgit:git-commit[1] show
21172125
files which are not currently tracked by Git. Directories which

builtin/commit.c

Lines changed: 64 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,14 @@ static int show_ignored_in_status, have_option_m;
112112
static const char *only_include_assumed;
113113
static 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

122124
static 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+
9641005
static 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

t/t7508-status.sh

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,4 +1335,66 @@ test_expect_failure '.git/config ignore=all suppresses submodule summary' '
13351335
git config -f .gitmodules --remove-section submodule.subname
13361336
'
13371337

1338+
test_expect_success 'setup of test environment' '
1339+
git config status.showUntrackedFiles no &&
1340+
git status -s >expected_short &&
1341+
git status --no-short >expected_noshort
1342+
'
1343+
1344+
test_expect_success '"status.short=true" same as "-s"' '
1345+
git -c status.short=true status >actual &&
1346+
test_cmp expected_short actual
1347+
'
1348+
1349+
test_expect_success '"status.short=true" weaker than "--no-short"' '
1350+
git -c status.short=true status --no-short >actual &&
1351+
test_cmp expected_noshort actual
1352+
'
1353+
1354+
test_expect_success '"status.short=false" same as "--no-short"' '
1355+
git -c status.short=false status >actual &&
1356+
test_cmp expected_noshort actual
1357+
'
1358+
1359+
test_expect_success '"status.short=false" weaker than "-s"' '
1360+
git -c status.short=false status -s >actual &&
1361+
test_cmp expected_short actual
1362+
'
1363+
1364+
test_expect_success '"status.branch=true" same as "-b"' '
1365+
git status -sb >expected_branch &&
1366+
git -c status.branch=true status -s >actual &&
1367+
test_cmp expected_branch actual
1368+
'
1369+
1370+
test_expect_success '"status.branch=true" different from "--no-branch"' '
1371+
git status -s --no-branch >expected_nobranch &&
1372+
git -c status.branch=true status -s >actual &&
1373+
test_must_fail test_cmp expected_nobranch actual
1374+
'
1375+
1376+
test_expect_success '"status.branch=true" weaker than "--no-branch"' '
1377+
git -c status.branch=true status -s --no-branch >actual &&
1378+
test_cmp expected_nobranch actual
1379+
'
1380+
1381+
test_expect_success '"status.branch=true" weaker than "--porcelain"' '
1382+
git -c status.branch=true status --porcelain >actual &&
1383+
test_cmp expected_nobranch actual
1384+
'
1385+
1386+
test_expect_success '"status.branch=false" same as "--no-branch"' '
1387+
git -c status.branch=false status -s >actual &&
1388+
test_cmp expected_nobranch actual
1389+
'
1390+
1391+
test_expect_success '"status.branch=false" weaker than "-b"' '
1392+
git -c status.branch=false status -sb >actual &&
1393+
test_cmp expected_branch actual
1394+
'
1395+
1396+
test_expect_success 'Restore default test environment' '
1397+
git config --unset status.showUntrackedFiles
1398+
'
1399+
13381400
test_done

wt-status.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ void wt_status_prepare(struct wt_status *s)
127127
s->change.strdup_strings = 1;
128128
s->untracked.strdup_strings = 1;
129129
s->ignored.strdup_strings = 1;
130+
s->show_branch = -1; /* unspecified */
130131
}
131132

132133
static void wt_status_print_unmerged_header(struct wt_status *s)

0 commit comments

Comments
 (0)