Skip to content

ompletion: complete all possible -no-<options>

Nguyễn Thái Ngọc Duy git 2 versions – New

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest3 patches 0 repliesNew
  2. v23 patches 2 repliesSuperseded

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3parse-options: option to let --git-completion-helper show negative formcontrib/completion/git-completion.bash parse-options.c t/t9902-completion.sh+46 -300 replies
2/3completion: suppress some -no- optionsbuiltin/checkout.c t/t9902-completion.sh+6 -60 replies
3/3completion: collapse extra --no-.. optionscontrib/completion/git-completion.bash parse-options.c t/t9902-completion.sh+115 -290 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v3 yet.

Read the v3 thread

Cover letter [PATCH v3 0/3] ompletion: complete all possible -no-<options>

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.

contrib/completion/git-completion.bash +4 -1
index 4eef353ee2..425d06256f 100644
@@ -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-}"
t/t9902-completion.sh +36 -0
index eb4a43584a..157ee7085d 100755
@@ -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(-)
Signature · 1 line
2.18.0.rc0.333.g22e6ee6cdf