3 # Copyright (c) 2012-2020 Felipe Contreras
6 test_description
='test bash completion'
8 # Override environment and always use master for the default initial branch
9 # name for these tests, so that rev completion candidates are as expected.
10 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=master
11 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
21 # Be careful when updating these lists:
23 # (1) The build tree may have build artifact from different branch, or
24 # the user's $PATH may have a random executable that may begin
25 # with "git-check" that are not part of the subcommands this build
26 # will ship, e.g. "check-ignore". The tests for completion for
27 # subcommand names tests how "check" is expanded; we limit the
28 # possible candidates to "checkout" and "check-attr" to make sure
29 # "check-attr", which is known by the filter function as a
30 # subcommand to be thrown out, while excluding other random files
31 # that happen to begin with "check" to avoid letting them get in
34 # (2) A test makes sure that common subcommands are included in the
35 # completion for "git <TAB>", and a plumbing is excluded. "add",
36 # "rebase" and "ls-files" are listed for this.
38 GIT_TESTING_ALL_COMMAND_LIST
='add checkout check-attr rebase ls-files'
39 GIT_TESTING_PORCELAIN_COMMAND_LIST
='add checkout rebase'
41 .
"$GIT_BUILD_DIR/contrib/completion/git-completion.bash"
43 # We don't need this function to actually join words or do anything special.
44 # Also, it's cleaner to avoid touching bash's internal completion variables.
45 # So let's override it with a minimal version for testing purposes.
46 _get_comp_words_by_ref
()
48 while [ $# -gt 0 ]; do
54 prev
=${_words[_cword-1]}
57 words
=("${_words[@]}")
70 echo "${COMPREPLY[*]}" > out
75 local -a COMPREPLY _words
78 test "${1: -1}" = ' ' && _words
[${#_words[@]}+1]=''
79 (( _cword
= ${#_words[@]} - 1 ))
80 __git_wrap__git_main
&& print_comp
83 # Test high-level completion
85 # 1: typed text so far (cur)
86 # 2: expected completion
91 printf '%s\n' "$2" >expected
93 sed -e 's/Z$//' |
sort >expected
95 run_completion
"$1" &&
96 sort out
>out_sorted
&&
97 test_cmp expected out_sorted
101 # The first argument is the typed text so far (cur); the rest are
102 # passed to __gitcomp. Expected output comes is read from the
103 # standard input, like test_completion().
106 local -a COMPREPLY
&&
107 sed -e 's/Z$//' >expected
&&
112 test_cmp expected out
117 # 1: current word (cur)
118 # -: the rest are passed to __gitcomp_nl
121 local -a COMPREPLY
&&
122 sed -e 's/Z$//' >expected
&&
127 test_cmp expected out
130 invalid_variable_name
='${foo.bar}'
132 actual
="$TRASH_DIRECTORY/actual"
134 if test_have_prereq MINGW
141 test_expect_success
'setup for __git_find_repo_path/__gitdir tests' '
142 mkdir -p subdir/subsubdir &&
144 git init -b main otherrepo
147 test_expect_success
'__git_find_repo_path - from command line (through $__git_dir)' '
148 echo "$ROOT/otherrepo/.git" >expected &&
150 __git_dir="$ROOT/otherrepo/.git" &&
151 __git_find_repo_path &&
152 echo "$__git_repo_path" >"$actual"
154 test_cmp expected "$actual"
157 test_expect_success
'__git_find_repo_path - .git directory in cwd' '
158 echo ".git" >expected &&
160 __git_find_repo_path &&
161 echo "$__git_repo_path" >"$actual"
163 test_cmp expected "$actual"
166 test_expect_success
'__git_find_repo_path - .git directory in parent' '
167 echo "$ROOT/.git" >expected &&
169 cd subdir/subsubdir &&
170 __git_find_repo_path &&
171 echo "$__git_repo_path" >"$actual"
173 test_cmp expected "$actual"
176 test_expect_success
'__git_find_repo_path - cwd is a .git directory' '
177 echo "." >expected &&
180 __git_find_repo_path &&
181 echo "$__git_repo_path" >"$actual"
183 test_cmp expected "$actual"
186 test_expect_success
'__git_find_repo_path - parent is a .git directory' '
187 echo "$ROOT/.git" >expected &&
190 __git_find_repo_path &&
191 echo "$__git_repo_path" >"$actual"
193 test_cmp expected "$actual"
196 test_expect_success
'__git_find_repo_path - $GIT_DIR set while .git directory in cwd' '
197 echo "$ROOT/otherrepo/.git" >expected &&
199 GIT_DIR="$ROOT/otherrepo/.git" &&
201 __git_find_repo_path &&
202 echo "$__git_repo_path" >"$actual"
204 test_cmp expected "$actual"
207 test_expect_success
'__git_find_repo_path - $GIT_DIR set while .git directory in parent' '
208 echo "$ROOT/otherrepo/.git" >expected &&
210 GIT_DIR="$ROOT/otherrepo/.git" &&
213 __git_find_repo_path &&
214 echo "$__git_repo_path" >"$actual"
216 test_cmp expected "$actual"
219 test_expect_success
'__git_find_repo_path - from command line while "git -C"' '
220 echo "$ROOT/.git" >expected &&
222 __git_dir="$ROOT/.git" &&
223 __git_C_args=(-C otherrepo) &&
224 __git_find_repo_path &&
225 echo "$__git_repo_path" >"$actual"
227 test_cmp expected "$actual"
230 test_expect_success
'__git_find_repo_path - relative dir from command line and "git -C"' '
231 echo "$ROOT/otherrepo/.git" >expected &&
234 __git_dir="otherrepo/.git" &&
235 __git_C_args=(-C ..) &&
236 __git_find_repo_path &&
237 echo "$__git_repo_path" >"$actual"
239 test_cmp expected "$actual"
242 test_expect_success
'__git_find_repo_path - $GIT_DIR set while "git -C"' '
243 echo "$ROOT/.git" >expected &&
245 GIT_DIR="$ROOT/.git" &&
247 __git_C_args=(-C otherrepo) &&
248 __git_find_repo_path &&
249 echo "$__git_repo_path" >"$actual"
251 test_cmp expected "$actual"
254 test_expect_success
'__git_find_repo_path - relative dir in $GIT_DIR and "git -C"' '
255 echo "$ROOT/otherrepo/.git" >expected &&
258 GIT_DIR="otherrepo/.git" &&
260 __git_C_args=(-C ..) &&
261 __git_find_repo_path &&
262 echo "$__git_repo_path" >"$actual"
264 test_cmp expected "$actual"
267 test_expect_success
'__git_find_repo_path - "git -C" while .git directory in cwd' '
268 echo "$ROOT/otherrepo/.git" >expected &&
270 __git_C_args=(-C otherrepo) &&
271 __git_find_repo_path &&
272 echo "$__git_repo_path" >"$actual"
274 test_cmp expected "$actual"
277 test_expect_success
'__git_find_repo_path - "git -C" while cwd is a .git directory' '
278 echo "$ROOT/otherrepo/.git" >expected &&
281 __git_C_args=(-C .. -C otherrepo) &&
282 __git_find_repo_path &&
283 echo "$__git_repo_path" >"$actual"
285 test_cmp expected "$actual"
288 test_expect_success
'__git_find_repo_path - "git -C" while .git directory in parent' '
289 echo "$ROOT/otherrepo/.git" >expected &&
292 __git_C_args=(-C .. -C otherrepo) &&
293 __git_find_repo_path &&
294 echo "$__git_repo_path" >"$actual"
296 test_cmp expected "$actual"
299 test_expect_success
'__git_find_repo_path - non-existing path in "git -C"' '
301 __git_C_args=(-C non-existing) &&
302 test_must_fail __git_find_repo_path &&
303 printf "$__git_repo_path" >"$actual"
305 test_must_be_empty "$actual"
308 test_expect_success
'__git_find_repo_path - non-existing path in $__git_dir' '
310 __git_dir="non-existing" &&
311 test_must_fail __git_find_repo_path &&
312 printf "$__git_repo_path" >"$actual"
314 test_must_be_empty "$actual"
317 test_expect_success
'__git_find_repo_path - non-existing $GIT_DIR' '
319 GIT_DIR="$ROOT/non-existing" &&
321 test_must_fail __git_find_repo_path &&
322 printf "$__git_repo_path" >"$actual"
324 test_must_be_empty "$actual"
327 test_expect_success
'__git_find_repo_path - gitfile in cwd' '
328 echo "$ROOT/otherrepo/.git" >expected &&
329 echo "gitdir: $ROOT/otherrepo/.git" >subdir/.git &&
330 test_when_finished "rm -f subdir/.git" &&
333 __git_find_repo_path &&
334 echo "$__git_repo_path" >"$actual"
336 test_cmp expected "$actual"
339 test_expect_success
'__git_find_repo_path - gitfile in parent' '
340 echo "$ROOT/otherrepo/.git" >expected &&
341 echo "gitdir: $ROOT/otherrepo/.git" >subdir/.git &&
342 test_when_finished "rm -f subdir/.git" &&
344 cd subdir/subsubdir &&
345 __git_find_repo_path &&
346 echo "$__git_repo_path" >"$actual"
348 test_cmp expected "$actual"
351 test_expect_success SYMLINKS
'__git_find_repo_path - resulting path avoids symlinks' '
352 echo "$ROOT/otherrepo/.git" >expected &&
353 mkdir otherrepo/dir &&
354 test_when_finished "rm -rf otherrepo/dir" &&
355 ln -s otherrepo/dir link &&
356 test_when_finished "rm -f link" &&
359 __git_find_repo_path &&
360 echo "$__git_repo_path" >"$actual"
362 test_cmp expected "$actual"
365 test_expect_success
'__git_find_repo_path - not a git repository' '
368 GIT_CEILING_DIRECTORIES="$ROOT" &&
369 export GIT_CEILING_DIRECTORIES &&
370 test_must_fail __git_find_repo_path &&
371 printf "$__git_repo_path" >"$actual"
373 test_must_be_empty "$actual"
376 test_expect_success
'__gitdir - finds repo' '
377 echo "$ROOT/.git" >expected &&
379 cd subdir/subsubdir &&
382 test_cmp expected "$actual"
386 test_expect_success
'__gitdir - returns error when cannot find repo' '
388 __git_dir="non-existing" &&
389 test_must_fail __gitdir >"$actual"
391 test_must_be_empty "$actual"
394 test_expect_success
'__gitdir - repo as argument' '
395 echo "otherrepo/.git" >expected &&
397 __gitdir "otherrepo" >"$actual"
399 test_cmp expected "$actual"
402 test_expect_success
'__gitdir - remote as argument' '
403 echo "remote" >expected &&
405 __gitdir "remote" >"$actual"
407 test_cmp expected "$actual"
411 test_expect_success
'__git_dequote - plain unquoted word' '
412 __git_dequote unquoted-word &&
413 test unquoted-word = "$dequoted_word"
416 # input: b\a\c\k\'\\\"s\l\a\s\h\es
417 # expected: back'\"slashes
418 test_expect_success
'__git_dequote - backslash escaped' '
419 __git_dequote "b\a\c\k\\'\''\\\\\\\"s\l\a\s\h\es" &&
420 test "back'\''\\\"slashes" = "$dequoted_word"
423 # input: sin'gle\' '"quo'ted
424 # expected: single\ "quoted
425 test_expect_success
'__git_dequote - single quoted' '
426 __git_dequote "'"sin'gle\\\\' '\\\"quo'ted"'" &&
427 test '\''single\ "quoted'\'' = "$dequoted_word"
430 # input: dou"ble\\" "\"\quot"ed
431 # expected: double\ "\quoted
432 test_expect_success
'__git_dequote - double quoted' '
433 __git_dequote '\''dou"ble\\" "\"\quot"ed'\'' &&
434 test '\''double\ "\quoted'\'' = "$dequoted_word"
437 # input: 'open single quote
438 test_expect_success
'__git_dequote - open single quote' '
439 __git_dequote "'\''open single quote" &&
440 test "open single quote" = "$dequoted_word"
443 # input: "open double quote
444 test_expect_success
'__git_dequote - open double quote' '
445 __git_dequote "\"open double quote" &&
446 test "open double quote" = "$dequoted_word"
450 test_expect_success
'__gitcomp_direct - puts everything into COMPREPLY as-is' '
451 sed -e "s/Z$//g" >expected <<-EOF &&
452 with-trailing-space Z
453 without-trailing-spaceZ
456 $invalid_variable_name Z
459 cur=should_be_ignored &&
460 __gitcomp_direct "$(cat expected)" &&
463 test_cmp expected out
466 test_expect_success
'__gitcomp - trailing space - options' '
467 test_gitcomp "--re" "--dry-run --reuse-message= --reedit-message=
468 --reset-author" <<-EOF
475 test_expect_success
'__gitcomp - trailing space - config keys' '
476 test_gitcomp "br" "branch. branch.autosetupmerge
477 branch.autosetuprebase browser." <<-\EOF
479 branch.autosetupmerge Z
480 branch.autosetuprebase Z
485 test_expect_success
'__gitcomp - option parameter' '
486 test_gitcomp "--strategy=re" "octopus ours recursive resolve subtree" \
493 test_expect_success
'__gitcomp - prefix' '
494 test_gitcomp "branch.me" "remote merge mergeoptions rebase" \
495 "branch.maint." "me" <<-\EOF
497 branch.maint.mergeoptions Z
501 test_expect_success
'__gitcomp - suffix' '
502 test_gitcomp "branch.me" "master maint next seen" "branch." \
509 test_expect_success
'__gitcomp - ignore optional negative options' '
510 test_gitcomp "--" "--abc --def --no-one -- --no-two" <<-\EOF
518 test_expect_success
'__gitcomp - ignore/narrow optional negative options' '
519 test_gitcomp "--a" "--abc --abcdef --no-one -- --no-two" <<-\EOF
525 test_expect_success
'__gitcomp - ignore/narrow optional negative options' '
526 test_gitcomp "--n" "--abc --def --no-one -- --no-two" <<-\EOF
532 test_expect_success
'__gitcomp - expand all negative options' '
533 test_gitcomp "--no-" "--abc --def --no-one -- --no-two" <<-\EOF
539 test_expect_success
'__gitcomp - expand/narrow all negative options' '
540 test_gitcomp "--no-o" "--abc --def --no-one -- --no-two" <<-\EOF
545 test_expect_success
'__gitcomp - equal skip' '
546 test_gitcomp "--option=" "--option=" <<-\EOF &&
549 test_gitcomp "option=" "option=" <<-\EOF
554 test_expect_success
'__gitcomp - doesnt fail because of invalid variable name' '
555 __gitcomp "$invalid_variable_name"
558 read -r -d "" refs
<<-\EOF
565 test_expect_success '__gitcomp_nl - trailing space
' '
566 test_gitcomp_nl
"m" "$refs" <<-EOF
572 test_expect_success '__gitcomp_nl
- prefix
' '
573 test_gitcomp_nl
"--fixup=m" "$refs" "--fixup=" "m" <<-EOF
579 test_expect_success '__gitcomp_nl
- suffix
' '
580 test_gitcomp_nl
"branch.ma" "$refs" "branch." "ma" "." <<-\EOF
586 test_expect_success '__gitcomp_nl - no suffix
' '
587 test_gitcomp_nl
"ma" "$refs" "" "ma" "" <<-\EOF
593 test_expect_success '__gitcomp_nl - doesnt fail because of invalid variable name
' '
594 __gitcomp_nl
"$invalid_variable_name"
597 test_expect_success '__git_remotes
- list remotes from
$GIT_DIR/remotes and from config
file' '
598 cat >expect
<<-EOF &&
604 test_when_finished
"rm -rf .git/remotes" &&
605 mkdir
-p .git
/remotes
&&
606 >.git
/remotes
/remote_from_file_1
&&
607 >.git
/remotes
/remote_from_file_2
&&
608 test_when_finished
"git remote remove remote_in_config_1" &&
609 git remote add remote_in_config_1 git
://remote_1
&&
610 test_when_finished
"git remote remove remote_in_config_2" &&
611 git remote add remote_in_config_2 git
://remote_2
&&
613 __git_remotes
>actual
615 test_cmp expect actual
618 test_expect_success '__git_is_configured_remote
' '
619 test_when_finished
"git remote remove remote_1" &&
620 git remote add remote_1 git
://remote_1
&&
621 test_when_finished
"git remote remove remote_2" &&
622 git remote add remote_2 git
://remote_2
&&
624 __git_is_configured_remote remote_2
&&
625 test_must_fail __git_is_configured_remote non-existent
629 test_expect_success 'setup
for ref completion
' '
630 git commit
--allow-empty -m initial
&&
631 git branch
-M main
&&
632 git branch matching-branch
&&
633 git tag matching-tag
&&
636 git commit
--allow-empty -m initial
&&
637 git branch
-m main main-in-other
&&
638 git branch branch-in-other
&&
641 git remote add other
"$ROOT/otherrepo/.git" &&
642 git fetch
--no-tags other
&&
643 rm -f .git
/FETCH_HEAD
&&
647 test_expect_success '__git_refs
- simple
' '
648 cat >expected
<<-EOF &&
652 other/branch-in-other
658 __git_refs
>"$actual"
660 test_cmp expected
"$actual"
663 test_expect_success '__git_refs
- full refs
' '
664 cat >expected
<<-EOF &&
666 refs/heads/matching-branch
667 refs/remotes/other/branch-in-other
668 refs/remotes/other/main-in-other
669 refs/tags/matching-tag
673 __git_refs
>"$actual"
675 test_cmp expected
"$actual"
678 test_expect_success '__git_refs
- repo given on the
command line
' '
679 cat >expected
<<-EOF &&
686 __git_dir
="$ROOT/otherrepo/.git" &&
688 __git_refs
>"$actual"
690 test_cmp expected
"$actual"
693 test_expect_success '__git_refs
- remote on
local file system
' '
694 cat >expected
<<-EOF &&
702 __git_refs otherrepo
>"$actual"
704 test_cmp expected
"$actual"
707 test_expect_success '__git_refs
- remote on
local file system
- full refs
' '
708 cat >expected
<<-EOF &&
709 refs/heads/branch-in-other
710 refs/heads/main-in-other
711 refs/tags/tag-in-other
715 __git_refs otherrepo
>"$actual"
717 test_cmp expected
"$actual"
720 test_expect_success '__git_refs
- configured remote
' '
721 cat >expected
<<-EOF &&
728 __git_refs other
>"$actual"
730 test_cmp expected
"$actual"
733 test_expect_success '__git_refs
- configured remote
- full refs
' '
734 cat >expected
<<-EOF &&
736 refs/heads/branch-in-other
737 refs/heads/main-in-other
738 refs/tags/tag-in-other
742 __git_refs other
>"$actual"
744 test_cmp expected
"$actual"
747 test_expect_success '__git_refs
- configured remote
- repo given on the
command line
' '
748 cat >expected
<<-EOF &&
755 __git_dir
="$ROOT/.git" &&
757 __git_refs other
>"$actual"
759 test_cmp expected
"$actual"
762 test_expect_success '__git_refs
- configured remote
- full refs
- repo given on the
command line
' '
763 cat >expected
<<-EOF &&
765 refs/heads/branch-in-other
766 refs/heads/main-in-other
767 refs/tags/tag-in-other
771 __git_dir
="$ROOT/.git" &&
773 __git_refs other
>"$actual"
775 test_cmp expected
"$actual"
778 test_expect_success '__git_refs
- configured remote
- remote name matches a directory
' '
779 cat >expected
<<-EOF &&
785 test_when_finished
"rm -rf other" &&
788 __git_refs other
>"$actual"
790 test_cmp expected
"$actual"
793 test_expect_success '__git_refs
- URL remote
' '
794 cat >expected
<<-EOF &&
802 __git_refs
"file://$ROOT/otherrepo/.git" >"$actual"
804 test_cmp expected
"$actual"
807 test_expect_success '__git_refs
- URL remote
- full refs
' '
808 cat >expected
<<-EOF &&
810 refs/heads/branch-in-other
811 refs/heads/main-in-other
812 refs/tags/tag-in-other
816 __git_refs
"file://$ROOT/otherrepo/.git" >"$actual"
818 test_cmp expected
"$actual"
821 test_expect_success '__git_refs
- non-existing remote
' '
824 __git_refs non-existing
>"$actual"
826 test_must_be_empty
"$actual"
829 test_expect_success '__git_refs
- non-existing remote
- full refs
' '
832 __git_refs non-existing
>"$actual"
834 test_must_be_empty
"$actual"
837 test_expect_success '__git_refs
- non-existing URL remote
' '
840 __git_refs
"file://$ROOT/non-existing" >"$actual"
842 test_must_be_empty
"$actual"
845 test_expect_success '__git_refs
- non-existing URL remote
- full refs
' '
848 __git_refs
"file://$ROOT/non-existing" >"$actual"
850 test_must_be_empty
"$actual"
853 test_expect_success '__git_refs
- not
in a git repository
' '
855 GIT_CEILING_DIRECTORIES
="$ROOT" &&
856 export GIT_CEILING_DIRECTORIES
&&
859 __git_refs
>"$actual"
861 test_must_be_empty
"$actual"
864 test_expect_success '__git_refs
- unique remote branches
for git checkout DWIMery
' '
865 cat >expected
<<-EOF &&
870 other/branch-in-other
873 remote/branch-in-remote
879 for remote_ref
in refs
/remotes
/other
/ambiguous \
880 refs
/remotes
/remote
/ambiguous \
881 refs
/remotes
/remote
/branch-in-remote
883 git update-ref
$remote_ref main
&&
884 test_when_finished
"git update-ref -d $remote_ref" ||
return 1
888 __git_refs
"" 1 >"$actual"
890 test_cmp expected
"$actual"
893 test_expect_success '__git_refs
- after
--opt=' '
894 cat >expected
<<-EOF &&
898 other/branch-in-other
904 __git_refs
"" "" "" "" >"$actual"
906 test_cmp expected
"$actual"
909 test_expect_success '__git_refs
- after
--opt= - full refs
' '
910 cat >expected
<<-EOF &&
912 refs/heads/matching-branch
913 refs/remotes/other/branch-in-other
914 refs/remotes/other/main-in-other
915 refs/tags/matching-tag
919 __git_refs
"" "" "" refs
/ >"$actual"
921 test_cmp expected
"$actual"
924 test_expect_success '__git refs
- excluding refs
' '
925 cat >expected
<<-EOF &&
929 ^other/branch-in-other
935 __git_refs
>"$actual"
937 test_cmp expected
"$actual"
940 test_expect_success '__git refs
- excluding full refs
' '
941 cat >expected
<<-EOF &&
943 ^refs/heads/matching-branch
944 ^refs/remotes/other/branch-in-other
945 ^refs/remotes/other/main-in-other
946 ^refs/tags/matching-tag
950 __git_refs
>"$actual"
952 test_cmp expected
"$actual"
955 test_expect_success 'setup
for filtering matching refs
' '
956 git branch matching
/branch
&&
957 git tag matching
/tag
&&
958 git
-C otherrepo branch matching
/branch-in-other
&&
959 git fetch
--no-tags other
&&
960 rm -f .git
/FETCH_HEAD
963 test_expect_success '__git_refs
- do not filter refs unless told so
' '
964 cat >expected
<<-EOF &&
969 other/branch-in-other
971 other/matching/branch-in-other
977 __git_refs
>"$actual"
979 test_cmp expected
"$actual"
982 test_expect_success '__git_refs
- only matching refs
' '
983 cat >expected
<<-EOF &&
991 __git_refs
"" "" "" "$cur" >"$actual"
993 test_cmp expected
"$actual"
996 test_expect_success '__git_refs
- only matching refs
- full refs
' '
997 cat >expected
<<-EOF &&
998 refs/heads/matching-branch
999 refs/heads/matching/branch
1002 cur
=refs
/heads
/mat
&&
1003 __git_refs
"" "" "" "$cur" >"$actual"
1005 test_cmp expected
"$actual"
1008 test_expect_success '__git_refs
- only matching refs
- remote on
local file system
' '
1009 cat >expected
<<-EOF &&
1011 matching/branch-in-other
1015 __git_refs otherrepo
"" "" "$cur" >"$actual"
1017 test_cmp expected
"$actual"
1020 test_expect_success '__git_refs
- only matching refs
- configured remote
' '
1021 cat >expected
<<-EOF &&
1023 matching/branch-in-other
1027 __git_refs other
"" "" "$cur" >"$actual"
1029 test_cmp expected
"$actual"
1032 test_expect_success '__git_refs
- only matching refs
- remote
- full refs
' '
1033 cat >expected
<<-EOF &&
1034 refs/heads/main-in-other
1035 refs/heads/matching/branch-in-other
1038 cur
=refs
/heads
/ma
&&
1039 __git_refs other
"" "" "$cur" >"$actual"
1041 test_cmp expected
"$actual"
1044 test_expect_success '__git_refs
- only matching refs
- checkout DWIMery
' '
1045 cat >expected
<<-EOF &&
1050 matching/branch-in-other
1052 for remote_ref
in refs
/remotes
/other
/ambiguous \
1053 refs
/remotes
/remote
/ambiguous \
1054 refs
/remotes
/remote
/branch-in-remote
1056 git update-ref
$remote_ref main
&&
1057 test_when_finished
"git update-ref -d $remote_ref" ||
return 1
1061 __git_refs
"" 1 "" "$cur" >"$actual"
1063 test_cmp expected
"$actual"
1066 test_expect_success 'teardown after filtering matching refs
' '
1067 git branch
-d matching
/branch
&&
1068 git tag
-d matching
/tag
&&
1069 git update-ref
-d refs
/remotes
/other
/matching
/branch-in-other
&&
1070 git
-C otherrepo branch
-D matching
/branch-in-other
1073 test_expect_success '__git_refs
- for-each-ref format specifiers
in prefix
' '
1074 cat >expected
<<-EOF &&
1075 evil-%%-%42-%(refname)..main
1078 cur
="evil-%%-%42-%(refname)..mai" &&
1079 __git_refs
"" "" "evil-%%-%42-%(refname).." mai
>"$actual"
1081 test_cmp expected
"$actual"
1084 test_expect_success '__git_complete_refs
- simple
' '
1085 sed -e "s/Z$//" >expected
<<-EOF &&
1089 other/branch-in-other Z
1090 other/main-in-other Z
1095 __git_complete_refs
&&
1098 test_cmp expected out
1101 test_expect_success '__git_complete_refs
- matching
' '
1102 sed -e "s/Z$//" >expected
<<-EOF &&
1108 __git_complete_refs
&&
1111 test_cmp expected out
1114 test_expect_success '__git_complete_refs
- remote
' '
1115 sed -e "s/Z$//" >expected
<<-EOF &&
1122 __git_complete_refs
--remote=other
&&
1125 test_cmp expected out
1128 test_expect_success '__git_complete_refs
- track
' '
1129 sed -e "s/Z$//" >expected
<<-EOF &&
1133 other/branch-in-other Z
1134 other/main-in-other Z
1141 __git_complete_refs
--track &&
1144 test_cmp expected out
1147 test_expect_success '__git_complete_refs
- current word
' '
1148 sed -e "s/Z$//" >expected
<<-EOF &&
1153 cur
="--option=mat" &&
1154 __git_complete_refs
--cur="${cur#*=}" &&
1157 test_cmp expected out
1160 test_expect_success '__git_complete_refs
- prefix
' '
1161 sed -e "s/Z$//" >expected
<<-EOF &&
1162 v1.0..matching-branch Z
1163 v1.0..matching-tag Z
1167 __git_complete_refs
--pfx=v1.0..
--cur=mat
&&
1170 test_cmp expected out
1173 test_expect_success '__git_complete_refs
- suffix
' '
1174 cat >expected
<<-EOF &&
1178 other/branch-in-other.
1179 other/main-in-other.
1184 __git_complete_refs
--sfx=.
&&
1187 test_cmp expected out
1190 test_expect_success '__git_complete_fetch_refspecs
- simple
' '
1191 sed -e "s/Z$//" >expected
<<-EOF &&
1193 branch-in-other:branch-in-other Z
1194 main-in-other:main-in-other Z
1198 __git_complete_fetch_refspecs other
&&
1201 test_cmp expected out
1204 test_expect_success '__git_complete_fetch_refspecs
- matching
' '
1205 sed -e "s/Z$//" >expected
<<-EOF &&
1206 branch-in-other:branch-in-other Z
1210 __git_complete_fetch_refspecs other
"" br
&&
1213 test_cmp expected out
1216 test_expect_success '__git_complete_fetch_refspecs
- prefix
' '
1217 sed -e "s/Z$//" >expected
<<-EOF &&
1219 +branch-in-other:branch-in-other Z
1220 +main-in-other:main-in-other Z
1224 __git_complete_fetch_refspecs other
"+" "" &&
1227 test_cmp expected out
1230 test_expect_success '__git_complete_fetch_refspecs
- fully qualified
' '
1231 sed -e "s/Z$//" >expected
<<-EOF &&
1232 refs/heads/branch-in-other:refs/heads/branch-in-other Z
1233 refs/heads/main-in-other:refs/heads/main-in-other Z
1234 refs/tags/tag-in-other:refs/tags/tag-in-other Z
1238 __git_complete_fetch_refspecs other
"" refs
/ &&
1241 test_cmp expected out
1244 test_expect_success '__git_complete_fetch_refspecs
- fully qualified
& prefix
' '
1245 sed -e "s/Z$//" >expected
<<-EOF &&
1246 +refs/heads/branch-in-other:refs/heads/branch-in-other Z
1247 +refs/heads/main-in-other:refs/heads/main-in-other Z
1248 +refs/tags/tag-in-other:refs/tags/tag-in-other Z
1252 __git_complete_fetch_refspecs other
+ refs
/ &&
1255 test_cmp expected out
1258 test_expect_success 'git switch
- with no options
, complete
local branches and unique remote branch names
for DWIM logic
' '
1259 test_completion
"git switch " <<-\EOF
1267 test_expect_success 'git bisect - when not bisecting
, complete only replay and start subcommands
' '
1268 test_completion
"git bisect " <<-\EOF
1274 test_expect_success 'git bisect - complete options to start subcommand
' '
1275 test_completion
"git bisect start --" <<-\EOF
1285 test_expect_success 'setup for git-bisect tests requiring a repo' '
1286 git init git-bisect &&
1289 echo "initial contents" >file &&
1291 git commit -am "Initial commit" &&
1293 echo "new line" >>file &&
1294 git commit -am "First change" &&
1295 echo "another new line" >>file &&
1296 git commit -am "Second change" &&
1301 test_expect_success 'git bisect - start subcommand arguments before double-dash are completed as revs
' '
1304 test_completion
"git bisect start " <<-\EOF
1313 # Note that these arguments are <pathspec>s, which in practice the fallback
1314 # completion (not the git completion) later ends up completing as paths.
1315 test_expect_success 'git bisect - start subcommand arguments after double-dash are not completed
' '
1318 test_completion
"git bisect start final initial -- " ""
1322 test_expect_success 'setup
for git-bisect tests requiring ongoing bisection
' '
1325 git bisect start
--term-new=custom_new
--term-old=custom_old final initial
1329 test_expect_success 'git-bisect
- when bisecting all subcommands are candidates
' '
1332 test_completion
"git bisect " <<-\EOF
1352 test_expect_success 'git-bisect - options to terms subcommand are candidates
' '
1355 test_completion
"git bisect terms --" <<-\EOF
1364 test_expect_success 'git-bisect - git-log options to visualize subcommand are candidates
' '
1367 # The completion used for git-log and here does not complete
1368 # every git-log option, so rather than hope to stay in sync
1369 # with exactly what it does we will just spot-test here.
1370 test_completion
"git bisect visualize --sta" <<-\EOF &&
1373 test_completion "git bisect visualize --summar" <<-\
EOF
1379 test_expect_success 'git-bisect - view subcommand is not a candidate
' '
1382 test_completion
"git bisect vi" <<-\EOF
1388 test_expect_success 'git-bisect - existing view subcommand is recognized and enables completion of git-log options
' '
1391 # The completion used for git-log and here does not complete
1392 # every git-log option, so rather than hope to stay in sync
1393 # with exactly what it does we will just spot-test here.
1394 test_completion
"git bisect view --sta" <<-\EOF &&
1397 test_completion "git bisect view --summar" <<-\
EOF
1403 test_expect_success 'git checkout - completes refs and unique remote branches
for DWIM
' '
1404 test_completion
"git checkout " <<-\EOF
1411 other/branch-in-other Z
1412 other/main-in-other Z
1416 test_expect_success 'git switch - with
--no-guess, complete only
local branches
' '
1417 test_completion
"git switch --no-guess " <<-\EOF
1423 test_expect_success 'git switch - with GIT_COMPLETION_CHECKOUT_NO_GUESS
=1, complete only
local branches
' '
1424 GIT_COMPLETION_CHECKOUT_NO_GUESS
=1 test_completion
"git switch " <<-\EOF
1430 test_expect_success 'git switch - --guess overrides GIT_COMPLETION_CHECKOUT_NO_GUESS
=1, complete
local branches and unique remote names
for DWIM logic
' '
1431 GIT_COMPLETION_CHECKOUT_NO_GUESS
=1 test_completion
"git switch --guess " <<-\EOF
1439 test_expect_success 'git switch - a later
--guess overrides previous
--no-guess, complete
local and remote unique branches
for DWIM
' '
1440 test_completion
"git switch --no-guess --guess " <<-\EOF
1448 test_expect_success 'git switch - a later
--no-guess overrides previous
--guess, complete only
local branches
' '
1449 test_completion
"git switch --guess --no-guess " <<-\EOF
1455 test_expect_success 'git checkout - with GIT_COMPLETION_NO_GUESS
=1 only completes refs
' '
1456 GIT_COMPLETION_CHECKOUT_NO_GUESS
=1 test_completion
"git checkout " <<-\EOF
1461 other/branch-in-other Z
1462 other/main-in-other Z
1466 test_expect_success 'git checkout - --guess overrides GIT_COMPLETION_NO_GUESS
=1, complete refs and unique remote branches
for DWIM
' '
1467 GIT_COMPLETION_CHECKOUT_NO_GUESS
=1 test_completion
"git checkout --guess " <<-\EOF
1474 other/branch-in-other Z
1475 other/main-in-other Z
1479 test_expect_success 'git checkout - with
--no-guess, only completes refs
' '
1480 test_completion
"git checkout --no-guess " <<-\EOF
1485 other/branch-in-other Z
1486 other/main-in-other Z
1490 test_expect_success 'git checkout - a later
--guess overrides previous
--no-guess, complete refs and unique remote branches
for DWIM
' '
1491 test_completion
"git checkout --no-guess --guess " <<-\EOF
1498 other/branch-in-other Z
1499 other/main-in-other Z
1503 test_expect_success 'git checkout - a later
--no-guess overrides previous
--guess, complete only refs
' '
1504 test_completion
"git checkout --guess --no-guess " <<-\EOF
1509 other/branch-in-other Z
1510 other/main-in-other Z
1514 test_expect_success 'git checkout - with checkout.guess
= false
, only completes refs
' '
1515 test_config checkout.guess false
&&
1516 test_completion
"git checkout " <<-\EOF
1521 other/branch-in-other Z
1522 other/main-in-other Z
1526 test_expect_success 'git checkout - with checkout.guess
= true
, completes refs and unique remote branches
for DWIM
' '
1527 test_config checkout.guess true
&&
1528 test_completion
"git checkout " <<-\EOF
1535 other/branch-in-other Z
1536 other/main-in-other Z
1540 test_expect_success 'git checkout - a later
--guess overrides previous checkout.guess
= false
, complete refs and unique remote branches
for DWIM
' '
1541 test_config checkout.guess false
&&
1542 test_completion
"git checkout --guess " <<-\EOF
1549 other/branch-in-other Z
1550 other/main-in-other Z
1554 test_expect_success 'git checkout - a later
--no-guess overrides previous checkout.guess
= true
, complete only refs
' '
1555 test_config checkout.guess true
&&
1556 test_completion
"git checkout --no-guess " <<-\EOF
1561 other/branch-in-other Z
1562 other/main-in-other Z
1566 test_expect_success 'git switch - with
--detach, complete all references
' '
1567 test_completion
"git switch --detach " <<-\EOF
1572 other/branch-in-other Z
1573 other/main-in-other Z
1577 test_expect_success 'git checkout - with
--detach, complete only references
' '
1578 test_completion
"git checkout --detach " <<-\EOF
1583 other/branch-in-other Z
1584 other/main-in-other Z
1588 test_expect_success 'setup sparse-checkout tests' '
1589 # set up sparse-checkout repo
1590 git init sparse-checkout &&
1592 cd sparse-checkout &&
1593 mkdir -p folder1/0/1 folder2/0 folder3 &&
1594 touch folder1/0/1/t.txt &&
1595 touch folder2/0/t.txt &&
1596 touch folder3/t.txt &&
1598 git commit -am "Initial commit"
1602 test_expect_success 'sparse-checkout completes subcommands' '
1603 test_completion "git sparse-checkout " <<-\
EOF
1613 test_expect_success 'cone mode sparse-checkout completes directory names' '
1614 # initialize sparse-checkout definitions
1615 git -C sparse-checkout sparse-checkout set --cone folder1/0 folder3 &&
1617 # test tab completion
1619 cd sparse-checkout &&
1620 test_completion "git sparse-checkout set f" <<-\EOF
1628 cd sparse-checkout &&
1629 test_completion "git sparse-checkout set folder1/" <<-\EOF
1635 cd sparse-checkout &&
1636 test_completion "git sparse-checkout set folder1/0/" <<-\EOF
1642 cd sparse-checkout/folder1 &&
1643 test_completion "git sparse-checkout add 0" <<-\EOF
1649 test_expect_success 'cone mode sparse-checkout completes directory names with spaces and accents' '
1650 # reset sparse-checkout
1651 git -C sparse-checkout sparse-checkout disable &&
1653 cd sparse-checkout &&
1654 mkdir "directory with spaces" &&
1655 mkdir "directory-with-áccent" &&
1656 >"directory with spaces/randomfile" &&
1657 >"directory-with-áccent/randomfile" &&
1659 git commit -m "Add directory with spaces and directory with accent" &&
1660 git sparse-checkout set --cone "directory with spaces" \
1661 "directory-with-áccent" &&
1662 test_completion "git sparse-checkout add dir" <<-\EOF &&
1663 directory with spaces/
1664 directory-with-áccent/
1666 rm -rf "directory with spaces" &&
1667 rm -rf "directory-with-áccent" &&
1669 git commit -m "Remove directory with spaces and directory with accent"
1673 # use FUNNYNAMES to avoid running on Windows, which doesn't permit tabs in paths
1674 test_expect_success FUNNYNAMES 'cone mode sparse-checkout completes directory names with tabs' '
1675 # reset sparse-checkout
1676 git -C sparse-checkout sparse-checkout disable &&
1678 cd sparse-checkout &&
1679 mkdir "$(printf "directory\twith\ttabs")" &&
1680 >"$(printf "directory\twith\ttabs")/randomfile" &&
1682 git commit -m "Add directory with tabs" &&
1683 git sparse-checkout set --cone \
1684 "$(printf "directory\twith\ttabs")" &&
1685 test_completion "git sparse-checkout add dir" <<-\EOF &&
1686 directory with tabs/
1688 rm -rf "$(printf "directory\twith\ttabs")" &&
1690 git commit -m "Remove directory with tabs"
1694 # use FUNNYNAMES to avoid running on Windows, and !CYGWIN for Cygwin, as neither permit backslashes in paths
1695 test_expect_success FUNNYNAMES,!CYGWIN 'cone mode sparse-checkout completes directory names with backslashes' '
1696 # reset sparse-checkout
1697 git -C sparse-checkout sparse-checkout disable &&
1699 cd sparse-checkout &&
1700 mkdir "directory\with\backslashes" &&
1701 >"directory\with\backslashes/randomfile" &&
1703 git commit -m "Add directory with backslashes" &&
1704 git sparse-checkout set --cone \
1705 "directory\with\backslashes" &&
1706 test_completion "git sparse-checkout add dir" <<-\EOF &&
1707 directory\with\backslashes/
1709 rm -rf "directory\with\backslashes" &&
1711 git commit -m "Remove directory with backslashes"
1715 test_expect_success 'non-cone mode sparse-checkout gives rooted paths' '
1716 # reset sparse-checkout repo to non-cone mode
1717 git -C sparse-checkout sparse-checkout disable &&
1718 git -C sparse-checkout sparse-checkout set --no-cone &&
1721 cd sparse-checkout &&
1722 # expected to be empty since we have not configured
1723 # custom completion for non-cone mode
1724 test_completion "git sparse-checkout set f" <<-\EOF
1725 /folder1/0/1/t.txt Z
1728 /folder1/out_sorted Z
1735 test_expect_success 'git sparse-checkout set --cone completes directory names' '
1736 git -C sparse-checkout sparse-checkout disable &&
1739 cd sparse-checkout &&
1740 test_completion "git sparse-checkout set --cone f" <<-\EOF
1748 test_expect_success 'git switch - with
-d, complete all references
' '
1749 test_completion
"git switch -d " <<-\EOF
1754 other/branch-in-other Z
1755 other/main-in-other Z
1759 test_expect_success 'git checkout - with
-d, complete only references
' '
1760 test_completion
"git checkout -d " <<-\EOF
1765 other/branch-in-other Z
1766 other/main-in-other Z
1770 test_expect_success 'git switch - with
--track, complete only remote branches
' '
1771 test_completion
"git switch --track " <<-\EOF &&
1772 other/branch-in-other Z
1773 other/main-in-other Z
1775 test_completion "git switch -t " <<-\
EOF
1776 other/branch-in-other Z
1777 other/main-in-other Z
1781 test_expect_success 'git checkout - with
--track, complete only remote branches
' '
1782 test_completion
"git checkout --track " <<-\EOF &&
1783 other/branch-in-other Z
1784 other/main-in-other Z
1786 test_completion "git checkout -t " <<-\
EOF
1787 other/branch-in-other Z
1788 other/main-in-other Z
1792 test_expect_success 'git switch - with
--no-track, complete only
local branch names
' '
1793 test_completion
"git switch --no-track " <<-\EOF
1799 test_expect_success 'git checkout - with
--no-track, complete only
local references
' '
1800 test_completion
"git checkout --no-track " <<-\EOF
1805 other/branch-in-other Z
1806 other/main-in-other Z
1810 test_expect_success 'git switch - with
-c, complete all references
' '
1811 test_completion
"git switch -c new-branch " <<-\EOF
1816 other/branch-in-other Z
1817 other/main-in-other Z
1821 test_expect_success 'git switch - with
-C, complete all references
' '
1822 test_completion
"git switch -C new-branch " <<-\EOF
1827 other/branch-in-other Z
1828 other/main-in-other Z
1832 test_expect_success 'git switch - with
-c and
--track, complete all references
' '
1833 test_completion
"git switch -c new-branch --track " <<-EOF
1838 other/branch-in-other Z
1839 other/main-in-other Z
1843 test_expect_success 'git switch
- with
-C and
--track, complete all references
' '
1844 test_completion
"git switch -C new-branch --track " <<-EOF
1849 other/branch-in-other Z
1850 other/main-in-other Z
1854 test_expect_success 'git switch
- with
-c and
--no-track, complete all references
' '
1855 test_completion
"git switch -c new-branch --no-track " <<-\EOF
1860 other/branch-in-other Z
1861 other/main-in-other Z
1865 test_expect_success 'git switch - with
-C and
--no-track, complete all references
' '
1866 test_completion
"git switch -C new-branch --no-track " <<-\EOF
1871 other/branch-in-other Z
1872 other/main-in-other Z
1876 test_expect_success 'git checkout - with
-b, complete all references
' '
1877 test_completion
"git checkout -b new-branch " <<-\EOF
1882 other/branch-in-other Z
1883 other/main-in-other Z
1887 test_expect_success 'git checkout - with
-B, complete all references
' '
1888 test_completion
"git checkout -B new-branch " <<-\EOF
1893 other/branch-in-other Z
1894 other/main-in-other Z
1898 test_expect_success 'git checkout - with
-b and
--track, complete all references
' '
1899 test_completion
"git checkout -b new-branch --track " <<-EOF
1904 other/branch-in-other Z
1905 other/main-in-other Z
1909 test_expect_success 'git checkout
- with
-B and
--track, complete all references
' '
1910 test_completion
"git checkout -B new-branch --track " <<-EOF
1915 other/branch-in-other Z
1916 other/main-in-other Z
1920 test_expect_success 'git checkout
- with
-b and
--no-track, complete all references
' '
1921 test_completion
"git checkout -b new-branch --no-track " <<-\EOF
1926 other/branch-in-other Z
1927 other/main-in-other Z
1931 test_expect_success 'git checkout - with
-B and
--no-track, complete all references
' '
1932 test_completion
"git checkout -B new-branch --no-track " <<-\EOF
1937 other/branch-in-other Z
1938 other/main-in-other Z
1942 test_expect_success 'git switch - for -c, complete
local branches and unique remote branches
' '
1943 test_completion
"git switch -c " <<-\EOF
1951 test_expect_success 'git switch - for -C, complete
local branches and unique remote branches
' '
1952 test_completion
"git switch -C " <<-\EOF
1960 test_expect_success 'git switch - for -c with
--no-guess, complete
local branches only
' '
1961 test_completion
"git switch --no-guess -c " <<-\EOF
1967 test_expect_success 'git switch - for -C with
--no-guess, complete
local branches only
' '
1968 test_completion
"git switch --no-guess -C " <<-\EOF
1974 test_expect_success 'git switch - for -c with
--no-track, complete
local branches only
' '
1975 test_completion
"git switch --no-track -c " <<-\EOF
1981 test_expect_success 'git switch - for -C with
--no-track, complete
local branches only
' '
1982 test_completion
"git switch --no-track -C " <<-\EOF
1988 test_expect_success 'git checkout - for -b, complete
local branches and unique remote branches
' '
1989 test_completion
"git checkout -b " <<-\EOF
1997 test_expect_success 'git checkout - for -B, complete
local branches and unique remote branches
' '
1998 test_completion
"git checkout -B " <<-\EOF
2006 test_expect_success 'git checkout - for -b with
--no-guess, complete
local branches only
' '
2007 test_completion
"git checkout --no-guess -b " <<-\EOF
2013 test_expect_success 'git checkout - for -B with
--no-guess, complete
local branches only
' '
2014 test_completion
"git checkout --no-guess -B " <<-\EOF
2020 test_expect_success 'git checkout - for -b with
--no-track, complete
local branches only
' '
2021 test_completion
"git checkout --no-track -b " <<-\EOF
2027 test_expect_success 'git checkout - for -B with
--no-track, complete
local branches only
' '
2028 test_completion
"git checkout --no-track -B " <<-\EOF
2034 test_expect_success 'git switch - with
--orphan completes
local branch names and unique remote branch names
' '
2035 test_completion
"git switch --orphan " <<-\EOF
2043 test_expect_success 'git switch - --orphan with branch already provided completes nothing
else' '
2044 test_completion
"git switch --orphan main " <<-\EOF
2049 test_expect_success 'git checkout - with
--orphan completes
local branch names and unique remote branch names
' '
2050 test_completion
"git checkout --orphan " <<-\EOF
2058 test_expect_success 'git checkout - --orphan with branch already provided completes
local refs
for a start-point
' '
2059 test_completion
"git checkout --orphan main " <<-\EOF
2064 other/branch-in-other Z
2065 other/main-in-other Z
2069 test_expect_success 'teardown after ref completion' '
2070 git branch -d matching-branch &&
2071 git tag -d matching-tag &&
2072 git remote remove other
2076 test_path_completion ()
2078 test $# = 2 || BUG "not 2 parameters to test_path_completion"
2080 local cur="$1" expected="$2"
2081 echo "$expected" >expected &&
2083 # In the following tests calling this function we only
2084 # care about how __git_complete_index_file() deals with
2085 # unusual characters in path names. By requesting only
2086 # untracked files we do not have to bother adding any
2087 # paths to the index in those tests.
2088 __git_complete_index_file --others &&
2091 test_cmp expected out
2094 test_expect_success 'setup for path completion tests' '
2098 touch simple-dir/simple-file \
2099 "spaces in dir/spaces in file" \
2100 "árvíztűrő/Сайн яваарай" &&
2101 if test_have_prereq !MINGW &&
2103 '$'separators\034in\035dir'' &&
2104 touch BS\\dir/DQ\"file \
2105 '$'separators\034in\035dir/sep\036in\037file''
2107 test_set_prereq FUNNIERNAMES
2109 rm -rf BS\\dir '$'separators\034in\035dir''
2113 test_expect_success '__git_complete_index_file - simple
' '
2114 test_path_completion simple simple-dir
&& # Bash is supposed to
2115 # add the trailing /.
2116 test_path_completion simple-dir
/simple simple-dir
/simple-file
2119 test_expect_success \
2120 '__git_complete_index_file
- escaped characters on cmdline
' '
2121 test_path_completion spac
"spaces in dir" && # Bash will turn this
2122 # into "spaces\ in\ dir"
2123 test_path_completion
"spaces\\ i" \
2125 test_path_completion
"spaces\\ in\\ dir/s" \
2126 "spaces in dir/spaces in file" &&
2127 test_path_completion
"spaces\\ in\\ dir/spaces\\ i" \
2128 "spaces in dir/spaces in file"
2131 test_expect_success \
2132 '__git_complete_index_file
- quoted characters on cmdline
' '
2133 # Testing with an opening but without a corresponding closing
2134 # double quote is important.
2135 test_path_completion
\"spac
"spaces in dir" &&
2136 test_path_completion
"\"spaces i" \
2138 test_path_completion
"\"spaces in dir/s" \
2139 "spaces in dir/spaces in file" &&
2140 test_path_completion
"\"spaces in dir/spaces i" \
2141 "spaces in dir/spaces in file"
2144 test_expect_success '__git_complete_index_file
- UTF-8
in ls-files output
' '
2145 test_path_completion á árvíztűrő
&&
2146 test_path_completion árvíztűrő
/С
"árvíztűrő/Сайн яваарай"
2149 test_expect_success FUNNIERNAMES \
2150 '__git_complete_index_file
- C-style escapes
in ls-files output
' '
2151 test_path_completion BS \
2153 test_path_completion BS
\\\\d \
2155 test_path_completion BS
\\\\dir
/DQ \
2157 test_path_completion BS
\\\\dir
/DQ
\\\"f \
2161 test_expect_success FUNNIERNAMES \
2162 '__git_complete_index_file
- \nnn
-escaped characters
in ls-files output
' '
2163 test_path_completion sep
'$'separators
\034in\035dir
'' &&
2164 test_path_completion
'$'separators
\034i
'' \
2165 '$'separators
\034in\035dir
'' &&
2166 test_path_completion
'$'separators
\034in\035dir
/sep
'' \
2167 '$'separators
\034in\035dir
/sep
\036in\037file'' &&
2168 test_path_completion
'$'separators
\034in\035dir
/sep
\036i
'' \
2169 '$'separators
\034in\035dir
/sep
\036in\037file''
2172 test_expect_success FUNNYNAMES \
2173 '__git_complete_index_file
- removing repeated quoted path components
' '
2174 test_when_finished
rm -r repeated-quoted
&&
2175 mkdir repeated-quoted
&& # A directory whose name in itself
2176 # would not be quoted ...
2177 >repeated-quoted
/0-file &&
2178 >repeated-quoted
/1\"file && # ... but here the file makes the
2179 # dirname quoted ...
2180 >repeated-quoted
/2-file &&
2181 >repeated-quoted
/3\"file && # ... and here, too.
2183 # Still, we shold only list the directory name only once.
2184 test_path_completion repeated repeated-quoted
2187 test_expect_success 'teardown after path completion tests
' '
2188 rm -rf simple-dir
"spaces in dir" árvíztűrő \
2189 BS
\\dir
'$'separators
\034in\035dir
''
2192 test_expect_success '__git_find_on_cmdline
- single match
' '
2193 echo list
>expect
&&
2195 words
=(git
command --opt list
) &&
2196 cword
=${#words[@]} &&
2198 __git_find_on_cmdline
"add list remove" >actual
2200 test_cmp expect actual
2203 test_expect_success '__git_find_on_cmdline
- multiple matches
' '
2204 echo remove
>expect
&&
2206 words
=(git
command -o --opt remove list add
) &&
2207 cword
=${#words[@]} &&
2209 __git_find_on_cmdline
"add list remove" >actual
2211 test_cmp expect actual
2214 test_expect_success '__git_find_on_cmdline
- no match
' '
2216 words
=(git
command --opt branch
) &&
2217 cword
=${#words[@]} &&
2219 __git_find_on_cmdline
"add list remove" >actual
2221 test_must_be_empty actual
2224 test_expect_success '__git_find_on_cmdline
- single match with index
' '
2225 echo "3 list" >expect
&&
2227 words
=(git
command --opt list
) &&
2228 cword
=${#words[@]} &&
2230 __git_find_on_cmdline
--show-idx "add list remove" >actual
2232 test_cmp expect actual
2235 test_expect_success '__git_find_on_cmdline
- multiple matches with index
' '
2236 echo "4 remove" >expect
&&
2238 words
=(git
command -o --opt remove list add
) &&
2239 cword
=${#words[@]} &&
2241 __git_find_on_cmdline
--show-idx "add list remove" >actual
2243 test_cmp expect actual
2246 test_expect_success '__git_find_on_cmdline
- no match with index
' '
2248 words
=(git
command --opt branch
) &&
2249 cword
=${#words[@]} &&
2251 __git_find_on_cmdline
--show-idx "add list remove" >actual
2253 test_must_be_empty actual
2256 test_expect_success '__git_find_on_cmdline
- ignores matches before
command with index
' '
2257 echo "6 remove" >expect
&&
2259 words
=(git
-C remove
command -o --opt remove list add
) &&
2260 cword
=${#words[@]} &&
2262 __git_find_on_cmdline
--show-idx "add list remove" >actual
2264 test_cmp expect actual
2267 test_expect_success '__git_get_config_variables
' '
2268 cat >expect
<<-EOF &&
2272 test_config interesting.name-1 good
&&
2273 test_config interesting.name-2 good
&&
2274 test_config subsection.interesting.name-3 bad
&&
2275 __git_get_config_variables interesting
>actual
&&
2276 test_cmp expect actual
2279 test_expect_success '__git_pretty_aliases
' '
2280 cat >expect
<<-EOF &&
2284 test_config pretty.author
"%an %ae" &&
2285 test_config pretty.
hash %H
&&
2286 __git_pretty_aliases
>actual
&&
2287 test_cmp expect actual
2290 test_expect_success 'basic
' '
2291 run_completion
"git " &&
2293 grep -q "^add \$" out
&&
2295 grep -q "^rebase \$" out
&&
2297 ! grep -q "^ls-files \$" out
&&
2299 run_completion
"git r" &&
2300 ! grep -q -v "^r" out
2303 test_expect_success 'double dash
"git" itself
' '
2304 test_completion
"git --" <<-\EOF
2317 --no-replace-objects Z
2322 test_expect_success 'double dash "git checkout"' '
2323 test_completion "git checkout --" <<-\
EOF
2333 --ignore-skip-worktree-bits Z
2334 --ignore-other-worktrees Z
2335 --recurse-submodules Z
2341 --pathspec-file-nul Z
2342 --pathspec-from-file=Z
2346 test_expect_success 'general options' '
2347 test_completion "git --ver" "--version " &&
2348 test_completion "git --hel" "--help " &&
2349 test_completion "git --exe" <<-\EOF &&
2353 test_completion "git --htm" "--html-path " &&
2354 test_completion "git --pag" "--paginate " &&
2355 test_completion "git --no-p" "--no-pager " &&
2356 test_completion "git --git" "--git-dir=" &&
2357 test_completion "git --wor" "--work-tree=" &&
2358 test_completion "git --nam" "--namespace=" &&
2359 test_completion "git --bar" "--bare " &&
2360 test_completion "git --inf" "--info-path " &&
2361 test_completion "git --no-r" "--no-replace-objects "
2364 test_expect_success 'general options plus command' '
2365 test_completion "git --version check" "checkout " &&
2366 test_completion "git --paginate check" "checkout " &&
2367 test_completion "git --git-dir=foo check" "checkout " &&
2368 test_completion "git --bare check" "checkout " &&
2369 test_completion "git --exec-path=foo check" "checkout " &&
2370 test_completion "git --html-path check" "checkout " &&
2371 test_completion "git --no-pager check" "checkout " &&
2372 test_completion "git --work-tree=foo check" "checkout " &&
2373 test_completion "git --namespace=foo check" "checkout " &&
2374 test_completion "git --paginate check" "checkout " &&
2375 test_completion "git --info-path check" "checkout " &&
2376 test_completion "git --no-replace-objects check" "checkout " &&
2377 test_completion "git --git-dir some/path check" "checkout " &&
2378 test_completion "git -c conf.var=value check" "checkout " &&
2379 test_completion "git -C some/path check" "checkout " &&
2380 test_completion "git --work-tree some/path check" "checkout " &&
2381 test_completion "git --namespace name/space check" "checkout "
2384 test_expect_success 'git --help completion' '
2385 test_completion "git --help ad" "add " &&
2386 test_completion "git --help core" "core-tutorial "
2389 test_expect_success 'completion.commands removes multiple commands' '
2390 test_config completion.commands "-cherry -mergetool" &&
2391 git --list-cmds=list-mainporcelain,list-complete,config >out &&
2392 ! grep -E "^(cherry|mergetool)$" out
2395 test_expect_success 'setup for integration tests' '
2396 echo content >file1 &&
2398 git add file1 file2 &&
2399 git commit -m one &&
2400 git branch mybranch &&
2404 test_expect_success 'checkout completes ref names' '
2405 test_completion "git checkout m" <<-\EOF
2412 test_expect_success 'checkout does not match ref names of a different case' '
2413 test_completion "git checkout M" ""
2416 test_expect_success 'checkout matches case insensitively with GIT_COMPLETION_IGNORE_CASE' '
2418 GIT_COMPLETION_IGNORE_CASE=1 &&
2419 test_completion "git checkout M" <<-\EOF
2427 test_expect_success 'checkout completes pseudo refs' '
2428 test_completion "git checkout H" <<-\EOF
2433 test_expect_success 'checkout completes pseudo refs case insensitively with GIT_COMPLETION_IGNORE_CASE' '
2435 GIT_COMPLETION_IGNORE_CASE=1 &&
2436 test_completion "git checkout h" <<-\EOF
2442 test_expect_success 'git -C <path> checkout uses the right repo' '
2443 test_completion "git -C subdir -C subsubdir -C .. -C ../otherrepo checkout b" <<-\EOF
2448 test_expect_success 'show completes all refs' '
2449 test_completion "git show m" <<-\EOF
2456 test_expect_success '<ref>: completes paths' '
2457 test_completion "git show mytag:f" <<-\EOF
2463 test_expect_success 'complete tree filename with spaces' '
2464 echo content >"name with spaces" &&
2465 git add "name with spaces" &&
2466 git commit -m spaces &&
2467 test_completion "git show HEAD:nam" <<-\EOF
2472 test_expect_success 'complete tree filename with metacharacters' '
2473 echo content >"name with \${meta}" &&
2474 git add "name with \${meta}" &&
2475 git commit -m meta &&
2476 test_completion "git show HEAD:nam" <<-\EOF
2482 test_expect_success PERL 'send-email' '
2483 test_completion "git send-email --cov" <<-\EOF &&
2484 --cover-from-description=Z
2487 test_completion "git send-email --val" <<-\EOF &&
2490 test_completion "git send-email ma" "main "
2493 test_expect_success 'complete files' '
2494 git init tmp && cd tmp &&
2495 test_when_finished "cd .. && rm -rf tmp" &&
2497 echo "expected" > .gitignore &&
2498 echo "out" >> .gitignore &&
2499 echo "out_sorted" >> .gitignore &&
2501 git add .gitignore &&
2502 test_completion "git commit " ".gitignore" &&
2504 git commit -m ignore &&
2507 test_completion "git add " "new" &&
2510 git commit -a -m new &&
2511 test_completion "git add " "" &&
2513 git mv new modified &&
2514 echo modify > modified &&
2515 test_completion "git add " "modified" &&
2517 mkdir -p some/deep &&
2518 touch some/deep/path &&
2519 test_completion "git add some/" "some/deep" &&
2520 git clean -f some &&
2524 : TODO .gitignore should not be here &&
2525 test_completion "git rm " <<-\EOF &&
2530 test_completion "git clean " "untracked" &&
2532 : TODO .gitignore should not be here &&
2533 test_completion "git mv " <<-\EOF &&
2539 touch dir/file-in-dir &&
2540 git add dir/file-in-dir &&
2541 git commit -m dir &&
2543 mkdir untracked-dir &&
2545 : TODO .gitignore should not be here &&
2546 test_completion "git mv modified " <<-\EOF &&
2554 test_completion "git commit " "modified" &&
2556 : TODO .gitignore should not be here &&
2557 test_completion "git ls-files " <<-\EOF &&
2564 test_completion "git add mom" "momified"
2567 test_expect_success "simple alias" '
2568 test_config alias.co checkout &&
2569 test_completion "git co m" <<-\EOF
2576 test_expect_success "recursive alias" '
2577 test_config alias.co checkout &&
2578 test_config alias.cod "co --detached" &&
2579 test_completion "git cod m" <<-\EOF
2586 test_expect_success "completion uses <cmd> completion for alias: !sh -c 'git <cmd> ...'" '
2587 test_config alias.co "!sh -c '"'"'git checkout ...'"'"'" &&
2588 test_completion "git co m" <<-\EOF
2595 test_expect_success 'completion uses <cmd> completion for alias: !f () { VAR=val git <cmd> ... }' '
2596 test_config alias.co "!f () { VAR=val git checkout ... ; } f" &&
2597 test_completion "git co m" <<-\EOF
2604 test_expect_success 'completion used <cmd> completion for alias: !f() { : git <cmd> ; ... }' '
2605 test_config alias.co "!f() { : git checkout ; if ... } f" &&
2606 test_completion "git co m" <<-\EOF
2613 test_expect_success 'completion used <cmd> completion for alias: !f() { : <cmd> ; ... }' '
2614 test_config alias.co "!f() { : checkout ; if ... } f" &&
2615 test_completion "git co m" <<-\EOF
2622 test_expect_success 'completion used <cmd> completion for alias: !f() { : <cmd>; ... }' '
2623 test_config alias.co "!f() { : checkout; if ... } f" &&
2624 test_completion "git co m" <<-\EOF
2631 test_expect_success 'completion without explicit _git_xxx function' '
2632 test_completion "git version --" <<-\EOF
2634 --no-build-options Z
2638 test_expect_failure 'complete with tilde expansion' '
2639 git init tmp && cd tmp &&
2640 test_when_finished "cd .. && rm -rf tmp" &&
2644 test_completion "git add ~/tmp/" "~/tmp/file"
2647 test_expect_success 'setup other remote for remote reference completion' '
2648 git remote add other otherrepo &&
2652 for flag in -d --delete
2654 test_expect_success "__git_complete_remote_or_refspec - push
$flag other
" '
2655 sed -e "s
/Z$
//" >expected <<-EOF &&
2659 words=(git push '$flag' other ma) &&
2660 cword=${#words[@]} cur=${words[cword-1]} &&
2662 __git_complete_remote_or_refspec &&
2665 test_cmp expected out
2668 test_expect_failure "__git_complete_remote_or_refspec
- push other
$flag" '
2669 sed -e "s
/Z$
//" >expected <<-EOF &&
2673 words=(git push other '$flag' ma) &&
2674 cword=${#words[@]} cur=${words[cword-1]} &&
2676 __git_complete_remote_or_refspec &&
2679 test_cmp expected out
2683 test_expect_success 'git config - section' '
2684 test_completion "git config br
" <<-\EOF
2690 test_expect_success 'git config - section include, includeIf' '
2691 test_completion "git config inclu
" <<-\EOF
2697 test_expect_success 'git config - variable name' '
2698 test_completion "git config log.d
" <<-\EOF
2705 test_expect_success 'git config - variable name include' '
2706 test_completion "git config include.p
" <<-\EOF
2711 test_expect_success 'git config - value' '
2712 test_completion "git config color.pager
" <<-\EOF
2718 test_expect_success 'git -c - section' '
2719 test_completion "git
-c br
" <<-\EOF
2725 test_expect_success 'git -c - variable name' '
2726 test_completion "git
-c log.d
" <<-\EOF
2733 test_expect_success 'git -c - value' '
2734 test_completion "git
-c color.pager
=" <<-\EOF
2740 test_expect_success 'git clone --config= - section' '
2741 test_completion "git clone
--config=br
" <<-\EOF
2747 test_expect_success 'git clone --config= - variable name' '
2748 test_completion "git clone
--config=log.d
" <<-\EOF
2755 test_expect_success 'git clone --config= - value' '
2756 test_completion "git clone
--config=color.pager
=" <<-\EOF
2762 test_expect_success 'options with value' '
2763 test_completion "git merge
-X diff-algorithm
=" <<-\EOF
2768 test_expect_success 'sourcing the completion script clears cached commands' '
2770 __git_compute_all_commands &&
2771 test -n "$__git_all_commands" &&
2772 . "$GIT_BUILD_DIR/contrib
/completion
/git-completion.bash
" &&
2773 test -z "$__git_all_commands"
2777 test_expect_success 'sourcing the completion script clears cached merge strategies' '
2779 __git_compute_merge_strategies &&
2780 test -n "$__git_merge_strategies" &&
2781 . "$GIT_BUILD_DIR/contrib
/completion
/git-completion.bash
" &&
2782 test -z "$__git_merge_strategies"
2786 test_expect_success 'sourcing the completion script clears cached --options' '
2788 __gitcomp_builtin checkout &&
2789 test -n "$__gitcomp_builtin_checkout" &&
2790 __gitcomp_builtin notes_edit &&
2791 test -n "$__gitcomp_builtin_notes_edit" &&
2792 . "$GIT_BUILD_DIR/contrib
/completion
/git-completion.bash
" &&
2793 test -z "$__gitcomp_builtin_checkout" &&
2794 test -z "$__gitcomp_builtin_notes_edit"
2798 test_expect_success 'option aliases are not shown by default' '
2799 test_completion "git clone
--recurs" "--recurse-submodules "
2802 test_expect_success 'option aliases are shown with GIT_COMPLETION_SHOW_ALL' '
2804 . "$GIT_BUILD_DIR/contrib
/completion
/git-completion.bash
" &&
2805 GIT_COMPLETION_SHOW_ALL=1 && export GIT_COMPLETION_SHOW_ALL &&
2806 test_completion "git clone
--recurs" <<-\EOF
2807 --recurse-submodules Z
2813 test_expect_success 'plumbing commands are excluded without GIT_COMPLETION_SHOW_ALL_COMMANDS' '
2815 . "$GIT_BUILD_DIR/contrib
/completion
/git-completion.bash
" &&
2816 sane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST &&
2818 # Just mainporcelain, not plumbing commands
2819 run_completion "git c
" &&
2820 grep checkout out &&
2825 test_expect_success 'all commands are shown with GIT_COMPLETION_SHOW_ALL_COMMANDS (also main non-builtin)' '
2827 . "$GIT_BUILD_DIR/contrib
/completion
/git-completion.bash
" &&
2828 GIT_COMPLETION_SHOW_ALL_COMMANDS=1 &&
2829 export GIT_COMPLETION_SHOW_ALL_COMMANDS &&
2830 sane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST &&
2832 # Both mainporcelain and plumbing commands
2833 run_completion "git c
" &&
2834 grep checkout out &&
2835 grep cat-file out &&
2837 # Check "gitk
", a "main
" command, but not a built-in + more plumbing
2838 run_completion "git g
" &&
2840 grep get-tar-commit-id out
2844 test_expect_success '__git_complete' '
2845 unset -f __git_wrap__git_main &&
2847 __git_complete foo __git_main &&
2848 __git_have_func __git_wrap__git_main &&
2849 unset -f __git_wrap__git_main &&
2851 __git_complete gf _git_fetch &&
2852 __git_have_func __git_wrap_git_fetch &&
2854 __git_complete foo git &&
2855 __git_have_func __git_wrap__git_main &&
2856 unset -f __git_wrap__git_main &&
2858 __git_complete gd git_diff &&
2859 __git_have_func __git_wrap_git_diff &&
2861 test_must_fail __git_complete ga missing