summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2018-06-06 09:41:39 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-06-11 17:38:10 (GMT)
commitb221b5ab9b92f3def37184db6e052ec87d7635b4 (patch)
tree746b57efa502a47df11f1003e062b3cbff0445db /t
parent3fe735e723102b631a5509dc5f2ce835616d92e7 (diff)
downloadgit-b221b5ab9b92f3def37184db6e052ec87d7635b4.zip
git-b221b5ab9b92f3def37184db6e052ec87d7635b4.tar.gz
git-b221b5ab9b92f3def37184db6e052ec87d7635b4.tar.bz2
completion: collapse extra --no-.. options
The commands that make use of --git-completion-helper feature could now produce a lot of --no-xxx options that a command can take. This in many case could nearly double the amount of completable options, using more screen estate and also harder to search for the wanted option. This patch attempts to mitigate that by collapsing extra --no- options, the ones that are added by --git-completion-helper and not in original struct option arrays. The "--no-..." option will be displayed in this case to hint about more options, e.g. > ~/w/git $ git clone -- --bare --origin= --branch= --progress --checkout --quiet --config= --recurse-submodules --depth= --reference= --dissociate --reference-if-able= --filter= --separate-git-dir= --hardlinks --shallow-exclude= --ipv4 --shallow-since= --ipv6 --shallow-submodules --jobs= --shared --local --single-branch --mirror --tags --no-... --template= --no-checkout --upload-pack= --no-hardlinks --verbose --no-tags and when you complete it with --no-<tab>, all negative options will be presented: > ~/w/git $ git clone --no- --no-bare --no-quiet --no-branch --no-recurse-submodules --no-checkout --no-reference --no-config --no-reference-if-able --no-depth --no-separate-git-dir --no-dissociate --no-shallow-exclude --no-filter --no-shallow-since --no-hardlinks --no-shallow-submodules --no-ipv4 --no-shared --no-ipv6 --no-single-branch --no-jobs --no-tags --no-local --no-template --no-mirror --no-upload-pack --no-origin --no-verbose --no-progress Corner case: to make sure that people will never accidentally complete the fake option "--no-..." there must be one real --no- in the first complete listing even if it's not from the original struct option. PS. This could could be made simpler with ";&" to fall through from "--no-*" block and share the code but ";&" is not available on bash-3 (i.e. Mac) Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't')
-rwxr-xr-xt/t9902-completion.sh49
1 files changed, 38 insertions, 11 deletions
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index 7e5e3ad..157ee70 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"
'
@@ -1237,29 +1273,20 @@ test_expect_success 'double dash "git" itself' '
test_expect_success 'double dash "git checkout"' '
test_completion "git checkout --" <<-\EOF
--quiet Z
- --no-quiet Z
--detach Z
- --no-detach Z
--track Z
- --no-track Z
--orphan=Z
- --no-orphan Z
--ours Z
--theirs Z
--merge Z
- --no-merge Z
--conflict=Z
- --no-conflict Z
--patch Z
- --no-patch Z
--ignore-skip-worktree-bits Z
- --no-ignore-skip-worktree-bits Z
--ignore-other-worktrees Z
- --no-ignore-other-worktrees Z
--recurse-submodules Z
- --no-recurse-submodules Z
--progress Z
- --no-progress Z
+ --no-quiet Z
+ --no-... Z
EOF
'