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 # "filter-branch" and "ls-files" are listed for this.
33 GIT_TESTING_ALL_COMMAND_LIST
='add checkout check-attr filter-branch ls-files'
34 GIT_TESTING_PORCELAIN_COMMAND_LIST
='add checkout filter-branch'
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$//' >expected
90 run_completion
"$1" &&
95 # The first argument is the typed text so far (cur); the rest are
96 # passed to __gitcomp. Expected output comes is read from the
97 # standard input, like test_completion().
100 local -a COMPREPLY
&&
101 sed -e 's/Z$//' >expected
&&
106 test_cmp expected out
111 # 1: current word (cur)
112 # -: the rest are passed to __gitcomp_nl
115 local -a COMPREPLY
&&
116 sed -e 's/Z$//' >expected
&&
121 test_cmp expected out
124 invalid_variable_name
='${foo.bar}'
126 actual
="$TRASH_DIRECTORY/actual"
128 if test_have_prereq MINGW
135 test_expect_success
'setup for __git_find_repo_path/__gitdir tests' '
136 mkdir -p subdir/subsubdir &&
141 test_expect_success
'__git_find_repo_path - from command line (through $__git_dir)' '
142 echo "$ROOT/otherrepo/.git" >expected &&
144 __git_dir="$ROOT/otherrepo/.git" &&
145 __git_find_repo_path &&
146 echo "$__git_repo_path" >"$actual"
148 test_cmp expected "$actual"
151 test_expect_success
'__git_find_repo_path - .git directory in cwd' '
152 echo ".git" >expected &&
154 __git_find_repo_path &&
155 echo "$__git_repo_path" >"$actual"
157 test_cmp expected "$actual"
160 test_expect_success
'__git_find_repo_path - .git directory in parent' '
161 echo "$ROOT/.git" >expected &&
163 cd subdir/subsubdir &&
164 __git_find_repo_path &&
165 echo "$__git_repo_path" >"$actual"
167 test_cmp expected "$actual"
170 test_expect_success
'__git_find_repo_path - cwd is a .git directory' '
171 echo "." >expected &&
174 __git_find_repo_path &&
175 echo "$__git_repo_path" >"$actual"
177 test_cmp expected "$actual"
180 test_expect_success
'__git_find_repo_path - parent is a .git directory' '
181 echo "$ROOT/.git" >expected &&
183 cd .git/refs/heads &&
184 __git_find_repo_path &&
185 echo "$__git_repo_path" >"$actual"
187 test_cmp expected "$actual"
190 test_expect_success
'__git_find_repo_path - $GIT_DIR set while .git directory in cwd' '
191 echo "$ROOT/otherrepo/.git" >expected &&
193 GIT_DIR="$ROOT/otherrepo/.git" &&
195 __git_find_repo_path &&
196 echo "$__git_repo_path" >"$actual"
198 test_cmp expected "$actual"
201 test_expect_success
'__git_find_repo_path - $GIT_DIR set while .git directory in parent' '
202 echo "$ROOT/otherrepo/.git" >expected &&
204 GIT_DIR="$ROOT/otherrepo/.git" &&
207 __git_find_repo_path &&
208 echo "$__git_repo_path" >"$actual"
210 test_cmp expected "$actual"
213 test_expect_success
'__git_find_repo_path - from command line while "git -C"' '
214 echo "$ROOT/.git" >expected &&
216 __git_dir="$ROOT/.git" &&
217 __git_C_args=(-C otherrepo) &&
218 __git_find_repo_path &&
219 echo "$__git_repo_path" >"$actual"
221 test_cmp expected "$actual"
224 test_expect_success
'__git_find_repo_path - relative dir from command line and "git -C"' '
225 echo "$ROOT/otherrepo/.git" >expected &&
228 __git_dir="otherrepo/.git" &&
229 __git_C_args=(-C ..) &&
230 __git_find_repo_path &&
231 echo "$__git_repo_path" >"$actual"
233 test_cmp expected "$actual"
236 test_expect_success
'__git_find_repo_path - $GIT_DIR set while "git -C"' '
237 echo "$ROOT/.git" >expected &&
239 GIT_DIR="$ROOT/.git" &&
241 __git_C_args=(-C otherrepo) &&
242 __git_find_repo_path &&
243 echo "$__git_repo_path" >"$actual"
245 test_cmp expected "$actual"
248 test_expect_success
'__git_find_repo_path - relative dir in $GIT_DIR and "git -C"' '
249 echo "$ROOT/otherrepo/.git" >expected &&
252 GIT_DIR="otherrepo/.git" &&
254 __git_C_args=(-C ..) &&
255 __git_find_repo_path &&
256 echo "$__git_repo_path" >"$actual"
258 test_cmp expected "$actual"
261 test_expect_success
'__git_find_repo_path - "git -C" while .git directory in cwd' '
262 echo "$ROOT/otherrepo/.git" >expected &&
264 __git_C_args=(-C otherrepo) &&
265 __git_find_repo_path &&
266 echo "$__git_repo_path" >"$actual"
268 test_cmp expected "$actual"
271 test_expect_success
'__git_find_repo_path - "git -C" while cwd is a .git directory' '
272 echo "$ROOT/otherrepo/.git" >expected &&
275 __git_C_args=(-C .. -C otherrepo) &&
276 __git_find_repo_path &&
277 echo "$__git_repo_path" >"$actual"
279 test_cmp expected "$actual"
282 test_expect_success
'__git_find_repo_path - "git -C" while .git directory in parent' '
283 echo "$ROOT/otherrepo/.git" >expected &&
286 __git_C_args=(-C .. -C otherrepo) &&
287 __git_find_repo_path &&
288 echo "$__git_repo_path" >"$actual"
290 test_cmp expected "$actual"
293 test_expect_success
'__git_find_repo_path - non-existing path in "git -C"' '
295 __git_C_args=(-C non-existing) &&
296 test_must_fail __git_find_repo_path &&
297 printf "$__git_repo_path" >"$actual"
299 test_must_be_empty "$actual"
302 test_expect_success
'__git_find_repo_path - non-existing path in $__git_dir' '
304 __git_dir="non-existing" &&
305 test_must_fail __git_find_repo_path &&
306 printf "$__git_repo_path" >"$actual"
308 test_must_be_empty "$actual"
311 test_expect_success
'__git_find_repo_path - non-existing $GIT_DIR' '
313 GIT_DIR="$ROOT/non-existing" &&
315 test_must_fail __git_find_repo_path &&
316 printf "$__git_repo_path" >"$actual"
318 test_must_be_empty "$actual"
321 test_expect_success
'__git_find_repo_path - gitfile in cwd' '
322 echo "$ROOT/otherrepo/.git" >expected &&
323 echo "gitdir: $ROOT/otherrepo/.git" >subdir/.git &&
324 test_when_finished "rm -f subdir/.git" &&
327 __git_find_repo_path &&
328 echo "$__git_repo_path" >"$actual"
330 test_cmp expected "$actual"
333 test_expect_success
'__git_find_repo_path - gitfile in parent' '
334 echo "$ROOT/otherrepo/.git" >expected &&
335 echo "gitdir: $ROOT/otherrepo/.git" >subdir/.git &&
336 test_when_finished "rm -f subdir/.git" &&
338 cd subdir/subsubdir &&
339 __git_find_repo_path &&
340 echo "$__git_repo_path" >"$actual"
342 test_cmp expected "$actual"
345 test_expect_success SYMLINKS
'__git_find_repo_path - resulting path avoids symlinks' '
346 echo "$ROOT/otherrepo/.git" >expected &&
347 mkdir otherrepo/dir &&
348 test_when_finished "rm -rf otherrepo/dir" &&
349 ln -s otherrepo/dir link &&
350 test_when_finished "rm -f link" &&
353 __git_find_repo_path &&
354 echo "$__git_repo_path" >"$actual"
356 test_cmp expected "$actual"
359 test_expect_success
'__git_find_repo_path - not a git repository' '
362 GIT_CEILING_DIRECTORIES="$ROOT" &&
363 export GIT_CEILING_DIRECTORIES &&
364 test_must_fail __git_find_repo_path &&
365 printf "$__git_repo_path" >"$actual"
367 test_must_be_empty "$actual"
370 test_expect_success
'__gitdir - finds repo' '
371 echo "$ROOT/.git" >expected &&
373 cd subdir/subsubdir &&
376 test_cmp expected "$actual"
380 test_expect_success
'__gitdir - returns error when cant find repo' '
382 __git_dir="non-existing" &&
383 test_must_fail __gitdir >"$actual"
385 test_must_be_empty "$actual"
388 test_expect_success
'__gitdir - repo as argument' '
389 echo "otherrepo/.git" >expected &&
391 __gitdir "otherrepo" >"$actual"
393 test_cmp expected "$actual"
396 test_expect_success
'__gitdir - remote as argument' '
397 echo "remote" >expected &&
399 __gitdir "remote" >"$actual"
401 test_cmp expected "$actual"
404 test_expect_success
'__gitcomp_direct - puts everything into COMPREPLY as-is' '
405 sed -e "s/Z$//g" >expected <<-EOF &&
406 with-trailing-space Z
407 without-trailing-spaceZ
410 $invalid_variable_name Z
413 cur=should_be_ignored &&
414 __gitcomp_direct "$(cat expected)" &&
417 test_cmp expected out
420 test_expect_success
'__gitcomp - trailing space - options' '
421 test_gitcomp "--re" "--dry-run --reuse-message= --reedit-message=
422 --reset-author" <<-EOF
429 test_expect_success
'__gitcomp - trailing space - config keys' '
430 test_gitcomp "br" "branch. branch.autosetupmerge
431 branch.autosetuprebase browser." <<-\EOF
433 branch.autosetupmerge Z
434 branch.autosetuprebase Z
439 test_expect_success
'__gitcomp - option parameter' '
440 test_gitcomp "--strategy=re" "octopus ours recursive resolve subtree" \
447 test_expect_success
'__gitcomp - prefix' '
448 test_gitcomp "branch.me" "remote merge mergeoptions rebase" \
449 "branch.maint." "me" <<-\EOF
451 branch.maint.mergeoptions Z
455 test_expect_success
'__gitcomp - suffix' '
456 test_gitcomp "branch.me" "master maint next pu" "branch." \
463 test_expect_success
'__gitcomp - doesnt fail because of invalid variable name' '
464 __gitcomp "$invalid_variable_name"
467 read -r -d "" refs
<<-\EOF
474 test_expect_success '__gitcomp_nl - trailing space
' '
475 test_gitcomp_nl
"m" "$refs" <<-EOF
481 test_expect_success '__gitcomp_nl
- prefix
' '
482 test_gitcomp_nl
"--fixup=m" "$refs" "--fixup=" "m" <<-EOF
488 test_expect_success '__gitcomp_nl
- suffix
' '
489 test_gitcomp_nl
"branch.ma" "$refs" "branch." "ma" "." <<-\EOF
495 test_expect_success '__gitcomp_nl - no suffix
' '
496 test_gitcomp_nl
"ma" "$refs" "" "ma" "" <<-\EOF
502 test_expect_success '__gitcomp_nl - doesnt fail because of invalid variable name
' '
503 __gitcomp_nl
"$invalid_variable_name"
506 test_expect_success '__git_remotes
- list remotes from
$GIT_DIR/remotes and from config
file' '
507 cat >expect
<<-EOF &&
513 test_when_finished
"rm -rf .git/remotes" &&
514 mkdir
-p .git
/remotes
&&
515 >.git
/remotes
/remote_from_file_1
&&
516 >.git
/remotes
/remote_from_file_2
&&
517 test_when_finished
"git remote remove remote_in_config_1" &&
518 git remote add remote_in_config_1 git
://remote_1
&&
519 test_when_finished
"git remote remove remote_in_config_2" &&
520 git remote add remote_in_config_2 git
://remote_2
&&
522 __git_remotes
>actual
524 test_cmp expect actual
527 test_expect_success '__git_is_configured_remote
' '
528 test_when_finished
"git remote remove remote_1" &&
529 git remote add remote_1 git
://remote_1
&&
530 test_when_finished
"git remote remove remote_2" &&
531 git remote add remote_2 git
://remote_2
&&
533 verbose __git_is_configured_remote remote_2
&&
534 test_must_fail __git_is_configured_remote non-existent
538 test_expect_success 'setup
for ref completion
' '
539 git commit
--allow-empty -m initial
&&
540 git branch matching-branch
&&
541 git tag matching-tag
&&
544 git commit
--allow-empty -m initial
&&
545 git branch
-m master master-in-other
&&
546 git branch branch-in-other
&&
549 git remote add other
"$ROOT/otherrepo/.git" &&
550 git fetch
--no-tags other
&&
551 rm -f .git
/FETCH_HEAD
&&
555 test_expect_success '__git_refs
- simple
' '
556 cat >expected
<<-EOF &&
560 other/branch-in-other
561 other/master-in-other
566 __git_refs
>"$actual"
568 test_cmp expected
"$actual"
571 test_expect_success '__git_refs
- full refs
' '
572 cat >expected
<<-EOF &&
574 refs/heads/matching-branch
575 refs/remotes/other/branch-in-other
576 refs/remotes/other/master-in-other
577 refs/tags/matching-tag
581 __git_refs
>"$actual"
583 test_cmp expected
"$actual"
586 test_expect_success '__git_refs
- repo given on the
command line
' '
587 cat >expected
<<-EOF &&
594 __git_dir
="$ROOT/otherrepo/.git" &&
596 __git_refs
>"$actual"
598 test_cmp expected
"$actual"
601 test_expect_success '__git_refs
- remote on
local file system
' '
602 cat >expected
<<-EOF &&
610 __git_refs otherrepo
>"$actual"
612 test_cmp expected
"$actual"
615 test_expect_success '__git_refs
- remote on
local file system
- full refs
' '
616 cat >expected
<<-EOF &&
617 refs/heads/branch-in-other
618 refs/heads/master-in-other
619 refs/tags/tag-in-other
623 __git_refs otherrepo
>"$actual"
625 test_cmp expected
"$actual"
628 test_expect_success '__git_refs
- configured remote
' '
629 cat >expected
<<-EOF &&
636 __git_refs other
>"$actual"
638 test_cmp expected
"$actual"
641 test_expect_success '__git_refs
- configured remote
- full refs
' '
642 cat >expected
<<-EOF &&
644 refs/heads/branch-in-other
645 refs/heads/master-in-other
646 refs/tags/tag-in-other
650 __git_refs other
>"$actual"
652 test_cmp expected
"$actual"
655 test_expect_success '__git_refs
- configured remote
- repo given on the
command line
' '
656 cat >expected
<<-EOF &&
663 __git_dir
="$ROOT/.git" &&
665 __git_refs other
>"$actual"
667 test_cmp expected
"$actual"
670 test_expect_success '__git_refs
- configured remote
- full refs
- repo given on the
command line
' '
671 cat >expected
<<-EOF &&
673 refs/heads/branch-in-other
674 refs/heads/master-in-other
675 refs/tags/tag-in-other
679 __git_dir
="$ROOT/.git" &&
681 __git_refs other
>"$actual"
683 test_cmp expected
"$actual"
686 test_expect_success '__git_refs
- configured remote
- remote name matches a directory
' '
687 cat >expected
<<-EOF &&
693 test_when_finished
"rm -rf other" &&
696 __git_refs other
>"$actual"
698 test_cmp expected
"$actual"
701 test_expect_success '__git_refs
- URL remote
' '
702 cat >expected
<<-EOF &&
710 __git_refs
"file://$ROOT/otherrepo/.git" >"$actual"
712 test_cmp expected
"$actual"
715 test_expect_success '__git_refs
- URL remote
- full refs
' '
716 cat >expected
<<-EOF &&
718 refs/heads/branch-in-other
719 refs/heads/master-in-other
720 refs/tags/tag-in-other
724 __git_refs
"file://$ROOT/otherrepo/.git" >"$actual"
726 test_cmp expected
"$actual"
729 test_expect_success '__git_refs
- non-existing remote
' '
732 __git_refs non-existing
>"$actual"
734 test_must_be_empty
"$actual"
737 test_expect_success '__git_refs
- non-existing remote
- full refs
' '
740 __git_refs non-existing
>"$actual"
742 test_must_be_empty
"$actual"
745 test_expect_success '__git_refs
- non-existing URL remote
' '
748 __git_refs
"file://$ROOT/non-existing" >"$actual"
750 test_must_be_empty
"$actual"
753 test_expect_success '__git_refs
- non-existing URL remote
- full refs
' '
756 __git_refs
"file://$ROOT/non-existing" >"$actual"
758 test_must_be_empty
"$actual"
761 test_expect_success '__git_refs
- not
in a git repository
' '
763 GIT_CEILING_DIRECTORIES
="$ROOT" &&
764 export GIT_CEILING_DIRECTORIES
&&
767 __git_refs
>"$actual"
769 test_must_be_empty
"$actual"
772 test_expect_success '__git_refs
- unique remote branches
for git checkout DWIMery
' '
773 cat >expected
<<-EOF &&
778 other/branch-in-other
779 other/master-in-other
781 remote/branch-in-remote
787 for remote_ref
in refs
/remotes
/other
/ambiguous \
788 refs
/remotes
/remote
/ambiguous \
789 refs
/remotes
/remote
/branch-in-remote
791 git update-ref
$remote_ref master
&&
792 test_when_finished
"git update-ref -d $remote_ref"
796 __git_refs
"" 1 >"$actual"
798 test_cmp expected
"$actual"
801 test_expect_success '__git_refs
- after
--opt=' '
802 cat >expected
<<-EOF &&
806 other/branch-in-other
807 other/master-in-other
812 __git_refs
"" "" "" "" >"$actual"
814 test_cmp expected
"$actual"
817 test_expect_success '__git_refs
- after
--opt= - full refs
' '
818 cat >expected
<<-EOF &&
820 refs/heads/matching-branch
821 refs/remotes/other/branch-in-other
822 refs/remotes/other/master-in-other
823 refs/tags/matching-tag
827 __git_refs
"" "" "" refs
/ >"$actual"
829 test_cmp expected
"$actual"
832 test_expect_success '__git refs
- exluding refs
' '
833 cat >expected
<<-EOF &&
837 ^other/branch-in-other
838 ^other/master-in-other
843 __git_refs
>"$actual"
845 test_cmp expected
"$actual"
848 test_expect_success '__git refs
- exluding full refs
' '
849 cat >expected
<<-EOF &&
851 ^refs/heads/matching-branch
852 ^refs/remotes/other/branch-in-other
853 ^refs/remotes/other/master-in-other
854 ^refs/tags/matching-tag
858 __git_refs
>"$actual"
860 test_cmp expected
"$actual"
863 test_expect_success 'setup
for filtering matching refs
' '
864 git branch matching
/branch
&&
865 git tag matching
/tag
&&
866 git
-C otherrepo branch matching
/branch-in-other
&&
867 git fetch
--no-tags other
&&
868 rm -f .git
/FETCH_HEAD
871 test_expect_success '__git_refs
- dont filter refs unless told so
' '
872 cat >expected
<<-EOF &&
877 other/branch-in-other
878 other/master-in-other
879 other/matching/branch-in-other
885 __git_refs
>"$actual"
887 test_cmp expected
"$actual"
890 test_expect_success '__git_refs
- only matching refs
' '
891 cat >expected
<<-EOF &&
899 __git_refs
"" "" "" "$cur" >"$actual"
901 test_cmp expected
"$actual"
904 test_expect_success '__git_refs
- only matching refs
- full refs
' '
905 cat >expected
<<-EOF &&
906 refs/heads/matching-branch
907 refs/heads/matching/branch
910 cur
=refs
/heads
/mat
&&
911 __git_refs
"" "" "" "$cur" >"$actual"
913 test_cmp expected
"$actual"
916 test_expect_success '__git_refs
- only matching refs
- remote on
local file system
' '
917 cat >expected
<<-EOF &&
919 matching/branch-in-other
923 __git_refs otherrepo
"" "" "$cur" >"$actual"
925 test_cmp expected
"$actual"
928 test_expect_success '__git_refs
- only matching refs
- configured remote
' '
929 cat >expected
<<-EOF &&
931 matching/branch-in-other
935 __git_refs other
"" "" "$cur" >"$actual"
937 test_cmp expected
"$actual"
940 test_expect_success '__git_refs
- only matching refs
- remote
- full refs
' '
941 cat >expected
<<-EOF &&
942 refs/heads/master-in-other
943 refs/heads/matching/branch-in-other
947 __git_refs other
"" "" "$cur" >"$actual"
949 test_cmp expected
"$actual"
952 test_expect_success '__git_refs
- only matching refs
- checkout DWIMery
' '
953 cat >expected
<<-EOF &&
958 matching/branch-in-other
960 for remote_ref
in refs
/remotes
/other
/ambiguous \
961 refs
/remotes
/remote
/ambiguous \
962 refs
/remotes
/remote
/branch-in-remote
964 git update-ref
$remote_ref master
&&
965 test_when_finished
"git update-ref -d $remote_ref"
969 __git_refs
"" 1 "" "$cur" >"$actual"
971 test_cmp expected
"$actual"
974 test_expect_success 'teardown after filtering matching refs
' '
975 git branch
-d matching
/branch
&&
976 git tag
-d matching
/tag
&&
977 git update-ref
-d refs
/remotes
/other
/matching
/branch-in-other
&&
978 git
-C otherrepo branch
-D matching
/branch-in-other
981 test_expect_success '__git_refs
- for-each-ref format specifiers
in prefix
' '
982 cat >expected
<<-EOF &&
983 evil-%%-%42-%(refname)..master
986 cur
="evil-%%-%42-%(refname)..mas" &&
987 __git_refs
"" "" "evil-%%-%42-%(refname).." mas
>"$actual"
989 test_cmp expected
"$actual"
992 test_expect_success '__git_complete_refs
- simple
' '
993 sed -e "s/Z$//" >expected
<<-EOF &&
997 other/branch-in-other Z
998 other/master-in-other Z
1003 __git_complete_refs
&&
1006 test_cmp expected out
1009 test_expect_success '__git_complete_refs
- matching
' '
1010 sed -e "s/Z$//" >expected
<<-EOF &&
1016 __git_complete_refs
&&
1019 test_cmp expected out
1022 test_expect_success '__git_complete_refs
- remote
' '
1023 sed -e "s/Z$//" >expected
<<-EOF &&
1030 __git_complete_refs
--remote=other
&&
1033 test_cmp expected out
1036 test_expect_success '__git_complete_refs
- track
' '
1037 sed -e "s/Z$//" >expected
<<-EOF &&
1041 other/branch-in-other Z
1042 other/master-in-other Z
1049 __git_complete_refs
--track &&
1052 test_cmp expected out
1055 test_expect_success '__git_complete_refs
- current word
' '
1056 sed -e "s/Z$//" >expected
<<-EOF &&
1061 cur
="--option=mat" &&
1062 __git_complete_refs
--cur="${cur#*=}" &&
1065 test_cmp expected out
1068 test_expect_success '__git_complete_refs
- prefix
' '
1069 sed -e "s/Z$//" >expected
<<-EOF &&
1070 v1.0..matching-branch Z
1071 v1.0..matching-tag Z
1075 __git_complete_refs
--pfx=v1.0..
--cur=mat
&&
1078 test_cmp expected out
1081 test_expect_success '__git_complete_refs
- suffix
' '
1082 cat >expected
<<-EOF &&
1086 other/branch-in-other.
1087 other/master-in-other.
1092 __git_complete_refs
--sfx=.
&&
1095 test_cmp expected out
1098 test_expect_success '__git_complete_fetch_refspecs
- simple
' '
1099 sed -e "s/Z$//" >expected
<<-EOF &&
1101 branch-in-other:branch-in-other Z
1102 master-in-other:master-in-other Z
1106 __git_complete_fetch_refspecs other
&&
1109 test_cmp expected out
1112 test_expect_success '__git_complete_fetch_refspecs
- matching
' '
1113 sed -e "s/Z$//" >expected
<<-EOF &&
1114 branch-in-other:branch-in-other Z
1118 __git_complete_fetch_refspecs other
"" br
&&
1121 test_cmp expected out
1124 test_expect_success '__git_complete_fetch_refspecs
- prefix
' '
1125 sed -e "s/Z$//" >expected
<<-EOF &&
1127 +branch-in-other:branch-in-other Z
1128 +master-in-other:master-in-other Z
1132 __git_complete_fetch_refspecs other
"+" "" &&
1135 test_cmp expected out
1138 test_expect_success '__git_complete_fetch_refspecs
- fully qualified
' '
1139 sed -e "s/Z$//" >expected
<<-EOF &&
1140 refs/heads/branch-in-other:refs/heads/branch-in-other Z
1141 refs/heads/master-in-other:refs/heads/master-in-other Z
1142 refs/tags/tag-in-other:refs/tags/tag-in-other Z
1146 __git_complete_fetch_refspecs other
"" refs
/ &&
1149 test_cmp expected out
1152 test_expect_success '__git_complete_fetch_refspecs
- fully qualified
& prefix
' '
1153 sed -e "s/Z$//" >expected
<<-EOF &&
1154 +refs/heads/branch-in-other:refs/heads/branch-in-other Z
1155 +refs/heads/master-in-other:refs/heads/master-in-other Z
1156 +refs/tags/tag-in-other:refs/tags/tag-in-other Z
1160 __git_complete_fetch_refspecs other
+ refs
/ &&
1163 test_cmp expected out
1166 test_expect_success 'teardown after ref completion
' '
1167 git branch
-d matching-branch
&&
1168 git tag
-d matching-tag
&&
1169 git remote remove other
1172 test_expect_success '__git_get_config_variables
' '
1173 cat >expect
<<-EOF &&
1177 test_config interesting.name-1 good
&&
1178 test_config interesting.name-2 good
&&
1179 test_config subsection.interesting.name-3 bad
&&
1180 __git_get_config_variables interesting
>actual
&&
1181 test_cmp expect actual
1184 test_expect_success '__git_pretty_aliases
' '
1185 cat >expect
<<-EOF &&
1189 test_config pretty.author
"%an %ae" &&
1190 test_config pretty.
hash %H
&&
1191 __git_pretty_aliases
>actual
&&
1192 test_cmp expect actual
1195 test_expect_success 'basic
' '
1196 run_completion
"git " &&
1198 grep -q "^add \$" out
&&
1200 grep -q "^filter-branch \$" out
&&
1202 ! grep -q "^ls-files \$" out
&&
1204 run_completion
"git f" &&
1205 ! grep -q -v "^f" out
1208 test_expect_success 'double dash
"git" itself
' '
1209 test_completion
"git --" <<-\EOF
1222 --no-replace-objects Z
1227 test_expect_success 'double dash "git checkout"' '
1228 test_completion "git checkout --" <<-\
EOF
1238 --ignore-skip-worktree-bits Z
1239 --ignore-other-worktrees Z
1240 --recurse-submodules Z
1243 --no-recurse-submodules Z
1247 test_expect_success 'general options' '
1248 test_completion "git --ver" "--version " &&
1249 test_completion "git --hel" "--help " &&
1250 test_completion "git --exe" <<-\EOF &&
1254 test_completion "git --htm" "--html-path " &&
1255 test_completion "git --pag" "--paginate " &&
1256 test_completion "git --no-p" "--no-pager " &&
1257 test_completion "git --git" "--git-dir=" &&
1258 test_completion "git --wor" "--work-tree=" &&
1259 test_completion "git --nam" "--namespace=" &&
1260 test_completion "git --bar" "--bare " &&
1261 test_completion "git --inf" "--info-path " &&
1262 test_completion "git --no-r" "--no-replace-objects "
1265 test_expect_success 'general options plus command' '
1266 test_completion "git --version check" "checkout " &&
1267 test_completion "git --paginate check" "checkout " &&
1268 test_completion "git --git-dir=foo check" "checkout " &&
1269 test_completion "git --bare check" "checkout " &&
1270 test_completion "git --exec-path=foo check" "checkout " &&
1271 test_completion "git --html-path check" "checkout " &&
1272 test_completion "git --no-pager check" "checkout " &&
1273 test_completion "git --work-tree=foo check" "checkout " &&
1274 test_completion "git --namespace=foo check" "checkout " &&
1275 test_completion "git --paginate check" "checkout " &&
1276 test_completion "git --info-path check" "checkout " &&
1277 test_completion "git --no-replace-objects check" "checkout " &&
1278 test_completion "git --git-dir some/path check" "checkout " &&
1279 test_completion "git -c conf.var=value check" "checkout " &&
1280 test_completion "git -C some/path check" "checkout " &&
1281 test_completion "git --work-tree some/path check" "checkout " &&
1282 test_completion "git --namespace name/space check" "checkout "
1285 test_expect_success 'git --help completion' '
1286 test_completion "git --help ad" "add " &&
1287 test_completion "git --help core" "core-tutorial "
1290 test_expect_success 'setup for integration tests' '
1291 echo content >file1 &&
1293 git add file1 file2 &&
1294 git commit -m one &&
1295 git branch mybranch &&
1299 test_expect_success 'checkout completes ref names' '
1300 test_completion "git checkout m" <<-\EOF
1307 test_expect_success 'git -C <path> checkout uses the right repo' '
1308 test_completion "git -C subdir -C subsubdir -C .. -C ../otherrepo checkout b" <<-\EOF
1313 test_expect_success 'show completes all refs' '
1314 test_completion "git show m" <<-\EOF
1321 test_expect_success '<ref>: completes paths' '
1322 test_completion "git show mytag:f" <<-\EOF
1328 test_expect_success 'complete tree filename with spaces' '
1329 echo content >"name with spaces" &&
1330 git add "name with spaces" &&
1331 git commit -m spaces &&
1332 test_completion "git show HEAD:nam" <<-\EOF
1337 test_expect_success 'complete tree filename with metacharacters' '
1338 echo content >"name with \${meta}" &&
1339 git add "name with \${meta}" &&
1340 git commit -m meta &&
1341 test_completion "git show HEAD:nam" <<-\EOF
1347 test_expect_success 'send-email' '
1348 test_completion "git send-email --cov" "--cover-letter " &&
1349 test_completion "git send-email ma" "master "
1352 test_expect_success 'complete files' '
1353 git init tmp && cd tmp &&
1354 test_when_finished "cd .. && rm -rf tmp" &&
1356 echo "expected" > .gitignore &&
1357 echo "out" >> .gitignore &&
1359 git add .gitignore &&
1360 test_completion "git commit " ".gitignore" &&
1362 git commit -m ignore &&
1365 test_completion "git add " "new" &&
1368 git commit -a -m new &&
1369 test_completion "git add " "" &&
1371 git mv new modified &&
1372 echo modify > modified &&
1373 test_completion "git add " "modified" &&
1377 : TODO .gitignore should not be here &&
1378 test_completion "git rm " <<-\EOF &&
1383 test_completion "git clean " "untracked" &&
1385 : TODO .gitignore should not be here &&
1386 test_completion "git mv " <<-\EOF &&
1392 touch dir/file-in-dir &&
1393 git add dir/file-in-dir &&
1394 git commit -m dir &&
1396 mkdir untracked-dir &&
1398 : TODO .gitignore should not be here &&
1399 test_completion "git mv modified " <<-\EOF &&
1407 test_completion "git commit " "modified" &&
1409 : TODO .gitignore should not be here &&
1410 test_completion "git ls-files " <<-\EOF &&
1417 test_completion "git add mom" "momified"
1420 test_expect_success "completion uses <cmd> completion for alias: !sh -c 'git <cmd> ...'" '
1421 test_config alias.co "!sh -c '"'"'git checkout ...'"'"'" &&
1422 test_completion "git co m" <<-\EOF
1429 test_expect_success 'completion uses <cmd> completion for alias: !f () { VAR=val git <cmd> ... }' '
1430 test_config alias.co "!f () { VAR=val git checkout ... ; } f" &&
1431 test_completion "git co m" <<-\EOF
1438 test_expect_success 'completion used <cmd> completion for alias: !f() { : git <cmd> ; ... }' '
1439 test_config alias.co "!f() { : git checkout ; if ... } f" &&
1440 test_completion "git co m" <<-\EOF
1447 test_expect_success 'completion without explicit _git_xxx function' '
1448 test_completion "git version --" <<-\EOF
1453 test_expect_failure 'complete with tilde expansion' '
1454 git init tmp && cd tmp &&
1455 test_when_finished "cd .. && rm -rf tmp" &&
1459 test_completion "git add ~/tmp/" "~/tmp/file"
1462 test_expect_success 'setup other remote for remote reference completion' '
1463 git remote add other otherrepo &&
1467 for flag in -d --delete
1469 test_expect_success "__git_complete_remote_or_refspec - push
$flag other
" '
1470 sed -e "s
/Z$
//" >expected <<-EOF &&
1474 words=(git push '$flag' other ma) &&
1475 cword=${#words[@]} cur=${words[cword-1]} &&
1476 __git_complete_remote_or_refspec &&
1479 test_cmp expected out
1482 test_expect_failure "__git_complete_remote_or_refspec
- push other
$flag" '
1483 sed -e "s
/Z$
//" >expected <<-EOF &&
1487 words=(git push other '$flag' ma) &&
1488 cword=${#words[@]} cur=${words[cword-1]} &&
1489 __git_complete_remote_or_refspec &&
1492 test_cmp expected out
1496 test_expect_success 'sourcing the completion script clears cached commands' '
1497 __git_compute_all_commands &&
1498 verbose test -n "$__git_all_commands" &&
1499 . "$GIT_BUILD_DIR/contrib
/completion
/git-completion.bash
" &&
1500 verbose test -z "$__git_all_commands"
1503 test_expect_success !GETTEXT_POISON 'sourcing the completion script clears cached merge strategies' '
1504 __git_compute_merge_strategies &&
1505 verbose test -n "$__git_merge_strategies" &&
1506 . "$GIT_BUILD_DIR/contrib
/completion
/git-completion.bash
" &&
1507 verbose test -z "$__git_merge_strategies"
1510 test_expect_success 'sourcing the completion script clears cached --options' '
1511 __gitcomp_builtin checkout &&
1512 verbose test -n "$__gitcomp_builtin_checkout" &&
1513 __gitcomp_builtin notes_edit &&
1514 verbose test -n "$__gitcomp_builtin_notes_edit" &&
1515 . "$GIT_BUILD_DIR/contrib
/completion
/git-completion.bash
" &&
1516 verbose test -z "$__gitcomp_builtin_checkout" &&
1517 verbose test -z "$__gitcomp_builtin_notes_edit"