3 # Copyright (c) 2012 Felipe Contreras
6 test_description='test bash completion'
16 # Be careful when updating these lists:
18 # (1) The build tree may have build artifact from different branch, or
19 # the user's $PATH may have a random executable that may begin
20 # with "git-check" that are not part of the subcommands this build
21 # will ship, e.g. "check-ignore". The tests for completion for
22 # subcommand names tests how "check" is expanded; we limit the
23 # possible candidates to "checkout" and "check-attr" to make sure
24 # "check-attr", which is known by the filter function as a
25 # subcommand to be thrown out, while excluding other random files
26 # that happen to begin with "check" to avoid letting them get in
29 # (2) A test makes sure that common subcommands are included in the
30 # completion for "git <TAB>", and a plumbing is excluded. "add",
31 # "rebase" and "ls-files" are listed for this.
33 GIT_TESTING_ALL_COMMAND_LIST='add checkout check-attr rebase ls-files'
34 GIT_TESTING_PORCELAIN_COMMAND_LIST='add checkout rebase'
36 . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash"
38 # We don't need this function to actually join words or do anything special.
39 # Also, it's cleaner to avoid touching bash's internal completion variables.
40 # So let's override it with a minimal version for testing purposes.
41 _get_comp_words_by_ref ()
43 while [ $# -gt 0 ]; do
49 prev=${_words[_cword-1]}
52 words=("${_words[@]}")
65 echo "${COMPREPLY[*]}" > out
70 local -a COMPREPLY _words
73 test "${1: -1}" = ' ' && _words[${#_words[@]}+1]=''
74 (( _cword = ${#_words[@]} - 1 ))
75 __git_wrap__git_main && print_comp
78 # Test high-level completion
80 # 1: typed text so far (cur)
81 # 2: expected completion
86 printf '%s\n' "$2" >expected
88 sed -e 's/Z$//' |sort >expected
90 run_completion "$1" &&
91 sort out >out_sorted &&
92 test_cmp expected out_sorted
96 # The first argument is the typed text so far (cur); the rest are
97 # passed to __gitcomp. Expected output comes is read from the
98 # standard input, like test_completion().
101 local -a COMPREPLY &&
102 sed -e 's/Z$//' >expected &&
107 test_cmp expected out
112 # 1: current word (cur)
113 # -: the rest are passed to __gitcomp_nl
116 local -a COMPREPLY &&
117 sed -e 's/Z$//' >expected &&
122 test_cmp expected out
125 invalid_variable_name='${foo.bar}'
127 actual="$TRASH_DIRECTORY/actual"
129 if test_have_prereq MINGW
136 test_expect_success 'setup for __git_find_repo_path/__gitdir tests' '
137 mkdir -p subdir/subsubdir &&
142 test_expect_success '__git_find_repo_path - from command line (through $__git_dir)' '
143 echo "$ROOT/otherrepo/.git" >expected &&
145 __git_dir="$ROOT/otherrepo/.git" &&
146 __git_find_repo_path &&
147 echo "$__git_repo_path" >"$actual"
149 test_cmp expected "$actual"
152 test_expect_success '__git_find_repo_path - .git directory in cwd' '
153 echo ".git" >expected &&
155 __git_find_repo_path &&
156 echo "$__git_repo_path" >"$actual"
158 test_cmp expected "$actual"
161 test_expect_success '__git_find_repo_path - .git directory in parent' '
162 echo "$ROOT/.git" >expected &&
164 cd subdir/subsubdir &&
165 __git_find_repo_path &&
166 echo "$__git_repo_path" >"$actual"
168 test_cmp expected "$actual"
171 test_expect_success '__git_find_repo_path - cwd is a .git directory' '
172 echo "." >expected &&
175 __git_find_repo_path &&
176 echo "$__git_repo_path" >"$actual"
178 test_cmp expected "$actual"
181 test_expect_success '__git_find_repo_path - parent is a .git directory' '
182 echo "$ROOT/.git" >expected &&
185 __git_find_repo_path &&
186 echo "$__git_repo_path" >"$actual"
188 test_cmp expected "$actual"
191 test_expect_success '__git_find_repo_path - $GIT_DIR set while .git directory in cwd' '
192 echo "$ROOT/otherrepo/.git" >expected &&
194 GIT_DIR="$ROOT/otherrepo/.git" &&
196 __git_find_repo_path &&
197 echo "$__git_repo_path" >"$actual"
199 test_cmp expected "$actual"
202 test_expect_success '__git_find_repo_path - $GIT_DIR set while .git directory in parent' '
203 echo "$ROOT/otherrepo/.git" >expected &&
205 GIT_DIR="$ROOT/otherrepo/.git" &&
208 __git_find_repo_path &&
209 echo "$__git_repo_path" >"$actual"
211 test_cmp expected "$actual"
214 test_expect_success '__git_find_repo_path - from command line while "git -C"' '
215 echo "$ROOT/.git" >expected &&
217 __git_dir="$ROOT/.git" &&
218 __git_C_args=(-C otherrepo) &&
219 __git_find_repo_path &&
220 echo "$__git_repo_path" >"$actual"
222 test_cmp expected "$actual"
225 test_expect_success '__git_find_repo_path - relative dir from command line and "git -C"' '
226 echo "$ROOT/otherrepo/.git" >expected &&
229 __git_dir="otherrepo/.git" &&
230 __git_C_args=(-C ..) &&
231 __git_find_repo_path &&
232 echo "$__git_repo_path" >"$actual"
234 test_cmp expected "$actual"
237 test_expect_success '__git_find_repo_path - $GIT_DIR set while "git -C"' '
238 echo "$ROOT/.git" >expected &&
240 GIT_DIR="$ROOT/.git" &&
242 __git_C_args=(-C otherrepo) &&
243 __git_find_repo_path &&
244 echo "$__git_repo_path" >"$actual"
246 test_cmp expected "$actual"
249 test_expect_success '__git_find_repo_path - relative dir in $GIT_DIR and "git -C"' '
250 echo "$ROOT/otherrepo/.git" >expected &&
253 GIT_DIR="otherrepo/.git" &&
255 __git_C_args=(-C ..) &&
256 __git_find_repo_path &&
257 echo "$__git_repo_path" >"$actual"
259 test_cmp expected "$actual"
262 test_expect_success '__git_find_repo_path - "git -C" while .git directory in cwd' '
263 echo "$ROOT/otherrepo/.git" >expected &&
265 __git_C_args=(-C otherrepo) &&
266 __git_find_repo_path &&
267 echo "$__git_repo_path" >"$actual"
269 test_cmp expected "$actual"
272 test_expect_success '__git_find_repo_path - "git -C" while cwd is a .git directory' '
273 echo "$ROOT/otherrepo/.git" >expected &&
276 __git_C_args=(-C .. -C otherrepo) &&
277 __git_find_repo_path &&
278 echo "$__git_repo_path" >"$actual"
280 test_cmp expected "$actual"
283 test_expect_success '__git_find_repo_path - "git -C" while .git directory in parent' '
284 echo "$ROOT/otherrepo/.git" >expected &&
287 __git_C_args=(-C .. -C otherrepo) &&
288 __git_find_repo_path &&
289 echo "$__git_repo_path" >"$actual"
291 test_cmp expected "$actual"
294 test_expect_success '__git_find_repo_path - non-existing path in "git -C"' '
296 __git_C_args=(-C non-existing) &&
297 test_must_fail __git_find_repo_path &&
298 printf "$__git_repo_path" >"$actual"
300 test_must_be_empty "$actual"
303 test_expect_success '__git_find_repo_path - non-existing path in $__git_dir' '
305 __git_dir="non-existing" &&
306 test_must_fail __git_find_repo_path &&
307 printf "$__git_repo_path" >"$actual"
309 test_must_be_empty "$actual"
312 test_expect_success '__git_find_repo_path - non-existing $GIT_DIR' '
314 GIT_DIR="$ROOT/non-existing" &&
316 test_must_fail __git_find_repo_path &&
317 printf "$__git_repo_path" >"$actual"
319 test_must_be_empty "$actual"
322 test_expect_success '__git_find_repo_path - gitfile in cwd' '
323 echo "$ROOT/otherrepo/.git" >expected &&
324 echo "gitdir: $ROOT/otherrepo/.git" >subdir/.git &&
325 test_when_finished "rm -f subdir/.git" &&
328 __git_find_repo_path &&
329 echo "$__git_repo_path" >"$actual"
331 test_cmp expected "$actual"
334 test_expect_success '__git_find_repo_path - gitfile in parent' '
335 echo "$ROOT/otherrepo/.git" >expected &&
336 echo "gitdir: $ROOT/otherrepo/.git" >subdir/.git &&
337 test_when_finished "rm -f subdir/.git" &&
339 cd subdir/subsubdir &&
340 __git_find_repo_path &&
341 echo "$__git_repo_path" >"$actual"
343 test_cmp expected "$actual"
346 test_expect_success SYMLINKS '__git_find_repo_path - resulting path avoids symlinks' '
347 echo "$ROOT/otherrepo/.git" >expected &&
348 mkdir otherrepo/dir &&
349 test_when_finished "rm -rf otherrepo/dir" &&
350 ln -s otherrepo/dir link &&
351 test_when_finished "rm -f link" &&
354 __git_find_repo_path &&
355 echo "$__git_repo_path" >"$actual"
357 test_cmp expected "$actual"
360 test_expect_success '__git_find_repo_path - not a git repository' '
363 GIT_CEILING_DIRECTORIES="$ROOT" &&
364 export GIT_CEILING_DIRECTORIES &&
365 test_must_fail __git_find_repo_path &&
366 printf "$__git_repo_path" >"$actual"
368 test_must_be_empty "$actual"
371 test_expect_success '__gitdir - finds repo' '
372 echo "$ROOT/.git" >expected &&
374 cd subdir/subsubdir &&
377 test_cmp expected "$actual"
381 test_expect_success '__gitdir - returns error when cannot find repo' '
383 __git_dir="non-existing" &&
384 test_must_fail __gitdir >"$actual"
386 test_must_be_empty "$actual"
389 test_expect_success '__gitdir - repo as argument' '
390 echo "otherrepo/.git" >expected &&
392 __gitdir "otherrepo" >"$actual"
394 test_cmp expected "$actual"
397 test_expect_success '__gitdir - remote as argument' '
398 echo "remote" >expected &&
400 __gitdir "remote" >"$actual"
402 test_cmp expected "$actual"
406 test_expect_success '__git_dequote - plain unquoted word' '
407 __git_dequote unquoted-word &&
408 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
451 $invalid_variable_name Z
454 cur=should_be_ignored &&
455 __gitcomp_direct "$(cat expected)" &&
458 test_cmp expected out
461 test_expect_success '__gitcomp - trailing space - options' '
462 test_gitcomp "--re" "--dry-run --reuse-message= --reedit-message=
463 --reset-author" <<-EOF
470 test_expect_success '__gitcomp - trailing space - config keys' '
471 test_gitcomp "br" "branch. branch.autosetupmerge
472 branch.autosetuprebase browser." <<-\EOF
474 branch.autosetupmerge Z
475 branch.autosetuprebase Z
480 test_expect_success '__gitcomp - option parameter' '
481 test_gitcomp "--strategy=re" "octopus ours recursive resolve subtree" \
488 test_expect_success '__gitcomp - prefix' '
489 test_gitcomp "branch.me" "remote merge mergeoptions rebase" \
490 "branch.maint." "me" <<-\EOF
492 branch.maint.mergeoptions Z
496 test_expect_success '__gitcomp - suffix' '
497 test_gitcomp "branch.me" "master maint next seen" "branch." \
504 test_expect_success '__gitcomp - ignore optional negative options' '
505 test_gitcomp "--" "--abc --def --no-one -- --no-two" <<-\EOF
513 test_expect_success '__gitcomp - ignore/narrow optional negative options' '
514 test_gitcomp "--a" "--abc --abcdef --no-one -- --no-two" <<-\EOF
520 test_expect_success '__gitcomp - ignore/narrow optional negative options' '
521 test_gitcomp "--n" "--abc --def --no-one -- --no-two" <<-\EOF
527 test_expect_success '__gitcomp - expand all negative options' '
528 test_gitcomp "--no-" "--abc --def --no-one -- --no-two" <<-\EOF
534 test_expect_success '__gitcomp - expand/narrow all negative options' '
535 test_gitcomp "--no-o" "--abc --def --no-one -- --no-two" <<-\EOF
540 test_expect_success '__gitcomp - doesnt fail because of invalid variable name' '
541 __gitcomp "$invalid_variable_name"
544 read -r -d "" refs <<-\EOF
551 test_expect_success '__gitcomp_nl - trailing space' '
552 test_gitcomp_nl "m" "$refs" <<-EOF
558 test_expect_success '__gitcomp_nl - prefix' '
559 test_gitcomp_nl "--fixup=m" "$refs" "--fixup=" "m" <<-EOF
565 test_expect_success '__gitcomp_nl - suffix' '
566 test_gitcomp_nl "branch.ma" "$refs" "branch." "ma" "." <<-\EOF
572 test_expect_success '__gitcomp_nl - no suffix' '
573 test_gitcomp_nl "ma" "$refs" "" "ma" "" <<-\EOF
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 &&
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
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 &&
621 git commit --allow-empty -m initial &&
622 git branch -m master master-in-other &&
623 git branch branch-in-other &&
626 git remote add other "$ROOT/otherrepo/.git" &&
627 git fetch --no-tags other &&
628 rm -f .git/FETCH_HEAD &&
632 test_expect_success '__git_refs - simple' '
633 cat >expected <<-EOF &&
637 other/branch-in-other
638 other/master-in-other
643 __git_refs >"$actual"
645 test_cmp expected "$actual"
648 test_expect_success '__git_refs - full refs' '
649 cat >expected <<-EOF &&
651 refs/heads/matching-branch
652 refs/remotes/other/branch-in-other
653 refs/remotes/other/master-in-other
654 refs/tags/matching-tag
658 __git_refs >"$actual"
660 test_cmp expected "$actual"
663 test_expect_success '__git_refs - repo given on the command line' '
664 cat >expected <<-EOF &&
671 __git_dir="$ROOT/otherrepo/.git" &&
673 __git_refs >"$actual"
675 test_cmp expected "$actual"
678 test_expect_success '__git_refs - remote on local file system' '
679 cat >expected <<-EOF &&
687 __git_refs otherrepo >"$actual"
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
700 __git_refs otherrepo >"$actual"
702 test_cmp expected "$actual"
705 test_expect_success '__git_refs - configured remote' '
706 cat >expected <<-EOF &&
713 __git_refs other >"$actual"
715 test_cmp expected "$actual"
718 test_expect_success '__git_refs - configured remote - full refs' '
719 cat >expected <<-EOF &&
721 refs/heads/branch-in-other
722 refs/heads/master-in-other
723 refs/tags/tag-in-other
727 __git_refs other >"$actual"
729 test_cmp expected "$actual"
732 test_expect_success '__git_refs - configured remote - repo given on the command line' '
733 cat >expected <<-EOF &&
740 __git_dir="$ROOT/.git" &&
742 __git_refs other >"$actual"
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 &&
750 refs/heads/branch-in-other
751 refs/heads/master-in-other
752 refs/tags/tag-in-other
756 __git_dir="$ROOT/.git" &&
758 __git_refs other >"$actual"
760 test_cmp expected "$actual"
763 test_expect_success '__git_refs - configured remote - remote name matches a directory' '
764 cat >expected <<-EOF &&
770 test_when_finished "rm -rf other" &&
773 __git_refs other >"$actual"
775 test_cmp expected "$actual"
778 test_expect_success '__git_refs - URL remote' '
779 cat >expected <<-EOF &&
787 __git_refs "file://$ROOT/otherrepo/.git" >"$actual"
789 test_cmp expected "$actual"
792 test_expect_success '__git_refs - URL remote - full refs' '
793 cat >expected <<-EOF &&
795 refs/heads/branch-in-other
796 refs/heads/master-in-other
797 refs/tags/tag-in-other
801 __git_refs "file://$ROOT/otherrepo/.git" >"$actual"
803 test_cmp expected "$actual"
806 test_expect_success '__git_refs - non-existing remote' '
809 __git_refs non-existing >"$actual"
811 test_must_be_empty "$actual"
814 test_expect_success '__git_refs - non-existing remote - full refs' '
817 __git_refs non-existing >"$actual"
819 test_must_be_empty "$actual"
822 test_expect_success '__git_refs - non-existing URL remote' '
825 __git_refs "file://$ROOT/non-existing" >"$actual"
827 test_must_be_empty "$actual"
830 test_expect_success '__git_refs - non-existing URL remote - full refs' '
833 __git_refs "file://$ROOT/non-existing" >"$actual"
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 &&
844 __git_refs >"$actual"
846 test_must_be_empty "$actual"
849 test_expect_success '__git_refs - unique remote branches for git checkout DWIMery' '
850 cat >expected <<-EOF &&
855 other/branch-in-other
856 other/master-in-other
858 remote/branch-in-remote
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"
873 __git_refs "" 1 >"$actual"
875 test_cmp expected "$actual"
878 test_expect_success '__git_refs - after --opt=' '
879 cat >expected <<-EOF &&
883 other/branch-in-other
884 other/master-in-other
889 __git_refs "" "" "" "" >"$actual"
891 test_cmp expected "$actual"
894 test_expect_success '__git_refs - after --opt= - full refs' '
895 cat >expected <<-EOF &&
897 refs/heads/matching-branch
898 refs/remotes/other/branch-in-other
899 refs/remotes/other/master-in-other
900 refs/tags/matching-tag
904 __git_refs "" "" "" refs/ >"$actual"
906 test_cmp expected "$actual"
909 test_expect_success '__git refs - exluding refs' '
910 cat >expected <<-EOF &&
914 ^other/branch-in-other
915 ^other/master-in-other
920 __git_refs >"$actual"
922 test_cmp expected "$actual"
925 test_expect_success '__git refs - exluding full refs' '
926 cat >expected <<-EOF &&
928 ^refs/heads/matching-branch
929 ^refs/remotes/other/branch-in-other
930 ^refs/remotes/other/master-in-other
931 ^refs/tags/matching-tag
935 __git_refs >"$actual"
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 &&
954 other/branch-in-other
955 other/master-in-other
956 other/matching/branch-in-other
962 __git_refs >"$actual"
964 test_cmp expected "$actual"
967 test_expect_success '__git_refs - only matching refs' '
968 cat >expected <<-EOF &&
976 __git_refs "" "" "" "$cur" >"$actual"
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"
990 test_cmp expected "$actual"
993 test_expect_success '__git_refs - only matching refs - remote on local file system' '
994 cat >expected <<-EOF &&
996 matching/branch-in-other
1000 __git_refs otherrepo "" "" "$cur" >"$actual"
1002 test_cmp expected "$actual"
1005 test_expect_success '__git_refs - only matching refs - configured remote' '
1006 cat >expected <<-EOF &&
1008 matching/branch-in-other
1012 __git_refs other "" "" "$cur" >"$actual"
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"
1026 test_cmp expected "$actual"
1029 test_expect_success '__git_refs - only matching refs - checkout DWIMery' '
1030 cat >expected <<-EOF &&
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"
1046 __git_refs "" 1 "" "$cur" >"$actual"
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 PREPARE_FOR_MAIN_BRANCH '__git_refs - for-each-ref format specifiers in prefix' '
1059 cat >expected <<-EOF &&
1060 evil-%%-%42-%(refname)..master
1063 cur="evil-%%-%42-%(refname)..mai" &&
1064 __git_refs "" "" "evil-%%-%42-%(refname).." mai >"$actual"
1066 test_cmp expected "$actual"
1069 test_expect_success '__git_complete_refs - simple' '
1070 sed -e "s/Z$//" >expected <<-EOF &&
1074 other/branch-in-other Z
1075 other/master-in-other Z
1080 __git_complete_refs &&
1083 test_cmp expected out
1086 test_expect_success '__git_complete_refs - matching' '
1087 sed -e "s/Z$//" >expected <<-EOF &&
1093 __git_complete_refs &&
1096 test_cmp expected out
1099 test_expect_success '__git_complete_refs - remote' '
1100 sed -e "s/Z$//" >expected <<-EOF &&
1107 __git_complete_refs --remote=other &&
1110 test_cmp expected out
1113 test_expect_success '__git_complete_refs - track' '
1114 sed -e "s/Z$//" >expected <<-EOF &&
1118 other/branch-in-other Z
1119 other/master-in-other Z
1126 __git_complete_refs --track &&
1129 test_cmp expected out
1132 test_expect_success '__git_complete_refs - current word' '
1133 sed -e "s/Z$//" >expected <<-EOF &&
1138 cur="--option=mat" &&
1139 __git_complete_refs --cur="${cur#*=}" &&
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
1152 __git_complete_refs --pfx=v1.0.. --cur=mat &&
1155 test_cmp expected out
1158 test_expect_success '__git_complete_refs - suffix' '
1159 cat >expected <<-EOF &&
1163 other/branch-in-other.
1164 other/master-in-other.
1169 __git_complete_refs --sfx=. &&
1172 test_cmp expected out
1175 test_expect_success '__git_complete_fetch_refspecs - simple' '
1176 sed -e "s/Z$//" >expected <<-EOF &&
1178 branch-in-other:branch-in-other Z
1179 master-in-other:master-in-other Z
1183 __git_complete_fetch_refspecs other &&
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
1195 __git_complete_fetch_refspecs other "" br &&
1198 test_cmp expected out
1201 test_expect_success '__git_complete_fetch_refspecs - prefix' '
1202 sed -e "s/Z$//" >expected <<-EOF &&
1204 +branch-in-other:branch-in-other Z
1205 +master-in-other:master-in-other Z
1209 __git_complete_fetch_refspecs other "+" "" &&
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
1223 __git_complete_fetch_refspecs other "" refs/ &&
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
1237 __git_complete_fetch_refspecs other + refs/ &&
1240 test_cmp expected out
1243 test_expect_success 'git switch - with no options, complete local branches and unique remote branch names for DWIM logic' '
1244 test_completion "git switch " <<-\EOF
1252 test_expect_success 'git checkout - completes refs and unique remote branches for DWIM' '
1253 test_completion "git checkout " <<-\EOF
1260 other/branch-in-other Z
1261 other/master-in-other Z
1265 test_expect_success 'git switch - with --no-guess, complete only local branches' '
1266 test_completion "git switch --no-guess " <<-\EOF
1272 test_expect_success 'git switch - with GIT_COMPLETION_CHECKOUT_NO_GUESS=1, complete only local branches' '
1273 GIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion "git switch " <<-\EOF
1279 test_expect_success 'git switch - --guess overrides GIT_COMPLETION_CHECKOUT_NO_GUESS=1, complete local branches and unique remote names for DWIM logic' '
1280 GIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion "git switch --guess " <<-\EOF
1288 test_expect_success 'git switch - a later --guess overrides previous --no-guess, complete local and remote unique branches for DWIM' '
1289 test_completion "git switch --no-guess --guess " <<-\EOF
1297 test_expect_success 'git switch - a later --no-guess overrides previous --guess, complete only local branches' '
1298 test_completion "git switch --guess --no-guess " <<-\EOF
1304 test_expect_success 'git checkout - with GIT_COMPLETION_NO_GUESS=1 only completes refs' '
1305 GIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion "git checkout " <<-\EOF
1310 other/branch-in-other Z
1311 other/master-in-other Z
1315 test_expect_success 'git checkout - --guess overrides GIT_COMPLETION_NO_GUESS=1, complete refs and unique remote branches for DWIM' '
1316 GIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion "git checkout --guess " <<-\EOF
1323 other/branch-in-other Z
1324 other/master-in-other Z
1328 test_expect_success 'git checkout - with --no-guess, only completes refs' '
1329 test_completion "git checkout --no-guess " <<-\EOF
1334 other/branch-in-other Z
1335 other/master-in-other Z
1339 test_expect_success 'git checkout - a later --guess overrides previous --no-guess, complete refs and unique remote branches for DWIM' '
1340 test_completion "git checkout --no-guess --guess " <<-\EOF
1347 other/branch-in-other Z
1348 other/master-in-other Z
1352 test_expect_success 'git checkout - a later --no-guess overrides previous --guess, complete only refs' '
1353 test_completion "git checkout --guess --no-guess " <<-\EOF
1358 other/branch-in-other Z
1359 other/master-in-other Z
1363 test_expect_success 'git checkout - with checkout.guess = false, only completes refs' '
1364 test_config checkout.guess false &&
1365 test_completion "git checkout " <<-\EOF
1370 other/branch-in-other Z
1371 other/master-in-other Z
1375 test_expect_success 'git checkout - with checkout.guess = true, completes refs and unique remote branches for DWIM' '
1376 test_config checkout.guess true &&
1377 test_completion "git checkout " <<-\EOF
1384 other/branch-in-other Z
1385 other/master-in-other Z
1389 test_expect_success 'git checkout - a later --guess overrides previous checkout.guess = false, complete refs and unique remote branches for DWIM' '
1390 test_config checkout.guess false &&
1391 test_completion "git checkout --guess " <<-\EOF
1398 other/branch-in-other Z
1399 other/master-in-other Z
1403 test_expect_success 'git checkout - a later --no-guess overrides previous checkout.guess = true, complete only refs' '
1404 test_config checkout.guess true &&
1405 test_completion "git checkout --no-guess " <<-\EOF
1410 other/branch-in-other Z
1411 other/master-in-other Z
1415 test_expect_success 'git switch - with --detach, complete all references' '
1416 test_completion "git switch --detach " <<-\EOF
1421 other/branch-in-other Z
1422 other/master-in-other Z
1426 test_expect_success 'git checkout - with --detach, complete only references' '
1427 test_completion "git checkout --detach " <<-\EOF
1432 other/branch-in-other Z
1433 other/master-in-other Z
1437 test_expect_success 'git switch - with -d, complete all references' '
1438 test_completion "git switch -d " <<-\EOF
1443 other/branch-in-other Z
1444 other/master-in-other Z
1448 test_expect_success 'git checkout - with -d, complete only references' '
1449 test_completion "git checkout -d " <<-\EOF
1454 other/branch-in-other Z
1455 other/master-in-other Z
1459 test_expect_success 'git switch - with --track, complete only remote branches' '
1460 test_completion "git switch --track " <<-\EOF
1461 other/branch-in-other Z
1462 other/master-in-other Z
1466 test_expect_success 'git checkout - with --track, complete only remote branches' '
1467 test_completion "git checkout --track " <<-\EOF
1468 other/branch-in-other Z
1469 other/master-in-other Z
1473 test_expect_success 'git switch - with --no-track, complete only local branch names' '
1474 test_completion "git switch --no-track " <<-\EOF
1480 test_expect_success 'git checkout - with --no-track, complete only local references' '
1481 test_completion "git checkout --no-track " <<-\EOF
1486 other/branch-in-other Z
1487 other/master-in-other Z
1491 test_expect_success 'git switch - with -c, complete all references' '
1492 test_completion "git switch -c new-branch " <<-\EOF
1497 other/branch-in-other Z
1498 other/master-in-other Z
1502 test_expect_success 'git switch - with -C, complete all references' '
1503 test_completion "git switch -C new-branch " <<-\EOF
1508 other/branch-in-other Z
1509 other/master-in-other Z
1513 test_expect_success 'git switch - with -c and --track, complete all references' '
1514 test_completion "git switch -c new-branch --track " <<-EOF
1519 other/branch-in-other Z
1520 other/master-in-other Z
1524 test_expect_success 'git switch - with -C and --track, complete all references' '
1525 test_completion "git switch -C new-branch --track " <<-EOF
1530 other/branch-in-other Z
1531 other/master-in-other Z
1535 test_expect_success 'git switch - with -c and --no-track, complete all references' '
1536 test_completion "git switch -c new-branch --no-track " <<-\EOF
1541 other/branch-in-other Z
1542 other/master-in-other Z
1546 test_expect_success 'git switch - with -C and --no-track, complete all references' '
1547 test_completion "git switch -C new-branch --no-track " <<-\EOF
1552 other/branch-in-other Z
1553 other/master-in-other Z
1557 test_expect_success 'git checkout - with -b, complete all references' '
1558 test_completion "git checkout -b new-branch " <<-\EOF
1563 other/branch-in-other Z
1564 other/master-in-other Z
1568 test_expect_success 'git checkout - with -B, complete all references' '
1569 test_completion "git checkout -B new-branch " <<-\EOF
1574 other/branch-in-other Z
1575 other/master-in-other Z
1579 test_expect_success 'git checkout - with -b and --track, complete all references' '
1580 test_completion "git checkout -b new-branch --track " <<-EOF
1585 other/branch-in-other Z
1586 other/master-in-other Z
1590 test_expect_success 'git checkout - with -B and --track, complete all references' '
1591 test_completion "git checkout -B new-branch --track " <<-EOF
1596 other/branch-in-other Z
1597 other/master-in-other Z
1601 test_expect_success 'git checkout - with -b and --no-track, complete all references' '
1602 test_completion "git checkout -b new-branch --no-track " <<-\EOF
1607 other/branch-in-other Z
1608 other/master-in-other Z
1612 test_expect_success 'git checkout - with -B and --no-track, complete all references' '
1613 test_completion "git checkout -B new-branch --no-track " <<-\EOF
1618 other/branch-in-other Z
1619 other/master-in-other Z
1623 test_expect_success 'git switch - for -c, complete local branches and unique remote branches' '
1624 test_completion "git switch -c " <<-\EOF
1632 test_expect_success 'git switch - for -C, complete local branches and unique remote branches' '
1633 test_completion "git switch -C " <<-\EOF
1641 test_expect_success 'git switch - for -c with --no-guess, complete local branches only' '
1642 test_completion "git switch --no-guess -c " <<-\EOF
1648 test_expect_success 'git switch - for -C with --no-guess, complete local branches only' '
1649 test_completion "git switch --no-guess -C " <<-\EOF
1655 test_expect_success 'git switch - for -c with --no-track, complete local branches only' '
1656 test_completion "git switch --no-track -c " <<-\EOF
1662 test_expect_success 'git switch - for -C with --no-track, complete local branches only' '
1663 test_completion "git switch --no-track -C " <<-\EOF
1669 test_expect_success 'git checkout - for -b, complete local branches and unique remote branches' '
1670 test_completion "git checkout -b " <<-\EOF
1678 test_expect_success 'git checkout - for -B, complete local branches and unique remote branches' '
1679 test_completion "git checkout -B " <<-\EOF
1687 test_expect_success 'git checkout - for -b with --no-guess, complete local branches only' '
1688 test_completion "git checkout --no-guess -b " <<-\EOF
1694 test_expect_success 'git checkout - for -B with --no-guess, complete local branches only' '
1695 test_completion "git checkout --no-guess -B " <<-\EOF
1701 test_expect_success 'git checkout - for -b with --no-track, complete local branches only' '
1702 test_completion "git checkout --no-track -b " <<-\EOF
1708 test_expect_success 'git checkout - for -B with --no-track, complete local branches only' '
1709 test_completion "git checkout --no-track -B " <<-\EOF
1715 test_expect_success 'git switch - with --orphan completes local branch names and unique remote branch names' '
1716 test_completion "git switch --orphan " <<-\EOF
1724 test_expect_success 'git switch - --orphan with branch already provided completes nothing else' '
1725 test_completion "git switch --orphan master " <<-\EOF
1730 test_expect_success 'git checkout - with --orphan completes local branch names and unique remote branch names' '
1731 test_completion "git checkout --orphan " <<-\EOF
1739 test_expect_success 'git checkout - --orphan with branch already provided completes local refs for a start-point' '
1740 test_completion "git checkout --orphan master " <<-\EOF
1745 other/branch-in-other Z
1746 other/master-in-other Z
1750 test_expect_success 'teardown after ref completion' '
1751 git branch -d matching-branch &&
1752 git tag -d matching-tag &&
1753 git remote remove other
1757 test_path_completion ()
1759 test $# = 2 || BUG "not 2 parameters to test_path_completion"
1761 local cur="$1" expected="$2"
1762 echo "$expected" >expected &&
1764 # In the following tests calling this function we only
1765 # care about how __git_complete_index_file() deals with
1766 # unusual characters in path names. By requesting only
1767 # untracked files we do not have to bother adding any
1768 # paths to the index in those tests.
1769 __git_complete_index_file --others &&
1772 test_cmp expected out
1775 test_expect_success 'setup for path completion tests' '
1779 touch simple-dir/simple-file \
1780 "spaces in dir/spaces in file" \
1781 "árvíztűrő/Сайн яваарай" &&
1782 if test_have_prereq !MINGW &&
1784 '$'separators\034in\035dir'' &&
1785 touch BS\\dir/DQ\"file \
1786 '$'separators\034in\035dir/sep\036in\037file''
1788 test_set_prereq FUNNIERNAMES
1790 rm -rf BS\\dir '$'separators\034in\035dir''
1794 test_expect_success '__git_complete_index_file - simple' '
1795 test_path_completion simple simple-dir && # Bash is supposed to
1796 # add the trailing /.
1797 test_path_completion simple-dir/simple simple-dir/simple-file
1800 test_expect_success \
1801 '__git_complete_index_file - escaped characters on cmdline' '
1802 test_path_completion spac "spaces in dir" && # Bash will turn this
1803 # into "spaces\ in\ dir"
1804 test_path_completion "spaces\\ i" \
1806 test_path_completion "spaces\\ in\\ dir/s" \
1807 "spaces in dir/spaces in file" &&
1808 test_path_completion "spaces\\ in\\ dir/spaces\\ i" \
1809 "spaces in dir/spaces in file"
1812 test_expect_success \
1813 '__git_complete_index_file - quoted characters on cmdline' '
1814 # Testing with an opening but without a corresponding closing
1815 # double quote is important.
1816 test_path_completion \"spac "spaces in dir" &&
1817 test_path_completion "\"spaces i" \
1819 test_path_completion "\"spaces in dir/s" \
1820 "spaces in dir/spaces in file" &&
1821 test_path_completion "\"spaces in dir/spaces i" \
1822 "spaces in dir/spaces in file"
1825 test_expect_success '__git_complete_index_file - UTF-8 in ls-files output' '
1826 test_path_completion á árvíztűrő &&
1827 test_path_completion árvíztűrő/С "árvíztűrő/Сайн яваарай"
1830 test_expect_success FUNNIERNAMES \
1831 '__git_complete_index_file - C-style escapes in ls-files output' '
1832 test_path_completion BS \
1834 test_path_completion BS\\\\d \
1836 test_path_completion BS\\\\dir/DQ \
1838 test_path_completion BS\\\\dir/DQ\\\"f \
1842 test_expect_success FUNNIERNAMES \
1843 '__git_complete_index_file - \nnn-escaped characters in ls-files output' '
1844 test_path_completion sep '$'separators\034in\035dir'' &&
1845 test_path_completion '$'separators\034i'' \
1846 '$'separators\034in\035dir'' &&
1847 test_path_completion '$'separators\034in\035dir/sep'' \
1848 '$'separators\034in\035dir/sep\036in\037file'' &&
1849 test_path_completion '$'separators\034in\035dir/sep\036i'' \
1850 '$'separators\034in\035dir/sep\036in\037file''
1853 test_expect_success FUNNYNAMES \
1854 '__git_complete_index_file - removing repeated quoted path components' '
1855 test_when_finished rm -r repeated-quoted &&
1856 mkdir repeated-quoted && # A directory whose name in itself
1857 # would not be quoted ...
1858 >repeated-quoted/0-file &&
1859 >repeated-quoted/1\"file && # ... but here the file makes the
1860 # dirname quoted ...
1861 >repeated-quoted/2-file &&
1862 >repeated-quoted/3\"file && # ... and here, too.
1864 # Still, we shold only list the directory name only once.
1865 test_path_completion repeated repeated-quoted
1868 test_expect_success 'teardown after path completion tests' '
1869 rm -rf simple-dir "spaces in dir" árvíztűrő \
1870 BS\\dir '$'separators\034in\035dir''
1873 test_expect_success '__git_find_on_cmdline - single match' '
1874 echo list >expect &&
1876 words=(git command --opt list) &&
1877 cword=${#words[@]} &&
1878 __git_find_on_cmdline "add list remove" >actual
1880 test_cmp expect actual
1883 test_expect_success '__git_find_on_cmdline - multiple matches' '
1884 echo remove >expect &&
1886 words=(git command -o --opt remove list add) &&
1887 cword=${#words[@]} &&
1888 __git_find_on_cmdline "add list remove" >actual
1890 test_cmp expect actual
1893 test_expect_success '__git_find_on_cmdline - no match' '
1895 words=(git command --opt branch) &&
1896 cword=${#words[@]} &&
1897 __git_find_on_cmdline "add list remove" >actual
1899 test_must_be_empty actual
1902 test_expect_success '__git_find_on_cmdline - single match with index' '
1903 echo "3 list" >expect &&
1905 words=(git command --opt list) &&
1906 cword=${#words[@]} &&
1907 __git_find_on_cmdline --show-idx "add list remove" >actual
1909 test_cmp expect actual
1912 test_expect_success '__git_find_on_cmdline - multiple matches with index' '
1913 echo "4 remove" >expect &&
1915 words=(git command -o --opt remove list add) &&
1916 cword=${#words[@]} &&
1917 __git_find_on_cmdline --show-idx "add list remove" >actual
1919 test_cmp expect actual
1922 test_expect_success '__git_find_on_cmdline - no match with index' '
1924 words=(git command --opt branch) &&
1925 cword=${#words[@]} &&
1926 __git_find_on_cmdline --show-idx "add list remove" >actual
1928 test_must_be_empty actual
1931 test_expect_success '__git_get_config_variables' '
1932 cat >expect <<-EOF &&
1936 test_config interesting.name-1 good &&
1937 test_config interesting.name-2 good &&
1938 test_config subsection.interesting.name-3 bad &&
1939 __git_get_config_variables interesting >actual &&
1940 test_cmp expect actual
1943 test_expect_success '__git_pretty_aliases' '
1944 cat >expect <<-EOF &&
1948 test_config pretty.author "%an %ae" &&
1949 test_config pretty.hash %H &&
1950 __git_pretty_aliases >actual &&
1951 test_cmp expect actual
1954 test_expect_success 'basic' '
1955 run_completion "git " &&
1957 grep -q "^add \$" out &&
1959 grep -q "^rebase \$" out &&
1961 ! grep -q "^ls-files \$" out &&
1963 run_completion "git r" &&
1964 ! grep -q -v "^r" out
1967 test_expect_success 'double dash "git" itself' '
1968 test_completion "git --" <<-\EOF
1981 --no-replace-objects Z
1986 test_expect_success 'double dash "git checkout"' '
1987 test_completion "git checkout --" <<-\EOF
1997 --ignore-skip-worktree-bits Z
1998 --ignore-other-worktrees Z
1999 --recurse-submodules Z
2005 --pathspec-file-nul Z
2006 --pathspec-from-file=Z
2010 test_expect_success 'general options' '
2011 test_completion "git --ver" "--version " &&
2012 test_completion "git --hel" "--help " &&
2013 test_completion "git --exe" <<-\EOF &&
2017 test_completion "git --htm" "--html-path " &&
2018 test_completion "git --pag" "--paginate " &&
2019 test_completion "git --no-p" "--no-pager " &&
2020 test_completion "git --git" "--git-dir=" &&
2021 test_completion "git --wor" "--work-tree=" &&
2022 test_completion "git --nam" "--namespace=" &&
2023 test_completion "git --bar" "--bare " &&
2024 test_completion "git --inf" "--info-path " &&
2025 test_completion "git --no-r" "--no-replace-objects "
2028 test_expect_success 'general options plus command' '
2029 test_completion "git --version check" "checkout " &&
2030 test_completion "git --paginate check" "checkout " &&
2031 test_completion "git --git-dir=foo check" "checkout " &&
2032 test_completion "git --bare check" "checkout " &&
2033 test_completion "git --exec-path=foo check" "checkout " &&
2034 test_completion "git --html-path check" "checkout " &&
2035 test_completion "git --no-pager check" "checkout " &&
2036 test_completion "git --work-tree=foo check" "checkout " &&
2037 test_completion "git --namespace=foo check" "checkout " &&
2038 test_completion "git --paginate check" "checkout " &&
2039 test_completion "git --info-path check" "checkout " &&
2040 test_completion "git --no-replace-objects check" "checkout " &&
2041 test_completion "git --git-dir some/path check" "checkout " &&
2042 test_completion "git -c conf.var=value check" "checkout " &&
2043 test_completion "git -C some/path check" "checkout " &&
2044 test_completion "git --work-tree some/path check" "checkout " &&
2045 test_completion "git --namespace name/space check" "checkout "
2048 test_expect_success 'git --help completion' '
2049 test_completion "git --help ad" "add " &&
2050 test_completion "git --help core" "core-tutorial "
2053 test_expect_success 'completion.commands removes multiple commands' '
2054 test_config completion.commands "-cherry -mergetool" &&
2055 git --list-cmds=list-mainporcelain,list-complete,config >out &&
2056 ! grep -E "^(cherry|mergetool)$" out
2059 test_expect_success 'setup for integration tests' '
2060 echo content >file1 &&
2062 git add file1 file2 &&
2063 git commit -m one &&
2064 git branch mybranch &&
2068 test_expect_success 'checkout completes ref names' '
2069 test_completion "git checkout m" <<-\EOF
2076 test_expect_success 'git -C <path> checkout uses the right repo' '
2077 test_completion "git -C subdir -C subsubdir -C .. -C ../otherrepo checkout b" <<-\EOF
2082 test_expect_success 'show completes all refs' '
2083 test_completion "git show m" <<-\EOF
2090 test_expect_success '<ref>: completes paths' '
2091 test_completion "git show mytag:f" <<-\EOF
2097 test_expect_success 'complete tree filename with spaces' '
2098 echo content >"name with spaces" &&
2099 git add "name with spaces" &&
2100 git commit -m spaces &&
2101 test_completion "git show HEAD:nam" <<-\EOF
2106 test_expect_success 'complete tree filename with metacharacters' '
2107 echo content >"name with \${meta}" &&
2108 git add "name with \${meta}" &&
2109 git commit -m meta &&
2110 test_completion "git show HEAD:nam" <<-\EOF
2116 test_expect_success PERL 'send-email' '
2117 test_completion "git send-email --cov" <<-\EOF &&
2118 --cover-from-description=Z
2121 test_completion "git send-email ma" "master "
2124 test_expect_success 'complete files' '
2125 git init tmp && cd tmp &&
2126 test_when_finished "cd .. && rm -rf tmp" &&
2128 echo "expected" > .gitignore &&
2129 echo "out" >> .gitignore &&
2130 echo "out_sorted" >> .gitignore &&
2132 git add .gitignore &&
2133 test_completion "git commit " ".gitignore" &&
2135 git commit -m ignore &&
2138 test_completion "git add " "new" &&
2141 git commit -a -m new &&
2142 test_completion "git add " "" &&
2144 git mv new modified &&
2145 echo modify > modified &&
2146 test_completion "git add " "modified" &&
2148 mkdir -p some/deep &&
2149 touch some/deep/path &&
2150 test_completion "git add some/" "some/deep" &&
2151 git clean -f some &&
2155 : TODO .gitignore should not be here &&
2156 test_completion "git rm " <<-\EOF &&
2161 test_completion "git clean " "untracked" &&
2163 : TODO .gitignore should not be here &&
2164 test_completion "git mv " <<-\EOF &&
2170 touch dir/file-in-dir &&
2171 git add dir/file-in-dir &&
2172 git commit -m dir &&
2174 mkdir untracked-dir &&
2176 : TODO .gitignore should not be here &&
2177 test_completion "git mv modified " <<-\EOF &&
2185 test_completion "git commit " "modified" &&
2187 : TODO .gitignore should not be here &&
2188 test_completion "git ls-files " <<-\EOF &&
2195 test_completion "git add mom" "momified"
2198 test_expect_success "completion uses <cmd> completion for alias: !sh -c 'git <cmd> ...'" '
2199 test_config alias.co "!sh -c '"'"'git checkout ...'"'"'" &&
2200 test_completion "git co m" <<-\EOF
2207 test_expect_success 'completion uses <cmd> completion for alias: !f () { VAR=val git <cmd> ... }' '
2208 test_config alias.co "!f () { VAR=val git checkout ... ; } f" &&
2209 test_completion "git co m" <<-\EOF
2216 test_expect_success 'completion used <cmd> completion for alias: !f() { : git <cmd> ; ... }' '
2217 test_config alias.co "!f() { : git checkout ; if ... } f" &&
2218 test_completion "git co m" <<-\EOF
2225 test_expect_success 'completion without explicit _git_xxx function' '
2226 test_completion "git version --" <<-\EOF
2228 --no-build-options Z
2232 test_expect_failure 'complete with tilde expansion' '
2233 git init tmp && cd tmp &&
2234 test_when_finished "cd .. && rm -rf tmp" &&
2238 test_completion "git add ~/tmp/" "~/tmp/file"
2241 test_expect_success 'setup other remote for remote reference completion' '
2242 git remote add other otherrepo &&
2246 for flag in -d --delete
2248 test_expect_success "__git_complete_remote_or_refspec - push $flag other" '
2249 sed -e "s/Z$//" >expected <<-EOF &&
2253 words=(git push '$flag' other ma) &&
2254 cword=${#words[@]} cur=${words[cword-1]} &&
2255 __git_complete_remote_or_refspec &&
2258 test_cmp expected out
2261 test_expect_failure "__git_complete_remote_or_refspec - push other $flag" '
2262 sed -e "s/Z$//" >expected <<-EOF &&
2266 words=(git push other '$flag' ma) &&
2267 cword=${#words[@]} cur=${words[cword-1]} &&
2268 __git_complete_remote_or_refspec &&
2271 test_cmp expected out
2275 test_expect_success 'git config - section' '
2276 test_completion "git config br" <<-\EOF
2282 test_expect_success 'git config - variable name' '
2283 test_completion "git config log.d" <<-\EOF
2289 test_expect_success 'git config - value' '
2290 test_completion "git config color.pager " <<-\EOF
2296 test_expect_success 'git -c - section' '
2297 test_completion "git -c br" <<-\EOF
2303 test_expect_success 'git -c - variable name' '
2304 test_completion "git -c log.d" <<-\EOF
2310 test_expect_success 'git -c - value' '
2311 test_completion "git -c color.pager=" <<-\EOF
2317 test_expect_success 'git clone --config= - section' '
2318 test_completion "git clone --config=br" <<-\EOF
2324 test_expect_success 'git clone --config= - variable name' '
2325 test_completion "git clone --config=log.d" <<-\EOF
2331 test_expect_success 'git clone --config= - value' '
2332 test_completion "git clone --config=color.pager=" <<-\EOF
2338 test_expect_success 'sourcing the completion script clears cached commands' '
2339 __git_compute_all_commands &&
2340 verbose test -n "$__git_all_commands" &&
2341 . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
2342 verbose test -z "$__git_all_commands"
2345 test_expect_success 'sourcing the completion script clears cached merge strategies' '
2346 GIT_TEST_GETTEXT_POISON=false &&
2347 __git_compute_merge_strategies &&
2348 verbose test -n "$__git_merge_strategies" &&
2349 . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
2350 verbose test -z "$__git_merge_strategies"
2353 test_expect_success 'sourcing the completion script clears cached --options' '
2354 __gitcomp_builtin checkout &&
2355 verbose test -n "$__gitcomp_builtin_checkout" &&
2356 __gitcomp_builtin notes_edit &&
2357 verbose test -n "$__gitcomp_builtin_notes_edit" &&
2358 . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
2359 verbose test -z "$__gitcomp_builtin_checkout" &&
2360 verbose test -z "$__gitcomp_builtin_notes_edit"