Skip to content

Commit bf0a352

Browse files
committed
Merge branch 'jc/show-untracked-false'
The status.showUntrackedFiles configuration variable had a name that tempts users to set a Boolean value expressed in our usual "false", "off", and "0", but it only took "no". This has been corrected so "true" and its synonyms are taken as "normal", while "false" and its synonyms are taken as "no". * jc/show-untracked-false: status: allow --untracked=false and friends status: unify parsing of --untracked= and status.showUntrackedFiles
2 parents 396430b + f66e1a0 commit bf0a352

File tree

6 files changed

+68
-30
lines changed

6 files changed

+68
-30
lines changed

Documentation/config/status.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ status.showUntrackedFiles::
5757
--
5858
+
5959
If this variable is not specified, it defaults to 'normal'.
60+
All usual spellings for Boolean value `true` are taken as `normal`
61+
and `false` as `no`.
6062
This variable can be overridden with the -u|--untracked-files option
6163
of linkgit:git-status[1] and linkgit:git-commit[1].
6264

Documentation/git-commit.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,8 @@ The possible options are:
347347
- 'normal' - Shows untracked files and directories
348348
- 'all' - Also shows individual files in untracked directories.
349349

350+
All usual spellings for Boolean value `true` are taken as `normal`
351+
and `false` as `no`.
350352
The default can be changed using the status.showUntrackedFiles
351353
configuration variable documented in linkgit:git-config[1].
352354
--

Documentation/git-status.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ Consider enabling untracked cache and split index if supported (see
7979
`git update-index --untracked-cache` and `git update-index
8080
--split-index`), Otherwise you can use `no` to have `git status`
8181
return more quickly without showing untracked files.
82+
All usual spellings for Boolean value `true` are taken as `normal`
83+
and `false` as `no`.
8284

8385
The default can be changed using the status.showUntrackedFiles
8486
configuration variable documented in linkgit:git-config[1].

builtin/commit.c

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,22 +1157,45 @@ static void handle_ignored_arg(struct wt_status *s)
11571157
die(_("Invalid ignored mode '%s'"), ignored_arg);
11581158
}
11591159

1160-
static void handle_untracked_files_arg(struct wt_status *s)
1160+
static enum untracked_status_type parse_untracked_setting_name(const char *u)
11611161
{
1162-
if (!untracked_files_arg)
1163-
; /* default already initialized */
1164-
else if (!strcmp(untracked_files_arg, "no"))
1165-
s->show_untracked_files = SHOW_NO_UNTRACKED_FILES;
1166-
else if (!strcmp(untracked_files_arg, "normal"))
1167-
s->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
1168-
else if (!strcmp(untracked_files_arg, "all"))
1169-
s->show_untracked_files = SHOW_ALL_UNTRACKED_FILES;
11701162
/*
11711163
* Please update $__git_untracked_file_modes in
11721164
* git-completion.bash when you add new options
11731165
*/
1166+
switch (git_parse_maybe_bool(u)) {
1167+
case 0:
1168+
u = "no";
1169+
break;
1170+
case 1:
1171+
u = "normal";
1172+
break;
1173+
default:
1174+
break;
1175+
}
1176+
1177+
if (!strcmp(u, "no"))
1178+
return SHOW_NO_UNTRACKED_FILES;
1179+
else if (!strcmp(u, "normal"))
1180+
return SHOW_NORMAL_UNTRACKED_FILES;
1181+
else if (!strcmp(u, "all"))
1182+
return SHOW_ALL_UNTRACKED_FILES;
11741183
else
1175-
die(_("Invalid untracked files mode '%s'"), untracked_files_arg);
1184+
return SHOW_UNTRACKED_FILES_ERROR;
1185+
}
1186+
1187+
static void handle_untracked_files_arg(struct wt_status *s)
1188+
{
1189+
enum untracked_status_type u;
1190+
1191+
if (!untracked_files_arg)
1192+
return; /* default already initialized */
1193+
1194+
u = parse_untracked_setting_name(untracked_files_arg);
1195+
if (u == SHOW_UNTRACKED_FILES_ERROR)
1196+
die(_("Invalid untracked files mode '%s'"),
1197+
untracked_files_arg);
1198+
s->show_untracked_files = u;
11761199
}
11771200

11781201
static const char *read_commit_message(const char *name)
@@ -1455,16 +1478,12 @@ static int git_status_config(const char *k, const char *v,
14551478
return 0;
14561479
}
14571480
if (!strcmp(k, "status.showuntrackedfiles")) {
1458-
if (!v)
1459-
return config_error_nonbool(k);
1460-
else if (!strcmp(v, "no"))
1461-
s->show_untracked_files = SHOW_NO_UNTRACKED_FILES;
1462-
else if (!strcmp(v, "normal"))
1463-
s->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
1464-
else if (!strcmp(v, "all"))
1465-
s->show_untracked_files = SHOW_ALL_UNTRACKED_FILES;
1466-
else
1481+
enum untracked_status_type u;
1482+
1483+
u = parse_untracked_setting_name(v);
1484+
if (u == SHOW_UNTRACKED_FILES_ERROR)
14671485
return error(_("Invalid untracked files mode '%s'"), v);
1486+
s->show_untracked_files = u;
14681487
return 0;
14691488
}
14701489
if (!strcmp(k, "diff.renamelimit")) {

t/t7508-status.sh

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -419,14 +419,19 @@ Changes not staged for commit:
419419
Untracked files not listed (use -u option to show untracked files)
420420
EOF
421421
git status -uno >output &&
422+
test_cmp expect output &&
423+
git status -ufalse >output &&
422424
test_cmp expect output
423425
'
424426

425-
test_expect_success 'status (status.showUntrackedFiles no)' '
426-
test_config status.showuntrackedfiles no &&
427-
git status >output &&
428-
test_cmp expect output
429-
'
427+
for no in no false 0
428+
do
429+
test_expect_success "status (status.showUntrackedFiles $no)" '
430+
test_config status.showuntrackedfiles "$no" &&
431+
git status >output &&
432+
test_cmp expect output
433+
'
434+
done
430435

431436
test_expect_success 'status -uno (advice.statusHints false)' '
432437
cat >expect <<EOF &&
@@ -488,14 +493,21 @@ Untracked files:
488493
489494
EOF
490495
git status -unormal >output &&
496+
test_cmp expect output &&
497+
git status -utrue >output &&
498+
test_cmp expect output &&
499+
git status -uyes >output &&
491500
test_cmp expect output
492501
'
493502

494-
test_expect_success 'status (status.showUntrackedFiles normal)' '
495-
test_config status.showuntrackedfiles normal &&
496-
git status >output &&
497-
test_cmp expect output
498-
'
503+
for normal in normal true 1
504+
do
505+
test_expect_success "status (status.showUntrackedFiles $normal)" '
506+
test_config status.showuntrackedfiles $normal &&
507+
git status >output &&
508+
test_cmp expect output
509+
'
510+
done
499511

500512
cat >expect <<EOF
501513
M dir1/modified

wt-status.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ enum color_wt_status {
2323
};
2424

2525
enum untracked_status_type {
26-
SHOW_NO_UNTRACKED_FILES,
26+
SHOW_UNTRACKED_FILES_ERROR = -1,
27+
SHOW_NO_UNTRACKED_FILES = 0,
2728
SHOW_NORMAL_UNTRACKED_FILES,
2829
SHOW_ALL_UNTRACKED_FILES
2930
};

0 commit comments

Comments
 (0)