{"thread":{"id":"61113","subject":"[PATCH 0/2] status --untracked=no","startedAt":"2024-03-13T17:32:17Z","lastAt":"2024-03-13T20:18:55Z","messageCount":4,"participants":["Junio C Hamano","Kristoffer Haugsbakk"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"490556","messageId":"20240313173214.962532-1-gitster@pobox.com","threadId":"61113","inReplyTo":null,"subject":"[PATCH 0/2] status --untracked=no","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-03-13T17:32:12Z","receivedAt":"2024-03-13T17:32:17Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jonas Wunderlich noticed that \"git status\" documentation mentioned\n\"--untracked-files=false\", which unfortunately is not even accepted\nby the command.  It is natural to expect that the \"--untracked\" option\nand the status.showuntrackedFiles configuration variable to take a\nBoolean value (\"do you want me to show untracked files?\"), but the\ncurrent code takes nothing but \"no\" as \"no, please do not show any\".\n\nJunio C Hamano (2):\n  status: unify parsing of --untracked= and status.showUntrackedFiles\n  status: allow --untracked=false and friends\n\n Documentation/config/status.txt |  2 ++\n Documentation/git-commit.txt    |  2 ++\n Documentation/git-status.txt    |  2 ++\n builtin/commit.c                | 57 ++++++++++++++++++++++-----------\n t/t7508-status.sh               | 32 ++++++++++++------\n wt-status.h                     |  3 +-\n 6 files changed, 68 insertions(+), 30 deletions(-)\n\n-- \n2.44.0-191-g945115026a\n\n"},{"id":"490557","messageId":"20240313173214.962532-2-gitster@pobox.com","threadId":"61113","inReplyTo":"20240313173214.962532-1-gitster@pobox.com","subject":"[PATCH 1/2] status: unify parsing of --untracked= and status.showUntrackedFiles","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-03-13T17:32:13Z","receivedAt":"2024-03-13T17:32:21Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"There are two code paths that take a string and parse it to enum\nuntracked_status_type.  Introduce a helper function and use it.\n\nAs these two places handle an error differently, add an additional\ninvalid value to the enum, and have the caller of the helper handle\nthe error condition, instead of dying or emitting error message from\nthe helper.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n builtin/commit.c | 44 +++++++++++++++++++++++++++-----------------\n wt-status.h      |  3 ++-\n 2 files changed, 29 insertions(+), 18 deletions(-)\n\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex a91197245f..e61e459ca9 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -1157,22 +1157,34 @@ static void handle_ignored_arg(struct wt_status *s)\n \t\tdie(_(\"Invalid ignored mode '%s'\"), ignored_arg);\n }\n \n-static void handle_untracked_files_arg(struct wt_status *s)\n+static enum untracked_status_type parse_untracked_setting_name(const char *u)\n {\n-\tif (!untracked_files_arg)\n-\t\t; /* default already initialized */\n-\telse if (!strcmp(untracked_files_arg, \"no\"))\n-\t\ts->show_untracked_files = SHOW_NO_UNTRACKED_FILES;\n-\telse if (!strcmp(untracked_files_arg, \"normal\"))\n-\t\ts->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;\n-\telse if (!strcmp(untracked_files_arg, \"all\"))\n-\t\ts->show_untracked_files = SHOW_ALL_UNTRACKED_FILES;\n \t/*\n \t * Please update $__git_untracked_file_modes in\n \t * git-completion.bash when you add new options\n \t */\n+\tif (!strcmp(u, \"no\"))\n+\t\treturn SHOW_NO_UNTRACKED_FILES;\n+\telse if (!strcmp(u, \"normal\"))\n+\t\treturn SHOW_NORMAL_UNTRACKED_FILES;\n+\telse if (!strcmp(u, \"all\"))\n+\t\treturn SHOW_ALL_UNTRACKED_FILES;\n \telse\n-\t\tdie(_(\"Invalid untracked files mode '%s'\"), untracked_files_arg);\n+\t\treturn SHOW_UNTRACKED_FILES_ERROR;\n+}\n+\n+static void handle_untracked_files_arg(struct wt_status *s)\n+{\n+\tenum untracked_status_type u;\n+\n+\tif (!untracked_files_arg)\n+\t\treturn; /* default already initialized */\n+\n+\tu = parse_untracked_setting_name(untracked_files_arg);\n+\tif (u == SHOW_UNTRACKED_FILES_ERROR)\n+\t\tdie(_(\"Invalid untracked files mode '%s'\"),\n+\t\t    untracked_files_arg);\n+\ts->show_untracked_files = u;\n }\n \n static const char *read_commit_message(const char *name)\n@@ -1455,16 +1467,14 @@ static int git_status_config(const char *k, const char *v,\n \t\treturn 0;\n \t}\n \tif (!strcmp(k, \"status.showuntrackedfiles\")) {\n+\t\tenum untracked_status_type u;\n+\n \t\tif (!v)\n \t\t\treturn config_error_nonbool(k);\n-\t\telse if (!strcmp(v, \"no\"))\n-\t\t\ts->show_untracked_files = SHOW_NO_UNTRACKED_FILES;\n-\t\telse if (!strcmp(v, \"normal\"))\n-\t\t\ts->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;\n-\t\telse if (!strcmp(v, \"all\"))\n-\t\t\ts->show_untracked_files = SHOW_ALL_UNTRACKED_FILES;\n-\t\telse\n+\t\tu = parse_untracked_setting_name(v);\n+\t\tif (u == SHOW_UNTRACKED_FILES_ERROR)\n \t\t\treturn error(_(\"Invalid untracked files mode '%s'\"), v);\n+\t\ts->show_untracked_files = u;\n \t\treturn 0;\n \t}\n \tif (!strcmp(k, \"diff.renamelimit\")) {\ndiff --git a/wt-status.h b/wt-status.h\nindex 5e99ba4707..4e377ce62b 100644\n--- a/wt-status.h\n+++ b/wt-status.h\n@@ -23,7 +23,8 @@ enum color_wt_status {\n };\n \n enum untracked_status_type {\n-\tSHOW_NO_UNTRACKED_FILES,\n+\tSHOW_UNTRACKED_FILES_ERROR = -1,\n+\tSHOW_NO_UNTRACKED_FILES = 0,\n \tSHOW_NORMAL_UNTRACKED_FILES,\n \tSHOW_ALL_UNTRACKED_FILES\n };\n-- \n2.44.0-191-g945115026a\n\n"},{"id":"490558","messageId":"20240313173214.962532-3-gitster@pobox.com","threadId":"61113","inReplyTo":"20240313173214.962532-1-gitster@pobox.com","subject":"[PATCH 2/2] status: allow --untracked=false and friends","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-03-13T17:32:14Z","receivedAt":"2024-03-13T17:32:22Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"It is natural to expect that the \"--untracked\" option and the\nstatus.showuntrackedFiles configuration variable to take a Boolean\nvalue (\"do you want me to show untracked files?\"), but the current\ncode takes nothing but \"no\" as \"no, please do not show any\".\n\nAllow the usual Boolean values to be given, and treat 'true' as\n\"normal\", and 'false' as \"no\".\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n Documentation/config/status.txt |  2 ++\n Documentation/git-commit.txt    |  2 ++\n Documentation/git-status.txt    |  2 ++\n builtin/commit.c                | 13 +++++++++++--\n t/t7508-status.sh               | 32 ++++++++++++++++++++++----------\n 5 files changed, 39 insertions(+), 12 deletions(-)\n\ndiff --git a/Documentation/config/status.txt b/Documentation/config/status.txt\nindex 2ff8237f8f..8caf90f51c 100644\n--- a/Documentation/config/status.txt\n+++ b/Documentation/config/status.txt\n@@ -57,6 +57,8 @@ status.showUntrackedFiles::\n --\n +\n If this variable is not specified, it defaults to 'normal'.\n+All usual spellings for Boolean value `true` are taken as `normal`\n+and `false` as `no`.\n This variable can be overridden with the -u|--untracked-files option\n of linkgit:git-status[1] and linkgit:git-commit[1].\n \ndiff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt\nindex a6cef5d820..89ecfc63a8 100644\n--- a/Documentation/git-commit.txt\n+++ b/Documentation/git-commit.txt\n@@ -347,6 +347,8 @@ The possible options are:\n \t- 'normal' - Shows untracked files and directories\n \t- 'all'    - Also shows individual files in untracked directories.\n \n+All usual spellings for Boolean value `true` are taken as `normal`\n+and `false` as `no`.\n The default can be changed using the status.showUntrackedFiles\n configuration variable documented in linkgit:git-config[1].\n --\ndiff --git a/Documentation/git-status.txt b/Documentation/git-status.txt\nindex b0f36fabfb..9a376886a5 100644\n--- a/Documentation/git-status.txt\n+++ b/Documentation/git-status.txt\n@@ -79,6 +79,8 @@ Consider enabling untracked cache and split index if supported (see\n `git update-index --untracked-cache` and `git update-index\n --split-index`), Otherwise you can use `no` to have `git status`\n return more quickly without showing untracked files.\n+All usual spellings for Boolean value `true` are taken as `normal`\n+and `false` as `no`.\n \n The default can be changed using the status.showUntrackedFiles\n configuration variable documented in linkgit:git-config[1].\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex e61e459ca9..ddf4198c92 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -1163,6 +1163,17 @@ static enum untracked_status_type parse_untracked_setting_name(const char *u)\n \t * Please update $__git_untracked_file_modes in\n \t * git-completion.bash when you add new options\n \t */\n+\tswitch (git_parse_maybe_bool(u)) {\n+\tcase 0:\n+\t\tu = \"no\";\n+\t\tbreak;\n+\tcase 1:\n+\t\tu = \"normal\";\n+\t\tbreak;\n+\tdefault:\n+\t\tbreak;\n+\t}\n+\n \tif (!strcmp(u, \"no\"))\n \t\treturn SHOW_NO_UNTRACKED_FILES;\n \telse if (!strcmp(u, \"normal\"))\n@@ -1469,8 +1480,6 @@ static int git_status_config(const char *k, const char *v,\n \tif (!strcmp(k, \"status.showuntrackedfiles\")) {\n \t\tenum untracked_status_type u;\n \n-\t\tif (!v)\n-\t\t\treturn config_error_nonbool(k);\n \t\tu = parse_untracked_setting_name(v);\n \t\tif (u == SHOW_UNTRACKED_FILES_ERROR)\n \t\t\treturn error(_(\"Invalid untracked files mode '%s'\"), v);\ndiff --git a/t/t7508-status.sh b/t/t7508-status.sh\nindex a3c18a4fc2..e9afa59968 100755\n--- a/t/t7508-status.sh\n+++ b/t/t7508-status.sh\n@@ -419,14 +419,19 @@ Changes not staged for commit:\n Untracked files not listed (use -u option to show untracked files)\n EOF\n \tgit status -uno >output &&\n+\ttest_cmp expect output &&\n+\tgit status -ufalse >output &&\n \ttest_cmp expect output\n '\n \n-test_expect_success 'status (status.showUntrackedFiles no)' '\n-\ttest_config status.showuntrackedfiles no &&\n-\tgit status >output &&\n-\ttest_cmp expect output\n-'\n+for no in no false 0\n+do\n+\ttest_expect_success \"status (status.showUntrackedFiles $no)\" '\n+\t\ttest_config status.showuntrackedfiles \"$no\" &&\n+\t\tgit status >output &&\n+\t\ttest_cmp expect output\n+\t'\n+done\n \n test_expect_success 'status -uno (advice.statusHints false)' '\n \tcat >expect <<EOF &&\n@@ -488,14 +493,21 @@ Untracked files:\n \n EOF\n \tgit status -unormal >output &&\n+\ttest_cmp expect output &&\n+\tgit status -utrue >output &&\n+\ttest_cmp expect output &&\n+\tgit status -uyes >output &&\n \ttest_cmp expect output\n '\n \n-test_expect_success 'status (status.showUntrackedFiles normal)' '\n-\ttest_config status.showuntrackedfiles normal &&\n-\tgit status >output &&\n-\ttest_cmp expect output\n-'\n+for normal in normal true 1\n+do\n+\ttest_expect_success \"status (status.showUntrackedFiles $normal)\" '\n+\t\ttest_config status.showuntrackedfiles $normal &&\n+\t\tgit status >output &&\n+\t\ttest_cmp expect output\n+\t'\n+done\n \n cat >expect <<EOF\n  M dir1/modified\n-- \n2.44.0-191-g945115026a\n\n"},{"id":"490578","messageId":"c24d304e-adc7-4f29-8ca5-77d8263108cc@app.fastmail.com","threadId":"61113","inReplyTo":"20240313173214.962532-3-gitster@pobox.com","subject":"Re: [PATCH 2/2] status: allow --untracked=false and friends","fromName":"Kristoffer Haugsbakk","fromEmail":"code@khaugsbakk.name","sentAt":"2024-03-13T20:17:41Z","receivedAt":"2024-03-13T20:18:55Z","isPatch":true,"sender":{"key":"code@khaugsbakk.name","avatar":"https://avatars.githubusercontent.com/u/2229597?v=4"},"body":"On Wed, Mar 13, 2024, at 18:32, Junio C Hamano wrote:\n> It is natural to expect that the \"--untracked\" option and the\n> status.showuntrackedFiles configuration variable to take a Boolean\n> value (\"do you want me to show untracked files?\"), but the current\n> code takes nothing but \"no\" as \"no, please do not show any\".\n>\n> Allow the usual Boolean values to be given, and treat 'true' as\n> \"normal\", and 'false' as \"no\".\n>\n> Signed-off-by: Junio C Hamano <gitster@pobox.com>\n\nMaybe:\n\n    Reported-by: Jonas Wunderlich <git@03j.de>\n\n-- \nKristoffer Haugsbakk\n\n"}]}