* [PATCH 0/2] status --untracked=no
@ 2024-03-13 17:32 Junio C Hamano
2024-03-13 17:32 ` [PATCH 1/2] status: unify parsing of --untracked= and status.showUntrackedFiles Junio C Hamano
2024-03-13 17:32 ` [PATCH 2/2] status: allow --untracked=false and friends Junio C Hamano
0 siblings, 2 replies; 4+ messages in thread
From: Junio C Hamano @ 2024-03-13 17:32 UTC (permalink / raw)
To: git
Jonas Wunderlich noticed that "git status" documentation mentioned
"--untracked-files=false", which unfortunately is not even accepted
by the command. 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".
Junio C Hamano (2):
status: unify parsing of --untracked= and status.showUntrackedFiles
status: allow --untracked=false and friends
Documentation/config/status.txt | 2 ++
Documentation/git-commit.txt | 2 ++
Documentation/git-status.txt | 2 ++
builtin/commit.c | 57 ++++++++++++++++++++++-----------
t/t7508-status.sh | 32 ++++++++++++------
wt-status.h | 3 +-
6 files changed, 68 insertions(+), 30 deletions(-)
--
2.44.0-191-g945115026a
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] status: unify parsing of --untracked= and status.showUntrackedFiles
2024-03-13 17:32 [PATCH 0/2] status --untracked=no Junio C Hamano
@ 2024-03-13 17:32 ` Junio C Hamano
2024-03-13 17:32 ` [PATCH 2/2] status: allow --untracked=false and friends Junio C Hamano
1 sibling, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2024-03-13 17:32 UTC (permalink / raw)
To: git
There are two code paths that take a string and parse it to enum
untracked_status_type. Introduce a helper function and use it.
As these two places handle an error differently, add an additional
invalid value to the enum, and have the caller of the helper handle
the error condition, instead of dying or emitting error message from
the helper.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
builtin/commit.c | 44 +++++++++++++++++++++++++++-----------------
wt-status.h | 3 ++-
2 files changed, 29 insertions(+), 18 deletions(-)
diff --git a/builtin/commit.c b/builtin/commit.c
index a91197245f..e61e459ca9 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1157,22 +1157,34 @@ static void handle_ignored_arg(struct wt_status *s)
die(_("Invalid ignored mode '%s'"), ignored_arg);
}
-static void handle_untracked_files_arg(struct wt_status *s)
+static enum untracked_status_type parse_untracked_setting_name(const char *u)
{
- if (!untracked_files_arg)
- ; /* default already initialized */
- else if (!strcmp(untracked_files_arg, "no"))
- s->show_untracked_files = SHOW_NO_UNTRACKED_FILES;
- else if (!strcmp(untracked_files_arg, "normal"))
- s->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
- else if (!strcmp(untracked_files_arg, "all"))
- s->show_untracked_files = SHOW_ALL_UNTRACKED_FILES;
/*
* Please update $__git_untracked_file_modes in
* git-completion.bash when you add new options
*/
+ if (!strcmp(u, "no"))
+ return SHOW_NO_UNTRACKED_FILES;
+ else if (!strcmp(u, "normal"))
+ return SHOW_NORMAL_UNTRACKED_FILES;
+ else if (!strcmp(u, "all"))
+ return SHOW_ALL_UNTRACKED_FILES;
else
- die(_("Invalid untracked files mode '%s'"), untracked_files_arg);
+ return SHOW_UNTRACKED_FILES_ERROR;
+}
+
+static void handle_untracked_files_arg(struct wt_status *s)
+{
+ enum untracked_status_type u;
+
+ if (!untracked_files_arg)
+ return; /* default already initialized */
+
+ u = parse_untracked_setting_name(untracked_files_arg);
+ if (u == SHOW_UNTRACKED_FILES_ERROR)
+ die(_("Invalid untracked files mode '%s'"),
+ untracked_files_arg);
+ s->show_untracked_files = u;
}
static const char *read_commit_message(const char *name)
@@ -1455,16 +1467,14 @@ static int git_status_config(const char *k, const char *v,
return 0;
}
if (!strcmp(k, "status.showuntrackedfiles")) {
+ enum untracked_status_type u;
+
if (!v)
return config_error_nonbool(k);
- else if (!strcmp(v, "no"))
- s->show_untracked_files = SHOW_NO_UNTRACKED_FILES;
- else if (!strcmp(v, "normal"))
- s->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
- else if (!strcmp(v, "all"))
- s->show_untracked_files = SHOW_ALL_UNTRACKED_FILES;
- else
+ u = parse_untracked_setting_name(v);
+ if (u == SHOW_UNTRACKED_FILES_ERROR)
return error(_("Invalid untracked files mode '%s'"), v);
+ s->show_untracked_files = u;
return 0;
}
if (!strcmp(k, "diff.renamelimit")) {
diff --git a/wt-status.h b/wt-status.h
index 5e99ba4707..4e377ce62b 100644
--- a/wt-status.h
+++ b/wt-status.h
@@ -23,7 +23,8 @@ enum color_wt_status {
};
enum untracked_status_type {
- SHOW_NO_UNTRACKED_FILES,
+ SHOW_UNTRACKED_FILES_ERROR = -1,
+ SHOW_NO_UNTRACKED_FILES = 0,
SHOW_NORMAL_UNTRACKED_FILES,
SHOW_ALL_UNTRACKED_FILES
};
--
2.44.0-191-g945115026a
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] status: allow --untracked=false and friends
2024-03-13 17:32 [PATCH 0/2] status --untracked=no Junio C Hamano
2024-03-13 17:32 ` [PATCH 1/2] status: unify parsing of --untracked= and status.showUntrackedFiles Junio C Hamano
@ 2024-03-13 17:32 ` Junio C Hamano
2024-03-13 20:17 ` Kristoffer Haugsbakk
1 sibling, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2024-03-13 17:32 UTC (permalink / raw)
To: git
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>
---
Documentation/config/status.txt | 2 ++
Documentation/git-commit.txt | 2 ++
Documentation/git-status.txt | 2 ++
builtin/commit.c | 13 +++++++++++--
t/t7508-status.sh | 32 ++++++++++++++++++++++----------
5 files changed, 39 insertions(+), 12 deletions(-)
diff --git a/Documentation/config/status.txt b/Documentation/config/status.txt
index 2ff8237f8f..8caf90f51c 100644
--- a/Documentation/config/status.txt
+++ b/Documentation/config/status.txt
@@ -57,6 +57,8 @@ status.showUntrackedFiles::
--
+
If this variable is not specified, it defaults to 'normal'.
+All usual spellings for Boolean value `true` are taken as `normal`
+and `false` as `no`.
This variable can be overridden with the -u|--untracked-files option
of linkgit:git-status[1] and linkgit:git-commit[1].
diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
index a6cef5d820..89ecfc63a8 100644
--- a/Documentation/git-commit.txt
+++ b/Documentation/git-commit.txt
@@ -347,6 +347,8 @@ The possible options are:
- 'normal' - Shows untracked files and directories
- 'all' - Also shows individual files in untracked directories.
+All usual spellings for Boolean value `true` are taken as `normal`
+and `false` as `no`.
The default can be changed using the status.showUntrackedFiles
configuration variable documented in linkgit:git-config[1].
--
diff --git a/Documentation/git-status.txt b/Documentation/git-status.txt
index b0f36fabfb..9a376886a5 100644
--- a/Documentation/git-status.txt
+++ b/Documentation/git-status.txt
@@ -79,6 +79,8 @@ Consider enabling untracked cache and split index if supported (see
`git update-index --untracked-cache` and `git update-index
--split-index`), Otherwise you can use `no` to have `git status`
return more quickly without showing untracked files.
+All usual spellings for Boolean value `true` are taken as `normal`
+and `false` as `no`.
The default can be changed using the status.showUntrackedFiles
configuration variable documented in linkgit:git-config[1].
diff --git a/builtin/commit.c b/builtin/commit.c
index e61e459ca9..ddf4198c92 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1163,6 +1163,17 @@ static enum untracked_status_type parse_untracked_setting_name(const char *u)
* Please update $__git_untracked_file_modes in
* git-completion.bash when you add new options
*/
+ switch (git_parse_maybe_bool(u)) {
+ case 0:
+ u = "no";
+ break;
+ case 1:
+ u = "normal";
+ break;
+ default:
+ break;
+ }
+
if (!strcmp(u, "no"))
return SHOW_NO_UNTRACKED_FILES;
else if (!strcmp(u, "normal"))
@@ -1469,8 +1480,6 @@ static int git_status_config(const char *k, const char *v,
if (!strcmp(k, "status.showuntrackedfiles")) {
enum untracked_status_type u;
- if (!v)
- return config_error_nonbool(k);
u = parse_untracked_setting_name(v);
if (u == SHOW_UNTRACKED_FILES_ERROR)
return error(_("Invalid untracked files mode '%s'"), v);
diff --git a/t/t7508-status.sh b/t/t7508-status.sh
index a3c18a4fc2..e9afa59968 100755
--- a/t/t7508-status.sh
+++ b/t/t7508-status.sh
@@ -419,14 +419,19 @@ Changes not staged for commit:
Untracked files not listed (use -u option to show untracked files)
EOF
git status -uno >output &&
+ test_cmp expect output &&
+ git status -ufalse >output &&
test_cmp expect output
'
-test_expect_success 'status (status.showUntrackedFiles no)' '
- test_config status.showuntrackedfiles no &&
- git status >output &&
- test_cmp expect output
-'
+for no in no false 0
+do
+ test_expect_success "status (status.showUntrackedFiles $no)" '
+ test_config status.showuntrackedfiles "$no" &&
+ git status >output &&
+ test_cmp expect output
+ '
+done
test_expect_success 'status -uno (advice.statusHints false)' '
cat >expect <<EOF &&
@@ -488,14 +493,21 @@ Untracked files:
EOF
git status -unormal >output &&
+ test_cmp expect output &&
+ git status -utrue >output &&
+ test_cmp expect output &&
+ git status -uyes >output &&
test_cmp expect output
'
-test_expect_success 'status (status.showUntrackedFiles normal)' '
- test_config status.showuntrackedfiles normal &&
- git status >output &&
- test_cmp expect output
-'
+for normal in normal true 1
+do
+ test_expect_success "status (status.showUntrackedFiles $normal)" '
+ test_config status.showuntrackedfiles $normal &&
+ git status >output &&
+ test_cmp expect output
+ '
+done
cat >expect <<EOF
M dir1/modified
--
2.44.0-191-g945115026a
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] status: allow --untracked=false and friends
2024-03-13 17:32 ` [PATCH 2/2] status: allow --untracked=false and friends Junio C Hamano
@ 2024-03-13 20:17 ` Kristoffer Haugsbakk
0 siblings, 0 replies; 4+ messages in thread
From: Kristoffer Haugsbakk @ 2024-03-13 20:17 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
On Wed, Mar 13, 2024, at 18:32, Junio C Hamano wrote:
> 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>
Maybe:
Reported-by: Jonas Wunderlich <git@03j.de>
--
Kristoffer Haugsbakk
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-03-13 20:18 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-13 17:32 [PATCH 0/2] status --untracked=no Junio C Hamano
2024-03-13 17:32 ` [PATCH 1/2] status: unify parsing of --untracked= and status.showUntrackedFiles Junio C Hamano
2024-03-13 17:32 ` [PATCH 2/2] status: allow --untracked=false and friends Junio C Hamano
2024-03-13 20:17 ` Kristoffer Haugsbakk
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).