{"thread":{"id":"54341","subject":"[PATCH 0/2] checkout: learn the checkout.guess config variable","startedAt":"2020-10-04T11:20:13Z","lastAt":"2020-10-08T05:48:29Z","messageCount":14,"participants":["Denton Liu","Junio C Hamano","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"406878","messageId":"cover.1601810233.git.liu.denton@gmail.com","threadId":"54341","inReplyTo":null,"subject":"[PATCH 0/2] checkout: learn the checkout.guess config variable","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2020-10-04T11:18:22Z","receivedAt":"2020-10-04T11:20:13Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"If a user does not wish to use DWIM behaviour, they must manually\nspecify git checkout --no-guess each time. Teach checkout and switch to\nhonour the checkout.guess config variable instead.\n\nDenton Liu (2):\n  Documentation/config/checkout: replace sq with backticks\n  checkout: learn to respect checkout.guess\n\n Documentation/config/checkout.txt      | 21 +++++++----\n Documentation/git-checkout.txt         |  3 ++\n Documentation/git-switch.txt           |  3 ++\n builtin/checkout.c                     |  7 +++-\n contrib/completion/git-completion.bash | 15 ++++++--\n t/t2024-checkout-dwim.sh               | 11 ++++++\n t/t2060-switch.sh                      |  5 ++-\n t/t9902-completion.sh                  | 52 ++++++++++++++++++++++++++\n 8 files changed, 103 insertions(+), 14 deletions(-)\n\n-- \n2.28.0.942.g77c4c6094c\n\n"},{"id":"406879","messageId":"f08d3f796a806b5ec20f12cc85683b2c2e99b1a8.1601810233.git.liu.denton@gmail.com","threadId":"54341","inReplyTo":"cover.1601810233.git.liu.denton@gmail.com","subject":"[PATCH 1/2] Documentation/config/checkout: replace sq with backticks","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2020-10-04T11:18:23Z","receivedAt":"2020-10-04T11:20:53Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"The modern style for Git documentation is to use backticks to quote\nany command-line documenation so that it is typeset in monospace.\nReplace all single quotes with backticks to conform to this.\n\nSigned-off-by: Denton Liu <liu.denton@gmail.com>\n---\n Documentation/config/checkout.txt | 16 ++++++++--------\n 1 file changed, 8 insertions(+), 8 deletions(-)\n\ndiff --git a/Documentation/config/checkout.txt b/Documentation/config/checkout.txt\nindex 6b646813ab..e3684a5459 100644\n--- a/Documentation/config/checkout.txt\n+++ b/Documentation/config/checkout.txt\n@@ -1,18 +1,18 @@\n checkout.defaultRemote::\n-\tWhen you run 'git checkout <something>'\n-\tor 'git switch <something>' and only have one\n+\tWhen you run `git checkout <something>`\n+\tor `git switch <something>` and only have one\n \tremote, it may implicitly fall back on checking out and\n-\ttracking e.g. 'origin/<something>'. This stops working as soon\n-\tas you have more than one remote with a '<something>'\n+\ttracking e.g. `origin/<something>`. This stops working as soon\n+\tas you have more than one remote with a `<something>`\n \treference. This setting allows for setting the name of a\n \tpreferred remote that should always win when it comes to\n \tdisambiguation. The typical use-case is to set this to\n \t`origin`.\n +\n Currently this is used by linkgit:git-switch[1] and\n-linkgit:git-checkout[1] when 'git checkout <something>'\n-or 'git switch <something>'\n-will checkout the '<something>' branch on another remote,\n-and by linkgit:git-worktree[1] when 'git worktree add' refers to a\n+linkgit:git-checkout[1] when `git checkout <something>`\n+or `git switch <something>`\n+will checkout the `<something>` branch on another remote,\n+and by linkgit:git-worktree[1] when `git worktree add` refers to a\n remote branch. This setting might be used for other checkout-like\n commands or functionality in the future.\n-- \n2.28.0.942.g77c4c6094c\n\n"},{"id":"406880","messageId":"8172602f6f1bbdfe39c8a1219dd3b9a222eb65fa.1601810233.git.liu.denton@gmail.com","threadId":"54341","inReplyTo":"cover.1601810233.git.liu.denton@gmail.com","subject":"[PATCH 2/2] checkout: learn to respect checkout.guess","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2020-10-04T11:18:24Z","receivedAt":"2020-10-04T11:21:13Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"The current behavior of git checkout/switch is that --guess is currently\nenabled by default. However, some users may not wish for this to happen\nautomatically. Instead of forcing users to specify --no-guess manually\neach time, teach these commands the checkout.guess configuration\nvariable that gives users the option to set a default behavior.\n\nTeach the completion script to recognize the new config variable and\ndisable DWIM logic if it is set to false.\n\nSigned-off-by: Denton Liu <liu.denton@gmail.com>\n---\n Documentation/config/checkout.txt      |  5 +++\n Documentation/git-checkout.txt         |  3 ++\n Documentation/git-switch.txt           |  3 ++\n builtin/checkout.c                     |  7 +++-\n contrib/completion/git-completion.bash | 15 ++++++--\n t/t2024-checkout-dwim.sh               | 11 ++++++\n t/t2060-switch.sh                      |  5 ++-\n t/t9902-completion.sh                  | 52 ++++++++++++++++++++++++++\n 8 files changed, 95 insertions(+), 6 deletions(-)\n\ndiff --git a/Documentation/config/checkout.txt b/Documentation/config/checkout.txt\nindex e3684a5459..2cddf7b4b4 100644\n--- a/Documentation/config/checkout.txt\n+++ b/Documentation/config/checkout.txt\n@@ -16,3 +16,8 @@ will checkout the `<something>` branch on another remote,\n and by linkgit:git-worktree[1] when `git worktree add` refers to a\n remote branch. This setting might be used for other checkout-like\n commands or functionality in the future.\n+\n+checkout.guess::\n+\tProvides the default value for the `--guess` or `--no-guess`\n+\toption in `git checkout` and `git switch`. See\n+\tlinkgit:git-switch[1] and linkgit:git-checkout[1].\ndiff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt\nindex afa5c11fd3..28f656d04e 100644\n--- a/Documentation/git-checkout.txt\n+++ b/Documentation/git-checkout.txt\n@@ -193,6 +193,9 @@ branches from there if `<branch>` is ambiguous but exists on the\n linkgit:git-config[1].\n +\n Use `--no-guess` to disable this.\n++\n+The default behavior can be set via the `checkout.guess` configuration\n+variable.\n \n -l::\n \tCreate the new branch's reflog; see linkgit:git-branch[1] for\ndiff --git a/Documentation/git-switch.txt b/Documentation/git-switch.txt\nindex 3759c3a265..5c438cd505 100644\n--- a/Documentation/git-switch.txt\n+++ b/Documentation/git-switch.txt\n@@ -103,6 +103,9 @@ ambiguous but exists on the 'origin' remote. See also\n `checkout.defaultRemote` in linkgit:git-config[1].\n +\n `--guess` is the default behavior. Use `--no-guess` to disable it.\n++\n+The default behavior can be set via the `checkout.guess` configuration\n+variable.\n \n -f::\n --force::\ndiff --git a/builtin/checkout.c b/builtin/checkout.c\nindex 0951f8fee5..0c0394a0d6 100644\n--- a/builtin/checkout.c\n+++ b/builtin/checkout.c\n@@ -1093,11 +1093,16 @@ static int switch_branches(const struct checkout_opts *opts,\n \n static int git_checkout_config(const char *var, const char *value, void *cb)\n {\n+\tstruct checkout_opts *opts = cb;\n+\n \tif (!strcmp(var, \"diff.ignoresubmodules\")) {\n-\t\tstruct checkout_opts *opts = cb;\n \t\thandle_ignore_submodules_arg(&opts->diff_options, value);\n \t\treturn 0;\n \t}\n+\tif (!strcmp(var, \"checkout.guess\")) {\n+\t\topts->dwim_new_local_branch = git_config_bool(var, value);\n+\t\treturn 0;\n+\t}\n \n \tif (starts_with(var, \"submodule.\"))\n \t\treturn git_default_submodule_config(var, value, NULL);\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 8be4a0316e..45ecbb9849 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -1470,11 +1470,12 @@ _git_bundle ()\n # To decide between the following rules in priority order\n # 1) the last provided of \"--guess\" or \"--no-guess\" explicitly enable or\n #    disable completion of DWIM logic respectively.\n-# 2) If the --no-track option is provided, take this as a hint to disable the\n+# 2) If checkout.guess is false, disable completion of DWIM logic.\n+# 3) If the --no-track option is provided, take this as a hint to disable the\n #    DWIM completion logic\n-# 3) If GIT_COMPLETION_CHECKOUT_NO_GUESS is set, disable the DWIM completion\n+# 4) If GIT_COMPLETION_CHECKOUT_NO_GUESS is set, disable the DWIM completion\n #    logic, as requested by the user.\n-# 4) Enable DWIM logic otherwise.\n+# 5) Enable DWIM logic otherwise.\n #\n __git_checkout_default_dwim_mode ()\n {\n@@ -1485,11 +1486,17 @@ __git_checkout_default_dwim_mode ()\n \tfi\n \n \t# --no-track disables DWIM, but with lower priority than\n-\t# --guess/--no-guess\n+\t# --guess/--no-guess/checkout.guess\n \tif [ -n \"$(__git_find_on_cmdline \"--no-track\")\" ]; then\n \t\tdwim_opt=\"\"\n \tfi\n \n+\t# checkout.guess = false disables DWIM, but with lower priority than\n+\t# --guess/--no-guess\n+\tif [ \"$(__git config --type=bool checkout.guess)\" = \"false\" ]; then\n+\t\tdwim_opt=\"\"\n+\tfi\n+\n \t# Find the last provided --guess or --no-guess\n \tlast_option=\"$(__git_find_last_on_cmdline \"--guess --no-guess\")\"\n \tcase \"$last_option\" in\ndiff --git a/t/t2024-checkout-dwim.sh b/t/t2024-checkout-dwim.sh\nindex accfa9aa4b..a4f8d3a67e 100755\n--- a/t/t2024-checkout-dwim.sh\n+++ b/t/t2024-checkout-dwim.sh\n@@ -166,6 +166,17 @@ test_expect_success '--no-guess suppresses branch auto-vivification' '\n \ttest_branch master\n '\n \n+test_expect_success 'checkout.guess = false suppresses branch auto-vivification' '\n+\tgit checkout -B master &&\n+\tstatus_uno_is_clean &&\n+\ttest_might_fail git branch -D bar &&\n+\n+\ttest_config checkout.guess false &&\n+\ttest_must_fail git checkout bar &&\n+\ttest_must_fail git rev-parse --verify refs/heads/bar &&\n+\ttest_branch master\n+'\n+\n test_expect_success 'setup more remotes with unconventional refspecs' '\n \tgit checkout -B master &&\n \tstatus_uno_is_clean &&\ndiff --git a/t/t2060-switch.sh b/t/t2060-switch.sh\nindex 2c1b8c0d6d..68c9101b02 100755\n--- a/t/t2060-switch.sh\n+++ b/t/t2060-switch.sh\n@@ -85,9 +85,12 @@ test_expect_success 'switching ignores file of same branch name' '\n \ttest_cmp expected actual\n '\n \n-test_expect_success 'guess and create branch ' '\n+test_expect_success 'guess and create branch' '\n \ttest_when_finished git switch master &&\n \ttest_must_fail git switch --no-guess foo &&\n+\ttest_config checkout.guess false &&\n+\ttest_must_fail git switch foo &&\n+\ttest_config checkout.guess true &&\n \tgit switch foo &&\n \techo refs/heads/foo >expected &&\n \tgit symbolic-ref HEAD >actual &&\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 8425b9a531..2b469a71ca 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -1360,6 +1360,58 @@ test_expect_success 'git checkout - a later --no-guess overrides previous --gues\n \tEOF\n '\n \n+test_expect_success 'git checkout - with checkout.guess = false, only completes refs' '\n+\ttest_config checkout.guess false &&\n+\ttest_completion \"git checkout \" <<-\\EOF\n+\tHEAD Z\n+\tmaster Z\n+\tmatching-branch Z\n+\tmatching-tag Z\n+\tother/branch-in-other Z\n+\tother/master-in-other Z\n+\tEOF\n+'\n+\n+test_expect_success 'git checkout - with checkout.guess = true, completes refs and unique remote branches for DWIM' '\n+\ttest_config checkout.guess true &&\n+\ttest_completion \"git checkout \" <<-\\EOF\n+\tHEAD Z\n+\tbranch-in-other Z\n+\tmaster Z\n+\tmaster-in-other Z\n+\tmatching-branch Z\n+\tmatching-tag Z\n+\tother/branch-in-other Z\n+\tother/master-in-other Z\n+\tEOF\n+'\n+\n+test_expect_success 'git checkout - a later --guess overrides previous checkout.guess = false, complete refs and unique remote branches for DWIM' '\n+\ttest_config checkout.guess false &&\n+\ttest_completion \"git checkout --guess \" <<-\\EOF\n+\tHEAD Z\n+\tbranch-in-other Z\n+\tmaster Z\n+\tmaster-in-other Z\n+\tmatching-branch Z\n+\tmatching-tag Z\n+\tother/branch-in-other Z\n+\tother/master-in-other Z\n+\tEOF\n+'\n+\n+test_expect_success 'git checkout - a later --no-guess overrides previous checkout.guess = true, complete only refs' '\n+\ttest_config checkout.guess true &&\n+\ttest_completion \"git checkout --no-guess \" <<-\\EOF\n+\tHEAD Z\n+\tmaster Z\n+\tmatching-branch Z\n+\tmatching-tag Z\n+\tother/branch-in-other Z\n+\tother/master-in-other Z\n+\tEOF\n+'\n+\n test_expect_success 'git switch - with --detach, complete all references' '\n \ttest_completion \"git switch --detach \" <<-\\EOF\n \tHEAD Z\n-- \n2.28.0.942.g77c4c6094c\n\n"},{"id":"406885","messageId":"xmqqwo057ul5.fsf@gitster.c.googlers.com","threadId":"54341","inReplyTo":"8172602f6f1bbdfe39c8a1219dd3b9a222eb65fa.1601810233.git.liu.denton@gmail.com","subject":"Re: [PATCH 2/2] checkout: learn to respect checkout.guess","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-10-04T17:46:14Z","receivedAt":"2020-10-04T17:46:58Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Denton Liu <liu.denton@gmail.com> writes:\n\n> The current behavior of git checkout/switch is that --guess is currently\n> enabled by default. However, some users may not wish for this to happen\n> automatically. Instead of forcing users to specify --no-guess manually\n> each time, teach these commands the checkout.guess configuration\n> variable that gives users the option to set a default behavior.\n>\n> Teach the completion script to recognize the new config variable and\n> disable DWIM logic if it is set to false.\n>\n> Signed-off-by: Denton Liu <liu.denton@gmail.com>\n> ---\n\nAsking for input from Dscho on how to futureproof the tests along\nthe same line as js/default-branch-name-part-2 topic.\n\n>  Documentation/config/checkout.txt      |  5 +++\n>  Documentation/git-checkout.txt         |  3 ++\n>  Documentation/git-switch.txt           |  3 ++\n>  builtin/checkout.c                     |  7 +++-\n>  contrib/completion/git-completion.bash | 15 ++++++--\n>  t/t2024-checkout-dwim.sh               | 11 ++++++\n>  t/t2060-switch.sh                      |  5 ++-\n>  t/t9902-completion.sh                  | 52 ++++++++++++++++++++++++++\n>  8 files changed, 95 insertions(+), 6 deletions(-)\n>\n> diff --git a/Documentation/config/checkout.txt b/Documentation/config/checkout.txt\n> index e3684a5459..2cddf7b4b4 100644\n> --- a/Documentation/config/checkout.txt\n> +++ b/Documentation/config/checkout.txt\n> @@ -16,3 +16,8 @@ will checkout the `<something>` branch on another remote,\n>  and by linkgit:git-worktree[1] when `git worktree add` refers to a\n>  remote branch. This setting might be used for other checkout-like\n>  commands or functionality in the future.\n> +\n> +checkout.guess::\n> +\tProvides the default value for the `--guess` or `--no-guess`\n> +\toption in `git checkout` and `git switch`. See\n> +\tlinkgit:git-switch[1] and linkgit:git-checkout[1].\n> diff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt\n> index afa5c11fd3..28f656d04e 100644\n> --- a/Documentation/git-checkout.txt\n> +++ b/Documentation/git-checkout.txt\n> @@ -193,6 +193,9 @@ branches from there if `<branch>` is ambiguous but exists on the\n>  linkgit:git-config[1].\n>  +\n>  Use `--no-guess` to disable this.\n> ++\n> +The default behavior can be set via the `checkout.guess` configuration\n> +variable.\n>  \n>  -l::\n>  \tCreate the new branch's reflog; see linkgit:git-branch[1] for\n> diff --git a/Documentation/git-switch.txt b/Documentation/git-switch.txt\n> index 3759c3a265..5c438cd505 100644\n> --- a/Documentation/git-switch.txt\n> +++ b/Documentation/git-switch.txt\n> @@ -103,6 +103,9 @@ ambiguous but exists on the 'origin' remote. See also\n>  `checkout.defaultRemote` in linkgit:git-config[1].\n>  +\n>  `--guess` is the default behavior. Use `--no-guess` to disable it.\n> ++\n> +The default behavior can be set via the `checkout.guess` configuration\n> +variable.\n>  \n>  -f::\n>  --force::\n> diff --git a/builtin/checkout.c b/builtin/checkout.c\n> index 0951f8fee5..0c0394a0d6 100644\n> --- a/builtin/checkout.c\n> +++ b/builtin/checkout.c\n> @@ -1093,11 +1093,16 @@ static int switch_branches(const struct checkout_opts *opts,\n>  \n>  static int git_checkout_config(const char *var, const char *value, void *cb)\n>  {\n> +\tstruct checkout_opts *opts = cb;\n> +\n>  \tif (!strcmp(var, \"diff.ignoresubmodules\")) {\n> -\t\tstruct checkout_opts *opts = cb;\n\nThis change does make sense even without a new configuration\nvariable, as 'cb' given by the caller applies to everything this\nfunction handles, not just for a particular configuration variable\n(not a suggestion to split this out as a separate clean-up patch; it\nis too small for it to be worth).\n\n>  \t\thandle_ignore_submodules_arg(&opts->diff_options, value);\n>  \t\treturn 0;\n>  \t}\n> +\tif (!strcmp(var, \"checkout.guess\")) {\n> +\t\topts->dwim_new_local_branch = git_config_bool(var, value);\n> +\t\treturn 0;\n> +\t}\n>  \n>  \tif (starts_with(var, \"submodule.\"))\n>  \t\treturn git_default_submodule_config(var, value, NULL);\n\nOK.\n\n> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\n> index 8be4a0316e..45ecbb9849 100644\n> --- a/contrib/completion/git-completion.bash\n> +++ b/contrib/completion/git-completion.bash\n> @@ -1470,11 +1470,12 @@ _git_bundle ()\n>  # To decide between the following rules in priority order\n>  # 1) the last provided of \"--guess\" or \"--no-guess\" explicitly enable or\n>  #    disable completion of DWIM logic respectively.\n> -# 2) If the --no-track option is provided, take this as a hint to disable the\n> +# 2) If checkout.guess is false, disable completion of DWIM logic.\n> +# 3) If the --no-track option is provided, take this as a hint to disable the\n>  #    DWIM completion logic\n> -# 3) If GIT_COMPLETION_CHECKOUT_NO_GUESS is set, disable the DWIM completion\n> +# 4) If GIT_COMPLETION_CHECKOUT_NO_GUESS is set, disable the DWIM completion\n>  #    logic, as requested by the user.\n> -# 4) Enable DWIM logic otherwise.\n> +# 5) Enable DWIM logic otherwise.\n>  #\n\nWe may went to consider dropping numbers from these entries, as\nnobody refers to another entry with its number (e.g. \"contrary to\nstep 2, if this condition holds, do X\"), and we already say \"in this\norder\" upfront.\n\n>  __git_checkout_default_dwim_mode ()\n>  {\n> @@ -1485,11 +1486,17 @@ __git_checkout_default_dwim_mode ()\n>  \tfi\n>  \n>  \t# --no-track disables DWIM, but with lower priority than\n> -\t# --guess/--no-guess\n> +\t# --guess/--no-guess/checkout.guess\n>  \tif [ -n \"$(__git_find_on_cmdline \"--no-track\")\" ]; then\n>  \t\tdwim_opt=\"\"\n>  \tfi\n>  \n> +\t# checkout.guess = false disables DWIM, but with lower priority than\n> +\t# --guess/--no-guess\n> +\tif [ \"$(__git config --type=bool checkout.guess)\" = \"false\" ]; then\n> +\t\tdwim_opt=\"\"\n> +\tfi\n> +\n>  \t# Find the last provided --guess or --no-guess\n>  \tlast_option=\"$(__git_find_last_on_cmdline \"--guess --no-guess\")\"\n>  \tcase \"$last_option\" in\n> diff --git a/t/t2024-checkout-dwim.sh b/t/t2024-checkout-dwim.sh\n> index accfa9aa4b..a4f8d3a67e 100755\n> --- a/t/t2024-checkout-dwim.sh\n> +++ b/t/t2024-checkout-dwim.sh\n> @@ -166,6 +166,17 @@ test_expect_success '--no-guess suppresses branch auto-vivification' '\n>  \ttest_branch master\n>  '\n>  \n> +test_expect_success 'checkout.guess = false suppresses branch auto-vivification' '\n> +\tgit checkout -B master &&\n> +\tstatus_uno_is_clean &&\n> +\ttest_might_fail git branch -D bar &&\n> +\n> +\ttest_config checkout.guess false &&\n> +\ttest_must_fail git checkout bar &&\n> +\ttest_must_fail git rev-parse --verify refs/heads/bar &&\n> +\ttest_branch master\n> +'\n> +\n>  test_expect_success 'setup more remotes with unconventional refspecs' '\n>  \tgit checkout -B master &&\n>  \tstatus_uno_is_clean &&\n> diff --git a/t/t2060-switch.sh b/t/t2060-switch.sh\n> index 2c1b8c0d6d..68c9101b02 100755\n> --- a/t/t2060-switch.sh\n> +++ b/t/t2060-switch.sh\n> @@ -85,9 +85,12 @@ test_expect_success 'switching ignores file of same branch name' '\n>  \ttest_cmp expected actual\n>  '\n>  \n> -test_expect_success 'guess and create branch ' '\n> +test_expect_success 'guess and create branch' '\n>  \ttest_when_finished git switch master &&\n>  \ttest_must_fail git switch --no-guess foo &&\n> +\ttest_config checkout.guess false &&\n> +\ttest_must_fail git switch foo &&\n> +\ttest_config checkout.guess true &&\n>  \tgit switch foo &&\n>  \techo refs/heads/foo >expected &&\n>  \tgit symbolic-ref HEAD >actual &&\n> diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\n> index 8425b9a531..2b469a71ca 100755\n> --- a/t/t9902-completion.sh\n> +++ b/t/t9902-completion.sh\n> @@ -1360,6 +1360,58 @@ test_expect_success 'git checkout - a later --no-guess overrides previous --gues\n>  \tEOF\n>  '\n>  \n> +test_expect_success 'git checkout - with checkout.guess = false, only completes refs' '\n> +\ttest_config checkout.guess false &&\n> +\ttest_completion \"git checkout \" <<-\\EOF\n> +\tHEAD Z\n> +\tmaster Z\n> +\tmatching-branch Z\n> +\tmatching-tag Z\n> +\tother/branch-in-other Z\n> +\tother/master-in-other Z\n> +\tEOF\n> +'\n> +\n> +test_expect_success 'git checkout - with checkout.guess = true, completes refs and unique remote branches for DWIM' '\n> +\ttest_config checkout.guess true &&\n> +\ttest_completion \"git checkout \" <<-\\EOF\n> +\tHEAD Z\n> +\tbranch-in-other Z\n> +\tmaster Z\n> +\tmaster-in-other Z\n> +\tmatching-branch Z\n> +\tmatching-tag Z\n> +\tother/branch-in-other Z\n> +\tother/master-in-other Z\n> +\tEOF\n> +'\n> +\n> +test_expect_success 'git checkout - a later --guess overrides previous checkout.guess = false, complete refs and unique remote branches for DWIM' '\n> +\ttest_config checkout.guess false &&\n> +\ttest_completion \"git checkout --guess \" <<-\\EOF\n> +\tHEAD Z\n> +\tbranch-in-other Z\n> +\tmaster Z\n> +\tmaster-in-other Z\n> +\tmatching-branch Z\n> +\tmatching-tag Z\n> +\tother/branch-in-other Z\n> +\tother/master-in-other Z\n> +\tEOF\n> +'\n> +\n> +test_expect_success 'git checkout - a later --no-guess overrides previous checkout.guess = true, complete only refs' '\n> +\ttest_config checkout.guess true &&\n> +\ttest_completion \"git checkout --no-guess \" <<-\\EOF\n> +\tHEAD Z\n> +\tmaster Z\n> +\tmatching-branch Z\n> +\tmatching-tag Z\n> +\tother/branch-in-other Z\n> +\tother/master-in-other Z\n> +\tEOF\n> +'\n> +\n>  test_expect_success 'git switch - with --detach, complete all references' '\n>  \ttest_completion \"git switch --detach \" <<-\\EOF\n>  \tHEAD Z\n"},{"id":"406986","messageId":"20201006080730.GA2419589@generichostname","threadId":"54341","inReplyTo":"xmqqwo057ul5.fsf@gitster.c.googlers.com","subject":"Re: [PATCH 2/2] checkout: learn to respect checkout.guess","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2020-10-06T08:07:30Z","receivedAt":"2020-10-06T08:07:37Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"Hi Junio,\n\nOn Sun, Oct 04, 2020 at 10:46:14AM -0700, Junio C Hamano wrote:\n> Denton Liu <liu.denton@gmail.com> writes:\n> \n> > The current behavior of git checkout/switch is that --guess is currently\n> > enabled by default. However, some users may not wish for this to happen\n> > automatically. Instead of forcing users to specify --no-guess manually\n> > each time, teach these commands the checkout.guess configuration\n> > variable that gives users the option to set a default behavior.\n> >\n> > Teach the completion script to recognize the new config variable and\n> > disable DWIM logic if it is set to false.\n> >\n> > Signed-off-by: Denton Liu <liu.denton@gmail.com>\n> > ---\n> \n> Asking for input from Dscho on how to futureproof the tests along\n> the same line as js/default-branch-name-part-2 topic.\n\nPerhaps we could extract lists that are repeated often into common files\nso that they only need to be changed in one place? Something like this:\n\n-- >8 --\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 7b7bc6e4bd..86da44231d 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -1240,8 +1240,8 @@ test_expect_success '__git_complete_fetch_refspecs - fully qualified & prefix' '\n \ttest_cmp expected out\n '\n \n-test_expect_success 'git switch - with no options, complete local branches and unique remote branch names for DWIM logic' '\n-\ttest_completion \"git switch \" <<-\\EOF\n+test_expect_success 'prepare expect files for DWIM tests' '\n+\tcat >local-and-unique-remote <<-\\EOF &&\n \tbranch-in-other Z\n \tmaster Z\n \tmaster-in-other Z\n@@ -1249,6 +1249,10 @@ test_expect_success 'git switch - with no options, complete local branches and u\n \tEOF\n '\n \n+test_expect_success 'git switch - with no options, complete local branches and unique remote branch names for DWIM logic' '\n+\ttest_completion \"git switch \" <local-and-unique-remote\n+'\n+\n test_expect_success 'git checkout - completes refs and unique remote branches for DWIM' '\n \ttest_completion \"git checkout \" <<-\\EOF\n \tHEAD Z\n"},{"id":"406995","messageId":"xmqqtuv75ha8.fsf@gitster.c.googlers.com","threadId":"54341","inReplyTo":"20201006080730.GA2419589@generichostname","subject":"Re: [PATCH 2/2] checkout: learn to respect checkout.guess","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-10-06T18:41:03Z","receivedAt":"2020-10-06T18:41:14Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Denton Liu <liu.denton@gmail.com> writes:\n\n> Hi Junio,\n>\n> On Sun, Oct 04, 2020 at 10:46:14AM -0700, Junio C Hamano wrote:\n>> Denton Liu <liu.denton@gmail.com> writes:\n>> \n>> > The current behavior of git checkout/switch is that --guess is currently\n>> > enabled by default. However, some users may not wish for this to happen\n>> > automatically. Instead of forcing users to specify --no-guess manually\n>> > each time, teach these commands the checkout.guess configuration\n>> > variable that gives users the option to set a default behavior.\n>> >\n>> > Teach the completion script to recognize the new config variable and\n>> > disable DWIM logic if it is set to false.\n>> >\n>> > Signed-off-by: Denton Liu <liu.denton@gmail.com>\n>> > ---\n>> \n>> Asking for input from Dscho on how to futureproof the tests along\n>> the same line as js/default-branch-name-part-2 topic.\n>\n> Perhaps we could extract lists that are repeated often into common files\n> so that they only need to be changed in one place? Something like this:\n\nor we can feed a prefix that is not 'm' so that master, main, or\nmaint branches are not involved at all in the completion?\n\n>\n> -- >8 --\n> diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\n> index 7b7bc6e4bd..86da44231d 100755\n> --- a/t/t9902-completion.sh\n> +++ b/t/t9902-completion.sh\n> @@ -1240,8 +1240,8 @@ test_expect_success '__git_complete_fetch_refspecs - fully qualified & prefix' '\n>  \ttest_cmp expected out\n>  '\n>  \n> -test_expect_success 'git switch - with no options, complete local branches and unique remote branch names for DWIM logic' '\n> -\ttest_completion \"git switch \" <<-\\EOF\n> +test_expect_success 'prepare expect files for DWIM tests' '\n> +\tcat >local-and-unique-remote <<-\\EOF &&\n>  \tbranch-in-other Z\n>  \tmaster Z\n>  \tmaster-in-other Z\n> @@ -1249,6 +1249,10 @@ test_expect_success 'git switch - with no options, complete local branches and u\n>  \tEOF\n>  '\n>  \n> +test_expect_success 'git switch - with no options, complete local branches and unique remote branch names for DWIM logic' '\n> +\ttest_completion \"git switch \" <local-and-unique-remote\n> +'\n> +\n>  test_expect_success 'git checkout - completes refs and unique remote branches for DWIM' '\n>  \ttest_completion \"git checkout \" <<-\\EOF\n>  \tHEAD Z\n"},{"id":"407001","messageId":"nycvar.QRO.7.76.6.2010062123060.50@tvgsbejvaqbjf.bet","threadId":"54341","inReplyTo":"xmqqtuv75ha8.fsf@gitster.c.googlers.com","subject":"Re: [PATCH 2/2] checkout: learn to respect checkout.guess","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-10-06T19:31:16Z","receivedAt":"2020-10-06T19:31:24Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Tue, 6 Oct 2020, Junio C Hamano wrote:\n\n> Denton Liu <liu.denton@gmail.com> writes:\n>\n> > On Sun, Oct 04, 2020 at 10:46:14AM -0700, Junio C Hamano wrote:\n> >> Denton Liu <liu.denton@gmail.com> writes:\n> >>\n> >> > The current behavior of git checkout/switch is that --guess is currently\n> >> > enabled by default. However, some users may not wish for this to happen\n> >> > automatically. Instead of forcing users to specify --no-guess manually\n> >> > each time, teach these commands the checkout.guess configuration\n> >> > variable that gives users the option to set a default behavior.\n> >> >\n> >> > Teach the completion script to recognize the new config variable and\n> >> > disable DWIM logic if it is set to false.\n> >> >\n> >> > Signed-off-by: Denton Liu <liu.denton@gmail.com>\n> >> > ---\n> >>\n> >> Asking for input from Dscho on how to futureproof the tests along\n> >> the same line as js/default-branch-name-part-2 topic.\n> >\n> > Perhaps we could extract lists that are repeated often into common files\n> > so that they only need to be changed in one place? Something like this:\n>\n> or we can feed a prefix that is not 'm' so that master, main, or\n> maint branches are not involved at all in the completion?\n\nWhile I appreciate the consideration, the issue should be easy enough to\naddress. I don't think we need to worry too much about that in the context\nof this here patch series.\n\nCiao,\nDscho\n\n>\n> >\n> > -- >8 --\n> > diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\n> > index 7b7bc6e4bd..86da44231d 100755\n> > --- a/t/t9902-completion.sh\n> > +++ b/t/t9902-completion.sh\n> > @@ -1240,8 +1240,8 @@ test_expect_success '__git_complete_fetch_refspecs - fully qualified & prefix' '\n> >  \ttest_cmp expected out\n> >  '\n> >\n> > -test_expect_success 'git switch - with no options, complete local branches and unique remote branch names for DWIM logic' '\n> > -\ttest_completion \"git switch \" <<-\\EOF\n> > +test_expect_success 'prepare expect files for DWIM tests' '\n> > +\tcat >local-and-unique-remote <<-\\EOF &&\n> >  \tbranch-in-other Z\n> >  \tmaster Z\n> >  \tmaster-in-other Z\n> > @@ -1249,6 +1249,10 @@ test_expect_success 'git switch - with no options, complete local branches and u\n> >  \tEOF\n> >  '\n> >\n> > +test_expect_success 'git switch - with no options, complete local branches and unique remote branch names for DWIM logic' '\n> > +\ttest_completion \"git switch \" <local-and-unique-remote\n> > +'\n> > +\n> >  test_expect_success 'git checkout - completes refs and unique remote branches for DWIM' '\n> >  \ttest_completion \"git checkout \" <<-\\EOF\n> >  \tHEAD Z\n>\n"},{"id":"407023","messageId":"f08d3f796a806b5ec20f12cc85683b2c2e99b1a8.1602047333.git.liu.denton@gmail.com","threadId":"54341","inReplyTo":"cover.1602047333.git.liu.denton@gmail.com","subject":"[PATCH v2 1/2] Documentation/config/checkout: replace sq with backticks","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2020-10-07T05:09:08Z","receivedAt":"2020-10-07T05:09:30Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"The modern style for Git documentation is to use backticks to quote\nany command-line documenation so that it is typeset in monospace.\nReplace all single quotes with backticks to conform to this.\n\nSigned-off-by: Denton Liu <liu.denton@gmail.com>\n---\n Documentation/config/checkout.txt | 16 ++++++++--------\n 1 file changed, 8 insertions(+), 8 deletions(-)\n\ndiff --git a/Documentation/config/checkout.txt b/Documentation/config/checkout.txt\nindex 6b646813ab..e3684a5459 100644\n--- a/Documentation/config/checkout.txt\n+++ b/Documentation/config/checkout.txt\n@@ -1,18 +1,18 @@\n checkout.defaultRemote::\n-\tWhen you run 'git checkout <something>'\n-\tor 'git switch <something>' and only have one\n+\tWhen you run `git checkout <something>`\n+\tor `git switch <something>` and only have one\n \tremote, it may implicitly fall back on checking out and\n-\ttracking e.g. 'origin/<something>'. This stops working as soon\n-\tas you have more than one remote with a '<something>'\n+\ttracking e.g. `origin/<something>`. This stops working as soon\n+\tas you have more than one remote with a `<something>`\n \treference. This setting allows for setting the name of a\n \tpreferred remote that should always win when it comes to\n \tdisambiguation. The typical use-case is to set this to\n \t`origin`.\n +\n Currently this is used by linkgit:git-switch[1] and\n-linkgit:git-checkout[1] when 'git checkout <something>'\n-or 'git switch <something>'\n-will checkout the '<something>' branch on another remote,\n-and by linkgit:git-worktree[1] when 'git worktree add' refers to a\n+linkgit:git-checkout[1] when `git checkout <something>`\n+or `git switch <something>`\n+will checkout the `<something>` branch on another remote,\n+and by linkgit:git-worktree[1] when `git worktree add` refers to a\n remote branch. This setting might be used for other checkout-like\n commands or functionality in the future.\n-- \n2.28.0.942.g77c4c6094c\n\n"},{"id":"407024","messageId":"cover.1602047333.git.liu.denton@gmail.com","threadId":"54341","inReplyTo":"cover.1601810233.git.liu.denton@gmail.com","subject":"[PATCH v2 0/2] checkout: learn the checkout.guess config variable","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2020-10-07T05:09:07Z","receivedAt":"2020-10-07T05:09:30Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"If a user does not wish to use DWIM behaviour, they must manually\nspecify git checkout --no-guess each time. Teach checkout and switch to\nhonour the checkout.guess config variable instead.\n\nChanges since v1:\n\n* Replace enumerated priority list with bullet points\n\nDenton Liu (2):\n  Documentation/config/checkout: replace sq with backticks\n  checkout: learn to respect checkout.guess\n\n Documentation/config/checkout.txt      | 21 +++++++----\n Documentation/git-checkout.txt         |  3 ++\n Documentation/git-switch.txt           |  3 ++\n builtin/checkout.c                     |  7 +++-\n contrib/completion/git-completion.bash | 25 ++++++++-----\n t/t2024-checkout-dwim.sh               | 11 ++++++\n t/t2060-switch.sh                      |  5 ++-\n t/t9902-completion.sh                  | 52 ++++++++++++++++++++++++++\n 8 files changed, 108 insertions(+), 19 deletions(-)\n\nRange-diff against v1:\n1:  f08d3f796a = 1:  f08d3f796a Documentation/config/checkout: replace sq with backticks\n2:  8172602f6f ! 2:  2678680a08 checkout: learn to respect checkout.guess\n    @@ builtin/checkout.c: static int switch_branches(const struct checkout_opts *opts,\n     \n      ## contrib/completion/git-completion.bash ##\n     @@ contrib/completion/git-completion.bash: _git_bundle ()\n    - # To decide between the following rules in priority order\n    - # 1) the last provided of \"--guess\" or \"--no-guess\" explicitly enable or\n    - #    disable completion of DWIM logic respectively.\n    + # Helper function to decide whether or not we should enable DWIM logic for\n    + # git-switch and git-checkout.\n    + #\n    +-# To decide between the following rules in priority order\n    +-# 1) the last provided of \"--guess\" or \"--no-guess\" explicitly enable or\n    +-#    disable completion of DWIM logic respectively.\n     -# 2) If the --no-track option is provided, take this as a hint to disable the\n    -+# 2) If checkout.guess is false, disable completion of DWIM logic.\n    -+# 3) If the --no-track option is provided, take this as a hint to disable the\n    - #    DWIM completion logic\n    +-#    DWIM completion logic\n     -# 3) If GIT_COMPLETION_CHECKOUT_NO_GUESS is set, disable the DWIM completion\n    -+# 4) If GIT_COMPLETION_CHECKOUT_NO_GUESS is set, disable the DWIM completion\n    - #    logic, as requested by the user.\n    +-#    logic, as requested by the user.\n     -# 4) Enable DWIM logic otherwise.\n    -+# 5) Enable DWIM logic otherwise.\n    ++# To decide between the following rules in decreasing priority order:\n    ++# - the last provided of \"--guess\" or \"--no-guess\" explicitly enable or\n    ++#   disable completion of DWIM logic respectively.\n    ++# - If checkout.guess is false, disable completion of DWIM logic.\n    ++# - If the --no-track option is provided, take this as a hint to disable the\n    ++#   DWIM completion logic\n    ++# - If GIT_COMPLETION_CHECKOUT_NO_GUESS is set, disable the DWIM completion\n    ++#   logic, as requested by the user.\n    ++# - Enable DWIM logic otherwise.\n      #\n      __git_checkout_default_dwim_mode ()\n      {\n-- \n2.28.0.942.g77c4c6094c\n\n"},{"id":"407025","messageId":"2678680a08e025e9652c6769501dbc604560394b.1602047333.git.liu.denton@gmail.com","threadId":"54341","inReplyTo":"cover.1602047333.git.liu.denton@gmail.com","subject":"[PATCH v2 2/2] checkout: learn to respect checkout.guess","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2020-10-07T05:09:09Z","receivedAt":"2020-10-07T05:09:32Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"The current behavior of git checkout/switch is that --guess is currently\nenabled by default. However, some users may not wish for this to happen\nautomatically. Instead of forcing users to specify --no-guess manually\neach time, teach these commands the checkout.guess configuration\nvariable that gives users the option to set a default behavior.\n\nTeach the completion script to recognize the new config variable and\ndisable DWIM logic if it is set to false.\n\nSigned-off-by: Denton Liu <liu.denton@gmail.com>\n---\n Documentation/config/checkout.txt      |  5 +++\n Documentation/git-checkout.txt         |  3 ++\n Documentation/git-switch.txt           |  3 ++\n builtin/checkout.c                     |  7 +++-\n contrib/completion/git-completion.bash | 25 ++++++++-----\n t/t2024-checkout-dwim.sh               | 11 ++++++\n t/t2060-switch.sh                      |  5 ++-\n t/t9902-completion.sh                  | 52 ++++++++++++++++++++++++++\n 8 files changed, 100 insertions(+), 11 deletions(-)\n\ndiff --git a/Documentation/config/checkout.txt b/Documentation/config/checkout.txt\nindex e3684a5459..2cddf7b4b4 100644\n--- a/Documentation/config/checkout.txt\n+++ b/Documentation/config/checkout.txt\n@@ -16,3 +16,8 @@ will checkout the `<something>` branch on another remote,\n and by linkgit:git-worktree[1] when `git worktree add` refers to a\n remote branch. This setting might be used for other checkout-like\n commands or functionality in the future.\n+\n+checkout.guess::\n+\tProvides the default value for the `--guess` or `--no-guess`\n+\toption in `git checkout` and `git switch`. See\n+\tlinkgit:git-switch[1] and linkgit:git-checkout[1].\ndiff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt\nindex afa5c11fd3..28f656d04e 100644\n--- a/Documentation/git-checkout.txt\n+++ b/Documentation/git-checkout.txt\n@@ -193,6 +193,9 @@ branches from there if `<branch>` is ambiguous but exists on the\n linkgit:git-config[1].\n +\n Use `--no-guess` to disable this.\n++\n+The default behavior can be set via the `checkout.guess` configuration\n+variable.\n \n -l::\n \tCreate the new branch's reflog; see linkgit:git-branch[1] for\ndiff --git a/Documentation/git-switch.txt b/Documentation/git-switch.txt\nindex 3759c3a265..5c438cd505 100644\n--- a/Documentation/git-switch.txt\n+++ b/Documentation/git-switch.txt\n@@ -103,6 +103,9 @@ ambiguous but exists on the 'origin' remote. See also\n `checkout.defaultRemote` in linkgit:git-config[1].\n +\n `--guess` is the default behavior. Use `--no-guess` to disable it.\n++\n+The default behavior can be set via the `checkout.guess` configuration\n+variable.\n \n -f::\n --force::\ndiff --git a/builtin/checkout.c b/builtin/checkout.c\nindex 0951f8fee5..0c0394a0d6 100644\n--- a/builtin/checkout.c\n+++ b/builtin/checkout.c\n@@ -1093,11 +1093,16 @@ static int switch_branches(const struct checkout_opts *opts,\n \n static int git_checkout_config(const char *var, const char *value, void *cb)\n {\n+\tstruct checkout_opts *opts = cb;\n+\n \tif (!strcmp(var, \"diff.ignoresubmodules\")) {\n-\t\tstruct checkout_opts *opts = cb;\n \t\thandle_ignore_submodules_arg(&opts->diff_options, value);\n \t\treturn 0;\n \t}\n+\tif (!strcmp(var, \"checkout.guess\")) {\n+\t\topts->dwim_new_local_branch = git_config_bool(var, value);\n+\t\treturn 0;\n+\t}\n \n \tif (starts_with(var, \"submodule.\"))\n \t\treturn git_default_submodule_config(var, value, NULL);\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 8be4a0316e..851c358cfc 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -1467,14 +1467,15 @@ _git_bundle ()\n # Helper function to decide whether or not we should enable DWIM logic for\n # git-switch and git-checkout.\n #\n-# To decide between the following rules in priority order\n-# 1) the last provided of \"--guess\" or \"--no-guess\" explicitly enable or\n-#    disable completion of DWIM logic respectively.\n-# 2) If the --no-track option is provided, take this as a hint to disable the\n-#    DWIM completion logic\n-# 3) If GIT_COMPLETION_CHECKOUT_NO_GUESS is set, disable the DWIM completion\n-#    logic, as requested by the user.\n-# 4) Enable DWIM logic otherwise.\n+# To decide between the following rules in decreasing priority order:\n+# - the last provided of \"--guess\" or \"--no-guess\" explicitly enable or\n+#   disable completion of DWIM logic respectively.\n+# - If checkout.guess is false, disable completion of DWIM logic.\n+# - If the --no-track option is provided, take this as a hint to disable the\n+#   DWIM completion logic\n+# - If GIT_COMPLETION_CHECKOUT_NO_GUESS is set, disable the DWIM completion\n+#   logic, as requested by the user.\n+# - Enable DWIM logic otherwise.\n #\n __git_checkout_default_dwim_mode ()\n {\n@@ -1485,11 +1486,17 @@ __git_checkout_default_dwim_mode ()\n \tfi\n \n \t# --no-track disables DWIM, but with lower priority than\n-\t# --guess/--no-guess\n+\t# --guess/--no-guess/checkout.guess\n \tif [ -n \"$(__git_find_on_cmdline \"--no-track\")\" ]; then\n \t\tdwim_opt=\"\"\n \tfi\n \n+\t# checkout.guess = false disables DWIM, but with lower priority than\n+\t# --guess/--no-guess\n+\tif [ \"$(__git config --type=bool checkout.guess)\" = \"false\" ]; then\n+\t\tdwim_opt=\"\"\n+\tfi\n+\n \t# Find the last provided --guess or --no-guess\n \tlast_option=\"$(__git_find_last_on_cmdline \"--guess --no-guess\")\"\n \tcase \"$last_option\" in\ndiff --git a/t/t2024-checkout-dwim.sh b/t/t2024-checkout-dwim.sh\nindex accfa9aa4b..a4f8d3a67e 100755\n--- a/t/t2024-checkout-dwim.sh\n+++ b/t/t2024-checkout-dwim.sh\n@@ -166,6 +166,17 @@ test_expect_success '--no-guess suppresses branch auto-vivification' '\n \ttest_branch master\n '\n \n+test_expect_success 'checkout.guess = false suppresses branch auto-vivification' '\n+\tgit checkout -B master &&\n+\tstatus_uno_is_clean &&\n+\ttest_might_fail git branch -D bar &&\n+\n+\ttest_config checkout.guess false &&\n+\ttest_must_fail git checkout bar &&\n+\ttest_must_fail git rev-parse --verify refs/heads/bar &&\n+\ttest_branch master\n+'\n+\n test_expect_success 'setup more remotes with unconventional refspecs' '\n \tgit checkout -B master &&\n \tstatus_uno_is_clean &&\ndiff --git a/t/t2060-switch.sh b/t/t2060-switch.sh\nindex 2c1b8c0d6d..68c9101b02 100755\n--- a/t/t2060-switch.sh\n+++ b/t/t2060-switch.sh\n@@ -85,9 +85,12 @@ test_expect_success 'switching ignores file of same branch name' '\n \ttest_cmp expected actual\n '\n \n-test_expect_success 'guess and create branch ' '\n+test_expect_success 'guess and create branch' '\n \ttest_when_finished git switch master &&\n \ttest_must_fail git switch --no-guess foo &&\n+\ttest_config checkout.guess false &&\n+\ttest_must_fail git switch foo &&\n+\ttest_config checkout.guess true &&\n \tgit switch foo &&\n \techo refs/heads/foo >expected &&\n \tgit symbolic-ref HEAD >actual &&\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 8425b9a531..2b469a71ca 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -1360,6 +1360,58 @@ test_expect_success 'git checkout - a later --no-guess overrides previous --gues\n \tEOF\n '\n \n+test_expect_success 'git checkout - with checkout.guess = false, only completes refs' '\n+\ttest_config checkout.guess false &&\n+\ttest_completion \"git checkout \" <<-\\EOF\n+\tHEAD Z\n+\tmaster Z\n+\tmatching-branch Z\n+\tmatching-tag Z\n+\tother/branch-in-other Z\n+\tother/master-in-other Z\n+\tEOF\n+'\n+\n+test_expect_success 'git checkout - with checkout.guess = true, completes refs and unique remote branches for DWIM' '\n+\ttest_config checkout.guess true &&\n+\ttest_completion \"git checkout \" <<-\\EOF\n+\tHEAD Z\n+\tbranch-in-other Z\n+\tmaster Z\n+\tmaster-in-other Z\n+\tmatching-branch Z\n+\tmatching-tag Z\n+\tother/branch-in-other Z\n+\tother/master-in-other Z\n+\tEOF\n+'\n+\n+test_expect_success 'git checkout - a later --guess overrides previous checkout.guess = false, complete refs and unique remote branches for DWIM' '\n+\ttest_config checkout.guess false &&\n+\ttest_completion \"git checkout --guess \" <<-\\EOF\n+\tHEAD Z\n+\tbranch-in-other Z\n+\tmaster Z\n+\tmaster-in-other Z\n+\tmatching-branch Z\n+\tmatching-tag Z\n+\tother/branch-in-other Z\n+\tother/master-in-other Z\n+\tEOF\n+'\n+\n+test_expect_success 'git checkout - a later --no-guess overrides previous checkout.guess = true, complete only refs' '\n+\ttest_config checkout.guess true &&\n+\ttest_completion \"git checkout --no-guess \" <<-\\EOF\n+\tHEAD Z\n+\tmaster Z\n+\tmatching-branch Z\n+\tmatching-tag Z\n+\tother/branch-in-other Z\n+\tother/master-in-other Z\n+\tEOF\n+'\n+\n test_expect_success 'git switch - with --detach, complete all references' '\n \ttest_completion \"git switch --detach \" <<-\\EOF\n \tHEAD Z\n-- \n2.28.0.942.g77c4c6094c\n\n"},{"id":"407072","messageId":"xmqqy2ki2daq.fsf@gitster.c.googlers.com","threadId":"54341","inReplyTo":"2678680a08e025e9652c6769501dbc604560394b.1602047333.git.liu.denton@gmail.com","subject":"Re: [PATCH v2 2/2] checkout: learn to respect checkout.guess","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-10-07T16:47:41Z","receivedAt":"2020-10-07T16:47:49Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Denton Liu <liu.denton@gmail.com> writes:\n\n> diff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt\n> index afa5c11fd3..28f656d04e 100644\n> --- a/Documentation/git-checkout.txt\n> +++ b/Documentation/git-checkout.txt\n> @@ -193,6 +193,9 @@ branches from there if `<branch>` is ambiguous but exists on the\n>  linkgit:git-config[1].\n>  +\n>  Use `--no-guess` to disable this.\n> ++\n> +The default behavior can be set via the `checkout.guess` configuration\n> +variable.\n>  \n>  -l::\n>  \tCreate the new branch's reflog; see linkgit:git-branch[1] for\n> diff --git a/Documentation/git-switch.txt b/Documentation/git-switch.txt\n> index 3759c3a265..5c438cd505 100644\n> --- a/Documentation/git-switch.txt\n> +++ b/Documentation/git-switch.txt\n> @@ -103,6 +103,9 @@ ambiguous but exists on the 'origin' remote. See also\n>  `checkout.defaultRemote` in linkgit:git-config[1].\n>  +\n>  `--guess` is the default behavior. Use `--no-guess` to disable it.\n> ++\n> +The default behavior can be set via the `checkout.guess` configuration\n> +variable.\n\nContrasting the above two, one cannot help but notice that it is\ntotally unclear how \"git checkout\" that is not explicitly told by\ncommand line or configuration behaves.  Perhaps \"`--guess` is the\ndefault behaviour.\" needs to be transplated from the description\nfor \"git switch\" to clarify?\n\nThis is not a new issue, but is made stand out even more prominently\ndue to the addition.\n\nThanks.\n"},{"id":"407117","messageId":"cover.1602136063.git.liu.denton@gmail.com","threadId":"54341","inReplyTo":"cover.1602047333.git.liu.denton@gmail.com","subject":"[PATCH v3 0/2] checkout: learn the checkout.guess config variable","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2020-10-08T05:48:13Z","receivedAt":"2020-10-08T05:48:26Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"If a user does not wish to use DWIM behaviour, they must manually\nspecify git checkout --no-guess each time. Teach checkout and switch to\nhonour the checkout.guess config variable instead.\n\nChanges since v1:\n\n* Replace enumerated priority list with bullet points\n\nChanges since v2:\n\n* Clarify that `--guess` is the default for checkout in the docs\n\nDenton Liu (2):\n  Documentation/config/checkout: replace sq with backticks\n  checkout: learn to respect checkout.guess\n\n Documentation/config/checkout.txt      | 21 +++++++----\n Documentation/git-checkout.txt         |  5 ++-\n Documentation/git-switch.txt           |  3 ++\n builtin/checkout.c                     |  7 +++-\n contrib/completion/git-completion.bash | 25 ++++++++-----\n t/t2024-checkout-dwim.sh               | 11 ++++++\n t/t2060-switch.sh                      |  5 ++-\n t/t9902-completion.sh                  | 52 ++++++++++++++++++++++++++\n 8 files changed, 109 insertions(+), 20 deletions(-)\n\nRange-diff against v2:\n1:  f08d3f796a = 1:  f08d3f796a Documentation/config/checkout: replace sq with backticks\n2:  2678680a08 ! 2:  eb9daf4bcd checkout: learn to respect checkout.guess\n    @@ Documentation/config/checkout.txt: will checkout the `<something>` branch on ano\n     \n      ## Documentation/git-checkout.txt ##\n     @@ Documentation/git-checkout.txt: branches from there if `<branch>` is ambiguous but exists on the\n    + 'origin' remote. See also `checkout.defaultRemote` in\n      linkgit:git-config[1].\n      +\n    - Use `--no-guess` to disable this.\n    +-Use `--no-guess` to disable this.\n    ++`--guess` is the default behavior. Use `--no-guess` to disable it.\n     ++\n     +The default behavior can be set via the `checkout.guess` configuration\n     +variable.\n-- \n2.28.0.942.g77c4c6094c\n\n"},{"id":"407118","messageId":"f08d3f796a806b5ec20f12cc85683b2c2e99b1a8.1602136063.git.liu.denton@gmail.com","threadId":"54341","inReplyTo":"cover.1602136063.git.liu.denton@gmail.com","subject":"[PATCH v3 1/2] Documentation/config/checkout: replace sq with backticks","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2020-10-08T05:48:14Z","receivedAt":"2020-10-08T05:48:28Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"The modern style for Git documentation is to use backticks to quote\nany command-line documenation so that it is typeset in monospace.\nReplace all single quotes with backticks to conform to this.\n\nSigned-off-by: Denton Liu <liu.denton@gmail.com>\n---\n Documentation/config/checkout.txt | 16 ++++++++--------\n 1 file changed, 8 insertions(+), 8 deletions(-)\n\ndiff --git a/Documentation/config/checkout.txt b/Documentation/config/checkout.txt\nindex 6b646813ab..e3684a5459 100644\n--- a/Documentation/config/checkout.txt\n+++ b/Documentation/config/checkout.txt\n@@ -1,18 +1,18 @@\n checkout.defaultRemote::\n-\tWhen you run 'git checkout <something>'\n-\tor 'git switch <something>' and only have one\n+\tWhen you run `git checkout <something>`\n+\tor `git switch <something>` and only have one\n \tremote, it may implicitly fall back on checking out and\n-\ttracking e.g. 'origin/<something>'. This stops working as soon\n-\tas you have more than one remote with a '<something>'\n+\ttracking e.g. `origin/<something>`. This stops working as soon\n+\tas you have more than one remote with a `<something>`\n \treference. This setting allows for setting the name of a\n \tpreferred remote that should always win when it comes to\n \tdisambiguation. The typical use-case is to set this to\n \t`origin`.\n +\n Currently this is used by linkgit:git-switch[1] and\n-linkgit:git-checkout[1] when 'git checkout <something>'\n-or 'git switch <something>'\n-will checkout the '<something>' branch on another remote,\n-and by linkgit:git-worktree[1] when 'git worktree add' refers to a\n+linkgit:git-checkout[1] when `git checkout <something>`\n+or `git switch <something>`\n+will checkout the `<something>` branch on another remote,\n+and by linkgit:git-worktree[1] when `git worktree add` refers to a\n remote branch. This setting might be used for other checkout-like\n commands or functionality in the future.\n-- \n2.28.0.942.g77c4c6094c\n\n"},{"id":"407119","messageId":"eb9daf4bcdf1d296aae924844f58848eee1798d5.1602136063.git.liu.denton@gmail.com","threadId":"54341","inReplyTo":"cover.1602136063.git.liu.denton@gmail.com","subject":"[PATCH v3 2/2] checkout: learn to respect checkout.guess","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2020-10-08T05:48:15Z","receivedAt":"2020-10-08T05:48:29Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"The current behavior of git checkout/switch is that --guess is currently\nenabled by default. However, some users may not wish for this to happen\nautomatically. Instead of forcing users to specify --no-guess manually\neach time, teach these commands the checkout.guess configuration\nvariable that gives users the option to set a default behavior.\n\nTeach the completion script to recognize the new config variable and\ndisable DWIM logic if it is set to false.\n\nSigned-off-by: Denton Liu <liu.denton@gmail.com>\n---\n Documentation/config/checkout.txt      |  5 +++\n Documentation/git-checkout.txt         |  5 ++-\n Documentation/git-switch.txt           |  3 ++\n builtin/checkout.c                     |  7 +++-\n contrib/completion/git-completion.bash | 25 ++++++++-----\n t/t2024-checkout-dwim.sh               | 11 ++++++\n t/t2060-switch.sh                      |  5 ++-\n t/t9902-completion.sh                  | 52 ++++++++++++++++++++++++++\n 8 files changed, 101 insertions(+), 12 deletions(-)\n\ndiff --git a/Documentation/config/checkout.txt b/Documentation/config/checkout.txt\nindex e3684a5459..2cddf7b4b4 100644\n--- a/Documentation/config/checkout.txt\n+++ b/Documentation/config/checkout.txt\n@@ -16,3 +16,8 @@ will checkout the `<something>` branch on another remote,\n and by linkgit:git-worktree[1] when `git worktree add` refers to a\n remote branch. This setting might be used for other checkout-like\n commands or functionality in the future.\n+\n+checkout.guess::\n+\tProvides the default value for the `--guess` or `--no-guess`\n+\toption in `git checkout` and `git switch`. See\n+\tlinkgit:git-switch[1] and linkgit:git-checkout[1].\ndiff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt\nindex afa5c11fd3..1435d3de9e 100644\n--- a/Documentation/git-checkout.txt\n+++ b/Documentation/git-checkout.txt\n@@ -192,7 +192,10 @@ branches from there if `<branch>` is ambiguous but exists on the\n 'origin' remote. See also `checkout.defaultRemote` in\n linkgit:git-config[1].\n +\n-Use `--no-guess` to disable this.\n+`--guess` is the default behavior. Use `--no-guess` to disable it.\n++\n+The default behavior can be set via the `checkout.guess` configuration\n+variable.\n \n -l::\n \tCreate the new branch's reflog; see linkgit:git-branch[1] for\ndiff --git a/Documentation/git-switch.txt b/Documentation/git-switch.txt\nindex 3759c3a265..5c438cd505 100644\n--- a/Documentation/git-switch.txt\n+++ b/Documentation/git-switch.txt\n@@ -103,6 +103,9 @@ ambiguous but exists on the 'origin' remote. See also\n `checkout.defaultRemote` in linkgit:git-config[1].\n +\n `--guess` is the default behavior. Use `--no-guess` to disable it.\n++\n+The default behavior can be set via the `checkout.guess` configuration\n+variable.\n \n -f::\n --force::\ndiff --git a/builtin/checkout.c b/builtin/checkout.c\nindex 0951f8fee5..0c0394a0d6 100644\n--- a/builtin/checkout.c\n+++ b/builtin/checkout.c\n@@ -1093,11 +1093,16 @@ static int switch_branches(const struct checkout_opts *opts,\n \n static int git_checkout_config(const char *var, const char *value, void *cb)\n {\n+\tstruct checkout_opts *opts = cb;\n+\n \tif (!strcmp(var, \"diff.ignoresubmodules\")) {\n-\t\tstruct checkout_opts *opts = cb;\n \t\thandle_ignore_submodules_arg(&opts->diff_options, value);\n \t\treturn 0;\n \t}\n+\tif (!strcmp(var, \"checkout.guess\")) {\n+\t\topts->dwim_new_local_branch = git_config_bool(var, value);\n+\t\treturn 0;\n+\t}\n \n \tif (starts_with(var, \"submodule.\"))\n \t\treturn git_default_submodule_config(var, value, NULL);\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 8be4a0316e..851c358cfc 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -1467,14 +1467,15 @@ _git_bundle ()\n # Helper function to decide whether or not we should enable DWIM logic for\n # git-switch and git-checkout.\n #\n-# To decide between the following rules in priority order\n-# 1) the last provided of \"--guess\" or \"--no-guess\" explicitly enable or\n-#    disable completion of DWIM logic respectively.\n-# 2) If the --no-track option is provided, take this as a hint to disable the\n-#    DWIM completion logic\n-# 3) If GIT_COMPLETION_CHECKOUT_NO_GUESS is set, disable the DWIM completion\n-#    logic, as requested by the user.\n-# 4) Enable DWIM logic otherwise.\n+# To decide between the following rules in decreasing priority order:\n+# - the last provided of \"--guess\" or \"--no-guess\" explicitly enable or\n+#   disable completion of DWIM logic respectively.\n+# - If checkout.guess is false, disable completion of DWIM logic.\n+# - If the --no-track option is provided, take this as a hint to disable the\n+#   DWIM completion logic\n+# - If GIT_COMPLETION_CHECKOUT_NO_GUESS is set, disable the DWIM completion\n+#   logic, as requested by the user.\n+# - Enable DWIM logic otherwise.\n #\n __git_checkout_default_dwim_mode ()\n {\n@@ -1485,11 +1486,17 @@ __git_checkout_default_dwim_mode ()\n \tfi\n \n \t# --no-track disables DWIM, but with lower priority than\n-\t# --guess/--no-guess\n+\t# --guess/--no-guess/checkout.guess\n \tif [ -n \"$(__git_find_on_cmdline \"--no-track\")\" ]; then\n \t\tdwim_opt=\"\"\n \tfi\n \n+\t# checkout.guess = false disables DWIM, but with lower priority than\n+\t# --guess/--no-guess\n+\tif [ \"$(__git config --type=bool checkout.guess)\" = \"false\" ]; then\n+\t\tdwim_opt=\"\"\n+\tfi\n+\n \t# Find the last provided --guess or --no-guess\n \tlast_option=\"$(__git_find_last_on_cmdline \"--guess --no-guess\")\"\n \tcase \"$last_option\" in\ndiff --git a/t/t2024-checkout-dwim.sh b/t/t2024-checkout-dwim.sh\nindex accfa9aa4b..a4f8d3a67e 100755\n--- a/t/t2024-checkout-dwim.sh\n+++ b/t/t2024-checkout-dwim.sh\n@@ -166,6 +166,17 @@ test_expect_success '--no-guess suppresses branch auto-vivification' '\n \ttest_branch master\n '\n \n+test_expect_success 'checkout.guess = false suppresses branch auto-vivification' '\n+\tgit checkout -B master &&\n+\tstatus_uno_is_clean &&\n+\ttest_might_fail git branch -D bar &&\n+\n+\ttest_config checkout.guess false &&\n+\ttest_must_fail git checkout bar &&\n+\ttest_must_fail git rev-parse --verify refs/heads/bar &&\n+\ttest_branch master\n+'\n+\n test_expect_success 'setup more remotes with unconventional refspecs' '\n \tgit checkout -B master &&\n \tstatus_uno_is_clean &&\ndiff --git a/t/t2060-switch.sh b/t/t2060-switch.sh\nindex 2c1b8c0d6d..68c9101b02 100755\n--- a/t/t2060-switch.sh\n+++ b/t/t2060-switch.sh\n@@ -85,9 +85,12 @@ test_expect_success 'switching ignores file of same branch name' '\n \ttest_cmp expected actual\n '\n \n-test_expect_success 'guess and create branch ' '\n+test_expect_success 'guess and create branch' '\n \ttest_when_finished git switch master &&\n \ttest_must_fail git switch --no-guess foo &&\n+\ttest_config checkout.guess false &&\n+\ttest_must_fail git switch foo &&\n+\ttest_config checkout.guess true &&\n \tgit switch foo &&\n \techo refs/heads/foo >expected &&\n \tgit symbolic-ref HEAD >actual &&\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 8425b9a531..2b469a71ca 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -1360,6 +1360,58 @@ test_expect_success 'git checkout - a later --no-guess overrides previous --gues\n \tEOF\n '\n \n+test_expect_success 'git checkout - with checkout.guess = false, only completes refs' '\n+\ttest_config checkout.guess false &&\n+\ttest_completion \"git checkout \" <<-\\EOF\n+\tHEAD Z\n+\tmaster Z\n+\tmatching-branch Z\n+\tmatching-tag Z\n+\tother/branch-in-other Z\n+\tother/master-in-other Z\n+\tEOF\n+'\n+\n+test_expect_success 'git checkout - with checkout.guess = true, completes refs and unique remote branches for DWIM' '\n+\ttest_config checkout.guess true &&\n+\ttest_completion \"git checkout \" <<-\\EOF\n+\tHEAD Z\n+\tbranch-in-other Z\n+\tmaster Z\n+\tmaster-in-other Z\n+\tmatching-branch Z\n+\tmatching-tag Z\n+\tother/branch-in-other Z\n+\tother/master-in-other Z\n+\tEOF\n+'\n+\n+test_expect_success 'git checkout - a later --guess overrides previous checkout.guess = false, complete refs and unique remote branches for DWIM' '\n+\ttest_config checkout.guess false &&\n+\ttest_completion \"git checkout --guess \" <<-\\EOF\n+\tHEAD Z\n+\tbranch-in-other Z\n+\tmaster Z\n+\tmaster-in-other Z\n+\tmatching-branch Z\n+\tmatching-tag Z\n+\tother/branch-in-other Z\n+\tother/master-in-other Z\n+\tEOF\n+'\n+\n+test_expect_success 'git checkout - a later --no-guess overrides previous checkout.guess = true, complete only refs' '\n+\ttest_config checkout.guess true &&\n+\ttest_completion \"git checkout --no-guess \" <<-\\EOF\n+\tHEAD Z\n+\tmaster Z\n+\tmatching-branch Z\n+\tmatching-tag Z\n+\tother/branch-in-other Z\n+\tother/master-in-other Z\n+\tEOF\n+'\n+\n test_expect_success 'git switch - with --detach, complete all references' '\n \ttest_completion \"git switch --detach \" <<-\\EOF\n \tHEAD Z\n-- \n2.28.0.942.g77c4c6094c\n\n"}]}