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$//' |
sort >expected
89 run_completion
"$1" &&
90 sort out
>out_sorted
&&
91 test_cmp expected out_sorted
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"
405 test_expect_success
'__git_dequote - plain unquoted word' '
406 __git_dequote unquoted-word &&
407 verbose test unquoted-word = "$dequoted_word"
410 # input: b\a\c\k\'\\\"s\l\a\s\h\es
411 # expected: back'\"slashes
412 test_expect_success
'__git_dequote - backslash escaped' '
413 __git_dequote "b\a\c\k\\'\''\\\\\\\"s\l\a\s\h\es" &&
414 verbose test "back'\''\\\"slashes" = "$dequoted_word"
417 # input: sin'gle\' '"quo'ted
418 # expected: single\ "quoted
419 test_expect_success
'__git_dequote - single quoted' '
420 __git_dequote "'"sin'gle\\\\' '\\\"quo'ted"'" &&
421 verbose test '\''single\ "quoted'\'' = "$dequoted_word"
424 # input: dou"ble\\" "\"\quot"ed
425 # expected: double\ "\quoted
426 test_expect_success
'__git_dequote - double quoted' '
427 __git_dequote '\''dou"ble\\" "\"\quot"ed'\'' &&
428 verbose test '\''double\ "\quoted'\'' = "$dequoted_word"
431 # input: 'open single quote
432 test_expect_success
'__git_dequote - open single quote' '
433 __git_dequote "'\''open single quote" &&
434 verbose test "open single quote" = "$dequoted_word"
437 # input: "open double quote
438 test_expect_success
'__git_dequote - open double quote' '
439 __git_dequote "\"open double quote" &&
440 verbose test "open double quote" = "$dequoted_word"
444 test_expect_success
'__gitcomp_direct - puts everything into COMPREPLY as-is' '
445 sed -e "s/Z$//g" >expected <<-EOF &&
446 with-trailing-space Z
447 without-trailing-spaceZ
450 $invalid_variable_name Z
453 cur=should_be_ignored &&
454 __gitcomp_direct "$(cat expected)" &&
457 test_cmp expected out
460 test_expect_success
'__gitcomp - trailing space - options' '
461 test_gitcomp "--re" "--dry-run --reuse-message= --reedit-message=
462 --reset-author" <<-EOF
469 test_expect_success
'__gitcomp - trailing space - config keys' '
470 test_gitcomp "br" "branch. branch.autosetupmerge
471 branch.autosetuprebase browser." <<-\EOF
473 branch.autosetupmerge Z
474 branch.autosetuprebase Z
479 test_expect_success
'__gitcomp - option parameter' '
480 test_gitcomp "--strategy=re" "octopus ours recursive resolve subtree" \
487 test_expect_success
'__gitcomp - prefix' '
488 test_gitcomp "branch.me" "remote merge mergeoptions rebase" \
489 "branch.maint." "me" <<-\EOF
491 branch.maint.mergeoptions Z
495 test_expect_success
'__gitcomp - suffix' '
496 test_gitcomp "branch.me" "master maint next pu" "branch." \
503 test_expect_success
'__gitcomp - doesnt fail because of invalid variable name' '
504 __gitcomp "$invalid_variable_name"
507 read -r -d "" refs
<<-\EOF
514 test_expect_success '__gitcomp_nl - trailing space
' '
515 test_gitcomp_nl
"m" "$refs" <<-EOF
521 test_expect_success '__gitcomp_nl
- prefix
' '
522 test_gitcomp_nl
"--fixup=m" "$refs" "--fixup=" "m" <<-EOF
528 test_expect_success '__gitcomp_nl
- suffix
' '
529 test_gitcomp_nl
"branch.ma" "$refs" "branch." "ma" "." <<-\EOF
535 test_expect_success '__gitcomp_nl - no suffix
' '
536 test_gitcomp_nl
"ma" "$refs" "" "ma" "" <<-\EOF
542 test_expect_success '__gitcomp_nl - doesnt fail because of invalid variable name
' '
543 __gitcomp_nl
"$invalid_variable_name"
546 test_expect_success '__git_remotes
- list remotes from
$GIT_DIR/remotes and from config
file' '
547 cat >expect
<<-EOF &&
553 test_when_finished
"rm -rf .git/remotes" &&
554 mkdir
-p .git
/remotes
&&
555 >.git
/remotes
/remote_from_file_1
&&
556 >.git
/remotes
/remote_from_file_2
&&
557 test_when_finished
"git remote remove remote_in_config_1" &&
558 git remote add remote_in_config_1 git
://remote_1
&&
559 test_when_finished
"git remote remove remote_in_config_2" &&
560 git remote add remote_in_config_2 git
://remote_2
&&
562 __git_remotes
>actual
564 test_cmp expect actual
567 test_expect_success '__git_is_configured_remote
' '
568 test_when_finished
"git remote remove remote_1" &&
569 git remote add remote_1 git
://remote_1
&&
570 test_when_finished
"git remote remove remote_2" &&
571 git remote add remote_2 git
://remote_2
&&
573 verbose __git_is_configured_remote remote_2
&&
574 test_must_fail __git_is_configured_remote non-existent
578 test_expect_success 'setup
for ref completion
' '
579 git commit
--allow-empty -m initial
&&
580 git branch matching-branch
&&
581 git tag matching-tag
&&
584 git commit
--allow-empty -m initial
&&
585 git branch
-m master master-in-other
&&
586 git branch branch-in-other
&&
589 git remote add other
"$ROOT/otherrepo/.git" &&
590 git fetch
--no-tags other
&&
591 rm -f .git
/FETCH_HEAD
&&
595 test_expect_success '__git_refs
- simple
' '
596 cat >expected
<<-EOF &&
600 other/branch-in-other
601 other/master-in-other
606 __git_refs
>"$actual"
608 test_cmp expected
"$actual"
611 test_expect_success '__git_refs
- full refs
' '
612 cat >expected
<<-EOF &&
614 refs/heads/matching-branch
615 refs/remotes/other/branch-in-other
616 refs/remotes/other/master-in-other
617 refs/tags/matching-tag
621 __git_refs
>"$actual"
623 test_cmp expected
"$actual"
626 test_expect_success '__git_refs
- repo given on the
command line
' '
627 cat >expected
<<-EOF &&
634 __git_dir
="$ROOT/otherrepo/.git" &&
636 __git_refs
>"$actual"
638 test_cmp expected
"$actual"
641 test_expect_success '__git_refs
- remote on
local file system
' '
642 cat >expected
<<-EOF &&
650 __git_refs otherrepo
>"$actual"
652 test_cmp expected
"$actual"
655 test_expect_success '__git_refs
- remote on
local file system
- full refs
' '
656 cat >expected
<<-EOF &&
657 refs/heads/branch-in-other
658 refs/heads/master-in-other
659 refs/tags/tag-in-other
663 __git_refs otherrepo
>"$actual"
665 test_cmp expected
"$actual"
668 test_expect_success '__git_refs
- configured remote
' '
669 cat >expected
<<-EOF &&
676 __git_refs other
>"$actual"
678 test_cmp expected
"$actual"
681 test_expect_success '__git_refs
- configured remote
- full refs
' '
682 cat >expected
<<-EOF &&
684 refs/heads/branch-in-other
685 refs/heads/master-in-other
686 refs/tags/tag-in-other
690 __git_refs other
>"$actual"
692 test_cmp expected
"$actual"
695 test_expect_success '__git_refs
- configured remote
- repo given on the
command line
' '
696 cat >expected
<<-EOF &&
703 __git_dir
="$ROOT/.git" &&
705 __git_refs other
>"$actual"
707 test_cmp expected
"$actual"
710 test_expect_success '__git_refs
- configured remote
- full refs
- repo given on the
command line
' '
711 cat >expected
<<-EOF &&
713 refs/heads/branch-in-other
714 refs/heads/master-in-other
715 refs/tags/tag-in-other
719 __git_dir
="$ROOT/.git" &&
721 __git_refs other
>"$actual"
723 test_cmp expected
"$actual"
726 test_expect_success '__git_refs
- configured remote
- remote name matches a directory
' '
727 cat >expected
<<-EOF &&
733 test_when_finished
"rm -rf other" &&
736 __git_refs other
>"$actual"
738 test_cmp expected
"$actual"
741 test_expect_success '__git_refs
- URL remote
' '
742 cat >expected
<<-EOF &&
750 __git_refs
"file://$ROOT/otherrepo/.git" >"$actual"
752 test_cmp expected
"$actual"
755 test_expect_success '__git_refs
- URL remote
- full refs
' '
756 cat >expected
<<-EOF &&
758 refs/heads/branch-in-other
759 refs/heads/master-in-other
760 refs/tags/tag-in-other
764 __git_refs
"file://$ROOT/otherrepo/.git" >"$actual"
766 test_cmp expected
"$actual"
769 test_expect_success '__git_refs
- non-existing remote
' '
772 __git_refs non-existing
>"$actual"
774 test_must_be_empty
"$actual"
777 test_expect_success '__git_refs
- non-existing remote
- full refs
' '
780 __git_refs non-existing
>"$actual"
782 test_must_be_empty
"$actual"
785 test_expect_success '__git_refs
- non-existing URL remote
' '
788 __git_refs
"file://$ROOT/non-existing" >"$actual"
790 test_must_be_empty
"$actual"
793 test_expect_success '__git_refs
- non-existing URL remote
- full refs
' '
796 __git_refs
"file://$ROOT/non-existing" >"$actual"
798 test_must_be_empty
"$actual"
801 test_expect_success '__git_refs
- not
in a git repository
' '
803 GIT_CEILING_DIRECTORIES
="$ROOT" &&
804 export GIT_CEILING_DIRECTORIES
&&
807 __git_refs
>"$actual"
809 test_must_be_empty
"$actual"
812 test_expect_success '__git_refs
- unique remote branches
for git checkout DWIMery
' '
813 cat >expected
<<-EOF &&
818 other/branch-in-other
819 other/master-in-other
821 remote/branch-in-remote
827 for remote_ref
in refs
/remotes
/other
/ambiguous \
828 refs
/remotes
/remote
/ambiguous \
829 refs
/remotes
/remote
/branch-in-remote
831 git update-ref
$remote_ref master
&&
832 test_when_finished
"git update-ref -d $remote_ref"
836 __git_refs
"" 1 >"$actual"
838 test_cmp expected
"$actual"
841 test_expect_success '__git_refs
- after
--opt=' '
842 cat >expected
<<-EOF &&
846 other/branch-in-other
847 other/master-in-other
852 __git_refs
"" "" "" "" >"$actual"
854 test_cmp expected
"$actual"
857 test_expect_success '__git_refs
- after
--opt= - full refs
' '
858 cat >expected
<<-EOF &&
860 refs/heads/matching-branch
861 refs/remotes/other/branch-in-other
862 refs/remotes/other/master-in-other
863 refs/tags/matching-tag
867 __git_refs
"" "" "" refs
/ >"$actual"
869 test_cmp expected
"$actual"
872 test_expect_success '__git refs
- exluding refs
' '
873 cat >expected
<<-EOF &&
877 ^other/branch-in-other
878 ^other/master-in-other
883 __git_refs
>"$actual"
885 test_cmp expected
"$actual"
888 test_expect_success '__git refs
- exluding full refs
' '
889 cat >expected
<<-EOF &&
891 ^refs/heads/matching-branch
892 ^refs/remotes/other/branch-in-other
893 ^refs/remotes/other/master-in-other
894 ^refs/tags/matching-tag
898 __git_refs
>"$actual"
900 test_cmp expected
"$actual"
903 test_expect_success 'setup
for filtering matching refs
' '
904 git branch matching
/branch
&&
905 git tag matching
/tag
&&
906 git
-C otherrepo branch matching
/branch-in-other
&&
907 git fetch
--no-tags other
&&
908 rm -f .git
/FETCH_HEAD
911 test_expect_success '__git_refs
- dont filter refs unless told so
' '
912 cat >expected
<<-EOF &&
917 other/branch-in-other
918 other/master-in-other
919 other/matching/branch-in-other
925 __git_refs
>"$actual"
927 test_cmp expected
"$actual"
930 test_expect_success '__git_refs
- only matching refs
' '
931 cat >expected
<<-EOF &&
939 __git_refs
"" "" "" "$cur" >"$actual"
941 test_cmp expected
"$actual"
944 test_expect_success '__git_refs
- only matching refs
- full refs
' '
945 cat >expected
<<-EOF &&
946 refs/heads/matching-branch
947 refs/heads/matching/branch
950 cur
=refs
/heads
/mat
&&
951 __git_refs
"" "" "" "$cur" >"$actual"
953 test_cmp expected
"$actual"
956 test_expect_success '__git_refs
- only matching refs
- remote on
local file system
' '
957 cat >expected
<<-EOF &&
959 matching/branch-in-other
963 __git_refs otherrepo
"" "" "$cur" >"$actual"
965 test_cmp expected
"$actual"
968 test_expect_success '__git_refs
- only matching refs
- configured remote
' '
969 cat >expected
<<-EOF &&
971 matching/branch-in-other
975 __git_refs other
"" "" "$cur" >"$actual"
977 test_cmp expected
"$actual"
980 test_expect_success '__git_refs
- only matching refs
- remote
- full refs
' '
981 cat >expected
<<-EOF &&
982 refs/heads/master-in-other
983 refs/heads/matching/branch-in-other
987 __git_refs other
"" "" "$cur" >"$actual"
989 test_cmp expected
"$actual"
992 test_expect_success '__git_refs
- only matching refs
- checkout DWIMery
' '
993 cat >expected
<<-EOF &&
998 matching/branch-in-other
1000 for remote_ref
in refs
/remotes
/other
/ambiguous \
1001 refs
/remotes
/remote
/ambiguous \
1002 refs
/remotes
/remote
/branch-in-remote
1004 git update-ref
$remote_ref master
&&
1005 test_when_finished
"git update-ref -d $remote_ref"
1009 __git_refs
"" 1 "" "$cur" >"$actual"
1011 test_cmp expected
"$actual"
1014 test_expect_success 'teardown after filtering matching refs
' '
1015 git branch
-d matching
/branch
&&
1016 git tag
-d matching
/tag
&&
1017 git update-ref
-d refs
/remotes
/other
/matching
/branch-in-other
&&
1018 git
-C otherrepo branch
-D matching
/branch-in-other
1021 test_expect_success '__git_refs
- for-each-ref format specifiers
in prefix
' '
1022 cat >expected
<<-EOF &&
1023 evil-%%-%42-%(refname)..master
1026 cur
="evil-%%-%42-%(refname)..mas" &&
1027 __git_refs
"" "" "evil-%%-%42-%(refname).." mas
>"$actual"
1029 test_cmp expected
"$actual"
1032 test_expect_success '__git_complete_refs
- simple
' '
1033 sed -e "s/Z$//" >expected
<<-EOF &&
1037 other/branch-in-other Z
1038 other/master-in-other Z
1043 __git_complete_refs
&&
1046 test_cmp expected out
1049 test_expect_success '__git_complete_refs
- matching
' '
1050 sed -e "s/Z$//" >expected
<<-EOF &&
1056 __git_complete_refs
&&
1059 test_cmp expected out
1062 test_expect_success '__git_complete_refs
- remote
' '
1063 sed -e "s/Z$//" >expected
<<-EOF &&
1070 __git_complete_refs
--remote=other
&&
1073 test_cmp expected out
1076 test_expect_success '__git_complete_refs
- track
' '
1077 sed -e "s/Z$//" >expected
<<-EOF &&
1081 other/branch-in-other Z
1082 other/master-in-other Z
1089 __git_complete_refs
--track &&
1092 test_cmp expected out
1095 test_expect_success '__git_complete_refs
- current word
' '
1096 sed -e "s/Z$//" >expected
<<-EOF &&
1101 cur
="--option=mat" &&
1102 __git_complete_refs
--cur="${cur#*=}" &&
1105 test_cmp expected out
1108 test_expect_success '__git_complete_refs
- prefix
' '
1109 sed -e "s/Z$//" >expected
<<-EOF &&
1110 v1.0..matching-branch Z
1111 v1.0..matching-tag Z
1115 __git_complete_refs
--pfx=v1.0..
--cur=mat
&&
1118 test_cmp expected out
1121 test_expect_success '__git_complete_refs
- suffix
' '
1122 cat >expected
<<-EOF &&
1126 other/branch-in-other.
1127 other/master-in-other.
1132 __git_complete_refs
--sfx=.
&&
1135 test_cmp expected out
1138 test_expect_success '__git_complete_fetch_refspecs
- simple
' '
1139 sed -e "s/Z$//" >expected
<<-EOF &&
1141 branch-in-other:branch-in-other Z
1142 master-in-other:master-in-other Z
1146 __git_complete_fetch_refspecs other
&&
1149 test_cmp expected out
1152 test_expect_success '__git_complete_fetch_refspecs
- matching
' '
1153 sed -e "s/Z$//" >expected
<<-EOF &&
1154 branch-in-other:branch-in-other Z
1158 __git_complete_fetch_refspecs other
"" br
&&
1161 test_cmp expected out
1164 test_expect_success '__git_complete_fetch_refspecs
- prefix
' '
1165 sed -e "s/Z$//" >expected
<<-EOF &&
1167 +branch-in-other:branch-in-other Z
1168 +master-in-other:master-in-other Z
1172 __git_complete_fetch_refspecs other
"+" "" &&
1175 test_cmp expected out
1178 test_expect_success '__git_complete_fetch_refspecs
- fully qualified
' '
1179 sed -e "s/Z$//" >expected
<<-EOF &&
1180 refs/heads/branch-in-other:refs/heads/branch-in-other Z
1181 refs/heads/master-in-other:refs/heads/master-in-other Z
1182 refs/tags/tag-in-other:refs/tags/tag-in-other Z
1186 __git_complete_fetch_refspecs other
"" refs
/ &&
1189 test_cmp expected out
1192 test_expect_success '__git_complete_fetch_refspecs
- fully qualified
& prefix
' '
1193 sed -e "s/Z$//" >expected
<<-EOF &&
1194 +refs/heads/branch-in-other:refs/heads/branch-in-other Z
1195 +refs/heads/master-in-other:refs/heads/master-in-other Z
1196 +refs/tags/tag-in-other:refs/tags/tag-in-other Z
1200 __git_complete_fetch_refspecs other
+ refs
/ &&
1203 test_cmp expected out
1206 test_expect_success 'teardown after ref completion
' '
1207 git branch
-d matching-branch
&&
1208 git tag
-d matching-tag
&&
1209 git remote remove other
1212 test_expect_success '__git_get_config_variables
' '
1213 cat >expect
<<-EOF &&
1217 test_config interesting.name-1 good
&&
1218 test_config interesting.name-2 good
&&
1219 test_config subsection.interesting.name-3 bad
&&
1220 __git_get_config_variables interesting
>actual
&&
1221 test_cmp expect actual
1224 test_expect_success '__git_pretty_aliases
' '
1225 cat >expect
<<-EOF &&
1229 test_config pretty.author
"%an %ae" &&
1230 test_config pretty.
hash %H
&&
1231 __git_pretty_aliases
>actual
&&
1232 test_cmp expect actual
1235 test_expect_success '__git_aliases
' '
1236 cat >expect
<<-EOF &&
1240 test_config
alias.ci commit
&&
1241 test_config
alias.co checkout
&&
1242 __git_aliases
>actual
&&
1243 test_cmp expect actual
1246 test_expect_success 'basic
' '
1247 run_completion
"git " &&
1249 grep -q "^add \$" out
&&
1251 grep -q "^filter-branch \$" out
&&
1253 ! grep -q "^ls-files \$" out
&&
1255 run_completion
"git f" &&
1256 ! grep -q -v "^f" out
1259 test_expect_success 'double dash
"git" itself
' '
1260 test_completion
"git --" <<-\EOF
1273 --no-replace-objects Z
1278 test_expect_success 'double dash "git checkout"' '
1279 test_completion "git checkout --" <<-\
EOF
1289 --ignore-skip-worktree-bits Z
1290 --ignore-other-worktrees Z
1291 --recurse-submodules Z
1294 --no-recurse-submodules Z
1298 test_expect_success 'general options' '
1299 test_completion "git --ver" "--version " &&
1300 test_completion "git --hel" "--help " &&
1301 test_completion "git --exe" <<-\EOF &&
1305 test_completion "git --htm" "--html-path " &&
1306 test_completion "git --pag" "--paginate " &&
1307 test_completion "git --no-p" "--no-pager " &&
1308 test_completion "git --git" "--git-dir=" &&
1309 test_completion "git --wor" "--work-tree=" &&
1310 test_completion "git --nam" "--namespace=" &&
1311 test_completion "git --bar" "--bare " &&
1312 test_completion "git --inf" "--info-path " &&
1313 test_completion "git --no-r" "--no-replace-objects "
1316 test_expect_success 'general options plus command' '
1317 test_completion "git --version check" "checkout " &&
1318 test_completion "git --paginate check" "checkout " &&
1319 test_completion "git --git-dir=foo check" "checkout " &&
1320 test_completion "git --bare check" "checkout " &&
1321 test_completion "git --exec-path=foo check" "checkout " &&
1322 test_completion "git --html-path check" "checkout " &&
1323 test_completion "git --no-pager check" "checkout " &&
1324 test_completion "git --work-tree=foo check" "checkout " &&
1325 test_completion "git --namespace=foo check" "checkout " &&
1326 test_completion "git --paginate check" "checkout " &&
1327 test_completion "git --info-path check" "checkout " &&
1328 test_completion "git --no-replace-objects check" "checkout " &&
1329 test_completion "git --git-dir some/path check" "checkout " &&
1330 test_completion "git -c conf.var=value check" "checkout " &&
1331 test_completion "git -C some/path check" "checkout " &&
1332 test_completion "git --work-tree some/path check" "checkout " &&
1333 test_completion "git --namespace name/space check" "checkout "
1336 test_expect_success 'git --help completion' '
1337 test_completion "git --help ad" "add " &&
1338 test_completion "git --help core" "core-tutorial "
1341 test_expect_success 'setup for integration tests' '
1342 echo content >file1 &&
1344 git add file1 file2 &&
1345 git commit -m one &&
1346 git branch mybranch &&
1350 test_expect_success 'checkout completes ref names' '
1351 test_completion "git checkout m" <<-\EOF
1358 test_expect_success 'git -C <path> checkout uses the right repo' '
1359 test_completion "git -C subdir -C subsubdir -C .. -C ../otherrepo checkout b" <<-\EOF
1364 test_expect_success 'show completes all refs' '
1365 test_completion "git show m" <<-\EOF
1372 test_expect_success '<ref>: completes paths' '
1373 test_completion "git show mytag:f" <<-\EOF
1379 test_expect_success 'complete tree filename with spaces' '
1380 echo content >"name with spaces" &&
1381 git add "name with spaces" &&
1382 git commit -m spaces &&
1383 test_completion "git show HEAD:nam" <<-\EOF
1388 test_expect_success 'complete tree filename with metacharacters' '
1389 echo content >"name with \${meta}" &&
1390 git add "name with \${meta}" &&
1391 git commit -m meta &&
1392 test_completion "git show HEAD:nam" <<-\EOF
1398 test_expect_success 'send-email' '
1399 test_completion "git send-email --cov" "--cover-letter " &&
1400 test_completion "git send-email ma" "master "
1403 test_expect_success 'complete files' '
1404 git init tmp && cd tmp &&
1405 test_when_finished "cd .. && rm -rf tmp" &&
1407 echo "expected" > .gitignore &&
1408 echo "out" >> .gitignore &&
1409 echo "out_sorted" >> .gitignore &&
1411 git add .gitignore &&
1412 test_completion "git commit " ".gitignore" &&
1414 git commit -m ignore &&
1417 test_completion "git add " "new" &&
1420 git commit -a -m new &&
1421 test_completion "git add " "" &&
1423 git mv new modified &&
1424 echo modify > modified &&
1425 test_completion "git add " "modified" &&
1429 : TODO .gitignore should not be here &&
1430 test_completion "git rm " <<-\EOF &&
1435 test_completion "git clean " "untracked" &&
1437 : TODO .gitignore should not be here &&
1438 test_completion "git mv " <<-\EOF &&
1444 touch dir/file-in-dir &&
1445 git add dir/file-in-dir &&
1446 git commit -m dir &&
1448 mkdir untracked-dir &&
1450 : TODO .gitignore should not be here &&
1451 test_completion "git mv modified " <<-\EOF &&
1459 test_completion "git commit " "modified" &&
1461 : TODO .gitignore should not be here &&
1462 test_completion "git ls-files " <<-\EOF &&
1469 test_completion "git add mom" "momified"
1472 # The next tests only care about how the completion script deals with
1473 # unusual characters in path names. By defining a custom completion
1474 # function to list untracked files they won't be influenced by future
1475 # changes of the completion functions of real git commands, and we
1476 # don't have to bother with adding files to the index in these tests.
1477 _git_test_path_comp ()
1479 __git_complete_index_file --others
1482 test_expect_success 'complete files - escaped characters on cmdline
' '
1483 test_when_finished
"rm -rf \"New|Dir\"" &&
1485 >"New|Dir/New&File.c" &&
1487 test_completion
"git test-path-comp N" \
1488 "New|Dir" && # Bash will turn this into "New\|Dir/"
1489 test_completion
"git test-path-comp New\\|D" \
1491 test_completion
"git test-path-comp New\\|Dir/N" \
1492 "New|Dir/New&File.c" && # Bash will turn this into
1493 # "New\|Dir/New\&File.c "
1494 test_completion
"git test-path-comp New\\|Dir/New\\&F" \
1495 "New|Dir/New&File.c"
1498 test_expect_success 'complete files
- quoted characters on cmdline
' '
1499 test_when_finished
"rm -r \"New(Dir\"" &&
1501 >"New(Dir/New)File.c" &&
1503 # Testing with an opening but without a corresponding closing
1504 # double quote is important.
1505 test_completion
"git test-path-comp \"New(D" "New(Dir" &&
1506 test_completion
"git test-path-comp \"New(Dir/New)F" \
1507 "New(Dir/New)File.c"
1510 test_expect_success 'complete files
- UTF-8
in ls-files output
' '
1511 test_when_finished
"rm -r árvíztűrő" &&
1513 >"árvíztűrő/Сайн яваарай" &&
1515 test_completion
"git test-path-comp á" "árvíztűrő" &&
1516 test_completion
"git test-path-comp árvíztűrő/С" \
1517 "árvíztűrő/Сайн яваарай"
1520 # Testing with a path containing a backslash is important.
1521 if test_have_prereq !MINGW &&
1522 mkdir 'New\Dir
' 2>/dev/null &&
1523 touch 'New\Dir
/New
"File.c' 2>/dev/null
1525 test_set_prereq FUNNYNAMES_BS_DQ
1527 say "Your filesystem does not allow
\\ and
\" in filenames.
"
1530 test_expect_success FUNNYNAMES_BS_DQ \
1531 'complete files - C-style escapes in ls-files output' '
1532 test_when_finished "rm -r \"New
\\\\Dir
\"" &&
1534 test_completion "git test-path-comp N
" "New
\\Dir
" &&
1535 test_completion "git test-path-comp New
\\\\D
" "New
\\Dir
" &&
1536 test_completion "git test-path-comp New
\\\\Dir
/N
" \
1537 "New
\\Dir
/New
\"File.c
" &&
1538 test_completion "git test-path-comp New
\\\\Dir
/New
\\\"F
" \
1539 "New
\\Dir
/New
\"File.c
"
1542 if test_have_prereq !MINGW &&
1543 mkdir $'New\034Special\035Dir' 2>/dev/null &&
1544 touch $'New\034Special\035Dir/New\036Special\037File' 2>/dev/null
1546 test_set_prereq FUNNYNAMES_SEPARATORS
1548 say 'Your filesystem does not allow special separator characters (FS, GS, RS, US) in filenames.'
1549 rm -rf $'New\034Special\035Dir'
1551 test_expect_success FUNNYNAMES_SEPARATORS \
1552 'complete files - \nnn-escaped control characters in ls-files output' '
1553 test_when_finished "rm -r '$'New
\034Special
\035Dir
''" &&
1555 # Note: these will be literal separator characters on the cmdline.
1556 test_completion "git test-path-comp N
" "'$'New
\034Special
\035Dir
''" &&
1557 test_completion "git test-path-comp
'$'New
\034S
''" \
1558 "'$'New
\034Special
\035Dir
''" &&
1559 test_completion "git test-path-comp
'$'New
\034Special
\035Dir
/''" \
1560 "'$'New
\034Special
\035Dir
/New
\036Special
\037File
''" &&
1561 test_completion "git test-path-comp
'$'New
\034Special
\035Dir
/New
\036S
''" \
1562 "'$'New
\034Special
\035Dir
/New
\036Special
\037File
''"
1565 test_expect_success FUNNYNAMES_BS_DQ \
1566 'complete files - removing repeated quoted path components' '
1567 test_when_finished rm -rf NewDir &&
1568 mkdir NewDir && # A dirname which in itself would not be quoted ...
1570 >NewDir/1\"file && # ... but here the file makes the dirname quoted ...
1572 >NewDir/3\"file && # ... and here, too.
1574 # Still, we should only list it once.
1575 test_completion "git test-path-comp New
" "NewDir
"
1579 test_expect_success "completion uses
<cmd
> completion
for alias: !sh
-c 'git <cmd> ...'" '
1580 test_config alias.co "!sh
-c '"'"'git checkout ...'"'"'" &&
1581 test_completion "git co m
" <<-\EOF
1588 test_expect_success 'completion uses <cmd> completion for alias: !f () { VAR=val git <cmd> ... }' '
1589 test_config alias.co "!f
() { VAR
=val git checkout ...
; } f
" &&
1590 test_completion "git co m
" <<-\EOF
1597 test_expect_success 'completion used <cmd> completion for alias: !f() { : git <cmd> ; ... }' '
1598 test_config alias.co "!f
() { : git checkout
; if ...
} f
" &&
1599 test_completion "git co m
" <<-\EOF
1606 test_expect_success 'completion without explicit _git_xxx function' '
1607 test_completion "git version
--" <<-\EOF
1612 test_expect_failure 'complete with tilde expansion' '
1613 git init tmp && cd tmp &&
1614 test_when_finished "cd ..
&& rm -rf tmp
" &&
1618 test_completion "git add ~
/tmp
/" "~
/tmp
/file"
1621 test_expect_success 'setup other remote for remote reference completion' '
1622 git remote add other otherrepo &&
1626 for flag in -d --delete
1628 test_expect_success "__git_complete_remote_or_refspec
- push
$flag other
" '
1629 sed -e "s
/Z$
//" >expected <<-EOF &&
1633 words=(git push '$flag' other ma) &&
1634 cword=${#words[@]} cur=${words[cword-1]} &&
1635 __git_complete_remote_or_refspec &&
1638 test_cmp expected out
1641 test_expect_failure "__git_complete_remote_or_refspec
- push other
$flag" '
1642 sed -e "s
/Z$
//" >expected <<-EOF &&
1646 words=(git push other '$flag' ma) &&
1647 cword=${#words[@]} cur=${words[cword-1]} &&
1648 __git_complete_remote_or_refspec &&
1651 test_cmp expected out
1655 test_expect_success 'sourcing the completion script clears cached commands' '
1656 __git_compute_all_commands &&
1657 verbose test -n "$__git_all_commands" &&
1658 . "$GIT_BUILD_DIR/contrib
/completion
/git-completion.bash
" &&
1659 verbose test -z "$__git_all_commands"
1662 test_expect_success 'sourcing the completion script clears cached porcelain commands' '
1663 __git_compute_porcelain_commands &&
1664 verbose test -n "$__git_porcelain_commands" &&
1665 . "$GIT_BUILD_DIR/contrib
/completion
/git-completion.bash
" &&
1666 verbose test -z "$__git_porcelain_commands"
1669 test_expect_success !GETTEXT_POISON 'sourcing the completion script clears cached merge strategies' '
1670 __git_compute_merge_strategies &&
1671 verbose test -n "$__git_merge_strategies" &&
1672 . "$GIT_BUILD_DIR/contrib
/completion
/git-completion.bash
" &&
1673 verbose test -z "$__git_merge_strategies"
1676 test_expect_success 'sourcing the completion script clears cached --options' '
1677 __gitcomp_builtin checkout &&
1678 verbose test -n "$__gitcomp_builtin_checkout" &&
1679 __gitcomp_builtin notes_edit &&
1680 verbose test -n "$__gitcomp_builtin_notes_edit" &&
1681 . "$GIT_BUILD_DIR/contrib
/completion
/git-completion.bash
" &&
1682 verbose test -z "$__gitcomp_builtin_checkout" &&
1683 verbose test -z "$__gitcomp_builtin_notes_edit"