3 # Copyright (c) 2012-2020 Felipe Contreras
6 test_description
='test bash completion'
8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=master
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
19 # Be careful when updating these lists:
21 # (1) The build tree may have build artifact from different branch, or
22 # the user's $PATH may have a random executable that may begin
23 # with "git-check" that are not part of the subcommands this build
24 # will ship, e.g. "check-ignore". The tests for completion for
25 # subcommand names tests how "check" is expanded; we limit the
26 # possible candidates to "checkout" and "check-attr" to make sure
27 # "check-attr", which is known by the filter function as a
28 # subcommand to be thrown out, while excluding other random files
29 # that happen to begin with "check" to avoid letting them get in
32 # (2) A test makes sure that common subcommands are included in the
33 # completion for "git <TAB>", and a plumbing is excluded. "add",
34 # "rebase" and "ls-files" are listed for this.
36 GIT_TESTING_ALL_COMMAND_LIST
='add checkout check-attr rebase ls-files'
37 GIT_TESTING_PORCELAIN_COMMAND_LIST
='add checkout rebase'
39 .
"$GIT_BUILD_DIR/contrib/completion/git-completion.bash"
41 # We don't need this function to actually join words or do anything special.
42 # Also, it's cleaner to avoid touching bash's internal completion variables.
43 # So let's override it with a minimal version for testing purposes.
44 _get_comp_words_by_ref
()
46 while [ $# -gt 0 ]; do
52 prev
=${_words[_cword-1]}
55 words
=("${_words[@]}")
68 echo "${COMPREPLY[*]}" > out
73 local -a COMPREPLY _words
76 test "${1: -1}" = ' ' && _words
[${#_words[@]}+1]=''
77 (( _cword
= ${#_words[@]} - 1 ))
78 __git_wrap__git_main
&& print_comp
81 # Test high-level completion
83 # 1: typed text so far (cur)
84 # 2: expected completion
89 printf '%s\n' "$2" >expected
91 sed -e 's/Z$//' |
sort >expected
93 run_completion
"$1" &&
94 sort out
>out_sorted
&&
95 test_cmp expected out_sorted
99 # The first argument is the typed text so far (cur); the rest are
100 # passed to __gitcomp. Expected output comes is read from the
101 # standard input, like test_completion().
104 local -a COMPREPLY
&&
105 sed -e 's/Z$//' >expected
&&
110 test_cmp expected out
115 # 1: current word (cur)
116 # -: the rest are passed to __gitcomp_nl
119 local -a COMPREPLY
&&
120 sed -e 's/Z$//' >expected
&&
125 test_cmp expected out
128 invalid_variable_name
='${foo.bar}'
130 actual
="$TRASH_DIRECTORY/actual"
132 if test_have_prereq MINGW
139 test_expect_success
'setup for __git_find_repo_path/__gitdir tests' '
140 mkdir -p subdir/subsubdir &&
142 git init -b main otherrepo
145 test_expect_success
'__git_find_repo_path - from command line (through $__git_dir)' '
146 echo "$ROOT/otherrepo/.git" >expected &&
148 __git_dir="$ROOT/otherrepo/.git" &&
149 __git_find_repo_path &&
150 echo "$__git_repo_path" >"$actual"
152 test_cmp expected "$actual"
155 test_expect_success
'__git_find_repo_path - .git directory in cwd' '
156 echo ".git" >expected &&
158 __git_find_repo_path &&
159 echo "$__git_repo_path" >"$actual"
161 test_cmp expected "$actual"
164 test_expect_success
'__git_find_repo_path - .git directory in parent' '
165 echo "$ROOT/.git" >expected &&
167 cd subdir/subsubdir &&
168 __git_find_repo_path &&
169 echo "$__git_repo_path" >"$actual"
171 test_cmp expected "$actual"
174 test_expect_success
'__git_find_repo_path - cwd is a .git directory' '
175 echo "." >expected &&
178 __git_find_repo_path &&
179 echo "$__git_repo_path" >"$actual"
181 test_cmp expected "$actual"
184 test_expect_success
'__git_find_repo_path - parent is a .git directory' '
185 echo "$ROOT/.git" >expected &&
188 __git_find_repo_path &&
189 echo "$__git_repo_path" >"$actual"
191 test_cmp expected "$actual"
194 test_expect_success
'__git_find_repo_path - $GIT_DIR set while .git directory in cwd' '
195 echo "$ROOT/otherrepo/.git" >expected &&
197 GIT_DIR="$ROOT/otherrepo/.git" &&
199 __git_find_repo_path &&
200 echo "$__git_repo_path" >"$actual"
202 test_cmp expected "$actual"
205 test_expect_success
'__git_find_repo_path - $GIT_DIR set while .git directory in parent' '
206 echo "$ROOT/otherrepo/.git" >expected &&
208 GIT_DIR="$ROOT/otherrepo/.git" &&
211 __git_find_repo_path &&
212 echo "$__git_repo_path" >"$actual"
214 test_cmp expected "$actual"
217 test_expect_success
'__git_find_repo_path - from command line while "git -C"' '
218 echo "$ROOT/.git" >expected &&
220 __git_dir="$ROOT/.git" &&
221 __git_C_args=(-C otherrepo) &&
222 __git_find_repo_path &&
223 echo "$__git_repo_path" >"$actual"
225 test_cmp expected "$actual"
228 test_expect_success
'__git_find_repo_path - relative dir from command line and "git -C"' '
229 echo "$ROOT/otherrepo/.git" >expected &&
232 __git_dir="otherrepo/.git" &&
233 __git_C_args=(-C ..) &&
234 __git_find_repo_path &&
235 echo "$__git_repo_path" >"$actual"
237 test_cmp expected "$actual"
240 test_expect_success
'__git_find_repo_path - $GIT_DIR set while "git -C"' '
241 echo "$ROOT/.git" >expected &&
243 GIT_DIR="$ROOT/.git" &&
245 __git_C_args=(-C otherrepo) &&
246 __git_find_repo_path &&
247 echo "$__git_repo_path" >"$actual"
249 test_cmp expected "$actual"
252 test_expect_success
'__git_find_repo_path - relative dir in $GIT_DIR and "git -C"' '
253 echo "$ROOT/otherrepo/.git" >expected &&
256 GIT_DIR="otherrepo/.git" &&
258 __git_C_args=(-C ..) &&
259 __git_find_repo_path &&
260 echo "$__git_repo_path" >"$actual"
262 test_cmp expected "$actual"
265 test_expect_success
'__git_find_repo_path - "git -C" while .git directory in cwd' '
266 echo "$ROOT/otherrepo/.git" >expected &&
268 __git_C_args=(-C otherrepo) &&
269 __git_find_repo_path &&
270 echo "$__git_repo_path" >"$actual"
272 test_cmp expected "$actual"
275 test_expect_success
'__git_find_repo_path - "git -C" while cwd is a .git directory' '
276 echo "$ROOT/otherrepo/.git" >expected &&
279 __git_C_args=(-C .. -C otherrepo) &&
280 __git_find_repo_path &&
281 echo "$__git_repo_path" >"$actual"
283 test_cmp expected "$actual"
286 test_expect_success
'__git_find_repo_path - "git -C" while .git directory in parent' '
287 echo "$ROOT/otherrepo/.git" >expected &&
290 __git_C_args=(-C .. -C otherrepo) &&
291 __git_find_repo_path &&
292 echo "$__git_repo_path" >"$actual"
294 test_cmp expected "$actual"
297 test_expect_success
'__git_find_repo_path - non-existing path in "git -C"' '
299 __git_C_args=(-C non-existing) &&
300 test_must_fail __git_find_repo_path &&
301 printf "$__git_repo_path" >"$actual"
303 test_must_be_empty "$actual"
306 test_expect_success
'__git_find_repo_path - non-existing path in $__git_dir' '
308 __git_dir="non-existing" &&
309 test_must_fail __git_find_repo_path &&
310 printf "$__git_repo_path" >"$actual"
312 test_must_be_empty "$actual"
315 test_expect_success
'__git_find_repo_path - non-existing $GIT_DIR' '
317 GIT_DIR="$ROOT/non-existing" &&
319 test_must_fail __git_find_repo_path &&
320 printf "$__git_repo_path" >"$actual"
322 test_must_be_empty "$actual"
325 test_expect_success
'__git_find_repo_path - gitfile in cwd' '
326 echo "$ROOT/otherrepo/.git" >expected &&
327 echo "gitdir: $ROOT/otherrepo/.git" >subdir/.git &&
328 test_when_finished "rm -f subdir/.git" &&
331 __git_find_repo_path &&
332 echo "$__git_repo_path" >"$actual"
334 test_cmp expected "$actual"
337 test_expect_success
'__git_find_repo_path - gitfile in parent' '
338 echo "$ROOT/otherrepo/.git" >expected &&
339 echo "gitdir: $ROOT/otherrepo/.git" >subdir/.git &&
340 test_when_finished "rm -f subdir/.git" &&
342 cd subdir/subsubdir &&
343 __git_find_repo_path &&
344 echo "$__git_repo_path" >"$actual"
346 test_cmp expected "$actual"
349 test_expect_success SYMLINKS
'__git_find_repo_path - resulting path avoids symlinks' '
350 echo "$ROOT/otherrepo/.git" >expected &&
351 mkdir otherrepo/dir &&
352 test_when_finished "rm -rf otherrepo/dir" &&
353 ln -s otherrepo/dir link &&
354 test_when_finished "rm -f link" &&
357 __git_find_repo_path &&
358 echo "$__git_repo_path" >"$actual"
360 test_cmp expected "$actual"
363 test_expect_success
'__git_find_repo_path - not a git repository' '
366 GIT_CEILING_DIRECTORIES="$ROOT" &&
367 export GIT_CEILING_DIRECTORIES &&
368 test_must_fail __git_find_repo_path &&
369 printf "$__git_repo_path" >"$actual"
371 test_must_be_empty "$actual"
374 test_expect_success
'__gitdir - finds repo' '
375 echo "$ROOT/.git" >expected &&
377 cd subdir/subsubdir &&
380 test_cmp expected "$actual"
384 test_expect_success
'__gitdir - returns error when cannot find repo' '
386 __git_dir="non-existing" &&
387 test_must_fail __gitdir >"$actual"
389 test_must_be_empty "$actual"
392 test_expect_success
'__gitdir - repo as argument' '
393 echo "otherrepo/.git" >expected &&
395 __gitdir "otherrepo" >"$actual"
397 test_cmp expected "$actual"
400 test_expect_success
'__gitdir - remote as argument' '
401 echo "remote" >expected &&
403 __gitdir "remote" >"$actual"
405 test_cmp expected "$actual"
409 test_expect_success
'__git_dequote - plain unquoted word' '
410 __git_dequote unquoted-word &&
411 verbose test unquoted-word = "$dequoted_word"
414 # input: b\a\c\k\'\\\"s\l\a\s\h\es
415 # expected: back'\"slashes
416 test_expect_success
'__git_dequote - backslash escaped' '
417 __git_dequote "b\a\c\k\\'\''\\\\\\\"s\l\a\s\h\es" &&
418 verbose test "back'\''\\\"slashes" = "$dequoted_word"
421 # input: sin'gle\' '"quo'ted
422 # expected: single\ "quoted
423 test_expect_success
'__git_dequote - single quoted' '
424 __git_dequote "'"sin'gle\\\\' '\\\"quo'ted"'" &&
425 verbose test '\''single\ "quoted'\'' = "$dequoted_word"
428 # input: dou"ble\\" "\"\quot"ed
429 # expected: double\ "\quoted
430 test_expect_success
'__git_dequote - double quoted' '
431 __git_dequote '\''dou"ble\\" "\"\quot"ed'\'' &&
432 verbose test '\''double\ "\quoted'\'' = "$dequoted_word"
435 # input: 'open single quote
436 test_expect_success
'__git_dequote - open single quote' '
437 __git_dequote "'\''open single quote" &&
438 verbose test "open single quote" = "$dequoted_word"
441 # input: "open double quote
442 test_expect_success
'__git_dequote - open double quote' '
443 __git_dequote "\"open double quote" &&
444 verbose test "open double quote" = "$dequoted_word"
448 test_expect_success
'__gitcomp_direct - puts everything into COMPREPLY as-is' '
449 sed -e "s/Z$//g" >expected <<-EOF &&
450 with-trailing-space Z
451 without-trailing-spaceZ
454 $invalid_variable_name Z
457 cur=should_be_ignored &&
458 __gitcomp_direct "$(cat expected)" &&
461 test_cmp expected out
464 test_expect_success
'__gitcomp - trailing space - options' '
465 test_gitcomp "--re" "--dry-run --reuse-message= --reedit-message=
466 --reset-author" <<-EOF
473 test_expect_success
'__gitcomp - trailing space - config keys' '
474 test_gitcomp "br" "branch. branch.autosetupmerge
475 branch.autosetuprebase browser." <<-\EOF
477 branch.autosetupmerge Z
478 branch.autosetuprebase Z
483 test_expect_success
'__gitcomp - option parameter' '
484 test_gitcomp "--strategy=re" "octopus ours recursive resolve subtree" \
491 test_expect_success
'__gitcomp - prefix' '
492 test_gitcomp "branch.me" "remote merge mergeoptions rebase" \
493 "branch.maint." "me" <<-\EOF
495 branch.maint.mergeoptions Z
499 test_expect_success
'__gitcomp - suffix' '
500 test_gitcomp "branch.me" "master maint next seen" "branch." \
507 test_expect_success
'__gitcomp - ignore optional negative options' '
508 test_gitcomp "--" "--abc --def --no-one -- --no-two" <<-\EOF
516 test_expect_success
'__gitcomp - ignore/narrow optional negative options' '
517 test_gitcomp "--a" "--abc --abcdef --no-one -- --no-two" <<-\EOF
523 test_expect_success
'__gitcomp - ignore/narrow optional negative options' '
524 test_gitcomp "--n" "--abc --def --no-one -- --no-two" <<-\EOF
530 test_expect_success
'__gitcomp - expand all negative options' '
531 test_gitcomp "--no-" "--abc --def --no-one -- --no-two" <<-\EOF
537 test_expect_success
'__gitcomp - expand/narrow all negative options' '
538 test_gitcomp "--no-o" "--abc --def --no-one -- --no-two" <<-\EOF
543 test_expect_success
'__gitcomp - equal skip' '
544 test_gitcomp "--option=" "--option=" <<-\EOF &&
547 test_gitcomp "option=" "option=" <<-\EOF
552 test_expect_success
'__gitcomp - doesnt fail because of invalid variable name' '
553 __gitcomp "$invalid_variable_name"
556 read -r -d "" refs
<<-\EOF
563 test_expect_success '__gitcomp_nl - trailing space
' '
564 test_gitcomp_nl
"m" "$refs" <<-EOF
570 test_expect_success '__gitcomp_nl
- prefix
' '
571 test_gitcomp_nl
"--fixup=m" "$refs" "--fixup=" "m" <<-EOF
577 test_expect_success '__gitcomp_nl
- suffix
' '
578 test_gitcomp_nl
"branch.ma" "$refs" "branch." "ma" "." <<-\EOF
584 test_expect_success '__gitcomp_nl - no suffix
' '
585 test_gitcomp_nl
"ma" "$refs" "" "ma" "" <<-\EOF
591 test_expect_success '__gitcomp_nl - doesnt fail because of invalid variable name
' '
592 __gitcomp_nl
"$invalid_variable_name"
595 test_expect_success '__git_remotes
- list remotes from
$GIT_DIR/remotes and from config
file' '
596 cat >expect
<<-EOF &&
602 test_when_finished
"rm -rf .git/remotes" &&
603 mkdir
-p .git
/remotes
&&
604 >.git
/remotes
/remote_from_file_1
&&
605 >.git
/remotes
/remote_from_file_2
&&
606 test_when_finished
"git remote remove remote_in_config_1" &&
607 git remote add remote_in_config_1 git
://remote_1
&&
608 test_when_finished
"git remote remove remote_in_config_2" &&
609 git remote add remote_in_config_2 git
://remote_2
&&
611 __git_remotes
>actual
613 test_cmp expect actual
616 test_expect_success '__git_is_configured_remote
' '
617 test_when_finished
"git remote remove remote_1" &&
618 git remote add remote_1 git
://remote_1
&&
619 test_when_finished
"git remote remove remote_2" &&
620 git remote add remote_2 git
://remote_2
&&
622 verbose __git_is_configured_remote remote_2
&&
623 test_must_fail __git_is_configured_remote non-existent
627 test_expect_success 'setup
for ref completion
' '
628 git commit
--allow-empty -m initial
&&
629 git branch
-M main
&&
630 git branch matching-branch
&&
631 git tag matching-tag
&&
634 git commit
--allow-empty -m initial
&&
635 git branch
-m main main-in-other
&&
636 git branch branch-in-other
&&
639 git remote add other
"$ROOT/otherrepo/.git" &&
640 git fetch
--no-tags other
&&
641 rm -f .git
/FETCH_HEAD
&&
645 test_expect_success '__git_refs
- simple
' '
646 cat >expected
<<-EOF &&
650 other/branch-in-other
656 __git_refs
>"$actual"
658 test_cmp expected
"$actual"
661 test_expect_success '__git_refs
- full refs
' '
662 cat >expected
<<-EOF &&
664 refs/heads/matching-branch
665 refs/remotes/other/branch-in-other
666 refs/remotes/other/main-in-other
667 refs/tags/matching-tag
671 __git_refs
>"$actual"
673 test_cmp expected
"$actual"
676 test_expect_success '__git_refs
- repo given on the
command line
' '
677 cat >expected
<<-EOF &&
684 __git_dir
="$ROOT/otherrepo/.git" &&
686 __git_refs
>"$actual"
688 test_cmp expected
"$actual"
691 test_expect_success '__git_refs
- remote on
local file system
' '
692 cat >expected
<<-EOF &&
700 __git_refs otherrepo
>"$actual"
702 test_cmp expected
"$actual"
705 test_expect_success '__git_refs
- remote on
local file system
- full refs
' '
706 cat >expected
<<-EOF &&
707 refs/heads/branch-in-other
708 refs/heads/main-in-other
709 refs/tags/tag-in-other
713 __git_refs otherrepo
>"$actual"
715 test_cmp expected
"$actual"
718 test_expect_success '__git_refs
- configured remote
' '
719 cat >expected
<<-EOF &&
726 __git_refs other
>"$actual"
728 test_cmp expected
"$actual"
731 test_expect_success '__git_refs
- configured remote
- full refs
' '
732 cat >expected
<<-EOF &&
734 refs/heads/branch-in-other
735 refs/heads/main-in-other
736 refs/tags/tag-in-other
740 __git_refs other
>"$actual"
742 test_cmp expected
"$actual"
745 test_expect_success '__git_refs
- configured remote
- repo given on the
command line
' '
746 cat >expected
<<-EOF &&
753 __git_dir
="$ROOT/.git" &&
755 __git_refs other
>"$actual"
757 test_cmp expected
"$actual"
760 test_expect_success '__git_refs
- configured remote
- full refs
- repo given on the
command line
' '
761 cat >expected
<<-EOF &&
763 refs/heads/branch-in-other
764 refs/heads/main-in-other
765 refs/tags/tag-in-other
769 __git_dir
="$ROOT/.git" &&
771 __git_refs other
>"$actual"
773 test_cmp expected
"$actual"
776 test_expect_success '__git_refs
- configured remote
- remote name matches a directory
' '
777 cat >expected
<<-EOF &&
783 test_when_finished
"rm -rf other" &&
786 __git_refs other
>"$actual"
788 test_cmp expected
"$actual"
791 test_expect_success '__git_refs
- URL remote
' '
792 cat >expected
<<-EOF &&
800 __git_refs
"file://$ROOT/otherrepo/.git" >"$actual"
802 test_cmp expected
"$actual"
805 test_expect_success '__git_refs
- URL remote
- full refs
' '
806 cat >expected
<<-EOF &&
808 refs/heads/branch-in-other
809 refs/heads/main-in-other
810 refs/tags/tag-in-other
814 __git_refs
"file://$ROOT/otherrepo/.git" >"$actual"
816 test_cmp expected
"$actual"
819 test_expect_success '__git_refs
- non-existing remote
' '
822 __git_refs non-existing
>"$actual"
824 test_must_be_empty
"$actual"
827 test_expect_success '__git_refs
- non-existing remote
- full refs
' '
830 __git_refs non-existing
>"$actual"
832 test_must_be_empty
"$actual"
835 test_expect_success '__git_refs
- non-existing URL remote
' '
838 __git_refs
"file://$ROOT/non-existing" >"$actual"
840 test_must_be_empty
"$actual"
843 test_expect_success '__git_refs
- non-existing URL remote
- full refs
' '
846 __git_refs
"file://$ROOT/non-existing" >"$actual"
848 test_must_be_empty
"$actual"
851 test_expect_success '__git_refs
- not
in a git repository
' '
853 GIT_CEILING_DIRECTORIES
="$ROOT" &&
854 export GIT_CEILING_DIRECTORIES
&&
857 __git_refs
>"$actual"
859 test_must_be_empty
"$actual"
862 test_expect_success '__git_refs
- unique remote branches
for git checkout DWIMery
' '
863 cat >expected
<<-EOF &&
868 other/branch-in-other
871 remote/branch-in-remote
877 for remote_ref
in refs
/remotes
/other
/ambiguous \
878 refs
/remotes
/remote
/ambiguous \
879 refs
/remotes
/remote
/branch-in-remote
881 git update-ref
$remote_ref main
&&
882 test_when_finished
"git update-ref -d $remote_ref"
886 __git_refs
"" 1 >"$actual"
888 test_cmp expected
"$actual"
891 test_expect_success '__git_refs
- after
--opt=' '
892 cat >expected
<<-EOF &&
896 other/branch-in-other
902 __git_refs
"" "" "" "" >"$actual"
904 test_cmp expected
"$actual"
907 test_expect_success '__git_refs
- after
--opt= - full refs
' '
908 cat >expected
<<-EOF &&
910 refs/heads/matching-branch
911 refs/remotes/other/branch-in-other
912 refs/remotes/other/main-in-other
913 refs/tags/matching-tag
917 __git_refs
"" "" "" refs
/ >"$actual"
919 test_cmp expected
"$actual"
922 test_expect_success '__git refs
- excluding refs
' '
923 cat >expected
<<-EOF &&
927 ^other/branch-in-other
933 __git_refs
>"$actual"
935 test_cmp expected
"$actual"
938 test_expect_success '__git refs
- excluding full refs
' '
939 cat >expected
<<-EOF &&
941 ^refs/heads/matching-branch
942 ^refs/remotes/other/branch-in-other
943 ^refs/remotes/other/main-in-other
944 ^refs/tags/matching-tag
948 __git_refs
>"$actual"
950 test_cmp expected
"$actual"
953 test_expect_success 'setup
for filtering matching refs
' '
954 git branch matching
/branch
&&
955 git tag matching
/tag
&&
956 git
-C otherrepo branch matching
/branch-in-other
&&
957 git fetch
--no-tags other
&&
958 rm -f .git
/FETCH_HEAD
961 test_expect_success '__git_refs
- do not filter refs unless told so
' '
962 cat >expected
<<-EOF &&
967 other/branch-in-other
969 other/matching/branch-in-other
975 __git_refs
>"$actual"
977 test_cmp expected
"$actual"
980 test_expect_success '__git_refs
- only matching refs
' '
981 cat >expected
<<-EOF &&
989 __git_refs
"" "" "" "$cur" >"$actual"
991 test_cmp expected
"$actual"
994 test_expect_success '__git_refs
- only matching refs
- full refs
' '
995 cat >expected
<<-EOF &&
996 refs/heads/matching-branch
997 refs/heads/matching/branch
1000 cur
=refs
/heads
/mat
&&
1001 __git_refs
"" "" "" "$cur" >"$actual"
1003 test_cmp expected
"$actual"
1006 test_expect_success '__git_refs
- only matching refs
- remote on
local file system
' '
1007 cat >expected
<<-EOF &&
1009 matching/branch-in-other
1013 __git_refs otherrepo
"" "" "$cur" >"$actual"
1015 test_cmp expected
"$actual"
1018 test_expect_success '__git_refs
- only matching refs
- configured remote
' '
1019 cat >expected
<<-EOF &&
1021 matching/branch-in-other
1025 __git_refs other
"" "" "$cur" >"$actual"
1027 test_cmp expected
"$actual"
1030 test_expect_success '__git_refs
- only matching refs
- remote
- full refs
' '
1031 cat >expected
<<-EOF &&
1032 refs/heads/main-in-other
1033 refs/heads/matching/branch-in-other
1036 cur
=refs
/heads
/ma
&&
1037 __git_refs other
"" "" "$cur" >"$actual"
1039 test_cmp expected
"$actual"
1042 test_expect_success '__git_refs
- only matching refs
- checkout DWIMery
' '
1043 cat >expected
<<-EOF &&
1048 matching/branch-in-other
1050 for remote_ref
in refs
/remotes
/other
/ambiguous \
1051 refs
/remotes
/remote
/ambiguous \
1052 refs
/remotes
/remote
/branch-in-remote
1054 git update-ref
$remote_ref main
&&
1055 test_when_finished
"git update-ref -d $remote_ref"
1059 __git_refs
"" 1 "" "$cur" >"$actual"
1061 test_cmp expected
"$actual"
1064 test_expect_success 'teardown after filtering matching refs
' '
1065 git branch
-d matching
/branch
&&
1066 git tag
-d matching
/tag
&&
1067 git update-ref
-d refs
/remotes
/other
/matching
/branch-in-other
&&
1068 git
-C otherrepo branch
-D matching
/branch-in-other
1071 test_expect_success '__git_refs
- for-each-ref format specifiers
in prefix
' '
1072 cat >expected
<<-EOF &&
1073 evil-%%-%42-%(refname)..main
1076 cur
="evil-%%-%42-%(refname)..mai" &&
1077 __git_refs
"" "" "evil-%%-%42-%(refname).." mai
>"$actual"
1079 test_cmp expected
"$actual"
1082 test_expect_success '__git_complete_refs
- simple
' '
1083 sed -e "s/Z$//" >expected
<<-EOF &&
1087 other/branch-in-other Z
1088 other/main-in-other Z
1093 __git_complete_refs
&&
1096 test_cmp expected out
1099 test_expect_success '__git_complete_refs
- matching
' '
1100 sed -e "s/Z$//" >expected
<<-EOF &&
1106 __git_complete_refs
&&
1109 test_cmp expected out
1112 test_expect_success '__git_complete_refs
- remote
' '
1113 sed -e "s/Z$//" >expected
<<-EOF &&
1120 __git_complete_refs
--remote=other
&&
1123 test_cmp expected out
1126 test_expect_success '__git_complete_refs
- track
' '
1127 sed -e "s/Z$//" >expected
<<-EOF &&
1131 other/branch-in-other Z
1132 other/main-in-other Z
1139 __git_complete_refs
--track &&
1142 test_cmp expected out
1145 test_expect_success '__git_complete_refs
- current word
' '
1146 sed -e "s/Z$//" >expected
<<-EOF &&
1151 cur
="--option=mat" &&
1152 __git_complete_refs
--cur="${cur#*=}" &&
1155 test_cmp expected out
1158 test_expect_success '__git_complete_refs
- prefix
' '
1159 sed -e "s/Z$//" >expected
<<-EOF &&
1160 v1.0..matching-branch Z
1161 v1.0..matching-tag Z
1165 __git_complete_refs
--pfx=v1.0..
--cur=mat
&&
1168 test_cmp expected out
1171 test_expect_success '__git_complete_refs
- suffix
' '
1172 cat >expected
<<-EOF &&
1176 other/branch-in-other.
1177 other/main-in-other.
1182 __git_complete_refs
--sfx=.
&&
1185 test_cmp expected out
1188 test_expect_success '__git_complete_fetch_refspecs
- simple
' '
1189 sed -e "s/Z$//" >expected
<<-EOF &&
1191 branch-in-other:branch-in-other Z
1192 main-in-other:main-in-other Z
1196 __git_complete_fetch_refspecs other
&&
1199 test_cmp expected out
1202 test_expect_success '__git_complete_fetch_refspecs
- matching
' '
1203 sed -e "s/Z$//" >expected
<<-EOF &&
1204 branch-in-other:branch-in-other Z
1208 __git_complete_fetch_refspecs other
"" br
&&
1211 test_cmp expected out
1214 test_expect_success '__git_complete_fetch_refspecs
- prefix
' '
1215 sed -e "s/Z$//" >expected
<<-EOF &&
1217 +branch-in-other:branch-in-other Z
1218 +main-in-other:main-in-other Z
1222 __git_complete_fetch_refspecs other
"+" "" &&
1225 test_cmp expected out
1228 test_expect_success '__git_complete_fetch_refspecs
- fully qualified
' '
1229 sed -e "s/Z$//" >expected
<<-EOF &&
1230 refs/heads/branch-in-other:refs/heads/branch-in-other Z
1231 refs/heads/main-in-other:refs/heads/main-in-other Z
1232 refs/tags/tag-in-other:refs/tags/tag-in-other Z
1236 __git_complete_fetch_refspecs other
"" refs
/ &&
1239 test_cmp expected out
1242 test_expect_success '__git_complete_fetch_refspecs
- fully qualified
& prefix
' '
1243 sed -e "s/Z$//" >expected
<<-EOF &&
1244 +refs/heads/branch-in-other:refs/heads/branch-in-other Z
1245 +refs/heads/main-in-other:refs/heads/main-in-other Z
1246 +refs/tags/tag-in-other:refs/tags/tag-in-other Z
1250 __git_complete_fetch_refspecs other
+ refs
/ &&
1253 test_cmp expected out
1256 test_expect_success 'git switch
- with no options
, complete
local branches and unique remote branch names
for DWIM logic
' '
1257 test_completion
"git switch " <<-\EOF
1265 test_expect_success 'git checkout - completes refs and unique remote branches
for DWIM
' '
1266 test_completion
"git checkout " <<-\EOF
1273 other/branch-in-other Z
1274 other/main-in-other Z
1278 test_expect_success 'git switch - with
--no-guess, complete only
local branches
' '
1279 test_completion
"git switch --no-guess " <<-\EOF
1285 test_expect_success 'git switch - with GIT_COMPLETION_CHECKOUT_NO_GUESS
=1, complete only
local branches
' '
1286 GIT_COMPLETION_CHECKOUT_NO_GUESS
=1 test_completion
"git switch " <<-\EOF
1292 test_expect_success 'git switch - --guess overrides GIT_COMPLETION_CHECKOUT_NO_GUESS
=1, complete
local branches and unique remote names
for DWIM logic
' '
1293 GIT_COMPLETION_CHECKOUT_NO_GUESS
=1 test_completion
"git switch --guess " <<-\EOF
1301 test_expect_success 'git switch - a later
--guess overrides previous
--no-guess, complete
local and remote unique branches
for DWIM
' '
1302 test_completion
"git switch --no-guess --guess " <<-\EOF
1310 test_expect_success 'git switch - a later
--no-guess overrides previous
--guess, complete only
local branches
' '
1311 test_completion
"git switch --guess --no-guess " <<-\EOF
1317 test_expect_success 'git checkout - with GIT_COMPLETION_NO_GUESS
=1 only completes refs
' '
1318 GIT_COMPLETION_CHECKOUT_NO_GUESS
=1 test_completion
"git checkout " <<-\EOF
1323 other/branch-in-other Z
1324 other/main-in-other Z
1328 test_expect_success 'git checkout - --guess overrides GIT_COMPLETION_NO_GUESS
=1, complete refs and unique remote branches
for DWIM
' '
1329 GIT_COMPLETION_CHECKOUT_NO_GUESS
=1 test_completion
"git checkout --guess " <<-\EOF
1336 other/branch-in-other Z
1337 other/main-in-other Z
1341 test_expect_success 'git checkout - with
--no-guess, only completes refs
' '
1342 test_completion
"git checkout --no-guess " <<-\EOF
1347 other/branch-in-other Z
1348 other/main-in-other Z
1352 test_expect_success 'git checkout - a later
--guess overrides previous
--no-guess, complete refs and unique remote branches
for DWIM
' '
1353 test_completion
"git checkout --no-guess --guess " <<-\EOF
1360 other/branch-in-other Z
1361 other/main-in-other Z
1365 test_expect_success 'git checkout - a later
--no-guess overrides previous
--guess, complete only refs
' '
1366 test_completion
"git checkout --guess --no-guess " <<-\EOF
1371 other/branch-in-other Z
1372 other/main-in-other Z
1376 test_expect_success 'git checkout - with checkout.guess
= false
, only completes refs
' '
1377 test_config checkout.guess false
&&
1378 test_completion
"git checkout " <<-\EOF
1383 other/branch-in-other Z
1384 other/main-in-other Z
1388 test_expect_success 'git checkout - with checkout.guess
= true
, completes refs and unique remote branches
for DWIM
' '
1389 test_config checkout.guess true
&&
1390 test_completion
"git checkout " <<-\EOF
1397 other/branch-in-other Z
1398 other/main-in-other Z
1402 test_expect_success 'git checkout - a later
--guess overrides previous checkout.guess
= false
, complete refs and unique remote branches
for DWIM
' '
1403 test_config checkout.guess false
&&
1404 test_completion
"git checkout --guess " <<-\EOF
1411 other/branch-in-other Z
1412 other/main-in-other Z
1416 test_expect_success 'git checkout - a later
--no-guess overrides previous checkout.guess
= true
, complete only refs
' '
1417 test_config checkout.guess true
&&
1418 test_completion
"git checkout --no-guess " <<-\EOF
1423 other/branch-in-other Z
1424 other/main-in-other Z
1428 test_expect_success 'git switch - with
--detach, complete all references
' '
1429 test_completion
"git switch --detach " <<-\EOF
1434 other/branch-in-other Z
1435 other/main-in-other Z
1439 test_expect_success 'git checkout - with
--detach, complete only references
' '
1440 test_completion
"git checkout --detach " <<-\EOF
1445 other/branch-in-other Z
1446 other/main-in-other Z
1450 test_expect_success 'git switch - with
-d, complete all references
' '
1451 test_completion
"git switch -d " <<-\EOF
1456 other/branch-in-other Z
1457 other/main-in-other Z
1461 test_expect_success 'git checkout - with
-d, complete only references
' '
1462 test_completion
"git checkout -d " <<-\EOF
1467 other/branch-in-other Z
1468 other/main-in-other Z
1472 test_expect_success 'git switch - with
--track, complete only remote branches
' '
1473 test_completion
"git switch --track " <<-\EOF
1474 other/branch-in-other Z
1475 other/main-in-other Z
1479 test_expect_success 'git checkout - with
--track, complete only remote branches
' '
1480 test_completion
"git checkout --track " <<-\EOF
1481 other/branch-in-other Z
1482 other/main-in-other Z
1486 test_expect_success 'git switch - with
--no-track, complete only
local branch names
' '
1487 test_completion
"git switch --no-track " <<-\EOF
1493 test_expect_success 'git checkout - with
--no-track, complete only
local references
' '
1494 test_completion
"git checkout --no-track " <<-\EOF
1499 other/branch-in-other Z
1500 other/main-in-other Z
1504 test_expect_success 'git switch - with
-c, complete all references
' '
1505 test_completion
"git switch -c new-branch " <<-\EOF
1510 other/branch-in-other Z
1511 other/main-in-other Z
1515 test_expect_success 'git switch - with
-C, complete all references
' '
1516 test_completion
"git switch -C new-branch " <<-\EOF
1521 other/branch-in-other Z
1522 other/main-in-other Z
1526 test_expect_success 'git switch - with
-c and
--track, complete all references
' '
1527 test_completion
"git switch -c new-branch --track " <<-EOF
1532 other/branch-in-other Z
1533 other/main-in-other Z
1537 test_expect_success 'git switch
- with
-C and
--track, complete all references
' '
1538 test_completion
"git switch -C new-branch --track " <<-EOF
1543 other/branch-in-other Z
1544 other/main-in-other Z
1548 test_expect_success 'git switch
- with
-c and
--no-track, complete all references
' '
1549 test_completion
"git switch -c new-branch --no-track " <<-\EOF
1554 other/branch-in-other Z
1555 other/main-in-other Z
1559 test_expect_success 'git switch - with
-C and
--no-track, complete all references
' '
1560 test_completion
"git switch -C new-branch --no-track " <<-\EOF
1565 other/branch-in-other Z
1566 other/main-in-other Z
1570 test_expect_success 'git checkout - with
-b, complete all references
' '
1571 test_completion
"git checkout -b new-branch " <<-\EOF
1576 other/branch-in-other Z
1577 other/main-in-other Z
1581 test_expect_success 'git checkout - with
-B, complete all references
' '
1582 test_completion
"git checkout -B new-branch " <<-\EOF
1587 other/branch-in-other Z
1588 other/main-in-other Z
1592 test_expect_success 'git checkout - with
-b and
--track, complete all references
' '
1593 test_completion
"git checkout -b new-branch --track " <<-EOF
1598 other/branch-in-other Z
1599 other/main-in-other Z
1603 test_expect_success 'git checkout
- with
-B and
--track, complete all references
' '
1604 test_completion
"git checkout -B new-branch --track " <<-EOF
1609 other/branch-in-other Z
1610 other/main-in-other Z
1614 test_expect_success 'git checkout
- with
-b and
--no-track, complete all references
' '
1615 test_completion
"git checkout -b new-branch --no-track " <<-\EOF
1620 other/branch-in-other Z
1621 other/main-in-other Z
1625 test_expect_success 'git checkout - with
-B and
--no-track, complete all references
' '
1626 test_completion
"git checkout -B new-branch --no-track " <<-\EOF
1631 other/branch-in-other Z
1632 other/main-in-other Z
1636 test_expect_success 'git switch - for -c, complete
local branches and unique remote branches
' '
1637 test_completion
"git switch -c " <<-\EOF
1645 test_expect_success 'git switch - for -C, complete
local branches and unique remote branches
' '
1646 test_completion
"git switch -C " <<-\EOF
1654 test_expect_success 'git switch - for -c with
--no-guess, complete
local branches only
' '
1655 test_completion
"git switch --no-guess -c " <<-\EOF
1661 test_expect_success 'git switch - for -C with
--no-guess, complete
local branches only
' '
1662 test_completion
"git switch --no-guess -C " <<-\EOF
1668 test_expect_success 'git switch - for -c with
--no-track, complete
local branches only
' '
1669 test_completion
"git switch --no-track -c " <<-\EOF
1675 test_expect_success 'git switch - for -C with
--no-track, complete
local branches only
' '
1676 test_completion
"git switch --no-track -C " <<-\EOF
1682 test_expect_success 'git checkout - for -b, complete
local branches and unique remote branches
' '
1683 test_completion
"git checkout -b " <<-\EOF
1691 test_expect_success 'git checkout - for -B, complete
local branches and unique remote branches
' '
1692 test_completion
"git checkout -B " <<-\EOF
1700 test_expect_success 'git checkout - for -b with
--no-guess, complete
local branches only
' '
1701 test_completion
"git checkout --no-guess -b " <<-\EOF
1707 test_expect_success 'git checkout - for -B with
--no-guess, complete
local branches only
' '
1708 test_completion
"git checkout --no-guess -B " <<-\EOF
1714 test_expect_success 'git checkout - for -b with
--no-track, complete
local branches only
' '
1715 test_completion
"git checkout --no-track -b " <<-\EOF
1721 test_expect_success 'git checkout - for -B with
--no-track, complete
local branches only
' '
1722 test_completion
"git checkout --no-track -B " <<-\EOF
1728 test_expect_success 'git switch - with
--orphan completes
local branch names and unique remote branch names
' '
1729 test_completion
"git switch --orphan " <<-\EOF
1737 test_expect_success 'git switch - --orphan with branch already provided completes nothing
else' '
1738 test_completion
"git switch --orphan main " <<-\EOF
1743 test_expect_success 'git checkout - with
--orphan completes
local branch names and unique remote branch names
' '
1744 test_completion
"git checkout --orphan " <<-\EOF
1752 test_expect_success 'git checkout - --orphan with branch already provided completes
local refs
for a start-point
' '
1753 test_completion
"git checkout --orphan main " <<-\EOF
1758 other/branch-in-other Z
1759 other/main-in-other Z
1763 test_expect_success 'teardown after ref completion' '
1764 git branch -d matching-branch &&
1765 git tag -d matching-tag &&
1766 git remote remove other
1770 test_path_completion ()
1772 test $# = 2 || BUG "not 2 parameters to test_path_completion"
1774 local cur="$1" expected="$2"
1775 echo "$expected" >expected &&
1777 # In the following tests calling this function we only
1778 # care about how __git_complete_index_file() deals with
1779 # unusual characters in path names. By requesting only
1780 # untracked files we do not have to bother adding any
1781 # paths to the index in those tests.
1782 __git_complete_index_file --others &&
1785 test_cmp expected out
1788 test_expect_success 'setup for path completion tests' '
1792 touch simple-dir/simple-file \
1793 "spaces in dir/spaces in file" \
1794 "árvíztűrő/Сайн яваарай" &&
1795 if test_have_prereq !MINGW &&
1797 '$'separators\034in\035dir'' &&
1798 touch BS\\dir/DQ\"file \
1799 '$'separators\034in\035dir/sep\036in\037file''
1801 test_set_prereq FUNNIERNAMES
1803 rm -rf BS\\dir '$'separators\034in\035dir''
1807 test_expect_success '__git_complete_index_file - simple
' '
1808 test_path_completion simple simple-dir
&& # Bash is supposed to
1809 # add the trailing /.
1810 test_path_completion simple-dir
/simple simple-dir
/simple-file
1813 test_expect_success \
1814 '__git_complete_index_file
- escaped characters on cmdline
' '
1815 test_path_completion spac
"spaces in dir" && # Bash will turn this
1816 # into "spaces\ in\ dir"
1817 test_path_completion
"spaces\\ i" \
1819 test_path_completion
"spaces\\ in\\ dir/s" \
1820 "spaces in dir/spaces in file" &&
1821 test_path_completion
"spaces\\ in\\ dir/spaces\\ i" \
1822 "spaces in dir/spaces in file"
1825 test_expect_success \
1826 '__git_complete_index_file
- quoted characters on cmdline
' '
1827 # Testing with an opening but without a corresponding closing
1828 # double quote is important.
1829 test_path_completion
\"spac
"spaces in dir" &&
1830 test_path_completion
"\"spaces i" \
1832 test_path_completion
"\"spaces in dir/s" \
1833 "spaces in dir/spaces in file" &&
1834 test_path_completion
"\"spaces in dir/spaces i" \
1835 "spaces in dir/spaces in file"
1838 test_expect_success '__git_complete_index_file
- UTF-8
in ls-files output
' '
1839 test_path_completion á árvíztűrő
&&
1840 test_path_completion árvíztűrő
/С
"árvíztűrő/Сайн яваарай"
1843 test_expect_success FUNNIERNAMES \
1844 '__git_complete_index_file
- C-style escapes
in ls-files output
' '
1845 test_path_completion BS \
1847 test_path_completion BS
\\\\d \
1849 test_path_completion BS
\\\\dir
/DQ \
1851 test_path_completion BS
\\\\dir
/DQ
\\\"f \
1855 test_expect_success FUNNIERNAMES \
1856 '__git_complete_index_file
- \nnn
-escaped characters
in ls-files output
' '
1857 test_path_completion sep
'$'separators
\034in\035dir
'' &&
1858 test_path_completion
'$'separators
\034i
'' \
1859 '$'separators
\034in\035dir
'' &&
1860 test_path_completion
'$'separators
\034in\035dir
/sep
'' \
1861 '$'separators
\034in\035dir
/sep
\036in\037file'' &&
1862 test_path_completion
'$'separators
\034in\035dir
/sep
\036i
'' \
1863 '$'separators
\034in\035dir
/sep
\036in\037file''
1866 test_expect_success FUNNYNAMES \
1867 '__git_complete_index_file
- removing repeated quoted path components
' '
1868 test_when_finished
rm -r repeated-quoted
&&
1869 mkdir repeated-quoted
&& # A directory whose name in itself
1870 # would not be quoted ...
1871 >repeated-quoted
/0-file &&
1872 >repeated-quoted
/1\"file && # ... but here the file makes the
1873 # dirname quoted ...
1874 >repeated-quoted
/2-file &&
1875 >repeated-quoted
/3\"file && # ... and here, too.
1877 # Still, we shold only list the directory name only once.
1878 test_path_completion repeated repeated-quoted
1881 test_expect_success 'teardown after path completion tests
' '
1882 rm -rf simple-dir
"spaces in dir" árvíztűrő \
1883 BS
\\dir
'$'separators
\034in\035dir
''
1886 test_expect_success '__git_find_on_cmdline
- single match
' '
1887 echo list
>expect
&&
1889 words
=(git
command --opt list
) &&
1890 cword
=${#words[@]} &&
1892 __git_find_on_cmdline
"add list remove" >actual
1894 test_cmp expect actual
1897 test_expect_success '__git_find_on_cmdline
- multiple matches
' '
1898 echo remove
>expect
&&
1900 words
=(git
command -o --opt remove list add
) &&
1901 cword
=${#words[@]} &&
1903 __git_find_on_cmdline
"add list remove" >actual
1905 test_cmp expect actual
1908 test_expect_success '__git_find_on_cmdline
- no match
' '
1910 words
=(git
command --opt branch
) &&
1911 cword
=${#words[@]} &&
1913 __git_find_on_cmdline
"add list remove" >actual
1915 test_must_be_empty actual
1918 test_expect_success '__git_find_on_cmdline
- single match with index
' '
1919 echo "3 list" >expect
&&
1921 words
=(git
command --opt list
) &&
1922 cword
=${#words[@]} &&
1924 __git_find_on_cmdline
--show-idx "add list remove" >actual
1926 test_cmp expect actual
1929 test_expect_success '__git_find_on_cmdline
- multiple matches with index
' '
1930 echo "4 remove" >expect
&&
1932 words
=(git
command -o --opt remove list add
) &&
1933 cword
=${#words[@]} &&
1935 __git_find_on_cmdline
--show-idx "add list remove" >actual
1937 test_cmp expect actual
1940 test_expect_success '__git_find_on_cmdline
- no match with index
' '
1942 words
=(git
command --opt branch
) &&
1943 cword
=${#words[@]} &&
1945 __git_find_on_cmdline
--show-idx "add list remove" >actual
1947 test_must_be_empty actual
1950 test_expect_success '__git_find_on_cmdline
- ignores matches before
command with index
' '
1951 echo "6 remove" >expect
&&
1953 words
=(git
-C remove
command -o --opt remove list add
) &&
1954 cword
=${#words[@]} &&
1956 __git_find_on_cmdline
--show-idx "add list remove" >actual
1958 test_cmp expect actual
1961 test_expect_success '__git_get_config_variables
' '
1962 cat >expect
<<-EOF &&
1966 test_config interesting.name-1 good
&&
1967 test_config interesting.name-2 good
&&
1968 test_config subsection.interesting.name-3 bad
&&
1969 __git_get_config_variables interesting
>actual
&&
1970 test_cmp expect actual
1973 test_expect_success '__git_pretty_aliases
' '
1974 cat >expect
<<-EOF &&
1978 test_config pretty.author
"%an %ae" &&
1979 test_config pretty.
hash %H
&&
1980 __git_pretty_aliases
>actual
&&
1981 test_cmp expect actual
1984 test_expect_success 'basic
' '
1985 run_completion
"git " &&
1987 grep -q "^add \$" out
&&
1989 grep -q "^rebase \$" out
&&
1991 ! grep -q "^ls-files \$" out
&&
1993 run_completion
"git r" &&
1994 ! grep -q -v "^r" out
1997 test_expect_success 'double dash
"git" itself
' '
1998 test_completion
"git --" <<-\EOF
2011 --no-replace-objects Z
2016 test_expect_success 'double dash "git checkout"' '
2017 test_completion "git checkout --" <<-\
EOF
2027 --ignore-skip-worktree-bits Z
2028 --ignore-other-worktrees Z
2029 --recurse-submodules Z
2035 --pathspec-file-nul Z
2036 --pathspec-from-file=Z
2040 test_expect_success 'general options' '
2041 test_completion "git --ver" "--version " &&
2042 test_completion "git --hel" "--help " &&
2043 test_completion "git --exe" <<-\EOF &&
2047 test_completion "git --htm" "--html-path " &&
2048 test_completion "git --pag" "--paginate " &&
2049 test_completion "git --no-p" "--no-pager " &&
2050 test_completion "git --git" "--git-dir=" &&
2051 test_completion "git --wor" "--work-tree=" &&
2052 test_completion "git --nam" "--namespace=" &&
2053 test_completion "git --bar" "--bare " &&
2054 test_completion "git --inf" "--info-path " &&
2055 test_completion "git --no-r" "--no-replace-objects "
2058 test_expect_success 'general options plus command' '
2059 test_completion "git --version check" "checkout " &&
2060 test_completion "git --paginate check" "checkout " &&
2061 test_completion "git --git-dir=foo check" "checkout " &&
2062 test_completion "git --bare check" "checkout " &&
2063 test_completion "git --exec-path=foo check" "checkout " &&
2064 test_completion "git --html-path check" "checkout " &&
2065 test_completion "git --no-pager check" "checkout " &&
2066 test_completion "git --work-tree=foo check" "checkout " &&
2067 test_completion "git --namespace=foo check" "checkout " &&
2068 test_completion "git --paginate check" "checkout " &&
2069 test_completion "git --info-path check" "checkout " &&
2070 test_completion "git --no-replace-objects check" "checkout " &&
2071 test_completion "git --git-dir some/path check" "checkout " &&
2072 test_completion "git -c conf.var=value check" "checkout " &&
2073 test_completion "git -C some/path check" "checkout " &&
2074 test_completion "git --work-tree some/path check" "checkout " &&
2075 test_completion "git --namespace name/space check" "checkout "
2078 test_expect_success 'git --help completion' '
2079 test_completion "git --help ad" "add " &&
2080 test_completion "git --help core" "core-tutorial "
2083 test_expect_success 'completion.commands removes multiple commands' '
2084 test_config completion.commands "-cherry -mergetool" &&
2085 git --list-cmds=list-mainporcelain,list-complete,config >out &&
2086 ! grep -E "^(cherry|mergetool)$" out
2089 test_expect_success 'setup for integration tests' '
2090 echo content >file1 &&
2092 git add file1 file2 &&
2093 git commit -m one &&
2094 git branch mybranch &&
2098 test_expect_success 'checkout completes ref names' '
2099 test_completion "git checkout m" <<-\EOF
2106 test_expect_success 'git -C <path> checkout uses the right repo' '
2107 test_completion "git -C subdir -C subsubdir -C .. -C ../otherrepo checkout b" <<-\EOF
2112 test_expect_success 'show completes all refs' '
2113 test_completion "git show m" <<-\EOF
2120 test_expect_success '<ref>: completes paths' '
2121 test_completion "git show mytag:f" <<-\EOF
2127 test_expect_success 'complete tree filename with spaces' '
2128 echo content >"name with spaces" &&
2129 git add "name with spaces" &&
2130 git commit -m spaces &&
2131 test_completion "git show HEAD:nam" <<-\EOF
2136 test_expect_success 'complete tree filename with metacharacters' '
2137 echo content >"name with \${meta}" &&
2138 git add "name with \${meta}" &&
2139 git commit -m meta &&
2140 test_completion "git show HEAD:nam" <<-\EOF
2146 test_expect_success PERL 'send-email' '
2147 test_completion "git send-email --cov" <<-\EOF &&
2148 --cover-from-description=Z
2151 test_completion "git send-email ma" "main "
2154 test_expect_success 'complete files' '
2155 git init tmp && cd tmp &&
2156 test_when_finished "cd .. && rm -rf tmp" &&
2158 echo "expected" > .gitignore &&
2159 echo "out" >> .gitignore &&
2160 echo "out_sorted" >> .gitignore &&
2162 git add .gitignore &&
2163 test_completion "git commit " ".gitignore" &&
2165 git commit -m ignore &&
2168 test_completion "git add " "new" &&
2171 git commit -a -m new &&
2172 test_completion "git add " "" &&
2174 git mv new modified &&
2175 echo modify > modified &&
2176 test_completion "git add " "modified" &&
2178 mkdir -p some/deep &&
2179 touch some/deep/path &&
2180 test_completion "git add some/" "some/deep" &&
2181 git clean -f some &&
2185 : TODO .gitignore should not be here &&
2186 test_completion "git rm " <<-\EOF &&
2191 test_completion "git clean " "untracked" &&
2193 : TODO .gitignore should not be here &&
2194 test_completion "git mv " <<-\EOF &&
2200 touch dir/file-in-dir &&
2201 git add dir/file-in-dir &&
2202 git commit -m dir &&
2204 mkdir untracked-dir &&
2206 : TODO .gitignore should not be here &&
2207 test_completion "git mv modified " <<-\EOF &&
2215 test_completion "git commit " "modified" &&
2217 : TODO .gitignore should not be here &&
2218 test_completion "git ls-files " <<-\EOF &&
2225 test_completion "git add mom" "momified"
2228 test_expect_success "simple alias" '
2229 test_config alias.co checkout &&
2230 test_completion "git co m" <<-\EOF
2237 test_expect_success "recursive alias" '
2238 test_config alias.co checkout &&
2239 test_config alias.cod "co --detached" &&
2240 test_completion "git cod m" <<-\EOF
2247 test_expect_success "completion uses <cmd> completion for alias: !sh -c 'git <cmd> ...'" '
2248 test_config alias.co "!sh -c '"'"'git checkout ...'"'"'" &&
2249 test_completion "git co m" <<-\EOF
2256 test_expect_success 'completion uses <cmd> completion for alias: !f () { VAR=val git <cmd> ... }' '
2257 test_config alias.co "!f () { VAR=val git checkout ... ; } f" &&
2258 test_completion "git co m" <<-\EOF
2265 test_expect_success 'completion used <cmd> completion for alias: !f() { : git <cmd> ; ... }' '
2266 test_config alias.co "!f() { : git checkout ; if ... } f" &&
2267 test_completion "git co m" <<-\EOF
2274 test_expect_success 'completion without explicit _git_xxx function' '
2275 test_completion "git version --" <<-\EOF
2277 --no-build-options Z
2281 test_expect_failure 'complete with tilde expansion' '
2282 git init tmp && cd tmp &&
2283 test_when_finished "cd .. && rm -rf tmp" &&
2287 test_completion "git add ~/tmp/" "~/tmp/file"
2290 test_expect_success 'setup other remote for remote reference completion' '
2291 git remote add other otherrepo &&
2295 for flag in -d --delete
2297 test_expect_success "__git_complete_remote_or_refspec - push
$flag other
" '
2298 sed -e "s
/Z$
//" >expected <<-EOF &&
2302 words=(git push '$flag' other ma) &&
2303 cword=${#words[@]} cur=${words[cword-1]} &&
2305 __git_complete_remote_or_refspec &&
2308 test_cmp expected out
2311 test_expect_failure "__git_complete_remote_or_refspec
- push other
$flag" '
2312 sed -e "s
/Z$
//" >expected <<-EOF &&
2316 words=(git push other '$flag' ma) &&
2317 cword=${#words[@]} cur=${words[cword-1]} &&
2319 __git_complete_remote_or_refspec &&
2322 test_cmp expected out
2326 test_expect_success 'git config - section' '
2327 test_completion "git config br
" <<-\EOF
2333 test_expect_success 'git config - variable name' '
2334 test_completion "git config log.d
" <<-\EOF
2341 test_expect_success 'git config - value' '
2342 test_completion "git config color.pager
" <<-\EOF
2348 test_expect_success 'git -c - section' '
2349 test_completion "git
-c br
" <<-\EOF
2355 test_expect_success 'git -c - variable name' '
2356 test_completion "git
-c log.d
" <<-\EOF
2363 test_expect_success 'git -c - value' '
2364 test_completion "git
-c color.pager
=" <<-\EOF
2370 test_expect_success 'git clone --config= - section' '
2371 test_completion "git clone
--config=br
" <<-\EOF
2377 test_expect_success 'git clone --config= - variable name' '
2378 test_completion "git clone
--config=log.d
" <<-\EOF
2385 test_expect_success 'git clone --config= - value' '
2386 test_completion "git clone
--config=color.pager
=" <<-\EOF
2392 test_expect_success 'options with value' '
2393 test_completion "git merge
-X diff-algorithm
=" <<-\EOF
2398 test_expect_success 'sourcing the completion script clears cached commands' '
2399 __git_compute_all_commands &&
2400 verbose test -n "$__git_all_commands" &&
2401 . "$GIT_BUILD_DIR/contrib
/completion
/git-completion.bash
" &&
2402 verbose test -z "$__git_all_commands"
2405 test_expect_success 'sourcing the completion script clears cached merge strategies' '
2406 __git_compute_merge_strategies &&
2407 verbose test -n "$__git_merge_strategies" &&
2408 . "$GIT_BUILD_DIR/contrib
/completion
/git-completion.bash
" &&
2409 verbose test -z "$__git_merge_strategies"
2412 test_expect_success 'sourcing the completion script clears cached --options' '
2413 __gitcomp_builtin checkout &&
2414 verbose test -n "$__gitcomp_builtin_checkout" &&
2415 __gitcomp_builtin notes_edit &&
2416 verbose test -n "$__gitcomp_builtin_notes_edit" &&
2417 . "$GIT_BUILD_DIR/contrib
/completion
/git-completion.bash
" &&
2418 verbose test -z "$__gitcomp_builtin_checkout" &&
2419 verbose test -z "$__gitcomp_builtin_notes_edit"
2422 test_expect_success 'option aliases are not shown by default' '
2423 test_completion "git clone
--recurs" "--recurse-submodules "
2426 test_expect_success 'option aliases are shown with GIT_COMPLETION_SHOW_ALL' '
2427 . "$GIT_BUILD_DIR/contrib
/completion
/git-completion.bash
" &&
2428 GIT_COMPLETION_SHOW_ALL=1 && export GIT_COMPLETION_SHOW_ALL &&
2429 test_completion "git clone
--recurs" <<-\EOF
2430 --recurse-submodules Z
2435 test_expect_success '__git_complete' '
2436 unset -f __git_wrap__git_main &&
2438 __git_complete foo __git_main &&
2439 __git_have_func __git_wrap__git_main &&
2440 unset -f __git_wrap__git_main &&
2442 __git_complete gf _git_fetch &&
2443 __git_have_func __git_wrap_git_fetch &&
2445 __git_complete foo git &&
2446 __git_have_func __git_wrap__git_main &&
2447 unset -f __git_wrap__git_main &&
2449 __git_complete gd git_diff &&
2450 __git_have_func __git_wrap_git_diff &&
2452 test_must_fail __git_complete ga missing