3 # Copyright (c) 2012-2020 Felipe Contreras
6 test_description='test bash completion'
8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
19 # Be careful when updating these lists:
21 # (1) The build tree may have build artifact from different branch, or
22 # the user's $PATH may have a random executable that may begin
23 # with "git-check" that are not part of the subcommands this build
24 # will ship, e.g. "check-ignore". The tests for completion for
25 # subcommand names tests how "check" is expanded; we limit the
26 # possible candidates to "checkout" and "check-attr" to make sure
27 # "check-attr", which is known by the filter function as a
28 # subcommand to be thrown out, while excluding other random files
29 # that happen to begin with "check" to avoid letting them get in
32 # (2) A test makes sure that common subcommands are included in the
33 # completion for "git <TAB>", and a plumbing is excluded. "add",
34 # "rebase" and "ls-files" are listed for this.
36 GIT_TESTING_ALL_COMMAND_LIST='add checkout check-attr rebase ls-files'
37 GIT_TESTING_PORCELAIN_COMMAND_LIST='add checkout rebase'
39 . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash"
41 # We don't need this function to actually join words or do anything special.
42 # Also, it's cleaner to avoid touching bash's internal completion variables.
43 # So let's override it with a minimal version for testing purposes.
44 _get_comp_words_by_ref ()
46 while [ $# -gt 0 ]; do
52 prev=${_words[_cword-1]}
55 words=("${_words[@]}")
68 echo "${COMPREPLY[*]}" > out
73 local -a COMPREPLY _words
76 test "${1: -1}" = ' ' && _words[${#_words[@]}+1]=''
77 (( _cword = ${#_words[@]} - 1 ))
78 __git_wrap__git_main && print_comp
81 # Test high-level completion
83 # 1: typed text so far (cur)
84 # 2: expected completion
89 printf '%s\n' "$2" >expected
91 sed -e 's/Z$//' |sort >expected
93 run_completion "$1" &&
94 sort out >out_sorted &&
95 test_cmp expected out_sorted
99 # The first argument is the typed text so far (cur); the rest are
100 # passed to __gitcomp. Expected output comes is read from the
101 # standard input, like test_completion().
104 local -a COMPREPLY &&
105 sed -e 's/Z$//' >expected &&
110 test_cmp expected out
115 # 1: current word (cur)
116 # -: the rest are passed to __gitcomp_nl
119 local -a COMPREPLY &&
120 sed -e 's/Z$//' >expected &&
125 test_cmp expected out
128 invalid_variable_name='${foo.bar}'
130 actual="$TRASH_DIRECTORY/actual"
132 if test_have_prereq MINGW
139 test_expect_success 'setup for __git_find_repo_path/__gitdir tests' '
140 mkdir -p subdir/subsubdir &&
145 test_expect_success '__git_find_repo_path - from command line (through $__git_dir)' '
146 echo "$ROOT/otherrepo/.git" >expected &&
148 __git_dir="$ROOT/otherrepo/.git" &&
149 __git_find_repo_path &&
150 echo "$__git_repo_path" >"$actual"
152 test_cmp expected "$actual"
155 test_expect_success '__git_find_repo_path - .git directory in cwd' '
156 echo ".git" >expected &&
158 __git_find_repo_path &&
159 echo "$__git_repo_path" >"$actual"
161 test_cmp expected "$actual"
164 test_expect_success '__git_find_repo_path - .git directory in parent' '
165 echo "$ROOT/.git" >expected &&
167 cd subdir/subsubdir &&
168 __git_find_repo_path &&
169 echo "$__git_repo_path" >"$actual"
171 test_cmp expected "$actual"
174 test_expect_success '__git_find_repo_path - cwd is a .git directory' '
175 echo "." >expected &&
178 __git_find_repo_path &&
179 echo "$__git_repo_path" >"$actual"
181 test_cmp expected "$actual"
184 test_expect_success '__git_find_repo_path - parent is a .git directory' '
185 echo "$ROOT/.git" >expected &&
188 __git_find_repo_path &&
189 echo "$__git_repo_path" >"$actual"
191 test_cmp expected "$actual"
194 test_expect_success '__git_find_repo_path - $GIT_DIR set while .git directory in cwd' '
195 echo "$ROOT/otherrepo/.git" >expected &&
197 GIT_DIR="$ROOT/otherrepo/.git" &&
199 __git_find_repo_path &&
200 echo "$__git_repo_path" >"$actual"
202 test_cmp expected "$actual"
205 test_expect_success '__git_find_repo_path - $GIT_DIR set while .git directory in parent' '
206 echo "$ROOT/otherrepo/.git" >expected &&
208 GIT_DIR="$ROOT/otherrepo/.git" &&
211 __git_find_repo_path &&
212 echo "$__git_repo_path" >"$actual"
214 test_cmp expected "$actual"
217 test_expect_success '__git_find_repo_path - from command line while "git -C"' '
218 echo "$ROOT/.git" >expected &&
220 __git_dir="$ROOT/.git" &&
221 __git_C_args=(-C otherrepo) &&
222 __git_find_repo_path &&
223 echo "$__git_repo_path" >"$actual"
225 test_cmp expected "$actual"
228 test_expect_success '__git_find_repo_path - relative dir from command line and "git -C"' '
229 echo "$ROOT/otherrepo/.git" >expected &&
232 __git_dir="otherrepo/.git" &&
233 __git_C_args=(-C ..) &&
234 __git_find_repo_path &&
235 echo "$__git_repo_path" >"$actual"
237 test_cmp expected "$actual"
240 test_expect_success '__git_find_repo_path - $GIT_DIR set while "git -C"' '
241 echo "$ROOT/.git" >expected &&
243 GIT_DIR="$ROOT/.git" &&
245 __git_C_args=(-C otherrepo) &&
246 __git_find_repo_path &&
247 echo "$__git_repo_path" >"$actual"
249 test_cmp expected "$actual"
252 test_expect_success '__git_find_repo_path - relative dir in $GIT_DIR and "git -C"' '
253 echo "$ROOT/otherrepo/.git" >expected &&
256 GIT_DIR="otherrepo/.git" &&
258 __git_C_args=(-C ..) &&
259 __git_find_repo_path &&
260 echo "$__git_repo_path" >"$actual"
262 test_cmp expected "$actual"
265 test_expect_success '__git_find_repo_path - "git -C" while .git directory in cwd' '
266 echo "$ROOT/otherrepo/.git" >expected &&
268 __git_C_args=(-C otherrepo) &&
269 __git_find_repo_path &&
270 echo "$__git_repo_path" >"$actual"
272 test_cmp expected "$actual"
275 test_expect_success '__git_find_repo_path - "git -C" while cwd is a .git directory' '
276 echo "$ROOT/otherrepo/.git" >expected &&
279 __git_C_args=(-C .. -C otherrepo) &&
280 __git_find_repo_path &&
281 echo "$__git_repo_path" >"$actual"
283 test_cmp expected "$actual"
286 test_expect_success '__git_find_repo_path - "git -C" while .git directory in parent' '
287 echo "$ROOT/otherrepo/.git" >expected &&
290 __git_C_args=(-C .. -C otherrepo) &&
291 __git_find_repo_path &&
292 echo "$__git_repo_path" >"$actual"
294 test_cmp expected "$actual"
297 test_expect_success '__git_find_repo_path - non-existing path in "git -C"' '
299 __git_C_args=(-C non-existing) &&
300 test_must_fail __git_find_repo_path &&
301 printf "$__git_repo_path" >"$actual"
303 test_must_be_empty "$actual"
306 test_expect_success '__git_find_repo_path - non-existing path in $__git_dir' '
308 __git_dir="non-existing" &&
309 test_must_fail __git_find_repo_path &&
310 printf "$__git_repo_path" >"$actual"
312 test_must_be_empty "$actual"
315 test_expect_success '__git_find_repo_path - non-existing $GIT_DIR' '
317 GIT_DIR="$ROOT/non-existing" &&
319 test_must_fail __git_find_repo_path &&
320 printf "$__git_repo_path" >"$actual"
322 test_must_be_empty "$actual"
325 test_expect_success '__git_find_repo_path - gitfile in cwd' '
326 echo "$ROOT/otherrepo/.git" >expected &&
327 echo "gitdir: $ROOT/otherrepo/.git" >subdir/.git &&
328 test_when_finished "rm -f subdir/.git" &&
331 __git_find_repo_path &&
332 echo "$__git_repo_path" >"$actual"
334 test_cmp expected "$actual"
337 test_expect_success '__git_find_repo_path - gitfile in parent' '
338 echo "$ROOT/otherrepo/.git" >expected &&
339 echo "gitdir: $ROOT/otherrepo/.git" >subdir/.git &&
340 test_when_finished "rm -f subdir/.git" &&
342 cd subdir/subsubdir &&
343 __git_find_repo_path &&
344 echo "$__git_repo_path" >"$actual"
346 test_cmp expected "$actual"
349 test_expect_success SYMLINKS '__git_find_repo_path - resulting path avoids symlinks' '
350 echo "$ROOT/otherrepo/.git" >expected &&
351 mkdir otherrepo/dir &&
352 test_when_finished "rm -rf otherrepo/dir" &&
353 ln -s otherrepo/dir link &&
354 test_when_finished "rm -f link" &&
357 __git_find_repo_path &&
358 echo "$__git_repo_path" >"$actual"
360 test_cmp expected "$actual"
363 test_expect_success '__git_find_repo_path - not a git repository' '
366 GIT_CEILING_DIRECTORIES="$ROOT" &&
367 export GIT_CEILING_DIRECTORIES &&
368 test_must_fail __git_find_repo_path &&
369 printf "$__git_repo_path" >"$actual"
371 test_must_be_empty "$actual"
374 test_expect_success '__gitdir - finds repo' '
375 echo "$ROOT/.git" >expected &&
377 cd subdir/subsubdir &&
380 test_cmp expected "$actual"
384 test_expect_success '__gitdir - returns error when cannot find repo' '
386 __git_dir="non-existing" &&
387 test_must_fail __gitdir >"$actual"
389 test_must_be_empty "$actual"
392 test_expect_success '__gitdir - repo as argument' '
393 echo "otherrepo/.git" >expected &&
395 __gitdir "otherrepo" >"$actual"
397 test_cmp expected "$actual"
400 test_expect_success '__gitdir - remote as argument' '
401 echo "remote" >expected &&
403 __gitdir "remote" >"$actual"
405 test_cmp expected "$actual"
409 test_expect_success '__git_dequote - plain unquoted word' '
410 __git_dequote unquoted-word &&
411 verbose test unquoted-word = "$dequoted_word"
414 # input: b\a\c\k\'\\\"s\l\a\s\h\es
415 # expected: back'\"slashes
416 test_expect_success '__git_dequote - backslash escaped' '
417 __git_dequote "b\a\c\k\\'\''\\\\\\\"s\l\a\s\h\es" &&
418 verbose test "back'\''\\\"slashes" = "$dequoted_word"
421 # input: sin'gle\' '"quo'ted
422 # expected: single\ "quoted
423 test_expect_success '__git_dequote - single quoted' '
424 __git_dequote "'"sin'gle\\\\' '\\\"quo'ted"'" &&
425 verbose test '\''single\ "quoted'\'' = "$dequoted_word"
428 # input: dou"ble\\" "\"\quot"ed
429 # expected: double\ "\quoted
430 test_expect_success '__git_dequote - double quoted' '
431 __git_dequote '\''dou"ble\\" "\"\quot"ed'\'' &&
432 verbose test '\''double\ "\quoted'\'' = "$dequoted_word"
435 # input: 'open single quote
436 test_expect_success '__git_dequote - open single quote' '
437 __git_dequote "'\''open single quote" &&
438 verbose test "open single quote" = "$dequoted_word"
441 # input: "open double quote
442 test_expect_success '__git_dequote - open double quote' '
443 __git_dequote "\"open double quote" &&
444 verbose test "open double quote" = "$dequoted_word"
448 test_expect_success '__gitcomp_direct - puts everything into COMPREPLY as-is' '
449 sed -e "s/Z$//g" >expected <<-EOF &&
450 with-trailing-space Z
451 without-trailing-spaceZ
454 $invalid_variable_name Z
457 cur=should_be_ignored &&
458 __gitcomp_direct "$(cat expected)" &&
461 test_cmp expected out
464 test_expect_success '__gitcomp - trailing space - options' '
465 test_gitcomp "--re" "--dry-run --reuse-message= --reedit-message=
466 --reset-author" <<-EOF
473 test_expect_success '__gitcomp - trailing space - config keys' '
474 test_gitcomp "br" "branch. branch.autosetupmerge
475 branch.autosetuprebase browser." <<-\EOF
477 branch.autosetupmerge Z
478 branch.autosetuprebase Z
483 test_expect_success '__gitcomp - option parameter' '
484 test_gitcomp "--strategy=re" "octopus ours recursive resolve subtree" \
491 test_expect_success '__gitcomp - prefix' '
492 test_gitcomp "branch.me" "remote merge mergeoptions rebase" \
493 "branch.maint." "me" <<-\EOF
495 branch.maint.mergeoptions Z
499 test_expect_success '__gitcomp - suffix' '
500 test_gitcomp "branch.me" "master maint next seen" "branch." \
507 test_expect_success '__gitcomp - ignore optional negative options' '
508 test_gitcomp "--" "--abc --def --no-one -- --no-two" <<-\EOF
516 test_expect_success '__gitcomp - ignore/narrow optional negative options' '
517 test_gitcomp "--a" "--abc --abcdef --no-one -- --no-two" <<-\EOF
523 test_expect_success '__gitcomp - ignore/narrow optional negative options' '
524 test_gitcomp "--n" "--abc --def --no-one -- --no-two" <<-\EOF
530 test_expect_success '__gitcomp - expand all negative options' '
531 test_gitcomp "--no-" "--abc --def --no-one -- --no-two" <<-\EOF
537 test_expect_success '__gitcomp - expand/narrow all negative options' '
538 test_gitcomp "--no-o" "--abc --def --no-one -- --no-two" <<-\EOF
543 test_expect_success '__gitcomp - doesnt fail because of invalid variable name' '
544 __gitcomp "$invalid_variable_name"
547 read -r -d "" refs <<-\EOF
554 test_expect_success '__gitcomp_nl - trailing space' '
555 test_gitcomp_nl "m" "$refs" <<-EOF
561 test_expect_success '__gitcomp_nl - prefix' '
562 test_gitcomp_nl "--fixup=m" "$refs" "--fixup=" "m" <<-EOF
568 test_expect_success '__gitcomp_nl - suffix' '
569 test_gitcomp_nl "branch.ma" "$refs" "branch." "ma" "." <<-\EOF
575 test_expect_success '__gitcomp_nl - no suffix' '
576 test_gitcomp_nl "ma" "$refs" "" "ma" "" <<-\EOF
582 test_expect_success '__gitcomp_nl - doesnt fail because of invalid variable name' '
583 __gitcomp_nl "$invalid_variable_name"
586 test_expect_success '__git_remotes - list remotes from $GIT_DIR/remotes and from config file' '
587 cat >expect <<-EOF &&
593 test_when_finished "rm -rf .git/remotes" &&
594 mkdir -p .git/remotes &&
595 >.git/remotes/remote_from_file_1 &&
596 >.git/remotes/remote_from_file_2 &&
597 test_when_finished "git remote remove remote_in_config_1" &&
598 git remote add remote_in_config_1 git://remote_1 &&
599 test_when_finished "git remote remove remote_in_config_2" &&
600 git remote add remote_in_config_2 git://remote_2 &&
602 __git_remotes >actual
604 test_cmp expect actual
607 test_expect_success '__git_is_configured_remote' '
608 test_when_finished "git remote remove remote_1" &&
609 git remote add remote_1 git://remote_1 &&
610 test_when_finished "git remote remove remote_2" &&
611 git remote add remote_2 git://remote_2 &&
613 verbose __git_is_configured_remote remote_2 &&
614 test_must_fail __git_is_configured_remote non-existent
618 test_expect_success 'setup for ref completion' '
619 git commit --allow-empty -m initial &&
620 git branch matching-branch &&
621 git tag matching-tag &&
624 git commit --allow-empty -m initial &&
625 git branch -m master master-in-other &&
626 git branch branch-in-other &&
629 git remote add other "$ROOT/otherrepo/.git" &&
630 git fetch --no-tags other &&
631 rm -f .git/FETCH_HEAD &&
635 test_expect_success '__git_refs - simple' '
636 cat >expected <<-EOF &&
640 other/branch-in-other
641 other/master-in-other
646 __git_refs >"$actual"
648 test_cmp expected "$actual"
651 test_expect_success '__git_refs - full refs' '
652 cat >expected <<-EOF &&
654 refs/heads/matching-branch
655 refs/remotes/other/branch-in-other
656 refs/remotes/other/master-in-other
657 refs/tags/matching-tag
661 __git_refs >"$actual"
663 test_cmp expected "$actual"
666 test_expect_success '__git_refs - repo given on the command line' '
667 cat >expected <<-EOF &&
674 __git_dir="$ROOT/otherrepo/.git" &&
676 __git_refs >"$actual"
678 test_cmp expected "$actual"
681 test_expect_success '__git_refs - remote on local file system' '
682 cat >expected <<-EOF &&
690 __git_refs otherrepo >"$actual"
692 test_cmp expected "$actual"
695 test_expect_success '__git_refs - remote on local file system - full refs' '
696 cat >expected <<-EOF &&
697 refs/heads/branch-in-other
698 refs/heads/master-in-other
699 refs/tags/tag-in-other
703 __git_refs otherrepo >"$actual"
705 test_cmp expected "$actual"
708 test_expect_success '__git_refs - configured remote' '
709 cat >expected <<-EOF &&
716 __git_refs other >"$actual"
718 test_cmp expected "$actual"
721 test_expect_success '__git_refs - configured remote - full refs' '
722 cat >expected <<-EOF &&
724 refs/heads/branch-in-other
725 refs/heads/master-in-other
726 refs/tags/tag-in-other
730 __git_refs other >"$actual"
732 test_cmp expected "$actual"
735 test_expect_success '__git_refs - configured remote - repo given on the command line' '
736 cat >expected <<-EOF &&
743 __git_dir="$ROOT/.git" &&
745 __git_refs other >"$actual"
747 test_cmp expected "$actual"
750 test_expect_success '__git_refs - configured remote - full refs - repo given on the command line' '
751 cat >expected <<-EOF &&
753 refs/heads/branch-in-other
754 refs/heads/master-in-other
755 refs/tags/tag-in-other
759 __git_dir="$ROOT/.git" &&
761 __git_refs other >"$actual"
763 test_cmp expected "$actual"
766 test_expect_success '__git_refs - configured remote - remote name matches a directory' '
767 cat >expected <<-EOF &&
773 test_when_finished "rm -rf other" &&
776 __git_refs other >"$actual"
778 test_cmp expected "$actual"
781 test_expect_success '__git_refs - URL remote' '
782 cat >expected <<-EOF &&
790 __git_refs "file://$ROOT/otherrepo/.git" >"$actual"
792 test_cmp expected "$actual"
795 test_expect_success '__git_refs - URL remote - full refs' '
796 cat >expected <<-EOF &&
798 refs/heads/branch-in-other
799 refs/heads/master-in-other
800 refs/tags/tag-in-other
804 __git_refs "file://$ROOT/otherrepo/.git" >"$actual"
806 test_cmp expected "$actual"
809 test_expect_success '__git_refs - non-existing remote' '
812 __git_refs non-existing >"$actual"
814 test_must_be_empty "$actual"
817 test_expect_success '__git_refs - non-existing remote - full refs' '
820 __git_refs non-existing >"$actual"
822 test_must_be_empty "$actual"
825 test_expect_success '__git_refs - non-existing URL remote' '
828 __git_refs "file://$ROOT/non-existing" >"$actual"
830 test_must_be_empty "$actual"
833 test_expect_success '__git_refs - non-existing URL remote - full refs' '
836 __git_refs "file://$ROOT/non-existing" >"$actual"
838 test_must_be_empty "$actual"
841 test_expect_success '__git_refs - not in a git repository' '
843 GIT_CEILING_DIRECTORIES="$ROOT" &&
844 export GIT_CEILING_DIRECTORIES &&
847 __git_refs >"$actual"
849 test_must_be_empty "$actual"
852 test_expect_success '__git_refs - unique remote branches for git checkout DWIMery' '
853 cat >expected <<-EOF &&
858 other/branch-in-other
859 other/master-in-other
861 remote/branch-in-remote
867 for remote_ref in refs/remotes/other/ambiguous \
868 refs/remotes/remote/ambiguous \
869 refs/remotes/remote/branch-in-remote
871 git update-ref $remote_ref master &&
872 test_when_finished "git update-ref -d $remote_ref"
876 __git_refs "" 1 >"$actual"
878 test_cmp expected "$actual"
881 test_expect_success '__git_refs - after --opt=' '
882 cat >expected <<-EOF &&
886 other/branch-in-other
887 other/master-in-other
892 __git_refs "" "" "" "" >"$actual"
894 test_cmp expected "$actual"
897 test_expect_success '__git_refs - after --opt= - full refs' '
898 cat >expected <<-EOF &&
900 refs/heads/matching-branch
901 refs/remotes/other/branch-in-other
902 refs/remotes/other/master-in-other
903 refs/tags/matching-tag
907 __git_refs "" "" "" refs/ >"$actual"
909 test_cmp expected "$actual"
912 test_expect_success '__git refs - exluding refs' '
913 cat >expected <<-EOF &&
917 ^other/branch-in-other
918 ^other/master-in-other
923 __git_refs >"$actual"
925 test_cmp expected "$actual"
928 test_expect_success '__git refs - exluding full refs' '
929 cat >expected <<-EOF &&
931 ^refs/heads/matching-branch
932 ^refs/remotes/other/branch-in-other
933 ^refs/remotes/other/master-in-other
934 ^refs/tags/matching-tag
938 __git_refs >"$actual"
940 test_cmp expected "$actual"
943 test_expect_success 'setup for filtering matching refs' '
944 git branch matching/branch &&
945 git tag matching/tag &&
946 git -C otherrepo branch matching/branch-in-other &&
947 git fetch --no-tags other &&
948 rm -f .git/FETCH_HEAD
951 test_expect_success '__git_refs - do not filter refs unless told so' '
952 cat >expected <<-EOF &&
957 other/branch-in-other
958 other/master-in-other
959 other/matching/branch-in-other
965 __git_refs >"$actual"
967 test_cmp expected "$actual"
970 test_expect_success '__git_refs - only matching refs' '
971 cat >expected <<-EOF &&
979 __git_refs "" "" "" "$cur" >"$actual"
981 test_cmp expected "$actual"
984 test_expect_success '__git_refs - only matching refs - full refs' '
985 cat >expected <<-EOF &&
986 refs/heads/matching-branch
987 refs/heads/matching/branch
990 cur=refs/heads/mat &&
991 __git_refs "" "" "" "$cur" >"$actual"
993 test_cmp expected "$actual"
996 test_expect_success '__git_refs - only matching refs - remote on local file system' '
997 cat >expected <<-EOF &&
999 matching/branch-in-other
1003 __git_refs otherrepo "" "" "$cur" >"$actual"
1005 test_cmp expected "$actual"
1008 test_expect_success '__git_refs - only matching refs - configured remote' '
1009 cat >expected <<-EOF &&
1011 matching/branch-in-other
1015 __git_refs other "" "" "$cur" >"$actual"
1017 test_cmp expected "$actual"
1020 test_expect_success '__git_refs - only matching refs - remote - full refs' '
1021 cat >expected <<-EOF &&
1022 refs/heads/master-in-other
1023 refs/heads/matching/branch-in-other
1026 cur=refs/heads/ma &&
1027 __git_refs other "" "" "$cur" >"$actual"
1029 test_cmp expected "$actual"
1032 test_expect_success '__git_refs - only matching refs - checkout DWIMery' '
1033 cat >expected <<-EOF &&
1038 matching/branch-in-other
1040 for remote_ref in refs/remotes/other/ambiguous \
1041 refs/remotes/remote/ambiguous \
1042 refs/remotes/remote/branch-in-remote
1044 git update-ref $remote_ref master &&
1045 test_when_finished "git update-ref -d $remote_ref"
1049 __git_refs "" 1 "" "$cur" >"$actual"
1051 test_cmp expected "$actual"
1054 test_expect_success 'teardown after filtering matching refs' '
1055 git branch -d matching/branch &&
1056 git tag -d matching/tag &&
1057 git update-ref -d refs/remotes/other/matching/branch-in-other &&
1058 git -C otherrepo branch -D matching/branch-in-other
1061 test_expect_success PREPARE_FOR_MAIN_BRANCH '__git_refs - for-each-ref format specifiers in prefix' '
1062 cat >expected <<-EOF &&
1063 evil-%%-%42-%(refname)..master
1066 cur="evil-%%-%42-%(refname)..mai" &&
1067 __git_refs "" "" "evil-%%-%42-%(refname).." mai >"$actual"
1069 test_cmp expected "$actual"
1072 test_expect_success '__git_complete_refs - simple' '
1073 sed -e "s/Z$//" >expected <<-EOF &&
1077 other/branch-in-other Z
1078 other/master-in-other Z
1083 __git_complete_refs &&
1086 test_cmp expected out
1089 test_expect_success '__git_complete_refs - matching' '
1090 sed -e "s/Z$//" >expected <<-EOF &&
1096 __git_complete_refs &&
1099 test_cmp expected out
1102 test_expect_success '__git_complete_refs - remote' '
1103 sed -e "s/Z$//" >expected <<-EOF &&
1110 __git_complete_refs --remote=other &&
1113 test_cmp expected out
1116 test_expect_success '__git_complete_refs - track' '
1117 sed -e "s/Z$//" >expected <<-EOF &&
1121 other/branch-in-other Z
1122 other/master-in-other Z
1129 __git_complete_refs --track &&
1132 test_cmp expected out
1135 test_expect_success '__git_complete_refs - current word' '
1136 sed -e "s/Z$//" >expected <<-EOF &&
1141 cur="--option=mat" &&
1142 __git_complete_refs --cur="${cur#*=}" &&
1145 test_cmp expected out
1148 test_expect_success '__git_complete_refs - prefix' '
1149 sed -e "s/Z$//" >expected <<-EOF &&
1150 v1.0..matching-branch Z
1151 v1.0..matching-tag Z
1155 __git_complete_refs --pfx=v1.0.. --cur=mat &&
1158 test_cmp expected out
1161 test_expect_success '__git_complete_refs - suffix' '
1162 cat >expected <<-EOF &&
1166 other/branch-in-other.
1167 other/master-in-other.
1172 __git_complete_refs --sfx=. &&
1175 test_cmp expected out
1178 test_expect_success '__git_complete_fetch_refspecs - simple' '
1179 sed -e "s/Z$//" >expected <<-EOF &&
1181 branch-in-other:branch-in-other Z
1182 master-in-other:master-in-other Z
1186 __git_complete_fetch_refspecs other &&
1189 test_cmp expected out
1192 test_expect_success '__git_complete_fetch_refspecs - matching' '
1193 sed -e "s/Z$//" >expected <<-EOF &&
1194 branch-in-other:branch-in-other Z
1198 __git_complete_fetch_refspecs other "" br &&
1201 test_cmp expected out
1204 test_expect_success '__git_complete_fetch_refspecs - prefix' '
1205 sed -e "s/Z$//" >expected <<-EOF &&
1207 +branch-in-other:branch-in-other Z
1208 +master-in-other:master-in-other Z
1212 __git_complete_fetch_refspecs other "+" "" &&
1215 test_cmp expected out
1218 test_expect_success '__git_complete_fetch_refspecs - fully qualified' '
1219 sed -e "s/Z$//" >expected <<-EOF &&
1220 refs/heads/branch-in-other:refs/heads/branch-in-other Z
1221 refs/heads/master-in-other:refs/heads/master-in-other Z
1222 refs/tags/tag-in-other:refs/tags/tag-in-other Z
1226 __git_complete_fetch_refspecs other "" refs/ &&
1229 test_cmp expected out
1232 test_expect_success '__git_complete_fetch_refspecs - fully qualified & prefix' '
1233 sed -e "s/Z$//" >expected <<-EOF &&
1234 +refs/heads/branch-in-other:refs/heads/branch-in-other Z
1235 +refs/heads/master-in-other:refs/heads/master-in-other Z
1236 +refs/tags/tag-in-other:refs/tags/tag-in-other Z
1240 __git_complete_fetch_refspecs other + refs/ &&
1243 test_cmp expected out
1246 test_expect_success 'git switch - with no options, complete local branches and unique remote branch names for DWIM logic' '
1247 test_completion "git switch " <<-\EOF
1255 test_expect_success 'git checkout - completes refs and unique remote branches for DWIM' '
1256 test_completion "git checkout " <<-\EOF
1263 other/branch-in-other Z
1264 other/master-in-other Z
1268 test_expect_success 'git switch - with --no-guess, complete only local branches' '
1269 test_completion "git switch --no-guess " <<-\EOF
1275 test_expect_success 'git switch - with GIT_COMPLETION_CHECKOUT_NO_GUESS=1, complete only local branches' '
1276 GIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion "git switch " <<-\EOF
1282 test_expect_success 'git switch - --guess overrides GIT_COMPLETION_CHECKOUT_NO_GUESS=1, complete local branches and unique remote names for DWIM logic' '
1283 GIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion "git switch --guess " <<-\EOF
1291 test_expect_success 'git switch - a later --guess overrides previous --no-guess, complete local and remote unique branches for DWIM' '
1292 test_completion "git switch --no-guess --guess " <<-\EOF
1300 test_expect_success 'git switch - a later --no-guess overrides previous --guess, complete only local branches' '
1301 test_completion "git switch --guess --no-guess " <<-\EOF
1307 test_expect_success 'git checkout - with GIT_COMPLETION_NO_GUESS=1 only completes refs' '
1308 GIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion "git checkout " <<-\EOF
1313 other/branch-in-other Z
1314 other/master-in-other Z
1318 test_expect_success 'git checkout - --guess overrides GIT_COMPLETION_NO_GUESS=1, complete refs and unique remote branches for DWIM' '
1319 GIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion "git checkout --guess " <<-\EOF
1326 other/branch-in-other Z
1327 other/master-in-other Z
1331 test_expect_success 'git checkout - with --no-guess, only completes refs' '
1332 test_completion "git checkout --no-guess " <<-\EOF
1337 other/branch-in-other Z
1338 other/master-in-other Z
1342 test_expect_success 'git checkout - a later --guess overrides previous --no-guess, complete refs and unique remote branches for DWIM' '
1343 test_completion "git checkout --no-guess --guess " <<-\EOF
1350 other/branch-in-other Z
1351 other/master-in-other Z
1355 test_expect_success 'git checkout - a later --no-guess overrides previous --guess, complete only refs' '
1356 test_completion "git checkout --guess --no-guess " <<-\EOF
1361 other/branch-in-other Z
1362 other/master-in-other Z
1366 test_expect_success 'git checkout - with checkout.guess = false, only completes refs' '
1367 test_config checkout.guess false &&
1368 test_completion "git checkout " <<-\EOF
1373 other/branch-in-other Z
1374 other/master-in-other Z
1378 test_expect_success 'git checkout - with checkout.guess = true, completes refs and unique remote branches for DWIM' '
1379 test_config checkout.guess true &&
1380 test_completion "git checkout " <<-\EOF
1387 other/branch-in-other Z
1388 other/master-in-other Z
1392 test_expect_success 'git checkout - a later --guess overrides previous checkout.guess = false, complete refs and unique remote branches for DWIM' '
1393 test_config checkout.guess false &&
1394 test_completion "git checkout --guess " <<-\EOF
1401 other/branch-in-other Z
1402 other/master-in-other Z
1406 test_expect_success 'git checkout - a later --no-guess overrides previous checkout.guess = true, complete only refs' '
1407 test_config checkout.guess true &&
1408 test_completion "git checkout --no-guess " <<-\EOF
1413 other/branch-in-other Z
1414 other/master-in-other Z
1418 test_expect_success 'git switch - with --detach, complete all references' '
1419 test_completion "git switch --detach " <<-\EOF
1424 other/branch-in-other Z
1425 other/master-in-other Z
1429 test_expect_success 'git checkout - with --detach, complete only references' '
1430 test_completion "git checkout --detach " <<-\EOF
1435 other/branch-in-other Z
1436 other/master-in-other Z
1440 test_expect_success 'git switch - with -d, complete all references' '
1441 test_completion "git switch -d " <<-\EOF
1446 other/branch-in-other Z
1447 other/master-in-other Z
1451 test_expect_success 'git checkout - with -d, complete only references' '
1452 test_completion "git checkout -d " <<-\EOF
1457 other/branch-in-other Z
1458 other/master-in-other Z
1462 test_expect_success 'git switch - with --track, complete only remote branches' '
1463 test_completion "git switch --track " <<-\EOF
1464 other/branch-in-other Z
1465 other/master-in-other Z
1469 test_expect_success 'git checkout - with --track, complete only remote branches' '
1470 test_completion "git checkout --track " <<-\EOF
1471 other/branch-in-other Z
1472 other/master-in-other Z
1476 test_expect_success 'git switch - with --no-track, complete only local branch names' '
1477 test_completion "git switch --no-track " <<-\EOF
1483 test_expect_success 'git checkout - with --no-track, complete only local references' '
1484 test_completion "git checkout --no-track " <<-\EOF
1489 other/branch-in-other Z
1490 other/master-in-other Z
1494 test_expect_success 'git switch - with -c, complete all references' '
1495 test_completion "git switch -c new-branch " <<-\EOF
1500 other/branch-in-other Z
1501 other/master-in-other Z
1505 test_expect_success 'git switch - with -C, complete all references' '
1506 test_completion "git switch -C new-branch " <<-\EOF
1511 other/branch-in-other Z
1512 other/master-in-other Z
1516 test_expect_success 'git switch - with -c and --track, complete all references' '
1517 test_completion "git switch -c new-branch --track " <<-EOF
1522 other/branch-in-other Z
1523 other/master-in-other Z
1527 test_expect_success 'git switch - with -C and --track, complete all references' '
1528 test_completion "git switch -C new-branch --track " <<-EOF
1533 other/branch-in-other Z
1534 other/master-in-other Z
1538 test_expect_success 'git switch - with -c and --no-track, complete all references' '
1539 test_completion "git switch -c new-branch --no-track " <<-\EOF
1544 other/branch-in-other Z
1545 other/master-in-other Z
1549 test_expect_success 'git switch - with -C and --no-track, complete all references' '
1550 test_completion "git switch -C new-branch --no-track " <<-\EOF
1555 other/branch-in-other Z
1556 other/master-in-other Z
1560 test_expect_success 'git checkout - with -b, complete all references' '
1561 test_completion "git checkout -b new-branch " <<-\EOF
1566 other/branch-in-other Z
1567 other/master-in-other Z
1571 test_expect_success 'git checkout - with -B, complete all references' '
1572 test_completion "git checkout -B new-branch " <<-\EOF
1577 other/branch-in-other Z
1578 other/master-in-other Z
1582 test_expect_success 'git checkout - with -b and --track, complete all references' '
1583 test_completion "git checkout -b new-branch --track " <<-EOF
1588 other/branch-in-other Z
1589 other/master-in-other Z
1593 test_expect_success 'git checkout - with -B and --track, complete all references' '
1594 test_completion "git checkout -B new-branch --track " <<-EOF
1599 other/branch-in-other Z
1600 other/master-in-other Z
1604 test_expect_success 'git checkout - with -b and --no-track, complete all references' '
1605 test_completion "git checkout -b new-branch --no-track " <<-\EOF
1610 other/branch-in-other Z
1611 other/master-in-other Z
1615 test_expect_success 'git checkout - with -B and --no-track, complete all references' '
1616 test_completion "git checkout -B new-branch --no-track " <<-\EOF
1621 other/branch-in-other Z
1622 other/master-in-other Z
1626 test_expect_success 'git switch - for -c, complete local branches and unique remote branches' '
1627 test_completion "git switch -c " <<-\EOF
1635 test_expect_success 'git switch - for -C, complete local branches and unique remote branches' '
1636 test_completion "git switch -C " <<-\EOF
1644 test_expect_success 'git switch - for -c with --no-guess, complete local branches only' '
1645 test_completion "git switch --no-guess -c " <<-\EOF
1651 test_expect_success 'git switch - for -C with --no-guess, complete local branches only' '
1652 test_completion "git switch --no-guess -C " <<-\EOF
1658 test_expect_success 'git switch - for -c with --no-track, complete local branches only' '
1659 test_completion "git switch --no-track -c " <<-\EOF
1665 test_expect_success 'git switch - for -C with --no-track, complete local branches only' '
1666 test_completion "git switch --no-track -C " <<-\EOF
1672 test_expect_success 'git checkout - for -b, complete local branches and unique remote branches' '
1673 test_completion "git checkout -b " <<-\EOF
1681 test_expect_success 'git checkout - for -B, complete local branches and unique remote branches' '
1682 test_completion "git checkout -B " <<-\EOF
1690 test_expect_success 'git checkout - for -b with --no-guess, complete local branches only' '
1691 test_completion "git checkout --no-guess -b " <<-\EOF
1697 test_expect_success 'git checkout - for -B with --no-guess, complete local branches only' '
1698 test_completion "git checkout --no-guess -B " <<-\EOF
1704 test_expect_success 'git checkout - for -b with --no-track, complete local branches only' '
1705 test_completion "git checkout --no-track -b " <<-\EOF
1711 test_expect_success 'git checkout - for -B with --no-track, complete local branches only' '
1712 test_completion "git checkout --no-track -B " <<-\EOF
1718 test_expect_success 'git switch - with --orphan completes local branch names and unique remote branch names' '
1719 test_completion "git switch --orphan " <<-\EOF
1727 test_expect_success 'git switch - --orphan with branch already provided completes nothing else' '
1728 test_completion "git switch --orphan master " <<-\EOF
1733 test_expect_success 'git checkout - with --orphan completes local branch names and unique remote branch names' '
1734 test_completion "git checkout --orphan " <<-\EOF
1742 test_expect_success 'git checkout - --orphan with branch already provided completes local refs for a start-point' '
1743 test_completion "git checkout --orphan master " <<-\EOF
1748 other/branch-in-other Z
1749 other/master-in-other Z
1753 test_expect_success 'teardown after ref completion' '
1754 git branch -d matching-branch &&
1755 git tag -d matching-tag &&
1756 git remote remove other
1760 test_path_completion ()
1762 test $# = 2 || BUG "not 2 parameters to test_path_completion"
1764 local cur="$1" expected="$2"
1765 echo "$expected" >expected &&
1767 # In the following tests calling this function we only
1768 # care about how __git_complete_index_file() deals with
1769 # unusual characters in path names. By requesting only
1770 # untracked files we do not have to bother adding any
1771 # paths to the index in those tests.
1772 __git_complete_index_file --others &&
1775 test_cmp expected out
1778 test_expect_success 'setup for path completion tests' '
1782 touch simple-dir/simple-file \
1783 "spaces in dir/spaces in file" \
1784 "árvíztűrő/Сайн яваарай" &&
1785 if test_have_prereq !MINGW &&
1787 '$'separators\034in\035dir'' &&
1788 touch BS\\dir/DQ\"file \
1789 '$'separators\034in\035dir/sep\036in\037file''
1791 test_set_prereq FUNNIERNAMES
1793 rm -rf BS\\dir '$'separators\034in\035dir''
1797 test_expect_success '__git_complete_index_file - simple' '
1798 test_path_completion simple simple-dir && # Bash is supposed to
1799 # add the trailing /.
1800 test_path_completion simple-dir/simple simple-dir/simple-file
1803 test_expect_success \
1804 '__git_complete_index_file - escaped characters on cmdline' '
1805 test_path_completion spac "spaces in dir" && # Bash will turn this
1806 # into "spaces\ in\ dir"
1807 test_path_completion "spaces\\ i" \
1809 test_path_completion "spaces\\ in\\ dir/s" \
1810 "spaces in dir/spaces in file" &&
1811 test_path_completion "spaces\\ in\\ dir/spaces\\ i" \
1812 "spaces in dir/spaces in file"
1815 test_expect_success \
1816 '__git_complete_index_file - quoted characters on cmdline' '
1817 # Testing with an opening but without a corresponding closing
1818 # double quote is important.
1819 test_path_completion \"spac "spaces in dir" &&
1820 test_path_completion "\"spaces i" \
1822 test_path_completion "\"spaces in dir/s" \
1823 "spaces in dir/spaces in file" &&
1824 test_path_completion "\"spaces in dir/spaces i" \
1825 "spaces in dir/spaces in file"
1828 test_expect_success '__git_complete_index_file - UTF-8 in ls-files output' '
1829 test_path_completion á árvíztűrő &&
1830 test_path_completion árvíztűrő/С "árvíztűrő/Сайн яваарай"
1833 test_expect_success FUNNIERNAMES \
1834 '__git_complete_index_file - C-style escapes in ls-files output' '
1835 test_path_completion BS \
1837 test_path_completion BS\\\\d \
1839 test_path_completion BS\\\\dir/DQ \
1841 test_path_completion BS\\\\dir/DQ\\\"f \
1845 test_expect_success FUNNIERNAMES \
1846 '__git_complete_index_file - \nnn-escaped characters in ls-files output' '
1847 test_path_completion sep '$'separators\034in\035dir'' &&
1848 test_path_completion '$'separators\034i'' \
1849 '$'separators\034in\035dir'' &&
1850 test_path_completion '$'separators\034in\035dir/sep'' \
1851 '$'separators\034in\035dir/sep\036in\037file'' &&
1852 test_path_completion '$'separators\034in\035dir/sep\036i'' \
1853 '$'separators\034in\035dir/sep\036in\037file''
1856 test_expect_success FUNNYNAMES \
1857 '__git_complete_index_file - removing repeated quoted path components' '
1858 test_when_finished rm -r repeated-quoted &&
1859 mkdir repeated-quoted && # A directory whose name in itself
1860 # would not be quoted ...
1861 >repeated-quoted/0-file &&
1862 >repeated-quoted/1\"file && # ... but here the file makes the
1863 # dirname quoted ...
1864 >repeated-quoted/2-file &&
1865 >repeated-quoted/3\"file && # ... and here, too.
1867 # Still, we shold only list the directory name only once.
1868 test_path_completion repeated repeated-quoted
1871 test_expect_success 'teardown after path completion tests' '
1872 rm -rf simple-dir "spaces in dir" árvíztűrő \
1873 BS\\dir '$'separators\034in\035dir''
1876 test_expect_success '__git_find_on_cmdline - single match' '
1877 echo list >expect &&
1879 words=(git command --opt list) &&
1880 cword=${#words[@]} &&
1881 __git_find_on_cmdline "add list remove" >actual
1883 test_cmp expect actual
1886 test_expect_success '__git_find_on_cmdline - multiple matches' '
1887 echo remove >expect &&
1889 words=(git command -o --opt remove list add) &&
1890 cword=${#words[@]} &&
1891 __git_find_on_cmdline "add list remove" >actual
1893 test_cmp expect actual
1896 test_expect_success '__git_find_on_cmdline - no match' '
1898 words=(git command --opt branch) &&
1899 cword=${#words[@]} &&
1900 __git_find_on_cmdline "add list remove" >actual
1902 test_must_be_empty actual
1905 test_expect_success '__git_find_on_cmdline - single match with index' '
1906 echo "3 list" >expect &&
1908 words=(git command --opt list) &&
1909 cword=${#words[@]} &&
1910 __git_find_on_cmdline --show-idx "add list remove" >actual
1912 test_cmp expect actual
1915 test_expect_success '__git_find_on_cmdline - multiple matches with index' '
1916 echo "4 remove" >expect &&
1918 words=(git command -o --opt remove list add) &&
1919 cword=${#words[@]} &&
1920 __git_find_on_cmdline --show-idx "add list remove" >actual
1922 test_cmp expect actual
1925 test_expect_success '__git_find_on_cmdline - no match with index' '
1927 words=(git command --opt branch) &&
1928 cword=${#words[@]} &&
1929 __git_find_on_cmdline --show-idx "add list remove" >actual
1931 test_must_be_empty actual
1934 test_expect_success '__git_get_config_variables' '
1935 cat >expect <<-EOF &&
1939 test_config interesting.name-1 good &&
1940 test_config interesting.name-2 good &&
1941 test_config subsection.interesting.name-3 bad &&
1942 __git_get_config_variables interesting >actual &&
1943 test_cmp expect actual
1946 test_expect_success '__git_pretty_aliases' '
1947 cat >expect <<-EOF &&
1951 test_config pretty.author "%an %ae" &&
1952 test_config pretty.hash %H &&
1953 __git_pretty_aliases >actual &&
1954 test_cmp expect actual
1957 test_expect_success 'basic' '
1958 run_completion "git " &&
1960 grep -q "^add \$" out &&
1962 grep -q "^rebase \$" out &&
1964 ! grep -q "^ls-files \$" out &&
1966 run_completion "git r" &&
1967 ! grep -q -v "^r" out
1970 test_expect_success 'double dash "git" itself' '
1971 test_completion "git --" <<-\EOF
1984 --no-replace-objects Z
1989 test_expect_success 'double dash "git checkout"' '
1990 test_completion "git checkout --" <<-\EOF
2000 --ignore-skip-worktree-bits Z
2001 --ignore-other-worktrees Z
2002 --recurse-submodules Z
2008 --pathspec-file-nul Z
2009 --pathspec-from-file=Z
2013 test_expect_success 'general options' '
2014 test_completion "git --ver" "--version " &&
2015 test_completion "git --hel" "--help " &&
2016 test_completion "git --exe" <<-\EOF &&
2020 test_completion "git --htm" "--html-path " &&
2021 test_completion "git --pag" "--paginate " &&
2022 test_completion "git --no-p" "--no-pager " &&
2023 test_completion "git --git" "--git-dir=" &&
2024 test_completion "git --wor" "--work-tree=" &&
2025 test_completion "git --nam" "--namespace=" &&
2026 test_completion "git --bar" "--bare " &&
2027 test_completion "git --inf" "--info-path " &&
2028 test_completion "git --no-r" "--no-replace-objects "
2031 test_expect_success 'general options plus command' '
2032 test_completion "git --version check" "checkout " &&
2033 test_completion "git --paginate check" "checkout " &&
2034 test_completion "git --git-dir=foo check" "checkout " &&
2035 test_completion "git --bare check" "checkout " &&
2036 test_completion "git --exec-path=foo check" "checkout " &&
2037 test_completion "git --html-path check" "checkout " &&
2038 test_completion "git --no-pager check" "checkout " &&
2039 test_completion "git --work-tree=foo check" "checkout " &&
2040 test_completion "git --namespace=foo check" "checkout " &&
2041 test_completion "git --paginate check" "checkout " &&
2042 test_completion "git --info-path check" "checkout " &&
2043 test_completion "git --no-replace-objects check" "checkout " &&
2044 test_completion "git --git-dir some/path check" "checkout " &&
2045 test_completion "git -c conf.var=value check" "checkout " &&
2046 test_completion "git -C some/path check" "checkout " &&
2047 test_completion "git --work-tree some/path check" "checkout " &&
2048 test_completion "git --namespace name/space check" "checkout "
2051 test_expect_success 'git --help completion' '
2052 test_completion "git --help ad" "add " &&
2053 test_completion "git --help core" "core-tutorial "
2056 test_expect_success 'completion.commands removes multiple commands' '
2057 test_config completion.commands "-cherry -mergetool" &&
2058 git --list-cmds=list-mainporcelain,list-complete,config >out &&
2059 ! grep -E "^(cherry|mergetool)$" out
2062 test_expect_success 'setup for integration tests' '
2063 echo content >file1 &&
2065 git add file1 file2 &&
2066 git commit -m one &&
2067 git branch mybranch &&
2071 test_expect_success 'checkout completes ref names' '
2072 test_completion "git checkout m" <<-\EOF
2079 test_expect_success 'git -C <path> checkout uses the right repo' '
2080 test_completion "git -C subdir -C subsubdir -C .. -C ../otherrepo checkout b" <<-\EOF
2085 test_expect_success 'show completes all refs' '
2086 test_completion "git show m" <<-\EOF
2093 test_expect_success '<ref>: completes paths' '
2094 test_completion "git show mytag:f" <<-\EOF
2100 test_expect_success 'complete tree filename with spaces' '
2101 echo content >"name with spaces" &&
2102 git add "name with spaces" &&
2103 git commit -m spaces &&
2104 test_completion "git show HEAD:nam" <<-\EOF
2109 test_expect_success 'complete tree filename with metacharacters' '
2110 echo content >"name with \${meta}" &&
2111 git add "name with \${meta}" &&
2112 git commit -m meta &&
2113 test_completion "git show HEAD:nam" <<-\EOF
2119 test_expect_success PERL 'send-email' '
2120 test_completion "git send-email --cov" <<-\EOF &&
2121 --cover-from-description=Z
2124 test_completion "git send-email ma" "master "
2127 test_expect_success 'complete files' '
2128 git init tmp && cd tmp &&
2129 test_when_finished "cd .. && rm -rf tmp" &&
2131 echo "expected" > .gitignore &&
2132 echo "out" >> .gitignore &&
2133 echo "out_sorted" >> .gitignore &&
2135 git add .gitignore &&
2136 test_completion "git commit " ".gitignore" &&
2138 git commit -m ignore &&
2141 test_completion "git add " "new" &&
2144 git commit -a -m new &&
2145 test_completion "git add " "" &&
2147 git mv new modified &&
2148 echo modify > modified &&
2149 test_completion "git add " "modified" &&
2151 mkdir -p some/deep &&
2152 touch some/deep/path &&
2153 test_completion "git add some/" "some/deep" &&
2154 git clean -f some &&
2158 : TODO .gitignore should not be here &&
2159 test_completion "git rm " <<-\EOF &&
2164 test_completion "git clean " "untracked" &&
2166 : TODO .gitignore should not be here &&
2167 test_completion "git mv " <<-\EOF &&
2173 touch dir/file-in-dir &&
2174 git add dir/file-in-dir &&
2175 git commit -m dir &&
2177 mkdir untracked-dir &&
2179 : TODO .gitignore should not be here &&
2180 test_completion "git mv modified " <<-\EOF &&
2188 test_completion "git commit " "modified" &&
2190 : TODO .gitignore should not be here &&
2191 test_completion "git ls-files " <<-\EOF &&
2198 test_completion "git add mom" "momified"
2201 test_expect_success "completion uses <cmd> completion for alias: !sh -c 'git <cmd> ...'" '
2202 test_config alias.co "!sh -c '"'"'git checkout ...'"'"'" &&
2203 test_completion "git co m" <<-\EOF
2210 test_expect_success 'completion uses <cmd> completion for alias: !f () { VAR=val git <cmd> ... }' '
2211 test_config alias.co "!f () { VAR=val git checkout ... ; } f" &&
2212 test_completion "git co m" <<-\EOF
2219 test_expect_success 'completion used <cmd> completion for alias: !f() { : git <cmd> ; ... }' '
2220 test_config alias.co "!f() { : git checkout ; if ... } f" &&
2221 test_completion "git co m" <<-\EOF
2228 test_expect_success 'completion without explicit _git_xxx function' '
2229 test_completion "git version --" <<-\EOF
2231 --no-build-options Z
2235 test_expect_failure 'complete with tilde expansion' '
2236 git init tmp && cd tmp &&
2237 test_when_finished "cd .. && rm -rf tmp" &&
2241 test_completion "git add ~/tmp/" "~/tmp/file"
2244 test_expect_success 'setup other remote for remote reference completion' '
2245 git remote add other otherrepo &&
2249 for flag in -d --delete
2251 test_expect_success "__git_complete_remote_or_refspec - push $flag other" '
2252 sed -e "s/Z$//" >expected <<-EOF &&
2256 words=(git push '$flag' other ma) &&
2257 cword=${#words[@]} cur=${words[cword-1]} &&
2258 __git_complete_remote_or_refspec &&
2261 test_cmp expected out
2264 test_expect_failure "__git_complete_remote_or_refspec - push other $flag" '
2265 sed -e "s/Z$//" >expected <<-EOF &&
2269 words=(git push other '$flag' ma) &&
2270 cword=${#words[@]} cur=${words[cword-1]} &&
2271 __git_complete_remote_or_refspec &&
2274 test_cmp expected out
2278 test_expect_success 'git config - section' '
2279 test_completion "git config br" <<-\EOF
2285 test_expect_success 'git config - variable name' '
2286 test_completion "git config log.d" <<-\EOF
2292 test_expect_success 'git config - value' '
2293 test_completion "git config color.pager " <<-\EOF
2299 test_expect_success 'git -c - section' '
2300 test_completion "git -c br" <<-\EOF
2306 test_expect_success 'git -c - variable name' '
2307 test_completion "git -c log.d" <<-\EOF
2313 test_expect_success 'git -c - value' '
2314 test_completion "git -c color.pager=" <<-\EOF
2320 test_expect_success 'git clone --config= - section' '
2321 test_completion "git clone --config=br" <<-\EOF
2327 test_expect_success 'git clone --config= - variable name' '
2328 test_completion "git clone --config=log.d" <<-\EOF
2334 test_expect_success 'git clone --config= - value' '
2335 test_completion "git clone --config=color.pager=" <<-\EOF
2341 test_expect_success 'sourcing the completion script clears cached commands' '
2342 __git_compute_all_commands &&
2343 verbose test -n "$__git_all_commands" &&
2344 . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
2345 verbose test -z "$__git_all_commands"
2348 test_expect_success 'sourcing the completion script clears cached merge strategies' '
2349 GIT_TEST_GETTEXT_POISON=false &&
2350 __git_compute_merge_strategies &&
2351 verbose test -n "$__git_merge_strategies" &&
2352 . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
2353 verbose test -z "$__git_merge_strategies"
2356 test_expect_success 'sourcing the completion script clears cached --options' '
2357 __gitcomp_builtin checkout &&
2358 verbose test -n "$__gitcomp_builtin_checkout" &&
2359 __gitcomp_builtin notes_edit &&
2360 verbose test -n "$__gitcomp_builtin_notes_edit" &&
2361 . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
2362 verbose test -z "$__gitcomp_builtin_checkout" &&
2363 verbose test -z "$__gitcomp_builtin_notes_edit"