3 # Copyright (c) 2012 Felipe Contreras
6 test_description='test bash completion'
16 # Be careful when updating this list:
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 # "filter-branch" and "ls-files" are listed for this.
33 GIT_TESTING_COMMAND_COMPLETION='add checkout check-attr filter-branch ls-files'
35 . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash"
37 # We don't need this function to actually join words or do anything special.
38 # Also, it's cleaner to avoid touching bash's internal completion variables.
39 # So let's override it with a minimal version for testing purposes.
40 _get_comp_words_by_ref ()
42 while [ $# -gt 0 ]; do
48 prev=${_words[_cword-1]}
51 words=("${_words[@]}")
64 echo "${COMPREPLY[*]}" > out
69 local -a COMPREPLY _words
72 test "${1: -1}" = ' ' && _words[${#_words[@]}+1]=''
73 (( _cword = ${#_words[@]} - 1 ))
74 __git_wrap__git_main && print_comp
77 # Test high-level completion
79 # 1: typed text so far (cur)
80 # 2: expected completion
85 printf '%s\n' "$2" >expected
87 sed -e 's/Z$//' >expected
89 run_completion "$1" &&
94 # The first argument is the typed text so far (cur); the rest are
95 # passed to __gitcomp. Expected output comes is read from the
96 # standard input, like test_completion().
100 sed -e 's/Z$//' >expected &&
105 test_cmp expected out
110 # 1: current word (cur)
111 # -: the rest are passed to __gitcomp_nl
114 local -a COMPREPLY &&
115 sed -e 's/Z$//' >expected &&
120 test_cmp expected out
123 invalid_variable_name='${foo.bar}'
125 actual="$TRASH_DIRECTORY/actual"
127 if test_have_prereq MINGW
134 test_expect_success 'setup for __git_find_repo_path/__gitdir tests' '
135 mkdir -p subdir/subsubdir &&
140 test_expect_success '__git_find_repo_path - from command line (through $__git_dir)' '
141 echo "$ROOT/otherrepo/.git" >expected &&
143 __git_dir="$ROOT/otherrepo/.git" &&
144 __git_find_repo_path &&
145 echo "$__git_repo_path" >"$actual"
147 test_cmp expected "$actual"
150 test_expect_success '__git_find_repo_path - .git directory in cwd' '
151 echo ".git" >expected &&
153 __git_find_repo_path &&
154 echo "$__git_repo_path" >"$actual"
156 test_cmp expected "$actual"
159 test_expect_success '__git_find_repo_path - .git directory in parent' '
160 echo "$ROOT/.git" >expected &&
162 cd subdir/subsubdir &&
163 __git_find_repo_path &&
164 echo "$__git_repo_path" >"$actual"
166 test_cmp expected "$actual"
169 test_expect_success '__git_find_repo_path - cwd is a .git directory' '
170 echo "." >expected &&
173 __git_find_repo_path &&
174 echo "$__git_repo_path" >"$actual"
176 test_cmp expected "$actual"
179 test_expect_success '__git_find_repo_path - parent is a .git directory' '
180 echo "$ROOT/.git" >expected &&
182 cd .git/refs/heads &&
183 __git_find_repo_path &&
184 echo "$__git_repo_path" >"$actual"
186 test_cmp expected "$actual"
189 test_expect_success '__git_find_repo_path - $GIT_DIR set while .git directory in cwd' '
190 echo "$ROOT/otherrepo/.git" >expected &&
192 GIT_DIR="$ROOT/otherrepo/.git" &&
194 __git_find_repo_path &&
195 echo "$__git_repo_path" >"$actual"
197 test_cmp expected "$actual"
200 test_expect_success '__git_find_repo_path - $GIT_DIR set while .git directory in parent' '
201 echo "$ROOT/otherrepo/.git" >expected &&
203 GIT_DIR="$ROOT/otherrepo/.git" &&
206 __git_find_repo_path &&
207 echo "$__git_repo_path" >"$actual"
209 test_cmp expected "$actual"
212 test_expect_success '__git_find_repo_path - from command line while "git -C"' '
213 echo "$ROOT/.git" >expected &&
215 __git_dir="$ROOT/.git" &&
216 __git_C_args=(-C otherrepo) &&
217 __git_find_repo_path &&
218 echo "$__git_repo_path" >"$actual"
220 test_cmp expected "$actual"
223 test_expect_success '__git_find_repo_path - relative dir from command line and "git -C"' '
224 echo "$ROOT/otherrepo/.git" >expected &&
227 __git_dir="otherrepo/.git" &&
228 __git_C_args=(-C ..) &&
229 __git_find_repo_path &&
230 echo "$__git_repo_path" >"$actual"
232 test_cmp expected "$actual"
235 test_expect_success '__git_find_repo_path - $GIT_DIR set while "git -C"' '
236 echo "$ROOT/.git" >expected &&
238 GIT_DIR="$ROOT/.git" &&
240 __git_C_args=(-C otherrepo) &&
241 __git_find_repo_path &&
242 echo "$__git_repo_path" >"$actual"
244 test_cmp expected "$actual"
247 test_expect_success '__git_find_repo_path - relative dir in $GIT_DIR and "git -C"' '
248 echo "$ROOT/otherrepo/.git" >expected &&
251 GIT_DIR="otherrepo/.git" &&
253 __git_C_args=(-C ..) &&
254 __git_find_repo_path &&
255 echo "$__git_repo_path" >"$actual"
257 test_cmp expected "$actual"
260 test_expect_success '__git_find_repo_path - "git -C" while .git directory in cwd' '
261 echo "$ROOT/otherrepo/.git" >expected &&
263 __git_C_args=(-C otherrepo) &&
264 __git_find_repo_path &&
265 echo "$__git_repo_path" >"$actual"
267 test_cmp expected "$actual"
270 test_expect_success '__git_find_repo_path - "git -C" while cwd is a .git directory' '
271 echo "$ROOT/otherrepo/.git" >expected &&
274 __git_C_args=(-C .. -C otherrepo) &&
275 __git_find_repo_path &&
276 echo "$__git_repo_path" >"$actual"
278 test_cmp expected "$actual"
281 test_expect_success '__git_find_repo_path - "git -C" while .git directory in parent' '
282 echo "$ROOT/otherrepo/.git" >expected &&
285 __git_C_args=(-C .. -C otherrepo) &&
286 __git_find_repo_path &&
287 echo "$__git_repo_path" >"$actual"
289 test_cmp expected "$actual"
292 test_expect_success '__git_find_repo_path - non-existing path in "git -C"' '
294 __git_C_args=(-C non-existing) &&
295 test_must_fail __git_find_repo_path &&
296 printf "$__git_repo_path" >"$actual"
298 test_must_be_empty "$actual"
301 test_expect_success '__git_find_repo_path - non-existing path in $__git_dir' '
303 __git_dir="non-existing" &&
304 test_must_fail __git_find_repo_path &&
305 printf "$__git_repo_path" >"$actual"
307 test_must_be_empty "$actual"
310 test_expect_success '__git_find_repo_path - non-existing $GIT_DIR' '
312 GIT_DIR="$ROOT/non-existing" &&
314 test_must_fail __git_find_repo_path &&
315 printf "$__git_repo_path" >"$actual"
317 test_must_be_empty "$actual"
320 test_expect_success '__git_find_repo_path - gitfile in cwd' '
321 echo "$ROOT/otherrepo/.git" >expected &&
322 echo "gitdir: $ROOT/otherrepo/.git" >subdir/.git &&
323 test_when_finished "rm -f subdir/.git" &&
326 __git_find_repo_path &&
327 echo "$__git_repo_path" >"$actual"
329 test_cmp expected "$actual"
332 test_expect_success '__git_find_repo_path - gitfile in parent' '
333 echo "$ROOT/otherrepo/.git" >expected &&
334 echo "gitdir: $ROOT/otherrepo/.git" >subdir/.git &&
335 test_when_finished "rm -f subdir/.git" &&
337 cd subdir/subsubdir &&
338 __git_find_repo_path &&
339 echo "$__git_repo_path" >"$actual"
341 test_cmp expected "$actual"
344 test_expect_success SYMLINKS '__git_find_repo_path - resulting path avoids symlinks' '
345 echo "$ROOT/otherrepo/.git" >expected &&
346 mkdir otherrepo/dir &&
347 test_when_finished "rm -rf otherrepo/dir" &&
348 ln -s otherrepo/dir link &&
349 test_when_finished "rm -f link" &&
352 __git_find_repo_path &&
353 echo "$__git_repo_path" >"$actual"
355 test_cmp expected "$actual"
358 test_expect_success '__git_find_repo_path - not a git repository' '
361 GIT_CEILING_DIRECTORIES="$ROOT" &&
362 export GIT_CEILING_DIRECTORIES &&
363 test_must_fail __git_find_repo_path &&
364 printf "$__git_repo_path" >"$actual"
366 test_must_be_empty "$actual"
369 test_expect_success '__gitdir - finds repo' '
370 echo "$ROOT/.git" >expected &&
372 cd subdir/subsubdir &&
375 test_cmp expected "$actual"
379 test_expect_success '__gitdir - returns error when cant find repo' '
381 __git_dir="non-existing" &&
382 test_must_fail __gitdir >"$actual"
384 test_must_be_empty "$actual"
387 test_expect_success '__gitdir - repo as argument' '
388 echo "otherrepo/.git" >expected &&
390 __gitdir "otherrepo" >"$actual"
392 test_cmp expected "$actual"
395 test_expect_success '__gitdir - remote as argument' '
396 echo "remote" >expected &&
398 __gitdir "remote" >"$actual"
400 test_cmp expected "$actual"
403 test_expect_success '__gitcomp_direct - puts everything into COMPREPLY as-is' '
404 sed -e "s/Z$//g" >expected <<-EOF &&
405 with-trailing-space Z
406 without-trailing-spaceZ
409 $invalid_variable_name Z
412 cur=should_be_ignored &&
413 __gitcomp_direct "$(cat expected)" &&
416 test_cmp expected out
419 test_expect_success '__gitcomp - trailing space - options' '
420 test_gitcomp "--re" "--dry-run --reuse-message= --reedit-message=
421 --reset-author" <<-EOF
428 test_expect_success '__gitcomp - trailing space - config keys' '
429 test_gitcomp "br" "branch. branch.autosetupmerge
430 branch.autosetuprebase browser." <<-\EOF
432 branch.autosetupmerge Z
433 branch.autosetuprebase Z
438 test_expect_success '__gitcomp - option parameter' '
439 test_gitcomp "--strategy=re" "octopus ours recursive resolve subtree" \
446 test_expect_success '__gitcomp - prefix' '
447 test_gitcomp "branch.me" "remote merge mergeoptions rebase" \
448 "branch.maint." "me" <<-\EOF
450 branch.maint.mergeoptions Z
454 test_expect_success '__gitcomp - suffix' '
455 test_gitcomp "branch.me" "master maint next pu" "branch." \
462 test_expect_success '__gitcomp - doesnt fail because of invalid variable name' '
463 __gitcomp "$invalid_variable_name"
466 read -r -d "" refs <<-\EOF
473 test_expect_success '__gitcomp_nl - trailing space' '
474 test_gitcomp_nl "m" "$refs" <<-EOF
480 test_expect_success '__gitcomp_nl - prefix' '
481 test_gitcomp_nl "--fixup=m" "$refs" "--fixup=" "m" <<-EOF
487 test_expect_success '__gitcomp_nl - suffix' '
488 test_gitcomp_nl "branch.ma" "$refs" "branch." "ma" "." <<-\EOF
494 test_expect_success '__gitcomp_nl - no suffix' '
495 test_gitcomp_nl "ma" "$refs" "" "ma" "" <<-\EOF
501 test_expect_success '__gitcomp_nl - doesnt fail because of invalid variable name' '
502 __gitcomp_nl "$invalid_variable_name"
505 test_expect_success '__git_remotes - list remotes from $GIT_DIR/remotes and from config file' '
506 cat >expect <<-EOF &&
512 test_when_finished "rm -rf .git/remotes" &&
513 mkdir -p .git/remotes &&
514 >.git/remotes/remote_from_file_1 &&
515 >.git/remotes/remote_from_file_2 &&
516 test_when_finished "git remote remove remote_in_config_1" &&
517 git remote add remote_in_config_1 git://remote_1 &&
518 test_when_finished "git remote remove remote_in_config_2" &&
519 git remote add remote_in_config_2 git://remote_2 &&
521 __git_remotes >actual
523 test_cmp expect actual
526 test_expect_success '__git_is_configured_remote' '
527 test_when_finished "git remote remove remote_1" &&
528 git remote add remote_1 git://remote_1 &&
529 test_when_finished "git remote remove remote_2" &&
530 git remote add remote_2 git://remote_2 &&
532 verbose __git_is_configured_remote remote_2 &&
533 test_must_fail __git_is_configured_remote non-existent
537 test_expect_success 'setup for ref completion' '
538 git commit --allow-empty -m initial &&
539 git branch matching-branch &&
540 git tag matching-tag &&
543 git commit --allow-empty -m initial &&
544 git branch -m master master-in-other &&
545 git branch branch-in-other &&
548 git remote add other "$ROOT/otherrepo/.git" &&
549 git fetch --no-tags other &&
550 rm -f .git/FETCH_HEAD &&
554 test_expect_success '__git_refs - simple' '
555 cat >expected <<-EOF &&
559 other/branch-in-other
560 other/master-in-other
565 __git_refs >"$actual"
567 test_cmp expected "$actual"
570 test_expect_success '__git_refs - full refs' '
571 cat >expected <<-EOF &&
573 refs/heads/matching-branch
574 refs/remotes/other/branch-in-other
575 refs/remotes/other/master-in-other
576 refs/tags/matching-tag
580 __git_refs >"$actual"
582 test_cmp expected "$actual"
585 test_expect_success '__git_refs - repo given on the command line' '
586 cat >expected <<-EOF &&
593 __git_dir="$ROOT/otherrepo/.git" &&
595 __git_refs >"$actual"
597 test_cmp expected "$actual"
600 test_expect_success '__git_refs - remote on local file system' '
601 cat >expected <<-EOF &&
609 __git_refs otherrepo >"$actual"
611 test_cmp expected "$actual"
614 test_expect_success '__git_refs - remote on local file system - full refs' '
615 cat >expected <<-EOF &&
616 refs/heads/branch-in-other
617 refs/heads/master-in-other
618 refs/tags/tag-in-other
622 __git_refs otherrepo >"$actual"
624 test_cmp expected "$actual"
627 test_expect_success '__git_refs - configured remote' '
628 cat >expected <<-EOF &&
635 __git_refs other >"$actual"
637 test_cmp expected "$actual"
640 test_expect_success '__git_refs - configured remote - full refs' '
641 cat >expected <<-EOF &&
643 refs/heads/branch-in-other
644 refs/heads/master-in-other
645 refs/tags/tag-in-other
649 __git_refs other >"$actual"
651 test_cmp expected "$actual"
654 test_expect_success '__git_refs - configured remote - repo given on the command line' '
655 cat >expected <<-EOF &&
662 __git_dir="$ROOT/.git" &&
664 __git_refs other >"$actual"
666 test_cmp expected "$actual"
669 test_expect_success '__git_refs - configured remote - full refs - repo given on the command line' '
670 cat >expected <<-EOF &&
672 refs/heads/branch-in-other
673 refs/heads/master-in-other
674 refs/tags/tag-in-other
678 __git_dir="$ROOT/.git" &&
680 __git_refs other >"$actual"
682 test_cmp expected "$actual"
685 test_expect_success '__git_refs - configured remote - remote name matches a directory' '
686 cat >expected <<-EOF &&
692 test_when_finished "rm -rf other" &&
695 __git_refs other >"$actual"
697 test_cmp expected "$actual"
700 test_expect_success '__git_refs - URL remote' '
701 cat >expected <<-EOF &&
709 __git_refs "file://$ROOT/otherrepo/.git" >"$actual"
711 test_cmp expected "$actual"
714 test_expect_success '__git_refs - URL remote - full refs' '
715 cat >expected <<-EOF &&
717 refs/heads/branch-in-other
718 refs/heads/master-in-other
719 refs/tags/tag-in-other
723 __git_refs "file://$ROOT/otherrepo/.git" >"$actual"
725 test_cmp expected "$actual"
728 test_expect_success '__git_refs - non-existing remote' '
731 __git_refs non-existing >"$actual"
733 test_must_be_empty "$actual"
736 test_expect_success '__git_refs - non-existing remote - full refs' '
739 __git_refs non-existing >"$actual"
741 test_must_be_empty "$actual"
744 test_expect_success '__git_refs - non-existing URL remote' '
747 __git_refs "file://$ROOT/non-existing" >"$actual"
749 test_must_be_empty "$actual"
752 test_expect_success '__git_refs - non-existing URL remote - full refs' '
755 __git_refs "file://$ROOT/non-existing" >"$actual"
757 test_must_be_empty "$actual"
760 test_expect_success '__git_refs - not in a git repository' '
762 GIT_CEILING_DIRECTORIES="$ROOT" &&
763 export GIT_CEILING_DIRECTORIES &&
766 __git_refs >"$actual"
768 test_must_be_empty "$actual"
771 test_expect_success '__git_refs - unique remote branches for git checkout DWIMery' '
772 cat >expected <<-EOF &&
777 other/branch-in-other
778 other/master-in-other
780 remote/branch-in-remote
786 for remote_ref in refs/remotes/other/ambiguous \
787 refs/remotes/remote/ambiguous \
788 refs/remotes/remote/branch-in-remote
790 git update-ref $remote_ref master &&
791 test_when_finished "git update-ref -d $remote_ref"
795 __git_refs "" 1 >"$actual"
797 test_cmp expected "$actual"
800 test_expect_success '__git_refs - after --opt=' '
801 cat >expected <<-EOF &&
805 other/branch-in-other
806 other/master-in-other
811 __git_refs "" "" "" "" >"$actual"
813 test_cmp expected "$actual"
816 test_expect_success '__git_refs - after --opt= - full refs' '
817 cat >expected <<-EOF &&
819 refs/heads/matching-branch
820 refs/remotes/other/branch-in-other
821 refs/remotes/other/master-in-other
822 refs/tags/matching-tag
826 __git_refs "" "" "" refs/ >"$actual"
828 test_cmp expected "$actual"
831 test_expect_success '__git refs - exluding refs' '
832 cat >expected <<-EOF &&
836 ^other/branch-in-other
837 ^other/master-in-other
842 __git_refs >"$actual"
844 test_cmp expected "$actual"
847 test_expect_success '__git refs - exluding full refs' '
848 cat >expected <<-EOF &&
850 ^refs/heads/matching-branch
851 ^refs/remotes/other/branch-in-other
852 ^refs/remotes/other/master-in-other
853 ^refs/tags/matching-tag
857 __git_refs >"$actual"
859 test_cmp expected "$actual"
862 test_expect_success 'setup for filtering matching refs' '
863 git branch matching/branch &&
864 git tag matching/tag &&
865 git -C otherrepo branch matching/branch-in-other &&
866 git fetch --no-tags other &&
867 rm -f .git/FETCH_HEAD
870 test_expect_success '__git_refs - dont filter refs unless told so' '
871 cat >expected <<-EOF &&
876 other/branch-in-other
877 other/master-in-other
878 other/matching/branch-in-other
884 __git_refs >"$actual"
886 test_cmp expected "$actual"
889 test_expect_success '__git_refs - only matching refs' '
890 cat >expected <<-EOF &&
898 __git_refs "" "" "" "$cur" >"$actual"
900 test_cmp expected "$actual"
903 test_expect_success '__git_refs - only matching refs - full refs' '
904 cat >expected <<-EOF &&
905 refs/heads/matching-branch
906 refs/heads/matching/branch
909 cur=refs/heads/mat &&
910 __git_refs "" "" "" "$cur" >"$actual"
912 test_cmp expected "$actual"
915 test_expect_success '__git_refs - only matching refs - remote on local file system' '
916 cat >expected <<-EOF &&
918 matching/branch-in-other
922 __git_refs otherrepo "" "" "$cur" >"$actual"
924 test_cmp expected "$actual"
927 test_expect_success '__git_refs - only matching refs - configured remote' '
928 cat >expected <<-EOF &&
930 matching/branch-in-other
934 __git_refs other "" "" "$cur" >"$actual"
936 test_cmp expected "$actual"
939 test_expect_success '__git_refs - only matching refs - remote - full refs' '
940 cat >expected <<-EOF &&
941 refs/heads/master-in-other
942 refs/heads/matching/branch-in-other
946 __git_refs other "" "" "$cur" >"$actual"
948 test_cmp expected "$actual"
951 test_expect_success '__git_refs - only matching refs - checkout DWIMery' '
952 cat >expected <<-EOF &&
957 matching/branch-in-other
959 for remote_ref in refs/remotes/other/ambiguous \
960 refs/remotes/remote/ambiguous \
961 refs/remotes/remote/branch-in-remote
963 git update-ref $remote_ref master &&
964 test_when_finished "git update-ref -d $remote_ref"
968 __git_refs "" 1 "" "$cur" >"$actual"
970 test_cmp expected "$actual"
973 test_expect_success 'teardown after filtering matching refs' '
974 git branch -d matching/branch &&
975 git tag -d matching/tag &&
976 git update-ref -d refs/remotes/other/matching/branch-in-other &&
977 git -C otherrepo branch -D matching/branch-in-other
980 test_expect_success '__git_refs - for-each-ref format specifiers in prefix' '
981 cat >expected <<-EOF &&
982 evil-%%-%42-%(refname)..master
985 cur="evil-%%-%42-%(refname)..mas" &&
986 __git_refs "" "" "evil-%%-%42-%(refname).." mas >"$actual"
988 test_cmp expected "$actual"
991 test_expect_success '__git_complete_refs - simple' '
992 sed -e "s/Z$//" >expected <<-EOF &&
996 other/branch-in-other Z
997 other/master-in-other Z
1002 __git_complete_refs &&
1005 test_cmp expected out
1008 test_expect_success '__git_complete_refs - matching' '
1009 sed -e "s/Z$//" >expected <<-EOF &&
1015 __git_complete_refs &&
1018 test_cmp expected out
1021 test_expect_success '__git_complete_refs - remote' '
1022 sed -e "s/Z$//" >expected <<-EOF &&
1029 __git_complete_refs --remote=other &&
1032 test_cmp expected out
1035 test_expect_success '__git_complete_refs - track' '
1036 sed -e "s/Z$//" >expected <<-EOF &&
1040 other/branch-in-other Z
1041 other/master-in-other Z
1048 __git_complete_refs --track &&
1051 test_cmp expected out
1054 test_expect_success '__git_complete_refs - current word' '
1055 sed -e "s/Z$//" >expected <<-EOF &&
1060 cur="--option=mat" &&
1061 __git_complete_refs --cur="${cur#*=}" &&
1064 test_cmp expected out
1067 test_expect_success '__git_complete_refs - prefix' '
1068 sed -e "s/Z$//" >expected <<-EOF &&
1069 v1.0..matching-branch Z
1070 v1.0..matching-tag Z
1074 __git_complete_refs --pfx=v1.0.. --cur=mat &&
1077 test_cmp expected out
1080 test_expect_success '__git_complete_refs - suffix' '
1081 cat >expected <<-EOF &&
1085 other/branch-in-other.
1086 other/master-in-other.
1091 __git_complete_refs --sfx=. &&
1094 test_cmp expected out
1097 test_expect_success '__git_complete_fetch_refspecs - simple' '
1098 sed -e "s/Z$//" >expected <<-EOF &&
1100 branch-in-other:branch-in-other Z
1101 master-in-other:master-in-other Z
1105 __git_complete_fetch_refspecs other &&
1108 test_cmp expected out
1111 test_expect_success '__git_complete_fetch_refspecs - matching' '
1112 sed -e "s/Z$//" >expected <<-EOF &&
1113 branch-in-other:branch-in-other Z
1117 __git_complete_fetch_refspecs other "" br &&
1120 test_cmp expected out
1123 test_expect_success '__git_complete_fetch_refspecs - prefix' '
1124 sed -e "s/Z$//" >expected <<-EOF &&
1126 +branch-in-other:branch-in-other Z
1127 +master-in-other:master-in-other Z
1131 __git_complete_fetch_refspecs other "+" "" &&
1134 test_cmp expected out
1137 test_expect_success '__git_complete_fetch_refspecs - fully qualified' '
1138 sed -e "s/Z$//" >expected <<-EOF &&
1139 refs/heads/branch-in-other:refs/heads/branch-in-other Z
1140 refs/heads/master-in-other:refs/heads/master-in-other Z
1141 refs/tags/tag-in-other:refs/tags/tag-in-other Z
1145 __git_complete_fetch_refspecs other "" refs/ &&
1148 test_cmp expected out
1151 test_expect_success '__git_complete_fetch_refspecs - fully qualified & prefix' '
1152 sed -e "s/Z$//" >expected <<-EOF &&
1153 +refs/heads/branch-in-other:refs/heads/branch-in-other Z
1154 +refs/heads/master-in-other:refs/heads/master-in-other Z
1155 +refs/tags/tag-in-other:refs/tags/tag-in-other Z
1159 __git_complete_fetch_refspecs other + refs/ &&
1162 test_cmp expected out
1165 test_expect_success 'teardown after ref completion' '
1166 git branch -d matching-branch &&
1167 git tag -d matching-tag &&
1168 git remote remove other
1171 test_expect_success '__git_get_config_variables' '
1172 cat >expect <<-EOF &&
1176 test_config interesting.name-1 good &&
1177 test_config interesting.name-2 good &&
1178 test_config subsection.interesting.name-3 bad &&
1179 __git_get_config_variables interesting >actual &&
1180 test_cmp expect actual
1183 test_expect_success '__git_pretty_aliases' '
1184 cat >expect <<-EOF &&
1188 test_config pretty.author "%an %ae" &&
1189 test_config pretty.hash %H &&
1190 __git_pretty_aliases >actual &&
1191 test_cmp expect actual
1194 test_expect_success '__git_aliases' '
1195 cat >expect <<-EOF &&
1199 test_config alias.ci commit &&
1200 test_config alias.co checkout &&
1201 __git_aliases >actual &&
1202 test_cmp expect actual
1205 test_expect_success 'basic' '
1206 run_completion "git " &&
1208 grep -q "^add \$" out &&
1210 grep -q "^filter-branch \$" out &&
1212 ! grep -q "^ls-files \$" out &&
1214 run_completion "git f" &&
1215 ! grep -q -v "^f" out
1218 test_expect_success 'double dash "git" itself' '
1219 test_completion "git --" <<-\EOF
1232 --no-replace-objects Z
1237 test_expect_success 'double dash "git checkout"' '
1238 test_completion "git checkout --" <<-\EOF
1251 test_expect_success 'general options' '
1252 test_completion "git --ver" "--version " &&
1253 test_completion "git --hel" "--help " &&
1254 test_completion "git --exe" <<-\EOF &&
1258 test_completion "git --htm" "--html-path " &&
1259 test_completion "git --pag" "--paginate " &&
1260 test_completion "git --no-p" "--no-pager " &&
1261 test_completion "git --git" "--git-dir=" &&
1262 test_completion "git --wor" "--work-tree=" &&
1263 test_completion "git --nam" "--namespace=" &&
1264 test_completion "git --bar" "--bare " &&
1265 test_completion "git --inf" "--info-path " &&
1266 test_completion "git --no-r" "--no-replace-objects "
1269 test_expect_success 'general options plus command' '
1270 test_completion "git --version check" "checkout " &&
1271 test_completion "git --paginate check" "checkout " &&
1272 test_completion "git --git-dir=foo check" "checkout " &&
1273 test_completion "git --bare check" "checkout " &&
1274 test_completion "git --exec-path=foo check" "checkout " &&
1275 test_completion "git --html-path check" "checkout " &&
1276 test_completion "git --no-pager check" "checkout " &&
1277 test_completion "git --work-tree=foo check" "checkout " &&
1278 test_completion "git --namespace=foo check" "checkout " &&
1279 test_completion "git --paginate check" "checkout " &&
1280 test_completion "git --info-path check" "checkout " &&
1281 test_completion "git --no-replace-objects check" "checkout " &&
1282 test_completion "git --git-dir some/path check" "checkout " &&
1283 test_completion "git -c conf.var=value check" "checkout " &&
1284 test_completion "git -C some/path check" "checkout " &&
1285 test_completion "git --work-tree some/path check" "checkout " &&
1286 test_completion "git --namespace name/space check" "checkout "
1289 test_expect_success 'git --help completion' '
1290 test_completion "git --help ad" "add " &&
1291 test_completion "git --help core" "core-tutorial "
1294 test_expect_success 'setup for integration tests' '
1295 echo content >file1 &&
1297 git add file1 file2 &&
1298 git commit -m one &&
1299 git branch mybranch &&
1303 test_expect_success 'checkout completes ref names' '
1304 test_completion "git checkout m" <<-\EOF
1311 test_expect_success 'git -C <path> checkout uses the right repo' '
1312 test_completion "git -C subdir -C subsubdir -C .. -C ../otherrepo checkout b" <<-\EOF
1317 test_expect_success 'show completes all refs' '
1318 test_completion "git show m" <<-\EOF
1325 test_expect_success '<ref>: completes paths' '
1326 test_completion "git show mytag:f" <<-\EOF
1332 test_expect_success 'complete tree filename with spaces' '
1333 echo content >"name with spaces" &&
1334 git add "name with spaces" &&
1335 git commit -m spaces &&
1336 test_completion "git show HEAD:nam" <<-\EOF
1341 test_expect_success 'complete tree filename with metacharacters' '
1342 echo content >"name with \${meta}" &&
1343 git add "name with \${meta}" &&
1344 git commit -m meta &&
1345 test_completion "git show HEAD:nam" <<-\EOF
1351 test_expect_success 'send-email' '
1352 test_completion "git send-email --cov" "--cover-letter " &&
1353 test_completion "git send-email ma" "master "
1356 test_expect_success 'complete files' '
1357 git init tmp && cd tmp &&
1358 test_when_finished "cd .. && rm -rf tmp" &&
1360 echo "expected" > .gitignore &&
1361 echo "out" >> .gitignore &&
1363 git add .gitignore &&
1364 test_completion "git commit " ".gitignore" &&
1366 git commit -m ignore &&
1369 test_completion "git add " "new" &&
1372 git commit -a -m new &&
1373 test_completion "git add " "" &&
1375 git mv new modified &&
1376 echo modify > modified &&
1377 test_completion "git add " "modified" &&
1381 : TODO .gitignore should not be here &&
1382 test_completion "git rm " <<-\EOF &&
1387 test_completion "git clean " "untracked" &&
1389 : TODO .gitignore should not be here &&
1390 test_completion "git mv " <<-\EOF &&
1396 touch dir/file-in-dir &&
1397 git add dir/file-in-dir &&
1398 git commit -m dir &&
1400 mkdir untracked-dir &&
1402 : TODO .gitignore should not be here &&
1403 test_completion "git mv modified " <<-\EOF &&
1411 test_completion "git commit " "modified" &&
1413 : TODO .gitignore should not be here &&
1414 test_completion "git ls-files " <<-\EOF &&
1421 test_completion "git add mom" "momified"
1424 test_expect_success "completion uses <cmd> completion for alias: !sh -c 'git <cmd> ...'" '
1425 test_config alias.co "!sh -c '"'"'git checkout ...'"'"'" &&
1426 test_completion "git co m" <<-\EOF
1433 test_expect_success 'completion uses <cmd> completion for alias: !f () { VAR=val git <cmd> ... }' '
1434 test_config alias.co "!f () { VAR=val git checkout ... ; } f" &&
1435 test_completion "git co m" <<-\EOF
1442 test_expect_success 'completion used <cmd> completion for alias: !f() { : git <cmd> ; ... }' '
1443 test_config alias.co "!f() { : git checkout ; if ... } f" &&
1444 test_completion "git co m" <<-\EOF
1451 test_expect_failure 'complete with tilde expansion' '
1452 git init tmp && cd tmp &&
1453 test_when_finished "cd .. && rm -rf tmp" &&
1457 test_completion "git add ~/tmp/" "~/tmp/file"