3 # Copyright (c) 2012-2020 Felipe Contreras
6 test_description
='test bash completion'
16 # Be careful when updating these lists:
18 # (1) The build tree may have build artifact from different branch, or
19 # the user's $PATH may have a random executable that may begin
20 # with "git-check" that are not part of the subcommands this build
21 # will ship, e.g. "check-ignore". The tests for completion for
22 # subcommand names tests how "check" is expanded; we limit the
23 # possible candidates to "checkout" and "check-attr" to make sure
24 # "check-attr", which is known by the filter function as a
25 # subcommand to be thrown out, while excluding other random files
26 # that happen to begin with "check" to avoid letting them get in
29 # (2) A test makes sure that common subcommands are included in the
30 # completion for "git <TAB>", and a plumbing is excluded. "add",
31 # "rebase" and "ls-files" are listed for this.
33 GIT_TESTING_ALL_COMMAND_LIST
='add checkout check-attr rebase ls-files'
34 GIT_TESTING_PORCELAIN_COMMAND_LIST
='add checkout rebase'
36 .
"$GIT_BUILD_DIR/contrib/completion/git-completion.bash"
38 # We don't need this function to actually join words or do anything special.
39 # Also, it's cleaner to avoid touching bash's internal completion variables.
40 # So let's override it with a minimal version for testing purposes.
41 _get_comp_words_by_ref
()
43 while [ $# -gt 0 ]; do
49 prev
=${_words[_cword-1]}
52 words
=("${_words[@]}")
65 echo "${COMPREPLY[*]}" > out
70 local -a COMPREPLY _words
73 test "${1: -1}" = ' ' && _words
[${#_words[@]}+1]=''
74 (( _cword
= ${#_words[@]} - 1 ))
75 __git_wrap__git_main
&& print_comp
78 # Test high-level completion
80 # 1: typed text so far (cur)
81 # 2: expected completion
86 printf '%s\n' "$2" >expected
88 sed -e 's/Z$//' |
sort >expected
90 run_completion
"$1" &&
91 sort out
>out_sorted
&&
92 test_cmp expected out_sorted
96 # The first argument is the typed text so far (cur); the rest are
97 # passed to __gitcomp. Expected output comes is read from the
98 # standard input, like test_completion().
101 local -a COMPREPLY
&&
102 sed -e 's/Z$//' >expected
&&
107 test_cmp expected out
112 # 1: current word (cur)
113 # -: the rest are passed to __gitcomp_nl
116 local -a COMPREPLY
&&
117 sed -e 's/Z$//' >expected
&&
122 test_cmp expected out
125 invalid_variable_name
='${foo.bar}'
127 actual
="$TRASH_DIRECTORY/actual"
129 if test_have_prereq MINGW
136 test_expect_success
'setup for __git_find_repo_path/__gitdir tests' '
137 mkdir -p subdir/subsubdir &&
139 git init -b main otherrepo
142 test_expect_success
'__git_find_repo_path - from command line (through $__git_dir)' '
143 echo "$ROOT/otherrepo/.git" >expected &&
145 __git_dir="$ROOT/otherrepo/.git" &&
146 __git_find_repo_path &&
147 echo "$__git_repo_path" >"$actual"
149 test_cmp expected "$actual"
152 test_expect_success
'__git_find_repo_path - .git directory in cwd' '
153 echo ".git" >expected &&
155 __git_find_repo_path &&
156 echo "$__git_repo_path" >"$actual"
158 test_cmp expected "$actual"
161 test_expect_success
'__git_find_repo_path - .git directory in parent' '
162 echo "$ROOT/.git" >expected &&
164 cd subdir/subsubdir &&
165 __git_find_repo_path &&
166 echo "$__git_repo_path" >"$actual"
168 test_cmp expected "$actual"
171 test_expect_success
'__git_find_repo_path - cwd is a .git directory' '
172 echo "." >expected &&
175 __git_find_repo_path &&
176 echo "$__git_repo_path" >"$actual"
178 test_cmp expected "$actual"
181 test_expect_success
'__git_find_repo_path - parent is a .git directory' '
182 echo "$ROOT/.git" >expected &&
185 __git_find_repo_path &&
186 echo "$__git_repo_path" >"$actual"
188 test_cmp expected "$actual"
191 test_expect_success
'__git_find_repo_path - $GIT_DIR set while .git directory in cwd' '
192 echo "$ROOT/otherrepo/.git" >expected &&
194 GIT_DIR="$ROOT/otherrepo/.git" &&
196 __git_find_repo_path &&
197 echo "$__git_repo_path" >"$actual"
199 test_cmp expected "$actual"
202 test_expect_success
'__git_find_repo_path - $GIT_DIR set while .git directory in parent' '
203 echo "$ROOT/otherrepo/.git" >expected &&
205 GIT_DIR="$ROOT/otherrepo/.git" &&
208 __git_find_repo_path &&
209 echo "$__git_repo_path" >"$actual"
211 test_cmp expected "$actual"
214 test_expect_success
'__git_find_repo_path - from command line while "git -C"' '
215 echo "$ROOT/.git" >expected &&
217 __git_dir="$ROOT/.git" &&
218 __git_C_args=(-C otherrepo) &&
219 __git_find_repo_path &&
220 echo "$__git_repo_path" >"$actual"
222 test_cmp expected "$actual"
225 test_expect_success
'__git_find_repo_path - relative dir from command line and "git -C"' '
226 echo "$ROOT/otherrepo/.git" >expected &&
229 __git_dir="otherrepo/.git" &&
230 __git_C_args=(-C ..) &&
231 __git_find_repo_path &&
232 echo "$__git_repo_path" >"$actual"
234 test_cmp expected "$actual"
237 test_expect_success
'__git_find_repo_path - $GIT_DIR set while "git -C"' '
238 echo "$ROOT/.git" >expected &&
240 GIT_DIR="$ROOT/.git" &&
242 __git_C_args=(-C otherrepo) &&
243 __git_find_repo_path &&
244 echo "$__git_repo_path" >"$actual"
246 test_cmp expected "$actual"
249 test_expect_success
'__git_find_repo_path - relative dir in $GIT_DIR and "git -C"' '
250 echo "$ROOT/otherrepo/.git" >expected &&
253 GIT_DIR="otherrepo/.git" &&
255 __git_C_args=(-C ..) &&
256 __git_find_repo_path &&
257 echo "$__git_repo_path" >"$actual"
259 test_cmp expected "$actual"
262 test_expect_success
'__git_find_repo_path - "git -C" while .git directory in cwd' '
263 echo "$ROOT/otherrepo/.git" >expected &&
265 __git_C_args=(-C otherrepo) &&
266 __git_find_repo_path &&
267 echo "$__git_repo_path" >"$actual"
269 test_cmp expected "$actual"
272 test_expect_success
'__git_find_repo_path - "git -C" while cwd is a .git directory' '
273 echo "$ROOT/otherrepo/.git" >expected &&
276 __git_C_args=(-C .. -C otherrepo) &&
277 __git_find_repo_path &&
278 echo "$__git_repo_path" >"$actual"
280 test_cmp expected "$actual"
283 test_expect_success
'__git_find_repo_path - "git -C" while .git directory in parent' '
284 echo "$ROOT/otherrepo/.git" >expected &&
287 __git_C_args=(-C .. -C otherrepo) &&
288 __git_find_repo_path &&
289 echo "$__git_repo_path" >"$actual"
291 test_cmp expected "$actual"
294 test_expect_success
'__git_find_repo_path - non-existing path in "git -C"' '
296 __git_C_args=(-C non-existing) &&
297 test_must_fail __git_find_repo_path &&
298 printf "$__git_repo_path" >"$actual"
300 test_must_be_empty "$actual"
303 test_expect_success
'__git_find_repo_path - non-existing path in $__git_dir' '
305 __git_dir="non-existing" &&
306 test_must_fail __git_find_repo_path &&
307 printf "$__git_repo_path" >"$actual"
309 test_must_be_empty "$actual"
312 test_expect_success
'__git_find_repo_path - non-existing $GIT_DIR' '
314 GIT_DIR="$ROOT/non-existing" &&
316 test_must_fail __git_find_repo_path &&
317 printf "$__git_repo_path" >"$actual"
319 test_must_be_empty "$actual"
322 test_expect_success
'__git_find_repo_path - gitfile in cwd' '
323 echo "$ROOT/otherrepo/.git" >expected &&
324 echo "gitdir: $ROOT/otherrepo/.git" >subdir/.git &&
325 test_when_finished "rm -f subdir/.git" &&
328 __git_find_repo_path &&
329 echo "$__git_repo_path" >"$actual"
331 test_cmp expected "$actual"
334 test_expect_success
'__git_find_repo_path - gitfile in parent' '
335 echo "$ROOT/otherrepo/.git" >expected &&
336 echo "gitdir: $ROOT/otherrepo/.git" >subdir/.git &&
337 test_when_finished "rm -f subdir/.git" &&
339 cd subdir/subsubdir &&
340 __git_find_repo_path &&
341 echo "$__git_repo_path" >"$actual"
343 test_cmp expected "$actual"
346 test_expect_success SYMLINKS
'__git_find_repo_path - resulting path avoids symlinks' '
347 echo "$ROOT/otherrepo/.git" >expected &&
348 mkdir otherrepo/dir &&
349 test_when_finished "rm -rf otherrepo/dir" &&
350 ln -s otherrepo/dir link &&
351 test_when_finished "rm -f link" &&
354 __git_find_repo_path &&
355 echo "$__git_repo_path" >"$actual"
357 test_cmp expected "$actual"
360 test_expect_success
'__git_find_repo_path - not a git repository' '
363 GIT_CEILING_DIRECTORIES="$ROOT" &&
364 export GIT_CEILING_DIRECTORIES &&
365 test_must_fail __git_find_repo_path &&
366 printf "$__git_repo_path" >"$actual"
368 test_must_be_empty "$actual"
371 test_expect_success
'__gitdir - finds repo' '
372 echo "$ROOT/.git" >expected &&
374 cd subdir/subsubdir &&
377 test_cmp expected "$actual"
381 test_expect_success
'__gitdir - returns error when cannot find repo' '
383 __git_dir="non-existing" &&
384 test_must_fail __gitdir >"$actual"
386 test_must_be_empty "$actual"
389 test_expect_success
'__gitdir - repo as argument' '
390 echo "otherrepo/.git" >expected &&
392 __gitdir "otherrepo" >"$actual"
394 test_cmp expected "$actual"
397 test_expect_success
'__gitdir - remote as argument' '
398 echo "remote" >expected &&
400 __gitdir "remote" >"$actual"
402 test_cmp expected "$actual"
406 test_expect_success
'__git_dequote - plain unquoted word' '
407 __git_dequote unquoted-word &&
408 test unquoted-word = "$dequoted_word"
411 # input: b\a\c\k\'\\\"s\l\a\s\h\es
412 # expected: back'\"slashes
413 test_expect_success
'__git_dequote - backslash escaped' '
414 __git_dequote "b\a\c\k\\'\''\\\\\\\"s\l\a\s\h\es" &&
415 test "back'\''\\\"slashes" = "$dequoted_word"
418 # input: sin'gle\' '"quo'ted
419 # expected: single\ "quoted
420 test_expect_success
'__git_dequote - single quoted' '
421 __git_dequote "'"sin'gle\\\\' '\\\"quo'ted"'" &&
422 test '\''single\ "quoted'\'' = "$dequoted_word"
425 # input: dou"ble\\" "\"\quot"ed
426 # expected: double\ "\quoted
427 test_expect_success
'__git_dequote - double quoted' '
428 __git_dequote '\''dou"ble\\" "\"\quot"ed'\'' &&
429 test '\''double\ "\quoted'\'' = "$dequoted_word"
432 # input: 'open single quote
433 test_expect_success
'__git_dequote - open single quote' '
434 __git_dequote "'\''open single quote" &&
435 test "open single quote" = "$dequoted_word"
438 # input: "open double quote
439 test_expect_success
'__git_dequote - open double quote' '
440 __git_dequote "\"open double quote" &&
441 test "open double quote" = "$dequoted_word"
445 test_expect_success
'__gitcomp_direct - puts everything into COMPREPLY as-is' '
446 sed -e "s/Z$//g" >expected <<-EOF &&
447 with-trailing-space Z
448 without-trailing-spaceZ
451 $invalid_variable_name Z
454 cur=should_be_ignored &&
455 __gitcomp_direct "$(cat expected)" &&
458 test_cmp expected out
461 test_expect_success
'__gitcomp - trailing space - options' '
462 test_gitcomp "--re" "--dry-run --reuse-message= --reedit-message=
463 --reset-author" <<-EOF
470 test_expect_success
'__gitcomp - trailing space - config keys' '
471 test_gitcomp "br" "branch. branch.autosetupmerge
472 branch.autosetuprebase browser." <<-\EOF
474 branch.autosetupmerge Z
475 branch.autosetuprebase Z
480 test_expect_success
'__gitcomp - option parameter' '
481 test_gitcomp "--strategy=re" "octopus ours recursive resolve subtree" \
488 test_expect_success
'__gitcomp - prefix' '
489 test_gitcomp "branch.me" "remote merge mergeoptions rebase" \
490 "branch.maint." "me" <<-\EOF
492 branch.maint.mergeoptions Z
496 test_expect_success
'__gitcomp - suffix' '
497 test_gitcomp "branch.me" "master maint next seen" "branch." \
504 test_expect_success
'__gitcomp - ignore optional negative options' '
505 test_gitcomp "--" "--abc --def --no-one -- --no-two" <<-\EOF
513 test_expect_success
'__gitcomp - ignore/narrow optional negative options' '
514 test_gitcomp "--a" "--abc --abcdef --no-one -- --no-two" <<-\EOF
520 test_expect_success
'__gitcomp - ignore/narrow optional negative options' '
521 test_gitcomp "--n" "--abc --def --no-one -- --no-two" <<-\EOF
527 test_expect_success
'__gitcomp - expand all negative options' '
528 test_gitcomp "--no-" "--abc --def --no-one -- --no-two" <<-\EOF
534 test_expect_success
'__gitcomp - expand/narrow all negative options' '
535 test_gitcomp "--no-o" "--abc --def --no-one -- --no-two" <<-\EOF
540 test_expect_success
'__gitcomp - equal skip' '
541 test_gitcomp "--option=" "--option=" <<-\EOF &&
544 test_gitcomp "option=" "option=" <<-\EOF
549 test_expect_success
'__gitcomp - doesnt fail because of invalid variable name' '
550 __gitcomp "$invalid_variable_name"
553 read -r -d "" refs
<<-\EOF
560 test_expect_success '__gitcomp_nl - trailing space
' '
561 test_gitcomp_nl
"m" "$refs" <<-EOF
567 test_expect_success '__gitcomp_nl
- prefix
' '
568 test_gitcomp_nl
"--fixup=m" "$refs" "--fixup=" "m" <<-EOF
574 test_expect_success '__gitcomp_nl
- suffix
' '
575 test_gitcomp_nl
"branch.ma" "$refs" "branch." "ma" "." <<-\EOF
581 test_expect_success '__gitcomp_nl - no suffix
' '
582 test_gitcomp_nl
"ma" "$refs" "" "ma" "" <<-\EOF
588 test_expect_success '__gitcomp_nl - doesnt fail because of invalid variable name
' '
589 __gitcomp_nl
"$invalid_variable_name"
592 test_expect_success '__git_remotes
- list remotes from
$GIT_DIR/remotes and from config
file' '
593 cat >expect
<<-EOF &&
599 test_when_finished
"rm -rf .git/remotes" &&
600 mkdir
-p .git
/remotes
&&
601 >.git
/remotes
/remote_from_file_1
&&
602 >.git
/remotes
/remote_from_file_2
&&
603 test_when_finished
"git remote remove remote_in_config_1" &&
604 git remote add remote_in_config_1 git
://remote_1
&&
605 test_when_finished
"git remote remove remote_in_config_2" &&
606 git remote add remote_in_config_2 git
://remote_2
&&
608 __git_remotes
>actual
610 test_cmp expect actual
613 test_expect_success '__git_is_configured_remote
' '
614 test_when_finished
"git remote remove remote_1" &&
615 git remote add remote_1 git
://remote_1
&&
616 test_when_finished
"git remote remove remote_2" &&
617 git remote add remote_2 git
://remote_2
&&
619 __git_is_configured_remote remote_2
&&
620 test_must_fail __git_is_configured_remote non-existent
624 test_expect_success 'setup
for ref completion
' '
625 git commit
--allow-empty -m initial
&&
626 git branch
-M main
&&
627 git branch matching-branch
&&
628 git tag matching-tag
&&
631 git commit
--allow-empty -m initial
&&
632 git branch
-m main main-in-other
&&
633 git branch branch-in-other
&&
636 git remote add other
"$ROOT/otherrepo/.git" &&
637 git fetch
--no-tags other
&&
638 rm -f .git
/FETCH_HEAD
&&
642 test_expect_success '__git_refs
- simple
' '
643 cat >expected
<<-EOF &&
647 other/branch-in-other
653 __git_refs
>"$actual"
655 test_cmp expected
"$actual"
658 test_expect_success '__git_refs
- full refs
' '
659 cat >expected
<<-EOF &&
661 refs/heads/matching-branch
662 refs/remotes/other/branch-in-other
663 refs/remotes/other/main-in-other
664 refs/tags/matching-tag
668 __git_refs
>"$actual"
670 test_cmp expected
"$actual"
673 test_expect_success '__git_refs
- repo given on the
command line
' '
674 cat >expected
<<-EOF &&
681 __git_dir
="$ROOT/otherrepo/.git" &&
683 __git_refs
>"$actual"
685 test_cmp expected
"$actual"
688 test_expect_success '__git_refs
- remote on
local file system
' '
689 cat >expected
<<-EOF &&
697 __git_refs otherrepo
>"$actual"
699 test_cmp expected
"$actual"
702 test_expect_success '__git_refs
- remote on
local file system
- full refs
' '
703 cat >expected
<<-EOF &&
704 refs/heads/branch-in-other
705 refs/heads/main-in-other
706 refs/tags/tag-in-other
710 __git_refs otherrepo
>"$actual"
712 test_cmp expected
"$actual"
715 test_expect_success '__git_refs
- configured remote
' '
716 cat >expected
<<-EOF &&
723 __git_refs other
>"$actual"
725 test_cmp expected
"$actual"
728 test_expect_success '__git_refs
- configured remote
- full refs
' '
729 cat >expected
<<-EOF &&
731 refs/heads/branch-in-other
732 refs/heads/main-in-other
733 refs/tags/tag-in-other
737 __git_refs other
>"$actual"
739 test_cmp expected
"$actual"
742 test_expect_success '__git_refs
- configured remote
- repo given on the
command line
' '
743 cat >expected
<<-EOF &&
750 __git_dir
="$ROOT/.git" &&
752 __git_refs other
>"$actual"
754 test_cmp expected
"$actual"
757 test_expect_success '__git_refs
- configured remote
- full refs
- repo given on the
command line
' '
758 cat >expected
<<-EOF &&
760 refs/heads/branch-in-other
761 refs/heads/main-in-other
762 refs/tags/tag-in-other
766 __git_dir
="$ROOT/.git" &&
768 __git_refs other
>"$actual"
770 test_cmp expected
"$actual"
773 test_expect_success '__git_refs
- configured remote
- remote name matches a directory
' '
774 cat >expected
<<-EOF &&
780 test_when_finished
"rm -rf other" &&
783 __git_refs other
>"$actual"
785 test_cmp expected
"$actual"
788 test_expect_success '__git_refs
- URL remote
' '
789 cat >expected
<<-EOF &&
797 __git_refs
"file://$ROOT/otherrepo/.git" >"$actual"
799 test_cmp expected
"$actual"
802 test_expect_success '__git_refs
- URL remote
- full refs
' '
803 cat >expected
<<-EOF &&
805 refs/heads/branch-in-other
806 refs/heads/main-in-other
807 refs/tags/tag-in-other
811 __git_refs
"file://$ROOT/otherrepo/.git" >"$actual"
813 test_cmp expected
"$actual"
816 test_expect_success '__git_refs
- non-existing remote
' '
819 __git_refs non-existing
>"$actual"
821 test_must_be_empty
"$actual"
824 test_expect_success '__git_refs
- non-existing remote
- full refs
' '
827 __git_refs non-existing
>"$actual"
829 test_must_be_empty
"$actual"
832 test_expect_success '__git_refs
- non-existing URL remote
' '
835 __git_refs
"file://$ROOT/non-existing" >"$actual"
837 test_must_be_empty
"$actual"
840 test_expect_success '__git_refs
- non-existing URL remote
- full refs
' '
843 __git_refs
"file://$ROOT/non-existing" >"$actual"
845 test_must_be_empty
"$actual"
848 test_expect_success '__git_refs
- not
in a git repository
' '
850 GIT_CEILING_DIRECTORIES
="$ROOT" &&
851 export GIT_CEILING_DIRECTORIES
&&
854 __git_refs
>"$actual"
856 test_must_be_empty
"$actual"
859 test_expect_success '__git_refs
- unique remote branches
for git checkout DWIMery
' '
860 cat >expected
<<-EOF &&
865 other/branch-in-other
868 remote/branch-in-remote
874 for remote_ref
in refs
/remotes
/other
/ambiguous \
875 refs
/remotes
/remote
/ambiguous \
876 refs
/remotes
/remote
/branch-in-remote
878 git update-ref
$remote_ref main
&&
879 test_when_finished
"git update-ref -d $remote_ref" ||
return 1
883 __git_refs
"" 1 >"$actual"
885 test_cmp expected
"$actual"
888 test_expect_success '__git_refs
- after
--opt=' '
889 cat >expected
<<-EOF &&
893 other/branch-in-other
899 __git_refs
"" "" "" "" >"$actual"
901 test_cmp expected
"$actual"
904 test_expect_success '__git_refs
- after
--opt= - full refs
' '
905 cat >expected
<<-EOF &&
907 refs/heads/matching-branch
908 refs/remotes/other/branch-in-other
909 refs/remotes/other/main-in-other
910 refs/tags/matching-tag
914 __git_refs
"" "" "" refs
/ >"$actual"
916 test_cmp expected
"$actual"
919 test_expect_success '__git refs
- excluding refs
' '
920 cat >expected
<<-EOF &&
924 ^other/branch-in-other
930 __git_refs
>"$actual"
932 test_cmp expected
"$actual"
935 test_expect_success '__git refs
- excluding full refs
' '
936 cat >expected
<<-EOF &&
938 ^refs/heads/matching-branch
939 ^refs/remotes/other/branch-in-other
940 ^refs/remotes/other/main-in-other
941 ^refs/tags/matching-tag
945 __git_refs
>"$actual"
947 test_cmp expected
"$actual"
950 test_expect_success 'setup
for filtering matching refs
' '
951 git branch matching
/branch
&&
952 git tag matching
/tag
&&
953 git
-C otherrepo branch matching
/branch-in-other
&&
954 git fetch
--no-tags other
&&
955 rm -f .git
/FETCH_HEAD
958 test_expect_success '__git_refs
- do not filter refs unless told so
' '
959 cat >expected
<<-EOF &&
964 other/branch-in-other
966 other/matching/branch-in-other
972 __git_refs
>"$actual"
974 test_cmp expected
"$actual"
977 test_expect_success '__git_refs
- only matching refs
' '
978 cat >expected
<<-EOF &&
986 __git_refs
"" "" "" "$cur" >"$actual"
988 test_cmp expected
"$actual"
991 test_expect_success '__git_refs
- only matching refs
- full refs
' '
992 cat >expected
<<-EOF &&
993 refs/heads/matching-branch
994 refs/heads/matching/branch
997 cur
=refs
/heads
/mat
&&
998 __git_refs
"" "" "" "$cur" >"$actual"
1000 test_cmp expected
"$actual"
1003 test_expect_success '__git_refs
- only matching refs
- remote on
local file system
' '
1004 cat >expected
<<-EOF &&
1006 matching/branch-in-other
1010 __git_refs otherrepo
"" "" "$cur" >"$actual"
1012 test_cmp expected
"$actual"
1015 test_expect_success '__git_refs
- only matching refs
- configured remote
' '
1016 cat >expected
<<-EOF &&
1018 matching/branch-in-other
1022 __git_refs other
"" "" "$cur" >"$actual"
1024 test_cmp expected
"$actual"
1027 test_expect_success '__git_refs
- only matching refs
- remote
- full refs
' '
1028 cat >expected
<<-EOF &&
1029 refs/heads/main-in-other
1030 refs/heads/matching/branch-in-other
1033 cur
=refs
/heads
/ma
&&
1034 __git_refs other
"" "" "$cur" >"$actual"
1036 test_cmp expected
"$actual"
1039 test_expect_success '__git_refs
- only matching refs
- checkout DWIMery
' '
1040 cat >expected
<<-EOF &&
1045 matching/branch-in-other
1047 for remote_ref
in refs
/remotes
/other
/ambiguous \
1048 refs
/remotes
/remote
/ambiguous \
1049 refs
/remotes
/remote
/branch-in-remote
1051 git update-ref
$remote_ref main
&&
1052 test_when_finished
"git update-ref -d $remote_ref" ||
return 1
1056 __git_refs
"" 1 "" "$cur" >"$actual"
1058 test_cmp expected
"$actual"
1061 test_expect_success 'teardown after filtering matching refs
' '
1062 git branch
-d matching
/branch
&&
1063 git tag
-d matching
/tag
&&
1064 git update-ref
-d refs
/remotes
/other
/matching
/branch-in-other
&&
1065 git
-C otherrepo branch
-D matching
/branch-in-other
1068 test_expect_success '__git_refs
- for-each-ref format specifiers
in prefix
' '
1069 cat >expected
<<-EOF &&
1070 evil-%%-%42-%(refname)..main
1073 cur
="evil-%%-%42-%(refname)..mai" &&
1074 __git_refs
"" "" "evil-%%-%42-%(refname).." mai
>"$actual"
1076 test_cmp expected
"$actual"
1079 test_expect_success '__git_complete_refs
- simple
' '
1080 sed -e "s/Z$//" >expected
<<-EOF &&
1084 other/branch-in-other Z
1085 other/main-in-other Z
1090 __git_complete_refs
&&
1093 test_cmp expected out
1096 test_expect_success '__git_complete_refs
- matching
' '
1097 sed -e "s/Z$//" >expected
<<-EOF &&
1103 __git_complete_refs
&&
1106 test_cmp expected out
1109 test_expect_success '__git_complete_refs
- remote
' '
1110 sed -e "s/Z$//" >expected
<<-EOF &&
1117 __git_complete_refs
--remote=other
&&
1120 test_cmp expected out
1123 test_expect_success '__git_complete_refs
- track
' '
1124 sed -e "s/Z$//" >expected
<<-EOF &&
1128 other/branch-in-other Z
1129 other/main-in-other Z
1136 __git_complete_refs
--track &&
1139 test_cmp expected out
1142 test_expect_success '__git_complete_refs
- current word
' '
1143 sed -e "s/Z$//" >expected
<<-EOF &&
1148 cur
="--option=mat" &&
1149 __git_complete_refs
--cur="${cur#*=}" &&
1152 test_cmp expected out
1155 test_expect_success '__git_complete_refs
- prefix
' '
1156 sed -e "s/Z$//" >expected
<<-EOF &&
1157 v1.0..matching-branch Z
1158 v1.0..matching-tag Z
1162 __git_complete_refs
--pfx=v1.0..
--cur=mat
&&
1165 test_cmp expected out
1168 test_expect_success '__git_complete_refs
- suffix
' '
1169 cat >expected
<<-EOF &&
1173 other/branch-in-other.
1174 other/main-in-other.
1179 __git_complete_refs
--sfx=.
&&
1182 test_cmp expected out
1185 test_expect_success '__git_complete_fetch_refspecs
- simple
' '
1186 sed -e "s/Z$//" >expected
<<-EOF &&
1188 branch-in-other:branch-in-other Z
1189 main-in-other:main-in-other Z
1193 __git_complete_fetch_refspecs other
&&
1196 test_cmp expected out
1199 test_expect_success '__git_complete_fetch_refspecs
- matching
' '
1200 sed -e "s/Z$//" >expected
<<-EOF &&
1201 branch-in-other:branch-in-other Z
1205 __git_complete_fetch_refspecs other
"" br
&&
1208 test_cmp expected out
1211 test_expect_success '__git_complete_fetch_refspecs
- prefix
' '
1212 sed -e "s/Z$//" >expected
<<-EOF &&
1214 +branch-in-other:branch-in-other Z
1215 +main-in-other:main-in-other Z
1219 __git_complete_fetch_refspecs other
"+" "" &&
1222 test_cmp expected out
1225 test_expect_success '__git_complete_fetch_refspecs
- fully qualified
' '
1226 sed -e "s/Z$//" >expected
<<-EOF &&
1227 refs/heads/branch-in-other:refs/heads/branch-in-other Z
1228 refs/heads/main-in-other:refs/heads/main-in-other Z
1229 refs/tags/tag-in-other:refs/tags/tag-in-other Z
1233 __git_complete_fetch_refspecs other
"" refs
/ &&
1236 test_cmp expected out
1239 test_expect_success '__git_complete_fetch_refspecs
- fully qualified
& prefix
' '
1240 sed -e "s/Z$//" >expected
<<-EOF &&
1241 +refs/heads/branch-in-other:refs/heads/branch-in-other Z
1242 +refs/heads/main-in-other:refs/heads/main-in-other Z
1243 +refs/tags/tag-in-other:refs/tags/tag-in-other Z
1247 __git_complete_fetch_refspecs other
+ refs
/ &&
1250 test_cmp expected out
1253 test_expect_success 'git switch
- with no options
, complete
local branches and unique remote branch names
for DWIM logic
' '
1254 test_completion
"git switch " <<-\EOF
1262 test_expect_success 'git checkout - completes refs and unique remote branches
for DWIM
' '
1263 test_completion
"git checkout " <<-\EOF
1270 other/branch-in-other Z
1271 other/main-in-other Z
1275 test_expect_success 'git switch - with
--no-guess, complete only
local branches
' '
1276 test_completion
"git switch --no-guess " <<-\EOF
1282 test_expect_success 'git switch - with GIT_COMPLETION_CHECKOUT_NO_GUESS
=1, complete only
local branches
' '
1283 GIT_COMPLETION_CHECKOUT_NO_GUESS
=1 test_completion
"git switch " <<-\EOF
1289 test_expect_success 'git switch - --guess overrides GIT_COMPLETION_CHECKOUT_NO_GUESS
=1, complete
local branches and unique remote names
for DWIM logic
' '
1290 GIT_COMPLETION_CHECKOUT_NO_GUESS
=1 test_completion
"git switch --guess " <<-\EOF
1298 test_expect_success 'git switch - a later
--guess overrides previous
--no-guess, complete
local and remote unique branches
for DWIM
' '
1299 test_completion
"git switch --no-guess --guess " <<-\EOF
1307 test_expect_success 'git switch - a later
--no-guess overrides previous
--guess, complete only
local branches
' '
1308 test_completion
"git switch --guess --no-guess " <<-\EOF
1314 test_expect_success 'git checkout - with GIT_COMPLETION_NO_GUESS
=1 only completes refs
' '
1315 GIT_COMPLETION_CHECKOUT_NO_GUESS
=1 test_completion
"git checkout " <<-\EOF
1320 other/branch-in-other Z
1321 other/main-in-other Z
1325 test_expect_success 'git checkout - --guess overrides GIT_COMPLETION_NO_GUESS
=1, complete refs and unique remote branches
for DWIM
' '
1326 GIT_COMPLETION_CHECKOUT_NO_GUESS
=1 test_completion
"git checkout --guess " <<-\EOF
1333 other/branch-in-other Z
1334 other/main-in-other Z
1338 test_expect_success 'git checkout - with
--no-guess, only completes refs
' '
1339 test_completion
"git checkout --no-guess " <<-\EOF
1344 other/branch-in-other Z
1345 other/main-in-other Z
1349 test_expect_success 'git checkout - a later
--guess overrides previous
--no-guess, complete refs and unique remote branches
for DWIM
' '
1350 test_completion
"git checkout --no-guess --guess " <<-\EOF
1357 other/branch-in-other Z
1358 other/main-in-other Z
1362 test_expect_success 'git checkout - a later
--no-guess overrides previous
--guess, complete only refs
' '
1363 test_completion
"git checkout --guess --no-guess " <<-\EOF
1368 other/branch-in-other Z
1369 other/main-in-other Z
1373 test_expect_success 'git checkout - with checkout.guess
= false
, only completes refs
' '
1374 test_config checkout.guess false
&&
1375 test_completion
"git checkout " <<-\EOF
1380 other/branch-in-other Z
1381 other/main-in-other Z
1385 test_expect_success 'git checkout - with checkout.guess
= true
, completes refs and unique remote branches
for DWIM
' '
1386 test_config checkout.guess true
&&
1387 test_completion
"git checkout " <<-\EOF
1394 other/branch-in-other Z
1395 other/main-in-other Z
1399 test_expect_success 'git checkout - a later
--guess overrides previous checkout.guess
= false
, complete refs and unique remote branches
for DWIM
' '
1400 test_config checkout.guess false
&&
1401 test_completion
"git checkout --guess " <<-\EOF
1408 other/branch-in-other Z
1409 other/main-in-other Z
1413 test_expect_success 'git checkout - a later
--no-guess overrides previous checkout.guess
= true
, complete only refs
' '
1414 test_config checkout.guess true
&&
1415 test_completion
"git checkout --no-guess " <<-\EOF
1420 other/branch-in-other Z
1421 other/main-in-other Z
1425 test_expect_success 'git switch - with
--detach, complete all references
' '
1426 test_completion
"git switch --detach " <<-\EOF
1431 other/branch-in-other Z
1432 other/main-in-other Z
1436 test_expect_success 'git checkout - with
--detach, complete only references
' '
1437 test_completion
"git checkout --detach " <<-\EOF
1442 other/branch-in-other Z
1443 other/main-in-other Z
1447 test_expect_success 'setup sparse-checkout tests' '
1448 # set up sparse-checkout repo
1449 git init sparse-checkout &&
1451 cd sparse-checkout &&
1452 mkdir -p folder1/0/1 folder2/0 folder3 &&
1453 touch folder1/0/1/t.txt &&
1454 touch folder2/0/t.txt &&
1455 touch folder3/t.txt &&
1457 git commit -am "Initial commit"
1461 test_expect_success 'sparse-checkout completes subcommands' '
1462 test_completion "git sparse-checkout " <<-\
EOF
1472 test_expect_success 'cone mode sparse-checkout completes directory names' '
1473 # initialize sparse-checkout definitions
1474 git -C sparse-checkout sparse-checkout set --cone folder1/0 folder3 &&
1476 # test tab completion
1478 cd sparse-checkout &&
1479 test_completion "git sparse-checkout set f" <<-\EOF
1487 cd sparse-checkout &&
1488 test_completion "git sparse-checkout set folder1/" <<-\EOF
1494 cd sparse-checkout &&
1495 test_completion "git sparse-checkout set folder1/0/" <<-\EOF
1501 cd sparse-checkout/folder1 &&
1502 test_completion "git sparse-checkout add 0" <<-\EOF
1508 test_expect_success 'cone mode sparse-checkout completes directory names with spaces and accents' '
1509 # reset sparse-checkout
1510 git -C sparse-checkout sparse-checkout disable &&
1512 cd sparse-checkout &&
1513 mkdir "directory with spaces" &&
1514 mkdir "directory-with-áccent" &&
1515 >"directory with spaces/randomfile" &&
1516 >"directory-with-áccent/randomfile" &&
1518 git commit -m "Add directory with spaces and directory with accent" &&
1519 git sparse-checkout set --cone "directory with spaces" \
1520 "directory-with-áccent" &&
1521 test_completion "git sparse-checkout add dir" <<-\EOF &&
1522 directory with spaces/
1523 directory-with-áccent/
1525 rm -rf "directory with spaces" &&
1526 rm -rf "directory-with-áccent" &&
1528 git commit -m "Remove directory with spaces and directory with accent"
1532 # use FUNNYNAMES to avoid running on Windows, which doesn't permit tabs in paths
1533 test_expect_success FUNNYNAMES 'cone mode sparse-checkout completes directory names with tabs' '
1534 # reset sparse-checkout
1535 git -C sparse-checkout sparse-checkout disable &&
1537 cd sparse-checkout &&
1538 mkdir "$(printf "directory\twith\ttabs")" &&
1539 >"$(printf "directory\twith\ttabs")/randomfile" &&
1541 git commit -m "Add directory with tabs" &&
1542 git sparse-checkout set --cone \
1543 "$(printf "directory\twith\ttabs")" &&
1544 test_completion "git sparse-checkout add dir" <<-\EOF &&
1545 directory with tabs/
1547 rm -rf "$(printf "directory\twith\ttabs")" &&
1549 git commit -m "Remove directory with tabs"
1553 # use FUNNYNAMES to avoid running on Windows, and !CYGWIN for Cygwin, as neither permit backslashes in paths
1554 test_expect_success FUNNYNAMES,!CYGWIN 'cone mode sparse-checkout completes directory names with backslashes' '
1555 # reset sparse-checkout
1556 git -C sparse-checkout sparse-checkout disable &&
1558 cd sparse-checkout &&
1559 mkdir "directory\with\backslashes" &&
1560 >"directory\with\backslashes/randomfile" &&
1562 git commit -m "Add directory with backslashes" &&
1563 git sparse-checkout set --cone \
1564 "directory\with\backslashes" &&
1565 test_completion "git sparse-checkout add dir" <<-\EOF &&
1566 directory\with\backslashes/
1568 rm -rf "directory\with\backslashes" &&
1570 git commit -m "Remove directory with backslashes"
1574 test_expect_success 'non-cone mode sparse-checkout uses bash completion' '
1575 # reset sparse-checkout repo to non-cone mode
1576 git -C sparse-checkout sparse-checkout disable &&
1577 git -C sparse-checkout sparse-checkout set --no-cone &&
1580 cd sparse-checkout &&
1581 # expected to be empty since we have not configured
1582 # custom completion for non-cone mode
1583 test_completion "git sparse-checkout set f" <<-\EOF
1589 test_expect_success 'git sparse-checkout set --cone completes directory names' '
1590 git -C sparse-checkout sparse-checkout disable &&
1593 cd sparse-checkout &&
1594 test_completion "git sparse-checkout set --cone f" <<-\EOF
1602 test_expect_success 'git switch - with
-d, complete all references
' '
1603 test_completion
"git switch -d " <<-\EOF
1608 other/branch-in-other Z
1609 other/main-in-other Z
1613 test_expect_success 'git checkout - with
-d, complete only references
' '
1614 test_completion
"git checkout -d " <<-\EOF
1619 other/branch-in-other Z
1620 other/main-in-other Z
1624 test_expect_success 'git switch - with
--track, complete only remote branches
' '
1625 test_completion
"git switch --track " <<-\EOF &&
1626 other/branch-in-other Z
1627 other/main-in-other Z
1629 test_completion "git switch -t " <<-\
EOF
1630 other/branch-in-other Z
1631 other/main-in-other Z
1635 test_expect_success 'git checkout - with
--track, complete only remote branches
' '
1636 test_completion
"git checkout --track " <<-\EOF &&
1637 other/branch-in-other Z
1638 other/main-in-other Z
1640 test_completion "git checkout -t " <<-\
EOF
1641 other/branch-in-other Z
1642 other/main-in-other Z
1646 test_expect_success 'git switch - with
--no-track, complete only
local branch names
' '
1647 test_completion
"git switch --no-track " <<-\EOF
1653 test_expect_success 'git checkout - with
--no-track, complete only
local references
' '
1654 test_completion
"git checkout --no-track " <<-\EOF
1659 other/branch-in-other Z
1660 other/main-in-other Z
1664 test_expect_success 'git switch - with
-c, complete all references
' '
1665 test_completion
"git switch -c new-branch " <<-\EOF
1670 other/branch-in-other Z
1671 other/main-in-other Z
1675 test_expect_success 'git switch - with
-C, complete all references
' '
1676 test_completion
"git switch -C new-branch " <<-\EOF
1681 other/branch-in-other Z
1682 other/main-in-other Z
1686 test_expect_success 'git switch - with
-c and
--track, complete all references
' '
1687 test_completion
"git switch -c new-branch --track " <<-EOF
1692 other/branch-in-other Z
1693 other/main-in-other Z
1697 test_expect_success 'git switch
- with
-C and
--track, complete all references
' '
1698 test_completion
"git switch -C new-branch --track " <<-EOF
1703 other/branch-in-other Z
1704 other/main-in-other Z
1708 test_expect_success 'git switch
- with
-c and
--no-track, complete all references
' '
1709 test_completion
"git switch -c new-branch --no-track " <<-\EOF
1714 other/branch-in-other Z
1715 other/main-in-other Z
1719 test_expect_success 'git switch - with
-C and
--no-track, complete all references
' '
1720 test_completion
"git switch -C new-branch --no-track " <<-\EOF
1725 other/branch-in-other Z
1726 other/main-in-other Z
1730 test_expect_success 'git checkout - with
-b, complete all references
' '
1731 test_completion
"git checkout -b new-branch " <<-\EOF
1736 other/branch-in-other Z
1737 other/main-in-other Z
1741 test_expect_success 'git checkout - with
-B, complete all references
' '
1742 test_completion
"git checkout -B new-branch " <<-\EOF
1747 other/branch-in-other Z
1748 other/main-in-other Z
1752 test_expect_success 'git checkout - with
-b and
--track, complete all references
' '
1753 test_completion
"git checkout -b new-branch --track " <<-EOF
1758 other/branch-in-other Z
1759 other/main-in-other Z
1763 test_expect_success 'git checkout
- with
-B and
--track, complete all references
' '
1764 test_completion
"git checkout -B new-branch --track " <<-EOF
1769 other/branch-in-other Z
1770 other/main-in-other Z
1774 test_expect_success 'git checkout
- with
-b and
--no-track, complete all references
' '
1775 test_completion
"git checkout -b new-branch --no-track " <<-\EOF
1780 other/branch-in-other Z
1781 other/main-in-other Z
1785 test_expect_success 'git checkout - with
-B and
--no-track, complete all references
' '
1786 test_completion
"git checkout -B new-branch --no-track " <<-\EOF
1791 other/branch-in-other Z
1792 other/main-in-other Z
1796 test_expect_success 'git switch - for -c, complete
local branches and unique remote branches
' '
1797 test_completion
"git switch -c " <<-\EOF
1805 test_expect_success 'git switch - for -C, complete
local branches and unique remote branches
' '
1806 test_completion
"git switch -C " <<-\EOF
1814 test_expect_success 'git switch - for -c with
--no-guess, complete
local branches only
' '
1815 test_completion
"git switch --no-guess -c " <<-\EOF
1821 test_expect_success 'git switch - for -C with
--no-guess, complete
local branches only
' '
1822 test_completion
"git switch --no-guess -C " <<-\EOF
1828 test_expect_success 'git switch - for -c with
--no-track, complete
local branches only
' '
1829 test_completion
"git switch --no-track -c " <<-\EOF
1835 test_expect_success 'git switch - for -C with
--no-track, complete
local branches only
' '
1836 test_completion
"git switch --no-track -C " <<-\EOF
1842 test_expect_success 'git checkout - for -b, complete
local branches and unique remote branches
' '
1843 test_completion
"git checkout -b " <<-\EOF
1851 test_expect_success 'git checkout - for -B, complete
local branches and unique remote branches
' '
1852 test_completion
"git checkout -B " <<-\EOF
1860 test_expect_success 'git checkout - for -b with
--no-guess, complete
local branches only
' '
1861 test_completion
"git checkout --no-guess -b " <<-\EOF
1867 test_expect_success 'git checkout - for -B with
--no-guess, complete
local branches only
' '
1868 test_completion
"git checkout --no-guess -B " <<-\EOF
1874 test_expect_success 'git checkout - for -b with
--no-track, complete
local branches only
' '
1875 test_completion
"git checkout --no-track -b " <<-\EOF
1881 test_expect_success 'git checkout - for -B with
--no-track, complete
local branches only
' '
1882 test_completion
"git checkout --no-track -B " <<-\EOF
1888 test_expect_success 'git switch - with
--orphan completes
local branch names and unique remote branch names
' '
1889 test_completion
"git switch --orphan " <<-\EOF
1897 test_expect_success 'git switch - --orphan with branch already provided completes nothing
else' '
1898 test_completion
"git switch --orphan main " <<-\EOF
1903 test_expect_success 'git checkout - with
--orphan completes
local branch names and unique remote branch names
' '
1904 test_completion
"git checkout --orphan " <<-\EOF
1912 test_expect_success 'git checkout - --orphan with branch already provided completes
local refs
for a start-point
' '
1913 test_completion
"git checkout --orphan main " <<-\EOF
1918 other/branch-in-other Z
1919 other/main-in-other Z
1923 test_expect_success 'teardown after ref completion' '
1924 git branch -d matching-branch &&
1925 git tag -d matching-tag &&
1926 git remote remove other
1930 test_path_completion ()
1932 test $# = 2 || BUG "not 2 parameters to test_path_completion"
1934 local cur="$1" expected="$2"
1935 echo "$expected" >expected &&
1937 # In the following tests calling this function we only
1938 # care about how __git_complete_index_file() deals with
1939 # unusual characters in path names. By requesting only
1940 # untracked files we do not have to bother adding any
1941 # paths to the index in those tests.
1942 __git_complete_index_file --others &&
1945 test_cmp expected out
1948 test_expect_success 'setup for path completion tests' '
1952 touch simple-dir/simple-file \
1953 "spaces in dir/spaces in file" \
1954 "árvíztűrő/Сайн яваарай" &&
1955 if test_have_prereq !MINGW &&
1957 '$'separators\034in\035dir'' &&
1958 touch BS\\dir/DQ\"file \
1959 '$'separators\034in\035dir/sep\036in\037file''
1961 test_set_prereq FUNNIERNAMES
1963 rm -rf BS\\dir '$'separators\034in\035dir''
1967 test_expect_success '__git_complete_index_file - simple
' '
1968 test_path_completion simple simple-dir
&& # Bash is supposed to
1969 # add the trailing /.
1970 test_path_completion simple-dir
/simple simple-dir
/simple-file
1973 test_expect_success \
1974 '__git_complete_index_file
- escaped characters on cmdline
' '
1975 test_path_completion spac
"spaces in dir" && # Bash will turn this
1976 # into "spaces\ in\ dir"
1977 test_path_completion
"spaces\\ i" \
1979 test_path_completion
"spaces\\ in\\ dir/s" \
1980 "spaces in dir/spaces in file" &&
1981 test_path_completion
"spaces\\ in\\ dir/spaces\\ i" \
1982 "spaces in dir/spaces in file"
1985 test_expect_success \
1986 '__git_complete_index_file
- quoted characters on cmdline
' '
1987 # Testing with an opening but without a corresponding closing
1988 # double quote is important.
1989 test_path_completion
\"spac
"spaces in dir" &&
1990 test_path_completion
"\"spaces i" \
1992 test_path_completion
"\"spaces in dir/s" \
1993 "spaces in dir/spaces in file" &&
1994 test_path_completion
"\"spaces in dir/spaces i" \
1995 "spaces in dir/spaces in file"
1998 test_expect_success '__git_complete_index_file
- UTF-8
in ls-files output
' '
1999 test_path_completion á árvíztűrő
&&
2000 test_path_completion árvíztűrő
/С
"árvíztűrő/Сайн яваарай"
2003 test_expect_success FUNNIERNAMES \
2004 '__git_complete_index_file
- C-style escapes
in ls-files output
' '
2005 test_path_completion BS \
2007 test_path_completion BS
\\\\d \
2009 test_path_completion BS
\\\\dir
/DQ \
2011 test_path_completion BS
\\\\dir
/DQ
\\\"f \
2015 test_expect_success FUNNIERNAMES \
2016 '__git_complete_index_file
- \nnn
-escaped characters
in ls-files output
' '
2017 test_path_completion sep
'$'separators
\034in\035dir
'' &&
2018 test_path_completion
'$'separators
\034i
'' \
2019 '$'separators
\034in\035dir
'' &&
2020 test_path_completion
'$'separators
\034in\035dir
/sep
'' \
2021 '$'separators
\034in\035dir
/sep
\036in\037file'' &&
2022 test_path_completion
'$'separators
\034in\035dir
/sep
\036i
'' \
2023 '$'separators
\034in\035dir
/sep
\036in\037file''
2026 test_expect_success FUNNYNAMES \
2027 '__git_complete_index_file
- removing repeated quoted path components
' '
2028 test_when_finished
rm -r repeated-quoted
&&
2029 mkdir repeated-quoted
&& # A directory whose name in itself
2030 # would not be quoted ...
2031 >repeated-quoted
/0-file &&
2032 >repeated-quoted
/1\"file && # ... but here the file makes the
2033 # dirname quoted ...
2034 >repeated-quoted
/2-file &&
2035 >repeated-quoted
/3\"file && # ... and here, too.
2037 # Still, we shold only list the directory name only once.
2038 test_path_completion repeated repeated-quoted
2041 test_expect_success 'teardown after path completion tests
' '
2042 rm -rf simple-dir
"spaces in dir" árvíztűrő \
2043 BS
\\dir
'$'separators
\034in\035dir
''
2046 test_expect_success '__git_find_on_cmdline
- single match
' '
2047 echo list
>expect
&&
2049 words
=(git
command --opt list
) &&
2050 cword
=${#words[@]} &&
2052 __git_find_on_cmdline
"add list remove" >actual
2054 test_cmp expect actual
2057 test_expect_success '__git_find_on_cmdline
- multiple matches
' '
2058 echo remove
>expect
&&
2060 words
=(git
command -o --opt remove list add
) &&
2061 cword
=${#words[@]} &&
2063 __git_find_on_cmdline
"add list remove" >actual
2065 test_cmp expect actual
2068 test_expect_success '__git_find_on_cmdline
- no match
' '
2070 words
=(git
command --opt branch
) &&
2071 cword
=${#words[@]} &&
2073 __git_find_on_cmdline
"add list remove" >actual
2075 test_must_be_empty actual
2078 test_expect_success '__git_find_on_cmdline
- single match with index
' '
2079 echo "3 list" >expect
&&
2081 words
=(git
command --opt list
) &&
2082 cword
=${#words[@]} &&
2084 __git_find_on_cmdline
--show-idx "add list remove" >actual
2086 test_cmp expect actual
2089 test_expect_success '__git_find_on_cmdline
- multiple matches with index
' '
2090 echo "4 remove" >expect
&&
2092 words
=(git
command -o --opt remove list add
) &&
2093 cword
=${#words[@]} &&
2095 __git_find_on_cmdline
--show-idx "add list remove" >actual
2097 test_cmp expect actual
2100 test_expect_success '__git_find_on_cmdline
- no match with index
' '
2102 words
=(git
command --opt branch
) &&
2103 cword
=${#words[@]} &&
2105 __git_find_on_cmdline
--show-idx "add list remove" >actual
2107 test_must_be_empty actual
2110 test_expect_success '__git_find_on_cmdline
- ignores matches before
command with index
' '
2111 echo "6 remove" >expect
&&
2113 words
=(git
-C remove
command -o --opt remove list add
) &&
2114 cword
=${#words[@]} &&
2116 __git_find_on_cmdline
--show-idx "add list remove" >actual
2118 test_cmp expect actual
2121 test_expect_success '__git_get_config_variables
' '
2122 cat >expect
<<-EOF &&
2126 test_config interesting.name-1 good
&&
2127 test_config interesting.name-2 good
&&
2128 test_config subsection.interesting.name-3 bad
&&
2129 __git_get_config_variables interesting
>actual
&&
2130 test_cmp expect actual
2133 test_expect_success '__git_pretty_aliases
' '
2134 cat >expect
<<-EOF &&
2138 test_config pretty.author
"%an %ae" &&
2139 test_config pretty.
hash %H
&&
2140 __git_pretty_aliases
>actual
&&
2141 test_cmp expect actual
2144 test_expect_success 'basic
' '
2145 run_completion
"git " &&
2147 grep -q "^add \$" out
&&
2149 grep -q "^rebase \$" out
&&
2151 ! grep -q "^ls-files \$" out
&&
2153 run_completion
"git r" &&
2154 ! grep -q -v "^r" out
2157 test_expect_success 'double dash
"git" itself
' '
2158 test_completion
"git --" <<-\EOF
2171 --no-replace-objects Z
2176 test_expect_success 'double dash "git checkout"' '
2177 test_completion "git checkout --" <<-\
EOF
2187 --ignore-skip-worktree-bits Z
2188 --ignore-other-worktrees Z
2189 --recurse-submodules Z
2195 --pathspec-file-nul Z
2196 --pathspec-from-file=Z
2200 test_expect_success 'general options' '
2201 test_completion "git --ver" "--version " &&
2202 test_completion "git --hel" "--help " &&
2203 test_completion "git --exe" <<-\EOF &&
2207 test_completion "git --htm" "--html-path " &&
2208 test_completion "git --pag" "--paginate " &&
2209 test_completion "git --no-p" "--no-pager " &&
2210 test_completion "git --git" "--git-dir=" &&
2211 test_completion "git --wor" "--work-tree=" &&
2212 test_completion "git --nam" "--namespace=" &&
2213 test_completion "git --bar" "--bare " &&
2214 test_completion "git --inf" "--info-path " &&
2215 test_completion "git --no-r" "--no-replace-objects "
2218 test_expect_success 'general options plus command' '
2219 test_completion "git --version check" "checkout " &&
2220 test_completion "git --paginate check" "checkout " &&
2221 test_completion "git --git-dir=foo check" "checkout " &&
2222 test_completion "git --bare check" "checkout " &&
2223 test_completion "git --exec-path=foo check" "checkout " &&
2224 test_completion "git --html-path check" "checkout " &&
2225 test_completion "git --no-pager check" "checkout " &&
2226 test_completion "git --work-tree=foo check" "checkout " &&
2227 test_completion "git --namespace=foo check" "checkout " &&
2228 test_completion "git --paginate check" "checkout " &&
2229 test_completion "git --info-path check" "checkout " &&
2230 test_completion "git --no-replace-objects check" "checkout " &&
2231 test_completion "git --git-dir some/path check" "checkout " &&
2232 test_completion "git -c conf.var=value check" "checkout " &&
2233 test_completion "git -C some/path check" "checkout " &&
2234 test_completion "git --work-tree some/path check" "checkout " &&
2235 test_completion "git --namespace name/space check" "checkout "
2238 test_expect_success 'git --help completion' '
2239 test_completion "git --help ad" "add " &&
2240 test_completion "git --help core" "core-tutorial "
2243 test_expect_success 'completion.commands removes multiple commands' '
2244 test_config completion.commands "-cherry -mergetool" &&
2245 git --list-cmds=list-mainporcelain,list-complete,config >out &&
2246 ! grep -E "^(cherry|mergetool)$" out
2249 test_expect_success 'setup for integration tests' '
2250 echo content >file1 &&
2252 git add file1 file2 &&
2253 git commit -m one &&
2254 git branch mybranch &&
2258 test_expect_success 'checkout completes ref names' '
2259 test_completion "git checkout m" <<-\EOF
2266 test_expect_success 'checkout does not match ref names of a different case' '
2267 test_completion "git checkout M" ""
2270 test_expect_success 'checkout matches case insensitively with GIT_COMPLETION_IGNORE_CASE' '
2272 GIT_COMPLETION_IGNORE_CASE=1 &&
2273 test_completion "git checkout M" <<-\EOF
2281 test_expect_success 'checkout completes pseudo refs' '
2282 test_completion "git checkout H" <<-\EOF
2287 test_expect_success 'checkout completes pseudo refs case insensitively with GIT_COMPLETION_IGNORE_CASE' '
2289 GIT_COMPLETION_IGNORE_CASE=1 &&
2290 test_completion "git checkout h" <<-\EOF
2296 test_expect_success 'git -C <path> checkout uses the right repo' '
2297 test_completion "git -C subdir -C subsubdir -C .. -C ../otherrepo checkout b" <<-\EOF
2302 test_expect_success 'show completes all refs' '
2303 test_completion "git show m" <<-\EOF
2310 test_expect_success '<ref>: completes paths' '
2311 test_completion "git show mytag:f" <<-\EOF
2317 test_expect_success 'complete tree filename with spaces' '
2318 echo content >"name with spaces" &&
2319 git add "name with spaces" &&
2320 git commit -m spaces &&
2321 test_completion "git show HEAD:nam" <<-\EOF
2326 test_expect_success 'complete tree filename with metacharacters' '
2327 echo content >"name with \${meta}" &&
2328 git add "name with \${meta}" &&
2329 git commit -m meta &&
2330 test_completion "git show HEAD:nam" <<-\EOF
2336 test_expect_success PERL 'send-email' '
2337 test_completion "git send-email --cov" <<-\EOF &&
2338 --cover-from-description=Z
2341 test_completion "git send-email --val" <<-\EOF &&
2344 test_completion "git send-email ma" "main "
2347 test_expect_success 'complete files' '
2348 git init tmp && cd tmp &&
2349 test_when_finished "cd .. && rm -rf tmp" &&
2351 echo "expected" > .gitignore &&
2352 echo "out" >> .gitignore &&
2353 echo "out_sorted" >> .gitignore &&
2355 git add .gitignore &&
2356 test_completion "git commit " ".gitignore" &&
2358 git commit -m ignore &&
2361 test_completion "git add " "new" &&
2364 git commit -a -m new &&
2365 test_completion "git add " "" &&
2367 git mv new modified &&
2368 echo modify > modified &&
2369 test_completion "git add " "modified" &&
2371 mkdir -p some/deep &&
2372 touch some/deep/path &&
2373 test_completion "git add some/" "some/deep" &&
2374 git clean -f some &&
2378 : TODO .gitignore should not be here &&
2379 test_completion "git rm " <<-\EOF &&
2384 test_completion "git clean " "untracked" &&
2386 : TODO .gitignore should not be here &&
2387 test_completion "git mv " <<-\EOF &&
2393 touch dir/file-in-dir &&
2394 git add dir/file-in-dir &&
2395 git commit -m dir &&
2397 mkdir untracked-dir &&
2399 : TODO .gitignore should not be here &&
2400 test_completion "git mv modified " <<-\EOF &&
2408 test_completion "git commit " "modified" &&
2410 : TODO .gitignore should not be here &&
2411 test_completion "git ls-files " <<-\EOF &&
2418 test_completion "git add mom" "momified"
2421 test_expect_success "simple alias" '
2422 test_config alias.co checkout &&
2423 test_completion "git co m" <<-\EOF
2430 test_expect_success "recursive alias" '
2431 test_config alias.co checkout &&
2432 test_config alias.cod "co --detached" &&
2433 test_completion "git cod m" <<-\EOF
2440 test_expect_success "completion uses <cmd> completion for alias: !sh -c 'git <cmd> ...'" '
2441 test_config alias.co "!sh -c '"'"'git checkout ...'"'"'" &&
2442 test_completion "git co m" <<-\EOF
2449 test_expect_success 'completion uses <cmd> completion for alias: !f () { VAR=val git <cmd> ... }' '
2450 test_config alias.co "!f () { VAR=val git checkout ... ; } f" &&
2451 test_completion "git co m" <<-\EOF
2458 test_expect_success 'completion used <cmd> completion for alias: !f() { : git <cmd> ; ... }' '
2459 test_config alias.co "!f() { : git checkout ; if ... } f" &&
2460 test_completion "git co m" <<-\EOF
2467 test_expect_success 'completion without explicit _git_xxx function' '
2468 test_completion "git version --" <<-\EOF
2470 --no-build-options Z
2474 test_expect_failure 'complete with tilde expansion' '
2475 git init tmp && cd tmp &&
2476 test_when_finished "cd .. && rm -rf tmp" &&
2480 test_completion "git add ~/tmp/" "~/tmp/file"
2483 test_expect_success 'setup other remote for remote reference completion' '
2484 git remote add other otherrepo &&
2488 for flag in -d --delete
2490 test_expect_success "__git_complete_remote_or_refspec - push
$flag other
" '
2491 sed -e "s
/Z$
//" >expected <<-EOF &&
2495 words=(git push '$flag' other ma) &&
2496 cword=${#words[@]} cur=${words[cword-1]} &&
2498 __git_complete_remote_or_refspec &&
2501 test_cmp expected out
2504 test_expect_failure "__git_complete_remote_or_refspec
- push other
$flag" '
2505 sed -e "s
/Z$
//" >expected <<-EOF &&
2509 words=(git push other '$flag' ma) &&
2510 cword=${#words[@]} cur=${words[cword-1]} &&
2512 __git_complete_remote_or_refspec &&
2515 test_cmp expected out
2519 test_expect_success 'git config - section' '
2520 test_completion "git config br
" <<-\EOF
2526 test_expect_success 'git config - section include, includeIf' '
2527 test_completion "git config inclu
" <<-\EOF
2533 test_expect_success 'git config - variable name' '
2534 test_completion "git config log.d
" <<-\EOF
2541 test_expect_success 'git config - variable name include' '
2542 test_completion "git config include.p
" <<-\EOF
2547 test_expect_success 'git config - value' '
2548 test_completion "git config color.pager
" <<-\EOF
2554 test_expect_success 'git -c - section' '
2555 test_completion "git
-c br
" <<-\EOF
2561 test_expect_success 'git -c - variable name' '
2562 test_completion "git
-c log.d
" <<-\EOF
2569 test_expect_success 'git -c - value' '
2570 test_completion "git
-c color.pager
=" <<-\EOF
2576 test_expect_success 'git clone --config= - section' '
2577 test_completion "git clone
--config=br
" <<-\EOF
2583 test_expect_success 'git clone --config= - variable name' '
2584 test_completion "git clone
--config=log.d
" <<-\EOF
2591 test_expect_success 'git clone --config= - value' '
2592 test_completion "git clone
--config=color.pager
=" <<-\EOF
2598 test_expect_success 'options with value' '
2599 test_completion "git merge
-X diff-algorithm
=" <<-\EOF
2604 test_expect_success 'sourcing the completion script clears cached commands' '
2606 __git_compute_all_commands &&
2607 test -n "$__git_all_commands" &&
2608 . "$GIT_BUILD_DIR/contrib
/completion
/git-completion.bash
" &&
2609 test -z "$__git_all_commands"
2613 test_expect_success 'sourcing the completion script clears cached merge strategies' '
2615 __git_compute_merge_strategies &&
2616 test -n "$__git_merge_strategies" &&
2617 . "$GIT_BUILD_DIR/contrib
/completion
/git-completion.bash
" &&
2618 test -z "$__git_merge_strategies"
2622 test_expect_success 'sourcing the completion script clears cached --options' '
2624 __gitcomp_builtin checkout &&
2625 test -n "$__gitcomp_builtin_checkout" &&
2626 __gitcomp_builtin notes_edit &&
2627 test -n "$__gitcomp_builtin_notes_edit" &&
2628 . "$GIT_BUILD_DIR/contrib
/completion
/git-completion.bash
" &&
2629 test -z "$__gitcomp_builtin_checkout" &&
2630 test -z "$__gitcomp_builtin_notes_edit"
2634 test_expect_success 'option aliases are not shown by default' '
2635 test_completion "git clone
--recurs" "--recurse-submodules "
2638 test_expect_success 'option aliases are shown with GIT_COMPLETION_SHOW_ALL' '
2640 . "$GIT_BUILD_DIR/contrib
/completion
/git-completion.bash
" &&
2641 GIT_COMPLETION_SHOW_ALL=1 && export GIT_COMPLETION_SHOW_ALL &&
2642 test_completion "git clone
--recurs" <<-\EOF
2643 --recurse-submodules Z
2649 test_expect_success 'plumbing commands are excluded without GIT_COMPLETION_SHOW_ALL_COMMANDS' '
2651 . "$GIT_BUILD_DIR/contrib
/completion
/git-completion.bash
" &&
2652 sane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST &&
2654 # Just mainporcelain, not plumbing commands
2655 run_completion "git c
" &&
2656 grep checkout out &&
2661 test_expect_success 'all commands are shown with GIT_COMPLETION_SHOW_ALL_COMMANDS (also main non-builtin)' '
2663 . "$GIT_BUILD_DIR/contrib
/completion
/git-completion.bash
" &&
2664 GIT_COMPLETION_SHOW_ALL_COMMANDS=1 &&
2665 export GIT_COMPLETION_SHOW_ALL_COMMANDS &&
2666 sane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST &&
2668 # Both mainporcelain and plumbing commands
2669 run_completion "git c
" &&
2670 grep checkout out &&
2671 grep cat-file out &&
2673 # Check "gitk
", a "main
" command, but not a built-in + more plumbing
2674 run_completion "git g
" &&
2676 grep get-tar-commit-id out
2680 test_expect_success '__git_complete' '
2681 unset -f __git_wrap__git_main &&
2683 __git_complete foo __git_main &&
2684 __git_have_func __git_wrap__git_main &&
2685 unset -f __git_wrap__git_main &&
2687 __git_complete gf _git_fetch &&
2688 __git_have_func __git_wrap_git_fetch &&
2690 __git_complete foo git &&
2691 __git_have_func __git_wrap__git_main &&
2692 unset -f __git_wrap__git_main &&
2694 __git_complete gd git_diff &&
2695 __git_have_func __git_wrap_git_diff &&
2697 test_must_fail __git_complete ga missing