]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'jc/show-untracked-false'
authorJunio C Hamano <gitster@pobox.com>
Thu, 28 Mar 2024 21:13:50 +0000 (14:13 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 28 Mar 2024 21:13:50 +0000 (14:13 -0700)
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

Documentation/config/status.txt
Documentation/git-commit.txt
Documentation/git-status.txt
builtin/commit.c
t/t7508-status.sh
wt-status.h

index 2ff8237f8fc4585e7a2a4c9e7a27f121bbd9d7e2..8caf90f51c19a3c64b777310e69691d4e2b6dbc2 100644 (file)
@@ -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].
 
index a6cef5d82038771c5f7e91f788f14de6394de158..89ecfc63a8d07f655137b753b306cf22586334cd 100644 (file)
@@ -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].
 --
index b0f36fabfb391c10582a6f0feb63fa596e693ddc..9a376886a5867a63d173d85162c57027f336f915 100644 (file)
@@ -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].
index f5a5a0ec53aafe58d99b2792d3c421f68ce5139d..b27b56c8bef3ea0c968392095519017151709ca2 100644 (file)
@@ -1157,22 +1157,45 @@ 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
         */
+       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"))
+               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 +1478,12 @@ static int git_status_config(const char *k, const char *v,
                return 0;
        }
        if (!strcmp(k, "status.showuntrackedfiles")) {
-               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
+               enum untracked_status_type u;
+
+               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")) {
index a3c18a4fc2764aa669556fe56961d254727bdab5..e9afa5996843e812e585753289fb04ce93fd7c00 100755 (executable)
@@ -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
index 5e99ba47073493aa4ee80a9501dd4375ec903d8f..4e377ce62b8b2871bb73cf900acff0a9bab40c6c 100644 (file)
@@ -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
 };