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 <gitster@pobox.com>

Junio C Hamano committed Mar 13, 2024 at 10:32 UTC f66e1a071bd66e64160d9e73428d6cd7bdcff84e
5 files changed +39 -12
Documentation/config/status.txt
+2
@@ -57,6 +57,8 @@ status.showUntrackedFiles::
57 --
58 +
59 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`.
62 This variable can be overridden with the -u|--untracked-files option
63 of linkgit:git-status[1] and linkgit:git-commit[1].
64
Documentation/git-commit.txt
+2
@@ -347,6 +347,8 @@ The possible options are:
347 - 'normal' - Shows untracked files and directories
348 - 'all' - Also shows individual files in untracked directories.
349
350 +All usual spellings for Boolean value `true` are taken as `normal`
351 +and `false` as `no`.
352 The default can be changed using the status.showUntrackedFiles
353 configuration variable documented in linkgit:git-config[1].
354 --
Documentation/git-status.txt
+2
@@ -79,6 +79,8 @@ Consider enabling untracked cache and split index if supported (see
79 `git update-index --untracked-cache` and `git update-index
80 --split-index`), Otherwise you can use `no` to have `git status`
81 return more quickly without showing untracked files.
82 +All usual spellings for Boolean value `true` are taken as `normal`
83 +and `false` as `no`.
84
85 The default can be changed using the status.showUntrackedFiles
86 configuration variable documented in linkgit:git-config[1].
builtin/commit.c
+11 -2
@@ -1163,6 +1163,17 @@ static enum untracked_status_type parse_untracked_setting_name(const char *u)
1163 * Please update $__git_untracked_file_modes in
1164 * git-completion.bash when you add new options
1165 */
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"))
@@ -1469,8 +1480,6 @@ static int git_status_config(const char *k, const char *v,
1480 if (!strcmp(k, "status.showuntrackedfiles")) {
1481 enum untracked_status_type u;
1482
1472 - if (!v)
1473 - return config_error_nonbool(k);
1483 u = parse_untracked_setting_name(v);
1484 if (u == SHOW_UNTRACKED_FILES_ERROR)
1485 return error(_("Invalid untracked files mode '%s'"), v);
t/t7508-status.sh
+22 -10
@@ -419,14 +419,19 @@ Changes not staged for commit:
419 Untracked files not listed (use -u option to show untracked files)
420 EOF
421 git status -uno >output &&
422 + test_cmp expect output &&
423 + git status -ufalse >output &&
424 test_cmp expect output
425 '
426
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
435
436 test_expect_success 'status -uno (advice.statusHints false)' '
437 cat >expect <<EOF &&
@@ -488,14 +493,21 @@ Untracked files:
493
494 EOF
495 git status -unormal >output &&
496 + test_cmp expect output &&
497 + git status -utrue >output &&
498 + test_cmp expect output &&
499 + git status -uyes >output &&
500 test_cmp expect output
501 '
502
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
511
512 cat >expect <<EOF
513 M dir1/modified