v3 fixes an annoying bug in 3/3. If you do "git commit --fi<tab>" then the "fi" part is eaten up by bash and you got back to "git commit --" on the command line. This is because we give COMPREPLY with two options "--fixup" and "--no-...". The second one forces the common prefix "--" for both of them, instead of "--fi". Bash does the rest according to the book. Some tests are added to verify new behavior in __gitcomp and make sure this does not happen again. diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 4eef353ee2..425d06256f 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -286,7 +286,10 @@ __gitcomp () local c i=0 IFS=$' \t\n' for c in $1; do if [[ $c == "--" ]]; then - COMPREPLY[i++]="${2-}--no-...${4-} " + c="--no-...${4-}" + if [[ $c == "$cur_"* ]]; then + COMPREPLY[i++]="${2-}$c " + fi break fi c="$c${4-}" diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index eb4a43584a..157ee7085d 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -459,6 +459,42 @@ test_expect_success '__gitcomp - suffix' ' EOF ' +test_expect_success '__gitcomp - ignore optional negative options' ' + test_gitcomp "--" "--abc --def --no-one -- --no-two" <<-\EOF + --abc Z + --def Z + --no-one Z + --no-... Z + EOF +' + +test_expect_success '__gitcomp - ignore/narrow optional negative options' ' + test_gitcomp "--a" "--abc --abcdef --no-one -- --no-two" <<-\EOF + --abc Z + --abcdef Z + EOF +' + +test_expect_success '__gitcomp - ignore/narrow optional negative options' ' + test_gitcomp "--n" "--abc --def --no-one -- --no-two" <<-\EOF + --no-one Z + --no-... Z + EOF +' + +test_expect_success '__gitcomp - expand all negative options' ' + test_gitcomp "--no-" "--abc --def --no-one -- --no-two" <<-\EOF + --no-one Z + --no-two Z + EOF +' + +test_expect_success '__gitcomp - expand/narrow all negative options' ' + test_gitcomp "--no-o" "--abc --def --no-one -- --no-two" <<-\EOF + --no-one Z + EOF +' + test_expect_success '__gitcomp - doesnt fail because of invalid variable name' ' __gitcomp "$invalid_variable_name" ' Nguyễn Thái Ngọc Duy (3): parse-options: option to let --git-completion-helper show negative form completion: suppress some -no- options completion: collapse extra --no-.. options builtin/checkout.c | 10 +++-- contrib/completion/git-completion.bash | 61 ++++++++++++++++---------- parse-options.c | 58 ++++++++++++++++++++++-- t/t9902-completion.sh | 41 ++++++++++++++++- 4 files changed, 136 insertions(+), 34 deletions(-) -- 2.18.0.rc0.333.g22e6ee6cdf