]> git.ipfire.org Git - thirdparty/git.git/commitdiff
completion: bash: fix for suboptions with value
authorFelipe Contreras <felipe.contreras@gmail.com>
Mon, 16 Aug 2021 09:10:23 +0000 (04:10 -0500)
committerJunio C Hamano <gitster@pobox.com>
Wed, 18 Aug 2021 18:17:25 +0000 (11:17 -0700)
We need to ignore options that don't start with -- as well.

Depending on the value of COMP_WORDBREAKS the last word could be
duplicated otherwise.

Can be tested with:

  git merge -X diff-algorithm=<tab>

Tested-by: David Aguilar <davvid@gmail.com>
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
contrib/completion/git-completion.bash
t/t9902-completion.sh

index 47b48fbab6614e73bfee7500e1c1c88b0ce4b608..05606609f97bd623a21664d1820cab33964a8863 100644 (file)
@@ -356,7 +356,7 @@ __gitcomp ()
        local cur_="${3-$cur}"
 
        case "$cur_" in
-       --*=)
+       *=)
                ;;
        --no-*)
                local c i=0 IFS=$' \t\n'
index cb057ef16134f76ea62e39d94e587700c84a1262..6b56e54fc37c67e5647234669311790889cbc017 100755 (executable)
@@ -540,6 +540,15 @@ test_expect_success '__gitcomp - expand/narrow all negative options' '
        EOF
 '
 
+test_expect_success '__gitcomp - equal skip' '
+       test_gitcomp "--option=" "--option=" <<-\EOF &&
+
+       EOF
+       test_gitcomp "option=" "option=" <<-\EOF
+
+       EOF
+'
+
 test_expect_success '__gitcomp - doesnt fail because of invalid variable name' '
        __gitcomp "$invalid_variable_name"
 '
@@ -2380,6 +2389,12 @@ test_expect_success 'git clone --config= - value' '
        EOF
 '
 
+test_expect_success 'options with value' '
+       test_completion "git merge -X diff-algorithm=" <<-\EOF
+
+       EOF
+'
+
 test_expect_success 'sourcing the completion script clears cached commands' '
        __git_compute_all_commands &&
        verbose test -n "$__git_all_commands" &&