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 - trailing space - options' '
404 test_gitcomp "--re" "--dry-run --reuse-message= --reedit-message=
405 --reset-author" <<-EOF
412 test_expect_success
'__gitcomp - trailing space - config keys' '
413 test_gitcomp "br" "branch. branch.autosetupmerge
414 branch.autosetuprebase browser." <<-\EOF
416 branch.autosetupmerge Z
417 branch.autosetuprebase Z
422 test_expect_success
'__gitcomp - option parameter' '
423 test_gitcomp "--strategy=re" "octopus ours recursive resolve subtree" \
430 test_expect_success
'__gitcomp - prefix' '
431 test_gitcomp "branch.me" "remote merge mergeoptions rebase" \
432 "branch.maint." "me" <<-\EOF
434 branch.maint.mergeoptions Z
438 test_expect_success
'__gitcomp - suffix' '
439 test_gitcomp "branch.me" "master maint next pu" "branch." \
446 test_expect_success
'__gitcomp - doesnt fail because of invalid variable name' '
447 __gitcomp "$invalid_variable_name"
450 read -r -d "" refs
<<-\EOF
457 test_expect_success '__gitcomp_nl - trailing space
' '
458 test_gitcomp_nl
"m" "$refs" <<-EOF
464 test_expect_success '__gitcomp_nl
- prefix
' '
465 test_gitcomp_nl
"--fixup=m" "$refs" "--fixup=" "m" <<-EOF
471 test_expect_success '__gitcomp_nl
- suffix
' '
472 test_gitcomp_nl
"branch.ma" "$refs" "branch." "ma" "." <<-\EOF
478 test_expect_success '__gitcomp_nl - no suffix
' '
479 test_gitcomp_nl
"ma" "$refs" "" "ma" "" <<-\EOF
485 test_expect_success '__gitcomp_nl - doesnt fail because of invalid variable name
' '
486 __gitcomp_nl
"$invalid_variable_name"
489 test_expect_success '__git_remotes
- list remotes from
$GIT_DIR/remotes and from config
file' '
490 cat >expect
<<-EOF &&
496 test_when_finished
"rm -rf .git/remotes" &&
497 mkdir
-p .git
/remotes
&&
498 >.git
/remotes
/remote_from_file_1
&&
499 >.git
/remotes
/remote_from_file_2
&&
500 test_when_finished
"git remote remove remote_in_config_1" &&
501 git remote add remote_in_config_1 git
://remote_1
&&
502 test_when_finished
"git remote remove remote_in_config_2" &&
503 git remote add remote_in_config_2 git
://remote_2
&&
505 __git_remotes
>actual
507 test_cmp expect actual
510 test_expect_success '__git_is_configured_remote
' '
511 test_when_finished
"git remote remove remote_1" &&
512 git remote add remote_1 git
://remote_1
&&
513 test_when_finished
"git remote remove remote_2" &&
514 git remote add remote_2 git
://remote_2
&&
516 verbose __git_is_configured_remote remote_2
&&
517 test_must_fail __git_is_configured_remote non-existent
521 test_expect_success 'setup
for ref completion
' '
522 git commit
--allow-empty -m initial
&&
523 git branch matching-branch
&&
524 git tag matching-tag
&&
527 git commit
--allow-empty -m initial
&&
528 git branch
-m master master-in-other
&&
529 git branch branch-in-other
&&
532 git remote add other
"$ROOT/otherrepo/.git" &&
533 git fetch
--no-tags other
&&
534 rm -f .git
/FETCH_HEAD
&&
538 test_expect_success '__git_refs
- simple
' '
539 cat >expected
<<-EOF &&
543 other/branch-in-other
544 other/master-in-other
549 __git_refs
>"$actual"
551 test_cmp expected
"$actual"
554 test_expect_success '__git_refs
- full refs
' '
555 cat >expected
<<-EOF &&
557 refs/heads/matching-branch
558 refs/remotes/other/branch-in-other
559 refs/remotes/other/master-in-other
560 refs/tags/matching-tag
564 __git_refs
>"$actual"
566 test_cmp expected
"$actual"
569 test_expect_success '__git_refs
- repo given on the
command line
' '
570 cat >expected
<<-EOF &&
577 __git_dir
="$ROOT/otherrepo/.git" &&
579 __git_refs
>"$actual"
581 test_cmp expected
"$actual"
584 test_expect_success '__git_refs
- remote on
local file system
' '
585 cat >expected
<<-EOF &&
593 __git_refs otherrepo
>"$actual"
595 test_cmp expected
"$actual"
598 test_expect_success '__git_refs
- remote on
local file system
- full refs
' '
599 cat >expected
<<-EOF &&
600 refs/heads/branch-in-other
601 refs/heads/master-in-other
602 refs/tags/tag-in-other
606 __git_refs otherrepo
>"$actual"
608 test_cmp expected
"$actual"
611 test_expect_success '__git_refs
- configured remote
' '
612 cat >expected
<<-EOF &&
619 __git_refs other
>"$actual"
621 test_cmp expected
"$actual"
624 test_expect_success '__git_refs
- configured remote
- full refs
' '
625 cat >expected
<<-EOF &&
627 refs/heads/branch-in-other
628 refs/heads/master-in-other
629 refs/tags/tag-in-other
633 __git_refs other
>"$actual"
635 test_cmp expected
"$actual"
638 test_expect_success '__git_refs
- configured remote
- repo given on the
command line
' '
639 cat >expected
<<-EOF &&
646 __git_dir
="$ROOT/.git" &&
648 __git_refs other
>"$actual"
650 test_cmp expected
"$actual"
653 test_expect_success '__git_refs
- configured remote
- full refs
- repo given on the
command line
' '
654 cat >expected
<<-EOF &&
656 refs/heads/branch-in-other
657 refs/heads/master-in-other
658 refs/tags/tag-in-other
662 __git_dir
="$ROOT/.git" &&
664 __git_refs other
>"$actual"
666 test_cmp expected
"$actual"
669 test_expect_success '__git_refs
- configured remote
- remote name matches a directory
' '
670 cat >expected
<<-EOF &&
676 test_when_finished
"rm -rf other" &&
679 __git_refs other
>"$actual"
681 test_cmp expected
"$actual"
684 test_expect_success '__git_refs
- URL remote
' '
685 cat >expected
<<-EOF &&
693 __git_refs
"file://$ROOT/otherrepo/.git" >"$actual"
695 test_cmp expected
"$actual"
698 test_expect_success '__git_refs
- URL remote
- full refs
' '
699 cat >expected
<<-EOF &&
701 refs/heads/branch-in-other
702 refs/heads/master-in-other
703 refs/tags/tag-in-other
707 __git_refs
"file://$ROOT/otherrepo/.git" >"$actual"
709 test_cmp expected
"$actual"
712 test_expect_success '__git_refs
- non-existing remote
' '
715 __git_refs non-existing
>"$actual"
717 test_must_be_empty
"$actual"
720 test_expect_success '__git_refs
- non-existing remote
- full refs
' '
723 __git_refs non-existing
>"$actual"
725 test_must_be_empty
"$actual"
728 test_expect_success '__git_refs
- non-existing URL remote
' '
731 __git_refs
"file://$ROOT/non-existing" >"$actual"
733 test_must_be_empty
"$actual"
736 test_expect_success '__git_refs
- non-existing URL remote
- full refs
' '
739 __git_refs
"file://$ROOT/non-existing" >"$actual"
741 test_must_be_empty
"$actual"
744 test_expect_success '__git_refs
- not
in a git repository
' '
746 GIT_CEILING_DIRECTORIES
="$ROOT" &&
747 export GIT_CEILING_DIRECTORIES
&&
750 __git_refs
>"$actual"
752 test_must_be_empty
"$actual"
755 test_expect_success '__git_refs
- unique remote branches
for git checkout DWIMery
' '
756 cat >expected
<<-EOF &&
761 other/branch-in-other
762 other/master-in-other
764 remote/branch-in-remote
770 for remote_ref
in refs
/remotes
/other
/ambiguous \
771 refs
/remotes
/remote
/ambiguous \
772 refs
/remotes
/remote
/branch-in-remote
774 git update-ref
$remote_ref master
&&
775 test_when_finished
"git update-ref -d $remote_ref"
779 __git_refs
"" 1 >"$actual"
781 test_cmp expected
"$actual"
784 test_expect_success '__git_refs
- after
--opt=' '
785 cat >expected
<<-EOF &&
789 other/branch-in-other
790 other/master-in-other
795 __git_refs
"" "" "" "" >"$actual"
797 test_cmp expected
"$actual"
800 test_expect_success '__git_refs
- after
--opt= - full refs
' '
801 cat >expected
<<-EOF &&
803 refs/heads/matching-branch
804 refs/remotes/other/branch-in-other
805 refs/remotes/other/master-in-other
806 refs/tags/matching-tag
810 __git_refs
"" "" "" refs
/ >"$actual"
812 test_cmp expected
"$actual"
815 test_expect_success '__git refs
- exluding refs
' '
816 cat >expected
<<-EOF &&
820 ^other/branch-in-other
821 ^other/master-in-other
826 __git_refs
>"$actual"
828 test_cmp expected
"$actual"
831 test_expect_success '__git refs
- exluding full refs
' '
832 cat >expected
<<-EOF &&
834 ^refs/heads/matching-branch
835 ^refs/remotes/other/branch-in-other
836 ^refs/remotes/other/master-in-other
837 ^refs/tags/matching-tag
841 __git_refs
>"$actual"
843 test_cmp expected
"$actual"
846 test_expect_success 'setup
for filtering matching refs
' '
847 git branch matching
/branch
&&
848 git tag matching
/tag
&&
849 git
-C otherrepo branch matching
/branch-in-other
&&
850 git fetch
--no-tags other
&&
851 rm -f .git
/FETCH_HEAD
854 test_expect_success '__git_refs
- dont filter refs unless told so
' '
855 cat >expected
<<-EOF &&
860 other/branch-in-other
861 other/master-in-other
862 other/matching/branch-in-other
868 __git_refs
>"$actual"
870 test_cmp expected
"$actual"
873 test_expect_success '__git_refs
- only matching refs
' '
874 cat >expected
<<-EOF &&
882 __git_refs
"" "" "" "$cur" >"$actual"
884 test_cmp expected
"$actual"
887 test_expect_success '__git_refs
- only matching refs
- full refs
' '
888 cat >expected
<<-EOF &&
889 refs/heads/matching-branch
890 refs/heads/matching/branch
893 cur
=refs
/heads
/mat
&&
894 __git_refs
"" "" "" "$cur" >"$actual"
896 test_cmp expected
"$actual"
899 test_expect_success '__git_refs
- only matching refs
- remote on
local file system
' '
900 cat >expected
<<-EOF &&
902 matching/branch-in-other
906 __git_refs otherrepo
"" "" "$cur" >"$actual"
908 test_cmp expected
"$actual"
911 test_expect_success '__git_refs
- only matching refs
- configured remote
' '
912 cat >expected
<<-EOF &&
914 matching/branch-in-other
918 __git_refs other
"" "" "$cur" >"$actual"
920 test_cmp expected
"$actual"
923 test_expect_success '__git_refs
- only matching refs
- remote
- full refs
' '
924 cat >expected
<<-EOF &&
925 refs/heads/master-in-other
926 refs/heads/matching/branch-in-other
930 __git_refs other
"" "" "$cur" >"$actual"
932 test_cmp expected
"$actual"
935 test_expect_success '__git_refs
- only matching refs
- checkout DWIMery
' '
936 cat >expected
<<-EOF &&
941 matching/branch-in-other
943 for remote_ref
in refs
/remotes
/other
/ambiguous \
944 refs
/remotes
/remote
/ambiguous \
945 refs
/remotes
/remote
/branch-in-remote
947 git update-ref
$remote_ref master
&&
948 test_when_finished
"git update-ref -d $remote_ref"
952 __git_refs
"" 1 "" "$cur" >"$actual"
954 test_cmp expected
"$actual"
957 test_expect_success 'teardown after filtering matching refs
' '
958 git branch
-d matching
/branch
&&
959 git tag
-d matching
/tag
&&
960 git update-ref
-d refs
/remotes
/other
/matching
/branch-in-other
&&
961 git
-C otherrepo branch
-D matching
/branch-in-other
964 test_expect_success '__git_complete_refs
- simple
' '
965 sed -e "s/Z$//" >expected
<<-EOF &&
969 other/branch-in-other Z
970 other/master-in-other Z
975 __git_complete_refs
&&
978 test_cmp expected out
981 test_expect_success '__git_complete_refs
- matching
' '
982 sed -e "s/Z$//" >expected
<<-EOF &&
988 __git_complete_refs
&&
991 test_cmp expected out
994 test_expect_success '__git_complete_refs
- remote
' '
995 sed -e "s/Z$//" >expected
<<-EOF &&
1002 __git_complete_refs
--remote=other
&&
1005 test_cmp expected out
1008 test_expect_success '__git_complete_refs
- track
' '
1009 sed -e "s/Z$//" >expected
<<-EOF &&
1013 other/branch-in-other Z
1014 other/master-in-other Z
1021 __git_complete_refs
--track &&
1024 test_cmp expected out
1027 test_expect_success '__git_complete_refs
- current word
' '
1028 sed -e "s/Z$//" >expected
<<-EOF &&
1033 cur
="--option=mat" &&
1034 __git_complete_refs
--cur="${cur#*=}" &&
1037 test_cmp expected out
1040 test_expect_success '__git_complete_refs
- prefix
' '
1041 sed -e "s/Z$//" >expected
<<-EOF &&
1042 v1.0..matching-branch Z
1043 v1.0..matching-tag Z
1047 __git_complete_refs
--pfx=v1.0..
--cur=mat
&&
1050 test_cmp expected out
1053 test_expect_success '__git_complete_refs
- suffix
' '
1054 cat >expected
<<-EOF &&
1058 other/branch-in-other.
1059 other/master-in-other.
1064 __git_complete_refs
--sfx=.
&&
1067 test_cmp expected out
1070 test_expect_success '__git_complete_fetch_refspecs
- simple
' '
1071 sed -e "s/Z$//" >expected
<<-EOF &&
1073 branch-in-other:branch-in-other Z
1074 master-in-other:master-in-other Z
1078 __git_complete_fetch_refspecs other
&&
1081 test_cmp expected out
1084 test_expect_success '__git_complete_fetch_refspecs
- matching
' '
1085 sed -e "s/Z$//" >expected
<<-EOF &&
1086 branch-in-other:branch-in-other Z
1090 __git_complete_fetch_refspecs other
"" br
&&
1093 test_cmp expected out
1096 test_expect_success '__git_complete_fetch_refspecs
- prefix
' '
1097 sed -e "s/Z$//" >expected
<<-EOF &&
1099 +branch-in-other:branch-in-other Z
1100 +master-in-other:master-in-other Z
1104 __git_complete_fetch_refspecs other
"+" "" &&
1107 test_cmp expected out
1110 test_expect_success '__git_complete_fetch_refspecs
- fully qualified
' '
1111 sed -e "s/Z$//" >expected
<<-EOF &&
1112 refs/heads/branch-in-other:refs/heads/branch-in-other Z
1113 refs/heads/master-in-other:refs/heads/master-in-other Z
1114 refs/tags/tag-in-other:refs/tags/tag-in-other Z
1118 __git_complete_fetch_refspecs other
"" refs
/ &&
1121 test_cmp expected out
1124 test_expect_success '__git_complete_fetch_refspecs
- fully qualified
& prefix
' '
1125 sed -e "s/Z$//" >expected
<<-EOF &&
1126 +refs/heads/branch-in-other:refs/heads/branch-in-other Z
1127 +refs/heads/master-in-other:refs/heads/master-in-other Z
1128 +refs/tags/tag-in-other:refs/tags/tag-in-other Z
1132 __git_complete_fetch_refspecs other
+ refs
/ &&
1135 test_cmp expected out
1138 test_expect_success 'teardown after ref completion
' '
1139 git branch
-d matching-branch
&&
1140 git tag
-d matching-tag
&&
1141 git remote remove other
1144 test_expect_success '__git_get_config_variables
' '
1145 cat >expect
<<-EOF &&
1149 test_config interesting.name-1 good
&&
1150 test_config interesting.name-2 good
&&
1151 test_config subsection.interesting.name-3 bad
&&
1152 __git_get_config_variables interesting
>actual
&&
1153 test_cmp expect actual
1156 test_expect_success '__git_pretty_aliases
' '
1157 cat >expect
<<-EOF &&
1161 test_config pretty.author
"%an %ae" &&
1162 test_config pretty.
hash %H
&&
1163 __git_pretty_aliases
>actual
&&
1164 test_cmp expect actual
1167 test_expect_success '__git_aliases
' '
1168 cat >expect
<<-EOF &&
1172 test_config
alias.ci commit
&&
1173 test_config
alias.co checkout
&&
1174 __git_aliases
>actual
&&
1175 test_cmp expect actual
1178 test_expect_success 'basic
' '
1179 run_completion
"git " &&
1181 grep -q "^add \$" out
&&
1183 grep -q "^filter-branch \$" out
&&
1185 ! grep -q "^ls-files \$" out
&&
1187 run_completion
"git f" &&
1188 ! grep -q -v "^f" out
1191 test_expect_success 'double dash
"git" itself
' '
1192 test_completion
"git --" <<-\EOF
1205 --no-replace-objects Z
1210 test_expect_success 'double dash "git checkout"' '
1211 test_completion "git checkout --" <<-\
EOF
1224 test_expect_success 'general options' '
1225 test_completion "git --ver" "--version " &&
1226 test_completion "git --hel" "--help " &&
1227 test_completion "git --exe" <<-\EOF &&
1231 test_completion "git --htm" "--html-path " &&
1232 test_completion "git --pag" "--paginate " &&
1233 test_completion "git --no-p" "--no-pager " &&
1234 test_completion "git --git" "--git-dir=" &&
1235 test_completion "git --wor" "--work-tree=" &&
1236 test_completion "git --nam" "--namespace=" &&
1237 test_completion "git --bar" "--bare " &&
1238 test_completion "git --inf" "--info-path " &&
1239 test_completion "git --no-r" "--no-replace-objects "
1242 test_expect_success 'general options plus command' '
1243 test_completion "git --version check" "checkout " &&
1244 test_completion "git --paginate check" "checkout " &&
1245 test_completion "git --git-dir=foo check" "checkout " &&
1246 test_completion "git --bare check" "checkout " &&
1247 test_completion "git --exec-path=foo check" "checkout " &&
1248 test_completion "git --html-path check" "checkout " &&
1249 test_completion "git --no-pager check" "checkout " &&
1250 test_completion "git --work-tree=foo check" "checkout " &&
1251 test_completion "git --namespace=foo check" "checkout " &&
1252 test_completion "git --paginate check" "checkout " &&
1253 test_completion "git --info-path check" "checkout " &&
1254 test_completion "git --no-replace-objects check" "checkout " &&
1255 test_completion "git --git-dir some/path check" "checkout " &&
1256 test_completion "git -c conf.var=value check" "checkout " &&
1257 test_completion "git -C some/path check" "checkout " &&
1258 test_completion "git --work-tree some/path check" "checkout " &&
1259 test_completion "git --namespace name/space check" "checkout "
1262 test_expect_success 'git --help completion' '
1263 test_completion "git --help ad" "add " &&
1264 test_completion "git --help core" "core-tutorial "
1267 test_expect_success 'setup for integration tests' '
1268 echo content >file1 &&
1270 git add file1 file2 &&
1271 git commit -m one &&
1272 git branch mybranch &&
1276 test_expect_success 'checkout completes ref names' '
1277 test_completion "git checkout m" <<-\EOF
1284 test_expect_success 'git -C <path> checkout uses the right repo' '
1285 test_completion "git -C subdir -C subsubdir -C .. -C ../otherrepo checkout b" <<-\EOF
1290 test_expect_success 'show completes all refs' '
1291 test_completion "git show m" <<-\EOF
1298 test_expect_success '<ref>: completes paths' '
1299 test_completion "git show mytag:f" <<-\EOF
1305 test_expect_success 'complete tree filename with spaces' '
1306 echo content >"name with spaces" &&
1307 git add "name with spaces" &&
1308 git commit -m spaces &&
1309 test_completion "git show HEAD:nam" <<-\EOF
1314 test_expect_success 'complete tree filename with metacharacters' '
1315 echo content >"name with \${meta}" &&
1316 git add "name with \${meta}" &&
1317 git commit -m meta &&
1318 test_completion "git show HEAD:nam" <<-\EOF
1324 test_expect_success 'send-email' '
1325 test_completion "git send-email --cov" "--cover-letter " &&
1326 test_completion "git send-email ma" "master "
1329 test_expect_success 'complete files' '
1330 git init tmp && cd tmp &&
1331 test_when_finished "cd .. && rm -rf tmp" &&
1333 echo "expected" > .gitignore &&
1334 echo "out" >> .gitignore &&
1336 git add .gitignore &&
1337 test_completion "git commit " ".gitignore" &&
1339 git commit -m ignore &&
1342 test_completion "git add " "new" &&
1345 git commit -a -m new &&
1346 test_completion "git add " "" &&
1348 git mv new modified &&
1349 echo modify > modified &&
1350 test_completion "git add " "modified" &&
1354 : TODO .gitignore should not be here &&
1355 test_completion "git rm " <<-\EOF &&
1360 test_completion "git clean " "untracked" &&
1362 : TODO .gitignore should not be here &&
1363 test_completion "git mv " <<-\EOF &&
1369 touch dir/file-in-dir &&
1370 git add dir/file-in-dir &&
1371 git commit -m dir &&
1373 mkdir untracked-dir &&
1375 : TODO .gitignore should not be here &&
1376 test_completion "git mv modified " <<-\EOF &&
1384 test_completion "git commit " "modified" &&
1386 : TODO .gitignore should not be here &&
1387 test_completion "git ls-files " <<-\EOF &&
1394 test_completion "git add mom" "momified"
1397 test_expect_success "completion uses <cmd> completion for alias: !sh -c 'git <cmd> ...'" '
1398 test_config alias.co "!sh -c '"'"'git checkout ...'"'"'" &&
1399 test_completion "git co m" <<-\EOF
1406 test_expect_success 'completion uses <cmd> completion for alias: !f () { VAR=val git <cmd> ... }' '
1407 test_config alias.co "!f () { VAR=val git checkout ... ; } f" &&
1408 test_completion "git co m" <<-\EOF
1415 test_expect_success 'completion used <cmd> completion for alias: !f() { : git <cmd> ; ... }' '
1416 test_config alias.co "!f() { : git checkout ; if ... } f" &&
1417 test_completion "git co m" <<-\EOF
1424 test_expect_failure 'complete with tilde expansion' '
1425 git init tmp && cd tmp &&
1426 test_when_finished "cd .. && rm -rf tmp" &&
1430 test_completion "git add ~/tmp/" "~/tmp/file"