Skip to content

Commit f66e1a0

Browse files
committed
status: allow --untracked=false and friends
It is natural to expect that the "--untracked" option and the status.showuntrackedFiles configuration variable to take a Boolean value ("do you want me to show untracked files?"), but the current code takes nothing but "no" as "no, please do not show any". Allow the usual Boolean values to be given, and treat 'true' as "normal", and 'false' as "no". Signed-off-by: Junio C Hamano <[email protected]>
1 parent 63acdc4 commit f66e1a0

File tree

5 files changed

+39
-12
lines changed

5 files changed

+39
-12
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: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,17 @@ static enum untracked_status_type parse_untracked_setting_name(const char *u)
11631163
* Please update $__git_untracked_file_modes in
11641164
* git-completion.bash when you add new options
11651165
*/
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+
11661177
if (!strcmp(u, "no"))
11671178
return SHOW_NO_UNTRACKED_FILES;
11681179
else if (!strcmp(u, "normal"))
@@ -1469,8 +1480,6 @@ static int git_status_config(const char *k, const char *v,
14691480
if (!strcmp(k, "status.showuntrackedfiles")) {
14701481
enum untracked_status_type u;
14711482

1472-
if (!v)
1473-
return config_error_nonbool(k);
14741483
u = parse_untracked_setting_name(v);
14751484
if (u == SHOW_UNTRACKED_FILES_ERROR)
14761485
return error(_("Invalid untracked files mode '%s'"), v);

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

0 commit comments

Comments
 (0)