l10n: bg.po: Updated Bulgarian translation (4839t)
[git/debian.git] / t / t9902-completion.sh
blob5505e5aa249e43b88455b0565f0f9348546d5e4c
1 #!/bin/sh
3 # Copyright (c) 2012 Felipe Contreras
6 test_description='test bash completion'
8 . ./lib-bash.sh
10 complete ()
12 # do nothing
13 return 0
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
27 # the way.
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
44 case "$1" in
45 cur)
46 cur=${_words[_cword]}
48 prev)
49 prev=${_words[_cword-1]}
51 words)
52 words=("${_words[@]}")
54 cword)
55 cword=$_cword
57 esac
58 shift
59 done
62 print_comp ()
64 local IFS=$'\n'
65 echo "${COMPREPLY[*]}" > out
68 run_completion ()
70 local -a COMPREPLY _words
71 local _cword
72 _words=( $1 )
73 test "${1: -1}" = ' ' && _words[${#_words[@]}+1]=''
74 (( _cword = ${#_words[@]} - 1 ))
75 __git_wrap__git_main && print_comp
78 # Test high-level completion
79 # Arguments are:
80 # 1: typed text so far (cur)
81 # 2: expected completion
82 test_completion ()
84 if test $# -gt 1
85 then
86 printf '%s\n' "$2" >expected
87 else
88 sed -e 's/Z$//' |sort >expected
89 fi &&
90 run_completion "$1" &&
91 sort out >out_sorted &&
92 test_cmp expected out_sorted
95 # Test __gitcomp.
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().
99 test_gitcomp ()
101 local -a COMPREPLY &&
102 sed -e 's/Z$//' >expected &&
103 local cur="$1" &&
104 shift &&
105 __gitcomp "$@" &&
106 print_comp &&
107 test_cmp expected out
110 # Test __gitcomp_nl
111 # Arguments are:
112 # 1: current word (cur)
113 # -: the rest are passed to __gitcomp_nl
114 test_gitcomp_nl ()
116 local -a COMPREPLY &&
117 sed -e 's/Z$//' >expected &&
118 local cur="$1" &&
119 shift &&
120 __gitcomp_nl "$@" &&
121 print_comp &&
122 test_cmp expected out
125 invalid_variable_name='${foo.bar}'
127 actual="$TRASH_DIRECTORY/actual"
129 if test_have_prereq MINGW
130 then
131 ROOT="$(pwd -W)"
132 else
133 ROOT="$(pwd)"
136 test_expect_success 'setup for __git_find_repo_path/__gitdir tests' '
137 mkdir -p subdir/subsubdir &&
138 mkdir -p non-repo &&
139 git init 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"
148 ) &&
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"
157 ) &&
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"
167 ) &&
168 test_cmp expected "$actual"
171 test_expect_success '__git_find_repo_path - cwd is a .git directory' '
172 echo "." >expected &&
174 cd .git &&
175 __git_find_repo_path &&
176 echo "$__git_repo_path" >"$actual"
177 ) &&
178 test_cmp expected "$actual"
181 test_expect_success '__git_find_repo_path - parent is a .git directory' '
182 echo "$ROOT/.git" >expected &&
184 cd .git/objects &&
185 __git_find_repo_path &&
186 echo "$__git_repo_path" >"$actual"
187 ) &&
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" &&
195 export GIT_DIR &&
196 __git_find_repo_path &&
197 echo "$__git_repo_path" >"$actual"
198 ) &&
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" &&
206 export GIT_DIR &&
207 cd subdir &&
208 __git_find_repo_path &&
209 echo "$__git_repo_path" >"$actual"
210 ) &&
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"
221 ) &&
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 &&
228 cd subdir &&
229 __git_dir="otherrepo/.git" &&
230 __git_C_args=(-C ..) &&
231 __git_find_repo_path &&
232 echo "$__git_repo_path" >"$actual"
233 ) &&
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" &&
241 export GIT_DIR &&
242 __git_C_args=(-C otherrepo) &&
243 __git_find_repo_path &&
244 echo "$__git_repo_path" >"$actual"
245 ) &&
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 &&
252 cd subdir &&
253 GIT_DIR="otherrepo/.git" &&
254 export GIT_DIR &&
255 __git_C_args=(-C ..) &&
256 __git_find_repo_path &&
257 echo "$__git_repo_path" >"$actual"
258 ) &&
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"
268 ) &&
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 &&
275 cd .git &&
276 __git_C_args=(-C .. -C otherrepo) &&
277 __git_find_repo_path &&
278 echo "$__git_repo_path" >"$actual"
279 ) &&
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 &&
286 cd subdir &&
287 __git_C_args=(-C .. -C otherrepo) &&
288 __git_find_repo_path &&
289 echo "$__git_repo_path" >"$actual"
290 ) &&
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"
299 ) &&
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"
308 ) &&
309 test_must_be_empty "$actual"
312 test_expect_success '__git_find_repo_path - non-existing $GIT_DIR' '
314 GIT_DIR="$ROOT/non-existing" &&
315 export GIT_DIR &&
316 test_must_fail __git_find_repo_path &&
317 printf "$__git_repo_path" >"$actual"
318 ) &&
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" &&
327 cd subdir &&
328 __git_find_repo_path &&
329 echo "$__git_repo_path" >"$actual"
330 ) &&
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"
342 ) &&
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" &&
353 cd link &&
354 __git_find_repo_path &&
355 echo "$__git_repo_path" >"$actual"
356 ) &&
357 test_cmp expected "$actual"
360 test_expect_success '__git_find_repo_path - not a git repository' '
362 cd non-repo &&
363 GIT_CEILING_DIRECTORIES="$ROOT" &&
364 export GIT_CEILING_DIRECTORIES &&
365 test_must_fail __git_find_repo_path &&
366 printf "$__git_repo_path" >"$actual"
367 ) &&
368 test_must_be_empty "$actual"
371 test_expect_success '__gitdir - finds repo' '
372 echo "$ROOT/.git" >expected &&
374 cd subdir/subsubdir &&
375 __gitdir >"$actual"
376 ) &&
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"
385 ) &&
386 test_must_be_empty "$actual"
389 test_expect_success '__gitdir - repo as argument' '
390 echo "otherrepo/.git" >expected &&
392 __gitdir "otherrepo" >"$actual"
393 ) &&
394 test_cmp expected "$actual"
397 test_expect_success '__gitdir - remote as argument' '
398 echo "remote" >expected &&
400 __gitdir "remote" >"$actual"
401 ) &&
402 test_cmp expected "$actual"
406 test_expect_success '__git_dequote - plain unquoted word' '
407 __git_dequote unquoted-word &&
408 verbose 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 verbose 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 verbose 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 verbose 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 verbose 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 verbose 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
449 --option Z
450 --option=Z
451 $invalid_variable_name Z
454 cur=should_be_ignored &&
455 __gitcomp_direct "$(cat expected)" &&
456 print_comp
457 ) &&
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
464 --reuse-message=Z
465 --reedit-message=Z
466 --reset-author Z
470 test_expect_success '__gitcomp - trailing space - config keys' '
471 test_gitcomp "br" "branch. branch.autosetupmerge
472 branch.autosetuprebase browser." <<-\EOF
473 branch.Z
474 branch.autosetupmerge Z
475 branch.autosetuprebase Z
476 browser.Z
480 test_expect_success '__gitcomp - option parameter' '
481 test_gitcomp "--strategy=re" "octopus ours recursive resolve subtree" \
482 "" "re" <<-\EOF
483 recursive Z
484 resolve Z
488 test_expect_success '__gitcomp - prefix' '
489 test_gitcomp "branch.me" "remote merge mergeoptions rebase" \
490 "branch.maint." "me" <<-\EOF
491 branch.maint.merge Z
492 branch.maint.mergeoptions Z
496 test_expect_success '__gitcomp - suffix' '
497 test_gitcomp "branch.me" "master maint next pu" "branch." \
498 "ma" "." <<-\EOF
499 branch.master.Z
500 branch.maint.Z
504 test_expect_success '__gitcomp - ignore optional negative options' '
505 test_gitcomp "--" "--abc --def --no-one -- --no-two" <<-\EOF
506 --abc Z
507 --def Z
508 --no-one Z
509 --no-... Z
513 test_expect_success '__gitcomp - ignore/narrow optional negative options' '
514 test_gitcomp "--a" "--abc --abcdef --no-one -- --no-two" <<-\EOF
515 --abc Z
516 --abcdef Z
520 test_expect_success '__gitcomp - ignore/narrow optional negative options' '
521 test_gitcomp "--n" "--abc --def --no-one -- --no-two" <<-\EOF
522 --no-one Z
523 --no-... Z
527 test_expect_success '__gitcomp - expand all negative options' '
528 test_gitcomp "--no-" "--abc --def --no-one -- --no-two" <<-\EOF
529 --no-one Z
530 --no-two Z
534 test_expect_success '__gitcomp - expand/narrow all negative options' '
535 test_gitcomp "--no-o" "--abc --def --no-one -- --no-two" <<-\EOF
536 --no-one Z
540 test_expect_success '__gitcomp - doesnt fail because of invalid variable name' '
541 __gitcomp "$invalid_variable_name"
544 read -r -d "" refs <<-\EOF
545 maint
546 master
547 next
551 test_expect_success '__gitcomp_nl - trailing space' '
552 test_gitcomp_nl "m" "$refs" <<-EOF
553 maint Z
554 master Z
558 test_expect_success '__gitcomp_nl - prefix' '
559 test_gitcomp_nl "--fixup=m" "$refs" "--fixup=" "m" <<-EOF
560 --fixup=maint Z
561 --fixup=master Z
565 test_expect_success '__gitcomp_nl - suffix' '
566 test_gitcomp_nl "branch.ma" "$refs" "branch." "ma" "." <<-\EOF
567 branch.maint.Z
568 branch.master.Z
572 test_expect_success '__gitcomp_nl - no suffix' '
573 test_gitcomp_nl "ma" "$refs" "" "ma" "" <<-\EOF
574 maintZ
575 masterZ
579 test_expect_success '__gitcomp_nl - doesnt fail because of invalid variable name' '
580 __gitcomp_nl "$invalid_variable_name"
583 test_expect_success '__git_remotes - list remotes from $GIT_DIR/remotes and from config file' '
584 cat >expect <<-EOF &&
585 remote_from_file_1
586 remote_from_file_2
587 remote_in_config_1
588 remote_in_config_2
590 test_when_finished "rm -rf .git/remotes" &&
591 mkdir -p .git/remotes &&
592 >.git/remotes/remote_from_file_1 &&
593 >.git/remotes/remote_from_file_2 &&
594 test_when_finished "git remote remove remote_in_config_1" &&
595 git remote add remote_in_config_1 git://remote_1 &&
596 test_when_finished "git remote remove remote_in_config_2" &&
597 git remote add remote_in_config_2 git://remote_2 &&
599 __git_remotes >actual
600 ) &&
601 test_cmp expect actual
604 test_expect_success '__git_is_configured_remote' '
605 test_when_finished "git remote remove remote_1" &&
606 git remote add remote_1 git://remote_1 &&
607 test_when_finished "git remote remove remote_2" &&
608 git remote add remote_2 git://remote_2 &&
610 verbose __git_is_configured_remote remote_2 &&
611 test_must_fail __git_is_configured_remote non-existent
615 test_expect_success 'setup for ref completion' '
616 git commit --allow-empty -m initial &&
617 git branch matching-branch &&
618 git tag matching-tag &&
620 cd otherrepo &&
621 git commit --allow-empty -m initial &&
622 git branch -m master master-in-other &&
623 git branch branch-in-other &&
624 git tag tag-in-other
625 ) &&
626 git remote add other "$ROOT/otherrepo/.git" &&
627 git fetch --no-tags other &&
628 rm -f .git/FETCH_HEAD &&
629 git init thirdrepo
632 test_expect_success '__git_refs - simple' '
633 cat >expected <<-EOF &&
634 HEAD
635 master
636 matching-branch
637 other/branch-in-other
638 other/master-in-other
639 matching-tag
642 cur= &&
643 __git_refs >"$actual"
644 ) &&
645 test_cmp expected "$actual"
648 test_expect_success '__git_refs - full refs' '
649 cat >expected <<-EOF &&
650 refs/heads/master
651 refs/heads/matching-branch
652 refs/remotes/other/branch-in-other
653 refs/remotes/other/master-in-other
654 refs/tags/matching-tag
657 cur=refs/heads/ &&
658 __git_refs >"$actual"
659 ) &&
660 test_cmp expected "$actual"
663 test_expect_success '__git_refs - repo given on the command line' '
664 cat >expected <<-EOF &&
665 HEAD
666 branch-in-other
667 master-in-other
668 tag-in-other
671 __git_dir="$ROOT/otherrepo/.git" &&
672 cur= &&
673 __git_refs >"$actual"
674 ) &&
675 test_cmp expected "$actual"
678 test_expect_success '__git_refs - remote on local file system' '
679 cat >expected <<-EOF &&
680 HEAD
681 branch-in-other
682 master-in-other
683 tag-in-other
686 cur= &&
687 __git_refs otherrepo >"$actual"
688 ) &&
689 test_cmp expected "$actual"
692 test_expect_success '__git_refs - remote on local file system - full refs' '
693 cat >expected <<-EOF &&
694 refs/heads/branch-in-other
695 refs/heads/master-in-other
696 refs/tags/tag-in-other
699 cur=refs/ &&
700 __git_refs otherrepo >"$actual"
701 ) &&
702 test_cmp expected "$actual"
705 test_expect_success '__git_refs - configured remote' '
706 cat >expected <<-EOF &&
707 HEAD
708 branch-in-other
709 master-in-other
712 cur= &&
713 __git_refs other >"$actual"
714 ) &&
715 test_cmp expected "$actual"
718 test_expect_success '__git_refs - configured remote - full refs' '
719 cat >expected <<-EOF &&
720 HEAD
721 refs/heads/branch-in-other
722 refs/heads/master-in-other
723 refs/tags/tag-in-other
726 cur=refs/ &&
727 __git_refs other >"$actual"
728 ) &&
729 test_cmp expected "$actual"
732 test_expect_success '__git_refs - configured remote - repo given on the command line' '
733 cat >expected <<-EOF &&
734 HEAD
735 branch-in-other
736 master-in-other
739 cd thirdrepo &&
740 __git_dir="$ROOT/.git" &&
741 cur= &&
742 __git_refs other >"$actual"
743 ) &&
744 test_cmp expected "$actual"
747 test_expect_success '__git_refs - configured remote - full refs - repo given on the command line' '
748 cat >expected <<-EOF &&
749 HEAD
750 refs/heads/branch-in-other
751 refs/heads/master-in-other
752 refs/tags/tag-in-other
755 cd thirdrepo &&
756 __git_dir="$ROOT/.git" &&
757 cur=refs/ &&
758 __git_refs other >"$actual"
759 ) &&
760 test_cmp expected "$actual"
763 test_expect_success '__git_refs - configured remote - remote name matches a directory' '
764 cat >expected <<-EOF &&
765 HEAD
766 branch-in-other
767 master-in-other
769 mkdir other &&
770 test_when_finished "rm -rf other" &&
772 cur= &&
773 __git_refs other >"$actual"
774 ) &&
775 test_cmp expected "$actual"
778 test_expect_success '__git_refs - URL remote' '
779 cat >expected <<-EOF &&
780 HEAD
781 branch-in-other
782 master-in-other
783 tag-in-other
786 cur= &&
787 __git_refs "file://$ROOT/otherrepo/.git" >"$actual"
788 ) &&
789 test_cmp expected "$actual"
792 test_expect_success '__git_refs - URL remote - full refs' '
793 cat >expected <<-EOF &&
794 HEAD
795 refs/heads/branch-in-other
796 refs/heads/master-in-other
797 refs/tags/tag-in-other
800 cur=refs/ &&
801 __git_refs "file://$ROOT/otherrepo/.git" >"$actual"
802 ) &&
803 test_cmp expected "$actual"
806 test_expect_success '__git_refs - non-existing remote' '
808 cur= &&
809 __git_refs non-existing >"$actual"
810 ) &&
811 test_must_be_empty "$actual"
814 test_expect_success '__git_refs - non-existing remote - full refs' '
816 cur=refs/ &&
817 __git_refs non-existing >"$actual"
818 ) &&
819 test_must_be_empty "$actual"
822 test_expect_success '__git_refs - non-existing URL remote' '
824 cur= &&
825 __git_refs "file://$ROOT/non-existing" >"$actual"
826 ) &&
827 test_must_be_empty "$actual"
830 test_expect_success '__git_refs - non-existing URL remote - full refs' '
832 cur=refs/ &&
833 __git_refs "file://$ROOT/non-existing" >"$actual"
834 ) &&
835 test_must_be_empty "$actual"
838 test_expect_success '__git_refs - not in a git repository' '
840 GIT_CEILING_DIRECTORIES="$ROOT" &&
841 export GIT_CEILING_DIRECTORIES &&
842 cd subdir &&
843 cur= &&
844 __git_refs >"$actual"
845 ) &&
846 test_must_be_empty "$actual"
849 test_expect_success '__git_refs - unique remote branches for git checkout DWIMery' '
850 cat >expected <<-EOF &&
851 HEAD
852 master
853 matching-branch
854 other/ambiguous
855 other/branch-in-other
856 other/master-in-other
857 remote/ambiguous
858 remote/branch-in-remote
859 matching-tag
860 branch-in-other
861 branch-in-remote
862 master-in-other
864 for remote_ref in refs/remotes/other/ambiguous \
865 refs/remotes/remote/ambiguous \
866 refs/remotes/remote/branch-in-remote
868 git update-ref $remote_ref master &&
869 test_when_finished "git update-ref -d $remote_ref"
870 done &&
872 cur= &&
873 __git_refs "" 1 >"$actual"
874 ) &&
875 test_cmp expected "$actual"
878 test_expect_success '__git_refs - after --opt=' '
879 cat >expected <<-EOF &&
880 HEAD
881 master
882 matching-branch
883 other/branch-in-other
884 other/master-in-other
885 matching-tag
888 cur="--opt=" &&
889 __git_refs "" "" "" "" >"$actual"
890 ) &&
891 test_cmp expected "$actual"
894 test_expect_success '__git_refs - after --opt= - full refs' '
895 cat >expected <<-EOF &&
896 refs/heads/master
897 refs/heads/matching-branch
898 refs/remotes/other/branch-in-other
899 refs/remotes/other/master-in-other
900 refs/tags/matching-tag
903 cur="--opt=refs/" &&
904 __git_refs "" "" "" refs/ >"$actual"
905 ) &&
906 test_cmp expected "$actual"
909 test_expect_success '__git refs - exluding refs' '
910 cat >expected <<-EOF &&
911 ^HEAD
912 ^master
913 ^matching-branch
914 ^other/branch-in-other
915 ^other/master-in-other
916 ^matching-tag
919 cur=^ &&
920 __git_refs >"$actual"
921 ) &&
922 test_cmp expected "$actual"
925 test_expect_success '__git refs - exluding full refs' '
926 cat >expected <<-EOF &&
927 ^refs/heads/master
928 ^refs/heads/matching-branch
929 ^refs/remotes/other/branch-in-other
930 ^refs/remotes/other/master-in-other
931 ^refs/tags/matching-tag
934 cur=^refs/ &&
935 __git_refs >"$actual"
936 ) &&
937 test_cmp expected "$actual"
940 test_expect_success 'setup for filtering matching refs' '
941 git branch matching/branch &&
942 git tag matching/tag &&
943 git -C otherrepo branch matching/branch-in-other &&
944 git fetch --no-tags other &&
945 rm -f .git/FETCH_HEAD
948 test_expect_success '__git_refs - do not filter refs unless told so' '
949 cat >expected <<-EOF &&
950 HEAD
951 master
952 matching-branch
953 matching/branch
954 other/branch-in-other
955 other/master-in-other
956 other/matching/branch-in-other
957 matching-tag
958 matching/tag
961 cur=master &&
962 __git_refs >"$actual"
963 ) &&
964 test_cmp expected "$actual"
967 test_expect_success '__git_refs - only matching refs' '
968 cat >expected <<-EOF &&
969 matching-branch
970 matching/branch
971 matching-tag
972 matching/tag
975 cur=mat &&
976 __git_refs "" "" "" "$cur" >"$actual"
977 ) &&
978 test_cmp expected "$actual"
981 test_expect_success '__git_refs - only matching refs - full refs' '
982 cat >expected <<-EOF &&
983 refs/heads/matching-branch
984 refs/heads/matching/branch
987 cur=refs/heads/mat &&
988 __git_refs "" "" "" "$cur" >"$actual"
989 ) &&
990 test_cmp expected "$actual"
993 test_expect_success '__git_refs - only matching refs - remote on local file system' '
994 cat >expected <<-EOF &&
995 master-in-other
996 matching/branch-in-other
999 cur=ma &&
1000 __git_refs otherrepo "" "" "$cur" >"$actual"
1001 ) &&
1002 test_cmp expected "$actual"
1005 test_expect_success '__git_refs - only matching refs - configured remote' '
1006 cat >expected <<-EOF &&
1007 master-in-other
1008 matching/branch-in-other
1011 cur=ma &&
1012 __git_refs other "" "" "$cur" >"$actual"
1013 ) &&
1014 test_cmp expected "$actual"
1017 test_expect_success '__git_refs - only matching refs - remote - full refs' '
1018 cat >expected <<-EOF &&
1019 refs/heads/master-in-other
1020 refs/heads/matching/branch-in-other
1023 cur=refs/heads/ma &&
1024 __git_refs other "" "" "$cur" >"$actual"
1025 ) &&
1026 test_cmp expected "$actual"
1029 test_expect_success '__git_refs - only matching refs - checkout DWIMery' '
1030 cat >expected <<-EOF &&
1031 matching-branch
1032 matching/branch
1033 matching-tag
1034 matching/tag
1035 matching/branch-in-other
1037 for remote_ref in refs/remotes/other/ambiguous \
1038 refs/remotes/remote/ambiguous \
1039 refs/remotes/remote/branch-in-remote
1041 git update-ref $remote_ref master &&
1042 test_when_finished "git update-ref -d $remote_ref"
1043 done &&
1045 cur=mat &&
1046 __git_refs "" 1 "" "$cur" >"$actual"
1047 ) &&
1048 test_cmp expected "$actual"
1051 test_expect_success 'teardown after filtering matching refs' '
1052 git branch -d matching/branch &&
1053 git tag -d matching/tag &&
1054 git update-ref -d refs/remotes/other/matching/branch-in-other &&
1055 git -C otherrepo branch -D matching/branch-in-other
1058 test_expect_success '__git_refs - for-each-ref format specifiers in prefix' '
1059 cat >expected <<-EOF &&
1060 evil-%%-%42-%(refname)..master
1063 cur="evil-%%-%42-%(refname)..mas" &&
1064 __git_refs "" "" "evil-%%-%42-%(refname).." mas >"$actual"
1065 ) &&
1066 test_cmp expected "$actual"
1069 test_expect_success '__git_complete_refs - simple' '
1070 sed -e "s/Z$//" >expected <<-EOF &&
1071 HEAD Z
1072 master Z
1073 matching-branch Z
1074 other/branch-in-other Z
1075 other/master-in-other Z
1076 matching-tag Z
1079 cur= &&
1080 __git_complete_refs &&
1081 print_comp
1082 ) &&
1083 test_cmp expected out
1086 test_expect_success '__git_complete_refs - matching' '
1087 sed -e "s/Z$//" >expected <<-EOF &&
1088 matching-branch Z
1089 matching-tag Z
1092 cur=mat &&
1093 __git_complete_refs &&
1094 print_comp
1095 ) &&
1096 test_cmp expected out
1099 test_expect_success '__git_complete_refs - remote' '
1100 sed -e "s/Z$//" >expected <<-EOF &&
1101 HEAD Z
1102 branch-in-other Z
1103 master-in-other Z
1106 cur= &&
1107 __git_complete_refs --remote=other &&
1108 print_comp
1109 ) &&
1110 test_cmp expected out
1113 test_expect_success '__git_complete_refs - track' '
1114 sed -e "s/Z$//" >expected <<-EOF &&
1115 HEAD Z
1116 master Z
1117 matching-branch Z
1118 other/branch-in-other Z
1119 other/master-in-other Z
1120 matching-tag Z
1121 branch-in-other Z
1122 master-in-other Z
1125 cur= &&
1126 __git_complete_refs --track &&
1127 print_comp
1128 ) &&
1129 test_cmp expected out
1132 test_expect_success '__git_complete_refs - current word' '
1133 sed -e "s/Z$//" >expected <<-EOF &&
1134 matching-branch Z
1135 matching-tag Z
1138 cur="--option=mat" &&
1139 __git_complete_refs --cur="${cur#*=}" &&
1140 print_comp
1141 ) &&
1142 test_cmp expected out
1145 test_expect_success '__git_complete_refs - prefix' '
1146 sed -e "s/Z$//" >expected <<-EOF &&
1147 v1.0..matching-branch Z
1148 v1.0..matching-tag Z
1151 cur=v1.0..mat &&
1152 __git_complete_refs --pfx=v1.0.. --cur=mat &&
1153 print_comp
1154 ) &&
1155 test_cmp expected out
1158 test_expect_success '__git_complete_refs - suffix' '
1159 cat >expected <<-EOF &&
1160 HEAD.
1161 master.
1162 matching-branch.
1163 other/branch-in-other.
1164 other/master-in-other.
1165 matching-tag.
1168 cur= &&
1169 __git_complete_refs --sfx=. &&
1170 print_comp
1171 ) &&
1172 test_cmp expected out
1175 test_expect_success '__git_complete_fetch_refspecs - simple' '
1176 sed -e "s/Z$//" >expected <<-EOF &&
1177 HEAD:HEAD Z
1178 branch-in-other:branch-in-other Z
1179 master-in-other:master-in-other Z
1182 cur= &&
1183 __git_complete_fetch_refspecs other &&
1184 print_comp
1185 ) &&
1186 test_cmp expected out
1189 test_expect_success '__git_complete_fetch_refspecs - matching' '
1190 sed -e "s/Z$//" >expected <<-EOF &&
1191 branch-in-other:branch-in-other Z
1194 cur=br &&
1195 __git_complete_fetch_refspecs other "" br &&
1196 print_comp
1197 ) &&
1198 test_cmp expected out
1201 test_expect_success '__git_complete_fetch_refspecs - prefix' '
1202 sed -e "s/Z$//" >expected <<-EOF &&
1203 +HEAD:HEAD Z
1204 +branch-in-other:branch-in-other Z
1205 +master-in-other:master-in-other Z
1208 cur="+" &&
1209 __git_complete_fetch_refspecs other "+" "" &&
1210 print_comp
1211 ) &&
1212 test_cmp expected out
1215 test_expect_success '__git_complete_fetch_refspecs - fully qualified' '
1216 sed -e "s/Z$//" >expected <<-EOF &&
1217 refs/heads/branch-in-other:refs/heads/branch-in-other Z
1218 refs/heads/master-in-other:refs/heads/master-in-other Z
1219 refs/tags/tag-in-other:refs/tags/tag-in-other Z
1222 cur=refs/ &&
1223 __git_complete_fetch_refspecs other "" refs/ &&
1224 print_comp
1225 ) &&
1226 test_cmp expected out
1229 test_expect_success '__git_complete_fetch_refspecs - fully qualified & prefix' '
1230 sed -e "s/Z$//" >expected <<-EOF &&
1231 +refs/heads/branch-in-other:refs/heads/branch-in-other Z
1232 +refs/heads/master-in-other:refs/heads/master-in-other Z
1233 +refs/tags/tag-in-other:refs/tags/tag-in-other Z
1236 cur=+refs/ &&
1237 __git_complete_fetch_refspecs other + refs/ &&
1238 print_comp
1239 ) &&
1240 test_cmp expected out
1243 test_expect_success 'teardown after ref completion' '
1244 git branch -d matching-branch &&
1245 git tag -d matching-tag &&
1246 git remote remove other
1250 test_path_completion ()
1252 test $# = 2 || BUG "not 2 parameters to test_path_completion"
1254 local cur="$1" expected="$2"
1255 echo "$expected" >expected &&
1257 # In the following tests calling this function we only
1258 # care about how __git_complete_index_file() deals with
1259 # unusual characters in path names. By requesting only
1260 # untracked files we do not have to bother adding any
1261 # paths to the index in those tests.
1262 __git_complete_index_file --others &&
1263 print_comp
1264 ) &&
1265 test_cmp expected out
1268 test_expect_success 'setup for path completion tests' '
1269 mkdir simple-dir \
1270 "spaces in dir" \
1271 árvíztűrő &&
1272 touch simple-dir/simple-file \
1273 "spaces in dir/spaces in file" \
1274 "árvíztűrő/Сайн яваарай" &&
1275 if test_have_prereq !MINGW &&
1276 mkdir BS\\dir \
1277 '$'separators\034in\035dir'' &&
1278 touch BS\\dir/DQ\"file \
1279 '$'separators\034in\035dir/sep\036in\037file''
1280 then
1281 test_set_prereq FUNNIERNAMES
1282 else
1283 rm -rf BS\\dir '$'separators\034in\035dir''
1287 test_expect_success '__git_complete_index_file - simple' '
1288 test_path_completion simple simple-dir && # Bash is supposed to
1289 # add the trailing /.
1290 test_path_completion simple-dir/simple simple-dir/simple-file
1293 test_expect_success \
1294 '__git_complete_index_file - escaped characters on cmdline' '
1295 test_path_completion spac "spaces in dir" && # Bash will turn this
1296 # into "spaces\ in\ dir"
1297 test_path_completion "spaces\\ i" \
1298 "spaces in dir" &&
1299 test_path_completion "spaces\\ in\\ dir/s" \
1300 "spaces in dir/spaces in file" &&
1301 test_path_completion "spaces\\ in\\ dir/spaces\\ i" \
1302 "spaces in dir/spaces in file"
1305 test_expect_success \
1306 '__git_complete_index_file - quoted characters on cmdline' '
1307 # Testing with an opening but without a corresponding closing
1308 # double quote is important.
1309 test_path_completion \"spac "spaces in dir" &&
1310 test_path_completion "\"spaces i" \
1311 "spaces in dir" &&
1312 test_path_completion "\"spaces in dir/s" \
1313 "spaces in dir/spaces in file" &&
1314 test_path_completion "\"spaces in dir/spaces i" \
1315 "spaces in dir/spaces in file"
1318 test_expect_success '__git_complete_index_file - UTF-8 in ls-files output' '
1319 test_path_completion á árvíztűrő &&
1320 test_path_completion árvíztűrő/С "árvíztűrő/Сайн яваарай"
1323 test_expect_success FUNNIERNAMES \
1324 '__git_complete_index_file - C-style escapes in ls-files output' '
1325 test_path_completion BS \
1326 BS\\dir &&
1327 test_path_completion BS\\\\d \
1328 BS\\dir &&
1329 test_path_completion BS\\\\dir/DQ \
1330 BS\\dir/DQ\"file &&
1331 test_path_completion BS\\\\dir/DQ\\\"f \
1332 BS\\dir/DQ\"file
1335 test_expect_success FUNNIERNAMES \
1336 '__git_complete_index_file - \nnn-escaped characters in ls-files output' '
1337 test_path_completion sep '$'separators\034in\035dir'' &&
1338 test_path_completion '$'separators\034i'' \
1339 '$'separators\034in\035dir'' &&
1340 test_path_completion '$'separators\034in\035dir/sep'' \
1341 '$'separators\034in\035dir/sep\036in\037file'' &&
1342 test_path_completion '$'separators\034in\035dir/sep\036i'' \
1343 '$'separators\034in\035dir/sep\036in\037file''
1346 test_expect_success FUNNYNAMES \
1347 '__git_complete_index_file - removing repeated quoted path components' '
1348 test_when_finished rm -r repeated-quoted &&
1349 mkdir repeated-quoted && # A directory whose name in itself
1350 # would not be quoted ...
1351 >repeated-quoted/0-file &&
1352 >repeated-quoted/1\"file && # ... but here the file makes the
1353 # dirname quoted ...
1354 >repeated-quoted/2-file &&
1355 >repeated-quoted/3\"file && # ... and here, too.
1357 # Still, we shold only list the directory name only once.
1358 test_path_completion repeated repeated-quoted
1361 test_expect_success 'teardown after path completion tests' '
1362 rm -rf simple-dir "spaces in dir" árvíztűrő \
1363 BS\\dir '$'separators\034in\035dir''
1366 test_expect_success '__git_find_on_cmdline - single match' '
1367 echo list >expect &&
1369 words=(git command --opt list) &&
1370 cword=${#words[@]} &&
1371 __git_find_on_cmdline "add list remove" >actual
1372 ) &&
1373 test_cmp expect actual
1376 test_expect_success '__git_find_on_cmdline - multiple matches' '
1377 echo remove >expect &&
1379 words=(git command -o --opt remove list add) &&
1380 cword=${#words[@]} &&
1381 __git_find_on_cmdline "add list remove" >actual
1382 ) &&
1383 test_cmp expect actual
1386 test_expect_success '__git_find_on_cmdline - no match' '
1388 words=(git command --opt branch) &&
1389 cword=${#words[@]} &&
1390 __git_find_on_cmdline "add list remove" >actual
1391 ) &&
1392 test_must_be_empty actual
1395 test_expect_success '__git_find_on_cmdline - single match with index' '
1396 echo "3 list" >expect &&
1398 words=(git command --opt list) &&
1399 cword=${#words[@]} &&
1400 __git_find_on_cmdline --show-idx "add list remove" >actual
1401 ) &&
1402 test_cmp expect actual
1405 test_expect_success '__git_find_on_cmdline - multiple matches with index' '
1406 echo "4 remove" >expect &&
1408 words=(git command -o --opt remove list add) &&
1409 cword=${#words[@]} &&
1410 __git_find_on_cmdline --show-idx "add list remove" >actual
1411 ) &&
1412 test_cmp expect actual
1415 test_expect_success '__git_find_on_cmdline - no match with index' '
1417 words=(git command --opt branch) &&
1418 cword=${#words[@]} &&
1419 __git_find_on_cmdline --show-idx "add list remove" >actual
1420 ) &&
1421 test_must_be_empty actual
1424 test_expect_success '__git_get_config_variables' '
1425 cat >expect <<-EOF &&
1426 name-1
1427 name-2
1429 test_config interesting.name-1 good &&
1430 test_config interesting.name-2 good &&
1431 test_config subsection.interesting.name-3 bad &&
1432 __git_get_config_variables interesting >actual &&
1433 test_cmp expect actual
1436 test_expect_success '__git_pretty_aliases' '
1437 cat >expect <<-EOF &&
1438 author
1439 hash
1441 test_config pretty.author "%an %ae" &&
1442 test_config pretty.hash %H &&
1443 __git_pretty_aliases >actual &&
1444 test_cmp expect actual
1447 test_expect_success 'basic' '
1448 run_completion "git " &&
1449 # built-in
1450 grep -q "^add \$" out &&
1451 # script
1452 grep -q "^rebase \$" out &&
1453 # plumbing
1454 ! grep -q "^ls-files \$" out &&
1456 run_completion "git r" &&
1457 ! grep -q -v "^r" out
1460 test_expect_success 'double dash "git" itself' '
1461 test_completion "git --" <<-\EOF
1462 --paginate Z
1463 --no-pager Z
1464 --git-dir=
1465 --bare Z
1466 --version Z
1467 --exec-path Z
1468 --exec-path=
1469 --html-path Z
1470 --man-path Z
1471 --info-path Z
1472 --work-tree=
1473 --namespace=
1474 --no-replace-objects Z
1475 --help Z
1479 test_expect_success 'double dash "git checkout"' '
1480 test_completion "git checkout --" <<-\EOF
1481 --quiet Z
1482 --detach Z
1483 --track Z
1484 --orphan=Z
1485 --ours Z
1486 --theirs Z
1487 --merge Z
1488 --conflict=Z
1489 --patch Z
1490 --ignore-skip-worktree-bits Z
1491 --ignore-other-worktrees Z
1492 --recurse-submodules Z
1493 --progress Z
1494 --guess Z
1495 --no-guess Z
1496 --no-... Z
1497 --overlay Z
1498 --pathspec-file-nul Z
1499 --pathspec-from-file=Z
1503 test_expect_success 'general options' '
1504 test_completion "git --ver" "--version " &&
1505 test_completion "git --hel" "--help " &&
1506 test_completion "git --exe" <<-\EOF &&
1507 --exec-path Z
1508 --exec-path=
1510 test_completion "git --htm" "--html-path " &&
1511 test_completion "git --pag" "--paginate " &&
1512 test_completion "git --no-p" "--no-pager " &&
1513 test_completion "git --git" "--git-dir=" &&
1514 test_completion "git --wor" "--work-tree=" &&
1515 test_completion "git --nam" "--namespace=" &&
1516 test_completion "git --bar" "--bare " &&
1517 test_completion "git --inf" "--info-path " &&
1518 test_completion "git --no-r" "--no-replace-objects "
1521 test_expect_success 'general options plus command' '
1522 test_completion "git --version check" "checkout " &&
1523 test_completion "git --paginate check" "checkout " &&
1524 test_completion "git --git-dir=foo check" "checkout " &&
1525 test_completion "git --bare check" "checkout " &&
1526 test_completion "git --exec-path=foo check" "checkout " &&
1527 test_completion "git --html-path check" "checkout " &&
1528 test_completion "git --no-pager check" "checkout " &&
1529 test_completion "git --work-tree=foo check" "checkout " &&
1530 test_completion "git --namespace=foo check" "checkout " &&
1531 test_completion "git --paginate check" "checkout " &&
1532 test_completion "git --info-path check" "checkout " &&
1533 test_completion "git --no-replace-objects check" "checkout " &&
1534 test_completion "git --git-dir some/path check" "checkout " &&
1535 test_completion "git -c conf.var=value check" "checkout " &&
1536 test_completion "git -C some/path check" "checkout " &&
1537 test_completion "git --work-tree some/path check" "checkout " &&
1538 test_completion "git --namespace name/space check" "checkout "
1541 test_expect_success 'git --help completion' '
1542 test_completion "git --help ad" "add " &&
1543 test_completion "git --help core" "core-tutorial "
1546 test_expect_success 'completion.commands removes multiple commands' '
1547 test_config completion.commands "-cherry -mergetool" &&
1548 git --list-cmds=list-mainporcelain,list-complete,config >out &&
1549 ! grep -E "^(cherry|mergetool)$" out
1552 test_expect_success 'setup for integration tests' '
1553 echo content >file1 &&
1554 echo more >file2 &&
1555 git add file1 file2 &&
1556 git commit -m one &&
1557 git branch mybranch &&
1558 git tag mytag
1561 test_expect_success 'checkout completes ref names' '
1562 test_completion "git checkout m" <<-\EOF
1563 master Z
1564 mybranch Z
1565 mytag Z
1569 test_expect_success 'git -C <path> checkout uses the right repo' '
1570 test_completion "git -C subdir -C subsubdir -C .. -C ../otherrepo checkout b" <<-\EOF
1571 branch-in-other Z
1575 test_expect_success 'show completes all refs' '
1576 test_completion "git show m" <<-\EOF
1577 master Z
1578 mybranch Z
1579 mytag Z
1583 test_expect_success '<ref>: completes paths' '
1584 test_completion "git show mytag:f" <<-\EOF
1585 file1Z
1586 file2Z
1590 test_expect_success 'complete tree filename with spaces' '
1591 echo content >"name with spaces" &&
1592 git add "name with spaces" &&
1593 git commit -m spaces &&
1594 test_completion "git show HEAD:nam" <<-\EOF
1595 name with spacesZ
1599 test_expect_success 'complete tree filename with metacharacters' '
1600 echo content >"name with \${meta}" &&
1601 git add "name with \${meta}" &&
1602 git commit -m meta &&
1603 test_completion "git show HEAD:nam" <<-\EOF
1604 name with ${meta}Z
1605 name with spacesZ
1609 test_expect_success PERL 'send-email' '
1610 test_completion "git send-email --cov" <<-\EOF &&
1611 --cover-from-description=Z
1612 --cover-letter Z
1614 test_completion "git send-email ma" "master "
1617 test_expect_success 'complete files' '
1618 git init tmp && cd tmp &&
1619 test_when_finished "cd .. && rm -rf tmp" &&
1621 echo "expected" > .gitignore &&
1622 echo "out" >> .gitignore &&
1623 echo "out_sorted" >> .gitignore &&
1625 git add .gitignore &&
1626 test_completion "git commit " ".gitignore" &&
1628 git commit -m ignore &&
1630 touch new &&
1631 test_completion "git add " "new" &&
1633 git add new &&
1634 git commit -a -m new &&
1635 test_completion "git add " "" &&
1637 git mv new modified &&
1638 echo modify > modified &&
1639 test_completion "git add " "modified" &&
1641 touch untracked &&
1643 : TODO .gitignore should not be here &&
1644 test_completion "git rm " <<-\EOF &&
1645 .gitignore
1646 modified
1649 test_completion "git clean " "untracked" &&
1651 : TODO .gitignore should not be here &&
1652 test_completion "git mv " <<-\EOF &&
1653 .gitignore
1654 modified
1657 mkdir dir &&
1658 touch dir/file-in-dir &&
1659 git add dir/file-in-dir &&
1660 git commit -m dir &&
1662 mkdir untracked-dir &&
1664 : TODO .gitignore should not be here &&
1665 test_completion "git mv modified " <<-\EOF &&
1666 .gitignore
1668 modified
1669 untracked
1670 untracked-dir
1673 test_completion "git commit " "modified" &&
1675 : TODO .gitignore should not be here &&
1676 test_completion "git ls-files " <<-\EOF &&
1677 .gitignore
1679 modified
1682 touch momified &&
1683 test_completion "git add mom" "momified"
1686 test_expect_success "completion uses <cmd> completion for alias: !sh -c 'git <cmd> ...'" '
1687 test_config alias.co "!sh -c '"'"'git checkout ...'"'"'" &&
1688 test_completion "git co m" <<-\EOF
1689 master Z
1690 mybranch Z
1691 mytag Z
1695 test_expect_success 'completion uses <cmd> completion for alias: !f () { VAR=val git <cmd> ... }' '
1696 test_config alias.co "!f () { VAR=val git checkout ... ; } f" &&
1697 test_completion "git co m" <<-\EOF
1698 master Z
1699 mybranch Z
1700 mytag Z
1704 test_expect_success 'completion used <cmd> completion for alias: !f() { : git <cmd> ; ... }' '
1705 test_config alias.co "!f() { : git checkout ; if ... } f" &&
1706 test_completion "git co m" <<-\EOF
1707 master Z
1708 mybranch Z
1709 mytag Z
1713 test_expect_success 'completion without explicit _git_xxx function' '
1714 test_completion "git version --" <<-\EOF
1715 --build-options Z
1716 --no-build-options Z
1720 test_expect_failure 'complete with tilde expansion' '
1721 git init tmp && cd tmp &&
1722 test_when_finished "cd .. && rm -rf tmp" &&
1724 touch ~/tmp/file &&
1726 test_completion "git add ~/tmp/" "~/tmp/file"
1729 test_expect_success 'setup other remote for remote reference completion' '
1730 git remote add other otherrepo &&
1731 git fetch other
1734 for flag in -d --delete
1736 test_expect_success "__git_complete_remote_or_refspec - push $flag other" '
1737 sed -e "s/Z$//" >expected <<-EOF &&
1738 master-in-other Z
1741 words=(git push '$flag' other ma) &&
1742 cword=${#words[@]} cur=${words[cword-1]} &&
1743 __git_complete_remote_or_refspec &&
1744 print_comp
1745 ) &&
1746 test_cmp expected out
1749 test_expect_failure "__git_complete_remote_or_refspec - push other $flag" '
1750 sed -e "s/Z$//" >expected <<-EOF &&
1751 master-in-other Z
1754 words=(git push other '$flag' ma) &&
1755 cword=${#words[@]} cur=${words[cword-1]} &&
1756 __git_complete_remote_or_refspec &&
1757 print_comp
1758 ) &&
1759 test_cmp expected out
1761 done
1763 test_expect_success 'git config - section' '
1764 test_completion "git config br" <<-\EOF
1765 branch.Z
1766 browser.Z
1770 test_expect_success 'git config - variable name' '
1771 test_completion "git config log.d" <<-\EOF
1772 log.date Z
1773 log.decorate Z
1777 test_expect_success 'git config - value' '
1778 test_completion "git config color.pager " <<-\EOF
1779 false Z
1780 true Z
1784 test_expect_success 'git -c - section' '
1785 test_completion "git -c br" <<-\EOF
1786 branch.Z
1787 browser.Z
1791 test_expect_success 'git -c - variable name' '
1792 test_completion "git -c log.d" <<-\EOF
1793 log.date=Z
1794 log.decorate=Z
1798 test_expect_success 'git -c - value' '
1799 test_completion "git -c color.pager=" <<-\EOF
1800 false Z
1801 true Z
1805 test_expect_success 'git clone --config= - section' '
1806 test_completion "git clone --config=br" <<-\EOF
1807 branch.Z
1808 browser.Z
1812 test_expect_success 'git clone --config= - variable name' '
1813 test_completion "git clone --config=log.d" <<-\EOF
1814 log.date=Z
1815 log.decorate=Z
1819 test_expect_success 'git clone --config= - value' '
1820 test_completion "git clone --config=color.pager=" <<-\EOF
1821 false Z
1822 true Z
1826 test_expect_success 'sourcing the completion script clears cached commands' '
1827 __git_compute_all_commands &&
1828 verbose test -n "$__git_all_commands" &&
1829 . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
1830 verbose test -z "$__git_all_commands"
1833 test_expect_success 'sourcing the completion script clears cached merge strategies' '
1834 GIT_TEST_GETTEXT_POISON=false &&
1835 __git_compute_merge_strategies &&
1836 verbose test -n "$__git_merge_strategies" &&
1837 . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
1838 verbose test -z "$__git_merge_strategies"
1841 test_expect_success 'sourcing the completion script clears cached --options' '
1842 __gitcomp_builtin checkout &&
1843 verbose test -n "$__gitcomp_builtin_checkout" &&
1844 __gitcomp_builtin notes_edit &&
1845 verbose test -n "$__gitcomp_builtin_notes_edit" &&
1846 . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
1847 verbose test -z "$__gitcomp_builtin_checkout" &&
1848 verbose test -z "$__gitcomp_builtin_notes_edit"
1851 test_done