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 - doesnt fail because of invalid variable name' '
544 __gitcomp "$invalid_variable_name"
547 read -r -d "" refs
<<-\EOF
554 test_expect_success '__gitcomp_nl - trailing space
' '
555 test_gitcomp_nl
"m" "$refs" <<-EOF
561 test_expect_success '__gitcomp_nl
- prefix
' '
562 test_gitcomp_nl
"--fixup=m" "$refs" "--fixup=" "m" <<-EOF
568 test_expect_success '__gitcomp_nl
- suffix
' '
569 test_gitcomp_nl
"branch.ma" "$refs" "branch." "ma" "." <<-\EOF
575 test_expect_success '__gitcomp_nl - no suffix
' '
576 test_gitcomp_nl
"ma" "$refs" "" "ma" "" <<-\EOF
582 test_expect_success '__gitcomp_nl - doesnt fail because of invalid variable name
' '
583 __gitcomp_nl
"$invalid_variable_name"
586 test_expect_success '__git_remotes
- list remotes from
$GIT_DIR/remotes and from config
file' '
587 cat >expect
<<-EOF &&
593 test_when_finished
"rm -rf .git/remotes" &&
594 mkdir
-p .git
/remotes
&&
595 >.git
/remotes
/remote_from_file_1
&&
596 >.git
/remotes
/remote_from_file_2
&&
597 test_when_finished
"git remote remove remote_in_config_1" &&
598 git remote add remote_in_config_1 git
://remote_1
&&
599 test_when_finished
"git remote remove remote_in_config_2" &&
600 git remote add remote_in_config_2 git
://remote_2
&&
602 __git_remotes
>actual
604 test_cmp expect actual
607 test_expect_success '__git_is_configured_remote
' '
608 test_when_finished
"git remote remove remote_1" &&
609 git remote add remote_1 git
://remote_1
&&
610 test_when_finished
"git remote remove remote_2" &&
611 git remote add remote_2 git
://remote_2
&&
613 verbose __git_is_configured_remote remote_2
&&
614 test_must_fail __git_is_configured_remote non-existent
618 test_expect_success 'setup
for ref completion
' '
619 git commit
--allow-empty -m initial
&&
620 git branch
-M main
&&
621 git branch matching-branch
&&
622 git tag matching-tag
&&
625 git commit
--allow-empty -m initial
&&
626 git branch
-m main main-in-other
&&
627 git branch branch-in-other
&&
630 git remote add other
"$ROOT/otherrepo/.git" &&
631 git fetch
--no-tags other
&&
632 rm -f .git
/FETCH_HEAD
&&
636 test_expect_success '__git_refs
- simple
' '
637 cat >expected
<<-EOF &&
641 other/branch-in-other
647 __git_refs
>"$actual"
649 test_cmp expected
"$actual"
652 test_expect_success '__git_refs
- full refs
' '
653 cat >expected
<<-EOF &&
655 refs/heads/matching-branch
656 refs/remotes/other/branch-in-other
657 refs/remotes/other/main-in-other
658 refs/tags/matching-tag
662 __git_refs
>"$actual"
664 test_cmp expected
"$actual"
667 test_expect_success '__git_refs
- repo given on the
command line
' '
668 cat >expected
<<-EOF &&
675 __git_dir
="$ROOT/otherrepo/.git" &&
677 __git_refs
>"$actual"
679 test_cmp expected
"$actual"
682 test_expect_success '__git_refs
- remote on
local file system
' '
683 cat >expected
<<-EOF &&
691 __git_refs otherrepo
>"$actual"
693 test_cmp expected
"$actual"
696 test_expect_success '__git_refs
- remote on
local file system
- full refs
' '
697 cat >expected
<<-EOF &&
698 refs/heads/branch-in-other
699 refs/heads/main-in-other
700 refs/tags/tag-in-other
704 __git_refs otherrepo
>"$actual"
706 test_cmp expected
"$actual"
709 test_expect_success '__git_refs
- configured remote
' '
710 cat >expected
<<-EOF &&
717 __git_refs other
>"$actual"
719 test_cmp expected
"$actual"
722 test_expect_success '__git_refs
- configured remote
- full refs
' '
723 cat >expected
<<-EOF &&
725 refs/heads/branch-in-other
726 refs/heads/main-in-other
727 refs/tags/tag-in-other
731 __git_refs other
>"$actual"
733 test_cmp expected
"$actual"
736 test_expect_success '__git_refs
- configured remote
- repo given on the
command line
' '
737 cat >expected
<<-EOF &&
744 __git_dir
="$ROOT/.git" &&
746 __git_refs other
>"$actual"
748 test_cmp expected
"$actual"
751 test_expect_success '__git_refs
- configured remote
- full refs
- repo given on the
command line
' '
752 cat >expected
<<-EOF &&
754 refs/heads/branch-in-other
755 refs/heads/main-in-other
756 refs/tags/tag-in-other
760 __git_dir
="$ROOT/.git" &&
762 __git_refs other
>"$actual"
764 test_cmp expected
"$actual"
767 test_expect_success '__git_refs
- configured remote
- remote name matches a directory
' '
768 cat >expected
<<-EOF &&
774 test_when_finished
"rm -rf other" &&
777 __git_refs other
>"$actual"
779 test_cmp expected
"$actual"
782 test_expect_success '__git_refs
- URL remote
' '
783 cat >expected
<<-EOF &&
791 __git_refs
"file://$ROOT/otherrepo/.git" >"$actual"
793 test_cmp expected
"$actual"
796 test_expect_success '__git_refs
- URL remote
- full refs
' '
797 cat >expected
<<-EOF &&
799 refs/heads/branch-in-other
800 refs/heads/main-in-other
801 refs/tags/tag-in-other
805 __git_refs
"file://$ROOT/otherrepo/.git" >"$actual"
807 test_cmp expected
"$actual"
810 test_expect_success '__git_refs
- non-existing remote
' '
813 __git_refs non-existing
>"$actual"
815 test_must_be_empty
"$actual"
818 test_expect_success '__git_refs
- non-existing remote
- full refs
' '
821 __git_refs non-existing
>"$actual"
823 test_must_be_empty
"$actual"
826 test_expect_success '__git_refs
- non-existing URL remote
' '
829 __git_refs
"file://$ROOT/non-existing" >"$actual"
831 test_must_be_empty
"$actual"
834 test_expect_success '__git_refs
- non-existing URL remote
- full refs
' '
837 __git_refs
"file://$ROOT/non-existing" >"$actual"
839 test_must_be_empty
"$actual"
842 test_expect_success '__git_refs
- not
in a git repository
' '
844 GIT_CEILING_DIRECTORIES
="$ROOT" &&
845 export GIT_CEILING_DIRECTORIES
&&
848 __git_refs
>"$actual"
850 test_must_be_empty
"$actual"
853 test_expect_success '__git_refs
- unique remote branches
for git checkout DWIMery
' '
854 cat >expected
<<-EOF &&
859 other/branch-in-other
862 remote/branch-in-remote
868 for remote_ref
in refs
/remotes
/other
/ambiguous \
869 refs
/remotes
/remote
/ambiguous \
870 refs
/remotes
/remote
/branch-in-remote
872 git update-ref
$remote_ref main
&&
873 test_when_finished
"git update-ref -d $remote_ref"
877 __git_refs
"" 1 >"$actual"
879 test_cmp expected
"$actual"
882 test_expect_success '__git_refs
- after
--opt=' '
883 cat >expected
<<-EOF &&
887 other/branch-in-other
893 __git_refs
"" "" "" "" >"$actual"
895 test_cmp expected
"$actual"
898 test_expect_success '__git_refs
- after
--opt= - full refs
' '
899 cat >expected
<<-EOF &&
901 refs/heads/matching-branch
902 refs/remotes/other/branch-in-other
903 refs/remotes/other/main-in-other
904 refs/tags/matching-tag
908 __git_refs
"" "" "" refs
/ >"$actual"
910 test_cmp expected
"$actual"
913 test_expect_success '__git refs
- excluding refs
' '
914 cat >expected
<<-EOF &&
918 ^other/branch-in-other
924 __git_refs
>"$actual"
926 test_cmp expected
"$actual"
929 test_expect_success '__git refs
- excluding full refs
' '
930 cat >expected
<<-EOF &&
932 ^refs/heads/matching-branch
933 ^refs/remotes/other/branch-in-other
934 ^refs/remotes/other/main-in-other
935 ^refs/tags/matching-tag
939 __git_refs
>"$actual"
941 test_cmp expected
"$actual"
944 test_expect_success 'setup
for filtering matching refs
' '
945 git branch matching
/branch
&&
946 git tag matching
/tag
&&
947 git
-C otherrepo branch matching
/branch-in-other
&&
948 git fetch
--no-tags other
&&
949 rm -f .git
/FETCH_HEAD
952 test_expect_success '__git_refs
- do not filter refs unless told so
' '
953 cat >expected
<<-EOF &&
958 other/branch-in-other
960 other/matching/branch-in-other
966 __git_refs
>"$actual"
968 test_cmp expected
"$actual"
971 test_expect_success '__git_refs
- only matching refs
' '
972 cat >expected
<<-EOF &&
980 __git_refs
"" "" "" "$cur" >"$actual"
982 test_cmp expected
"$actual"
985 test_expect_success '__git_refs
- only matching refs
- full refs
' '
986 cat >expected
<<-EOF &&
987 refs/heads/matching-branch
988 refs/heads/matching/branch
991 cur
=refs
/heads
/mat
&&
992 __git_refs
"" "" "" "$cur" >"$actual"
994 test_cmp expected
"$actual"
997 test_expect_success '__git_refs
- only matching refs
- remote on
local file system
' '
998 cat >expected
<<-EOF &&
1000 matching/branch-in-other
1004 __git_refs otherrepo
"" "" "$cur" >"$actual"
1006 test_cmp expected
"$actual"
1009 test_expect_success '__git_refs
- only matching refs
- configured remote
' '
1010 cat >expected
<<-EOF &&
1012 matching/branch-in-other
1016 __git_refs other
"" "" "$cur" >"$actual"
1018 test_cmp expected
"$actual"
1021 test_expect_success '__git_refs
- only matching refs
- remote
- full refs
' '
1022 cat >expected
<<-EOF &&
1023 refs/heads/main-in-other
1024 refs/heads/matching/branch-in-other
1027 cur
=refs
/heads
/ma
&&
1028 __git_refs other
"" "" "$cur" >"$actual"
1030 test_cmp expected
"$actual"
1033 test_expect_success '__git_refs
- only matching refs
- checkout DWIMery
' '
1034 cat >expected
<<-EOF &&
1039 matching/branch-in-other
1041 for remote_ref
in refs
/remotes
/other
/ambiguous \
1042 refs
/remotes
/remote
/ambiguous \
1043 refs
/remotes
/remote
/branch-in-remote
1045 git update-ref
$remote_ref main
&&
1046 test_when_finished
"git update-ref -d $remote_ref"
1050 __git_refs
"" 1 "" "$cur" >"$actual"
1052 test_cmp expected
"$actual"
1055 test_expect_success 'teardown after filtering matching refs
' '
1056 git branch
-d matching
/branch
&&
1057 git tag
-d matching
/tag
&&
1058 git update-ref
-d refs
/remotes
/other
/matching
/branch-in-other
&&
1059 git
-C otherrepo branch
-D matching
/branch-in-other
1062 test_expect_success '__git_refs
- for-each-ref format specifiers
in prefix
' '
1063 cat >expected
<<-EOF &&
1064 evil-%%-%42-%(refname)..main
1067 cur
="evil-%%-%42-%(refname)..mai" &&
1068 __git_refs
"" "" "evil-%%-%42-%(refname).." mai
>"$actual"
1070 test_cmp expected
"$actual"
1073 test_expect_success '__git_complete_refs
- simple
' '
1074 sed -e "s/Z$//" >expected
<<-EOF &&
1078 other/branch-in-other Z
1079 other/main-in-other Z
1084 __git_complete_refs
&&
1087 test_cmp expected out
1090 test_expect_success '__git_complete_refs
- matching
' '
1091 sed -e "s/Z$//" >expected
<<-EOF &&
1097 __git_complete_refs
&&
1100 test_cmp expected out
1103 test_expect_success '__git_complete_refs
- remote
' '
1104 sed -e "s/Z$//" >expected
<<-EOF &&
1111 __git_complete_refs
--remote=other
&&
1114 test_cmp expected out
1117 test_expect_success '__git_complete_refs
- track
' '
1118 sed -e "s/Z$//" >expected
<<-EOF &&
1122 other/branch-in-other Z
1123 other/main-in-other Z
1130 __git_complete_refs
--track &&
1133 test_cmp expected out
1136 test_expect_success '__git_complete_refs
- current word
' '
1137 sed -e "s/Z$//" >expected
<<-EOF &&
1142 cur
="--option=mat" &&
1143 __git_complete_refs
--cur="${cur#*=}" &&
1146 test_cmp expected out
1149 test_expect_success '__git_complete_refs
- prefix
' '
1150 sed -e "s/Z$//" >expected
<<-EOF &&
1151 v1.0..matching-branch Z
1152 v1.0..matching-tag Z
1156 __git_complete_refs
--pfx=v1.0..
--cur=mat
&&
1159 test_cmp expected out
1162 test_expect_success '__git_complete_refs
- suffix
' '
1163 cat >expected
<<-EOF &&
1167 other/branch-in-other.
1168 other/main-in-other.
1173 __git_complete_refs
--sfx=.
&&
1176 test_cmp expected out
1179 test_expect_success '__git_complete_fetch_refspecs
- simple
' '
1180 sed -e "s/Z$//" >expected
<<-EOF &&
1182 branch-in-other:branch-in-other Z
1183 main-in-other:main-in-other Z
1187 __git_complete_fetch_refspecs other
&&
1190 test_cmp expected out
1193 test_expect_success '__git_complete_fetch_refspecs
- matching
' '
1194 sed -e "s/Z$//" >expected
<<-EOF &&
1195 branch-in-other:branch-in-other Z
1199 __git_complete_fetch_refspecs other
"" br
&&
1202 test_cmp expected out
1205 test_expect_success '__git_complete_fetch_refspecs
- prefix
' '
1206 sed -e "s/Z$//" >expected
<<-EOF &&
1208 +branch-in-other:branch-in-other Z
1209 +main-in-other:main-in-other Z
1213 __git_complete_fetch_refspecs other
"+" "" &&
1216 test_cmp expected out
1219 test_expect_success '__git_complete_fetch_refspecs
- fully qualified
' '
1220 sed -e "s/Z$//" >expected
<<-EOF &&
1221 refs/heads/branch-in-other:refs/heads/branch-in-other Z
1222 refs/heads/main-in-other:refs/heads/main-in-other Z
1223 refs/tags/tag-in-other:refs/tags/tag-in-other Z
1227 __git_complete_fetch_refspecs other
"" refs
/ &&
1230 test_cmp expected out
1233 test_expect_success '__git_complete_fetch_refspecs
- fully qualified
& prefix
' '
1234 sed -e "s/Z$//" >expected
<<-EOF &&
1235 +refs/heads/branch-in-other:refs/heads/branch-in-other Z
1236 +refs/heads/main-in-other:refs/heads/main-in-other Z
1237 +refs/tags/tag-in-other:refs/tags/tag-in-other Z
1241 __git_complete_fetch_refspecs other
+ refs
/ &&
1244 test_cmp expected out
1247 test_expect_success 'git switch
- with no options
, complete
local branches and unique remote branch names
for DWIM logic
' '
1248 test_completion
"git switch " <<-\EOF
1256 test_expect_success 'git checkout - completes refs and unique remote branches
for DWIM
' '
1257 test_completion
"git checkout " <<-\EOF
1264 other/branch-in-other Z
1265 other/main-in-other Z
1269 test_expect_success 'git switch - with
--no-guess, complete only
local branches
' '
1270 test_completion
"git switch --no-guess " <<-\EOF
1276 test_expect_success 'git switch - with GIT_COMPLETION_CHECKOUT_NO_GUESS
=1, complete only
local branches
' '
1277 GIT_COMPLETION_CHECKOUT_NO_GUESS
=1 test_completion
"git switch " <<-\EOF
1283 test_expect_success 'git switch - --guess overrides GIT_COMPLETION_CHECKOUT_NO_GUESS
=1, complete
local branches and unique remote names
for DWIM logic
' '
1284 GIT_COMPLETION_CHECKOUT_NO_GUESS
=1 test_completion
"git switch --guess " <<-\EOF
1292 test_expect_success 'git switch - a later
--guess overrides previous
--no-guess, complete
local and remote unique branches
for DWIM
' '
1293 test_completion
"git switch --no-guess --guess " <<-\EOF
1301 test_expect_success 'git switch - a later
--no-guess overrides previous
--guess, complete only
local branches
' '
1302 test_completion
"git switch --guess --no-guess " <<-\EOF
1308 test_expect_success 'git checkout - with GIT_COMPLETION_NO_GUESS
=1 only completes refs
' '
1309 GIT_COMPLETION_CHECKOUT_NO_GUESS
=1 test_completion
"git checkout " <<-\EOF
1314 other/branch-in-other Z
1315 other/main-in-other Z
1319 test_expect_success 'git checkout - --guess overrides GIT_COMPLETION_NO_GUESS
=1, complete refs and unique remote branches
for DWIM
' '
1320 GIT_COMPLETION_CHECKOUT_NO_GUESS
=1 test_completion
"git checkout --guess " <<-\EOF
1327 other/branch-in-other Z
1328 other/main-in-other Z
1332 test_expect_success 'git checkout - with
--no-guess, only completes refs
' '
1333 test_completion
"git checkout --no-guess " <<-\EOF
1338 other/branch-in-other Z
1339 other/main-in-other Z
1343 test_expect_success 'git checkout - a later
--guess overrides previous
--no-guess, complete refs and unique remote branches
for DWIM
' '
1344 test_completion
"git checkout --no-guess --guess " <<-\EOF
1351 other/branch-in-other Z
1352 other/main-in-other Z
1356 test_expect_success 'git checkout - a later
--no-guess overrides previous
--guess, complete only refs
' '
1357 test_completion
"git checkout --guess --no-guess " <<-\EOF
1362 other/branch-in-other Z
1363 other/main-in-other Z
1367 test_expect_success 'git checkout - with checkout.guess
= false
, only completes refs
' '
1368 test_config checkout.guess false
&&
1369 test_completion
"git checkout " <<-\EOF
1374 other/branch-in-other Z
1375 other/main-in-other Z
1379 test_expect_success 'git checkout - with checkout.guess
= true
, completes refs and unique remote branches
for DWIM
' '
1380 test_config checkout.guess true
&&
1381 test_completion
"git checkout " <<-\EOF
1388 other/branch-in-other Z
1389 other/main-in-other Z
1393 test_expect_success 'git checkout - a later
--guess overrides previous checkout.guess
= false
, complete refs and unique remote branches
for DWIM
' '
1394 test_config checkout.guess false
&&
1395 test_completion
"git checkout --guess " <<-\EOF
1402 other/branch-in-other Z
1403 other/main-in-other Z
1407 test_expect_success 'git checkout - a later
--no-guess overrides previous checkout.guess
= true
, complete only refs
' '
1408 test_config checkout.guess true
&&
1409 test_completion
"git checkout --no-guess " <<-\EOF
1414 other/branch-in-other Z
1415 other/main-in-other Z
1419 test_expect_success 'git switch - with
--detach, complete all references
' '
1420 test_completion
"git switch --detach " <<-\EOF
1425 other/branch-in-other Z
1426 other/main-in-other Z
1430 test_expect_success 'git checkout - with
--detach, complete only references
' '
1431 test_completion
"git checkout --detach " <<-\EOF
1436 other/branch-in-other Z
1437 other/main-in-other Z
1441 test_expect_success 'git switch - with
-d, complete all references
' '
1442 test_completion
"git switch -d " <<-\EOF
1447 other/branch-in-other Z
1448 other/main-in-other Z
1452 test_expect_success 'git checkout - with
-d, complete only references
' '
1453 test_completion
"git checkout -d " <<-\EOF
1458 other/branch-in-other Z
1459 other/main-in-other Z
1463 test_expect_success 'git switch - with
--track, complete only remote branches
' '
1464 test_completion
"git switch --track " <<-\EOF
1465 other/branch-in-other Z
1466 other/main-in-other Z
1470 test_expect_success 'git checkout - with
--track, complete only remote branches
' '
1471 test_completion
"git checkout --track " <<-\EOF
1472 other/branch-in-other Z
1473 other/main-in-other Z
1477 test_expect_success 'git switch - with
--no-track, complete only
local branch names
' '
1478 test_completion
"git switch --no-track " <<-\EOF
1484 test_expect_success 'git checkout - with
--no-track, complete only
local references
' '
1485 test_completion
"git checkout --no-track " <<-\EOF
1490 other/branch-in-other Z
1491 other/main-in-other Z
1495 test_expect_success 'git switch - with
-c, complete all references
' '
1496 test_completion
"git switch -c new-branch " <<-\EOF
1501 other/branch-in-other Z
1502 other/main-in-other Z
1506 test_expect_success 'git switch - with
-C, complete all references
' '
1507 test_completion
"git switch -C new-branch " <<-\EOF
1512 other/branch-in-other Z
1513 other/main-in-other Z
1517 test_expect_success 'git switch - with
-c and
--track, complete all references
' '
1518 test_completion
"git switch -c new-branch --track " <<-EOF
1523 other/branch-in-other Z
1524 other/main-in-other Z
1528 test_expect_success 'git switch
- with
-C and
--track, complete all references
' '
1529 test_completion
"git switch -C new-branch --track " <<-EOF
1534 other/branch-in-other Z
1535 other/main-in-other Z
1539 test_expect_success 'git switch
- with
-c and
--no-track, complete all references
' '
1540 test_completion
"git switch -c new-branch --no-track " <<-\EOF
1545 other/branch-in-other Z
1546 other/main-in-other Z
1550 test_expect_success 'git switch - with
-C and
--no-track, complete all references
' '
1551 test_completion
"git switch -C new-branch --no-track " <<-\EOF
1556 other/branch-in-other Z
1557 other/main-in-other Z
1561 test_expect_success 'git checkout - with
-b, complete all references
' '
1562 test_completion
"git checkout -b new-branch " <<-\EOF
1567 other/branch-in-other Z
1568 other/main-in-other Z
1572 test_expect_success 'git checkout - with
-B, complete all references
' '
1573 test_completion
"git checkout -B new-branch " <<-\EOF
1578 other/branch-in-other Z
1579 other/main-in-other Z
1583 test_expect_success 'git checkout - with
-b and
--track, complete all references
' '
1584 test_completion
"git checkout -b new-branch --track " <<-EOF
1589 other/branch-in-other Z
1590 other/main-in-other Z
1594 test_expect_success 'git checkout
- with
-B and
--track, complete all references
' '
1595 test_completion
"git checkout -B new-branch --track " <<-EOF
1600 other/branch-in-other Z
1601 other/main-in-other Z
1605 test_expect_success 'git checkout
- with
-b and
--no-track, complete all references
' '
1606 test_completion
"git checkout -b new-branch --no-track " <<-\EOF
1611 other/branch-in-other Z
1612 other/main-in-other Z
1616 test_expect_success 'git checkout - with
-B and
--no-track, complete all references
' '
1617 test_completion
"git checkout -B new-branch --no-track " <<-\EOF
1622 other/branch-in-other Z
1623 other/main-in-other Z
1627 test_expect_success 'git switch - for -c, complete
local branches and unique remote branches
' '
1628 test_completion
"git switch -c " <<-\EOF
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 with
--no-guess, complete
local branches only
' '
1646 test_completion
"git switch --no-guess -c " <<-\EOF
1652 test_expect_success 'git switch - for -C with
--no-guess, complete
local branches only
' '
1653 test_completion
"git switch --no-guess -C " <<-\EOF
1659 test_expect_success 'git switch - for -c with
--no-track, complete
local branches only
' '
1660 test_completion
"git switch --no-track -c " <<-\EOF
1666 test_expect_success 'git switch - for -C with
--no-track, complete
local branches only
' '
1667 test_completion
"git switch --no-track -C " <<-\EOF
1673 test_expect_success 'git checkout - for -b, complete
local branches and unique remote branches
' '
1674 test_completion
"git checkout -b " <<-\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 with
--no-guess, complete
local branches only
' '
1692 test_completion
"git checkout --no-guess -b " <<-\EOF
1698 test_expect_success 'git checkout - for -B with
--no-guess, complete
local branches only
' '
1699 test_completion
"git checkout --no-guess -B " <<-\EOF
1705 test_expect_success 'git checkout - for -b with
--no-track, complete
local branches only
' '
1706 test_completion
"git checkout --no-track -b " <<-\EOF
1712 test_expect_success 'git checkout - for -B with
--no-track, complete
local branches only
' '
1713 test_completion
"git checkout --no-track -B " <<-\EOF
1719 test_expect_success 'git switch - with
--orphan completes
local branch names and unique remote branch names
' '
1720 test_completion
"git switch --orphan " <<-\EOF
1728 test_expect_success 'git switch - --orphan with branch already provided completes nothing
else' '
1729 test_completion
"git switch --orphan main " <<-\EOF
1734 test_expect_success 'git checkout - with
--orphan completes
local branch names and unique remote branch names
' '
1735 test_completion
"git checkout --orphan " <<-\EOF
1743 test_expect_success 'git checkout - --orphan with branch already provided completes
local refs
for a start-point
' '
1744 test_completion
"git checkout --orphan main " <<-\EOF
1749 other/branch-in-other Z
1750 other/main-in-other Z
1754 test_expect_success 'teardown after ref completion' '
1755 git branch -d matching-branch &&
1756 git tag -d matching-tag &&
1757 git remote remove other
1761 test_path_completion ()
1763 test $# = 2 || BUG "not 2 parameters to test_path_completion"
1765 local cur="$1" expected="$2"
1766 echo "$expected" >expected &&
1768 # In the following tests calling this function we only
1769 # care about how __git_complete_index_file() deals with
1770 # unusual characters in path names. By requesting only
1771 # untracked files we do not have to bother adding any
1772 # paths to the index in those tests.
1773 __git_complete_index_file --others &&
1776 test_cmp expected out
1779 test_expect_success 'setup for path completion tests' '
1783 touch simple-dir/simple-file \
1784 "spaces in dir/spaces in file" \
1785 "árvíztűrő/Сайн яваарай" &&
1786 if test_have_prereq !MINGW &&
1788 '$'separators\034in\035dir'' &&
1789 touch BS\\dir/DQ\"file \
1790 '$'separators\034in\035dir/sep\036in\037file''
1792 test_set_prereq FUNNIERNAMES
1794 rm -rf BS\\dir '$'separators\034in\035dir''
1798 test_expect_success '__git_complete_index_file - simple
' '
1799 test_path_completion simple simple-dir
&& # Bash is supposed to
1800 # add the trailing /.
1801 test_path_completion simple-dir
/simple simple-dir
/simple-file
1804 test_expect_success \
1805 '__git_complete_index_file
- escaped characters on cmdline
' '
1806 test_path_completion spac
"spaces in dir" && # Bash will turn this
1807 # into "spaces\ in\ dir"
1808 test_path_completion
"spaces\\ i" \
1810 test_path_completion
"spaces\\ in\\ dir/s" \
1811 "spaces in dir/spaces in file" &&
1812 test_path_completion
"spaces\\ in\\ dir/spaces\\ i" \
1813 "spaces in dir/spaces in file"
1816 test_expect_success \
1817 '__git_complete_index_file
- quoted characters on cmdline
' '
1818 # Testing with an opening but without a corresponding closing
1819 # double quote is important.
1820 test_path_completion
\"spac
"spaces in dir" &&
1821 test_path_completion
"\"spaces i" \
1823 test_path_completion
"\"spaces in dir/s" \
1824 "spaces in dir/spaces in file" &&
1825 test_path_completion
"\"spaces in dir/spaces i" \
1826 "spaces in dir/spaces in file"
1829 test_expect_success '__git_complete_index_file
- UTF-8
in ls-files output
' '
1830 test_path_completion á árvíztűrő
&&
1831 test_path_completion árvíztűrő
/С
"árvíztűrő/Сайн яваарай"
1834 test_expect_success FUNNIERNAMES \
1835 '__git_complete_index_file
- C-style escapes
in ls-files output
' '
1836 test_path_completion BS \
1838 test_path_completion BS
\\\\d \
1840 test_path_completion BS
\\\\dir
/DQ \
1842 test_path_completion BS
\\\\dir
/DQ
\\\"f \
1846 test_expect_success FUNNIERNAMES \
1847 '__git_complete_index_file
- \nnn
-escaped characters
in ls-files output
' '
1848 test_path_completion sep
'$'separators
\034in\035dir
'' &&
1849 test_path_completion
'$'separators
\034i
'' \
1850 '$'separators
\034in\035dir
'' &&
1851 test_path_completion
'$'separators
\034in\035dir
/sep
'' \
1852 '$'separators
\034in\035dir
/sep
\036in\037file'' &&
1853 test_path_completion
'$'separators
\034in\035dir
/sep
\036i
'' \
1854 '$'separators
\034in\035dir
/sep
\036in\037file''
1857 test_expect_success FUNNYNAMES \
1858 '__git_complete_index_file
- removing repeated quoted path components
' '
1859 test_when_finished
rm -r repeated-quoted
&&
1860 mkdir repeated-quoted
&& # A directory whose name in itself
1861 # would not be quoted ...
1862 >repeated-quoted
/0-file &&
1863 >repeated-quoted
/1\"file && # ... but here the file makes the
1864 # dirname quoted ...
1865 >repeated-quoted
/2-file &&
1866 >repeated-quoted
/3\"file && # ... and here, too.
1868 # Still, we shold only list the directory name only once.
1869 test_path_completion repeated repeated-quoted
1872 test_expect_success 'teardown after path completion tests
' '
1873 rm -rf simple-dir
"spaces in dir" árvíztűrő \
1874 BS
\\dir
'$'separators
\034in\035dir
''
1877 test_expect_success '__git_find_on_cmdline
- single match
' '
1878 echo list
>expect
&&
1880 words
=(git
command --opt list
) &&
1881 cword
=${#words[@]} &&
1883 __git_find_on_cmdline
"add list remove" >actual
1885 test_cmp expect actual
1888 test_expect_success '__git_find_on_cmdline
- multiple matches
' '
1889 echo remove
>expect
&&
1891 words
=(git
command -o --opt remove list add
) &&
1892 cword
=${#words[@]} &&
1894 __git_find_on_cmdline
"add list remove" >actual
1896 test_cmp expect actual
1899 test_expect_success '__git_find_on_cmdline
- no match
' '
1901 words
=(git
command --opt branch
) &&
1902 cword
=${#words[@]} &&
1904 __git_find_on_cmdline
"add list remove" >actual
1906 test_must_be_empty actual
1909 test_expect_success '__git_find_on_cmdline
- single match with index
' '
1910 echo "3 list" >expect
&&
1912 words
=(git
command --opt list
) &&
1913 cword
=${#words[@]} &&
1915 __git_find_on_cmdline
--show-idx "add list remove" >actual
1917 test_cmp expect actual
1920 test_expect_success '__git_find_on_cmdline
- multiple matches with index
' '
1921 echo "4 remove" >expect
&&
1923 words
=(git
command -o --opt remove list add
) &&
1924 cword
=${#words[@]} &&
1926 __git_find_on_cmdline
--show-idx "add list remove" >actual
1928 test_cmp expect actual
1931 test_expect_success '__git_find_on_cmdline
- no match with index
' '
1933 words
=(git
command --opt branch
) &&
1934 cword
=${#words[@]} &&
1936 __git_find_on_cmdline
--show-idx "add list remove" >actual
1938 test_must_be_empty actual
1941 test_expect_success '__git_find_on_cmdline
- ignores matches before
command with index
' '
1942 echo "6 remove" >expect
&&
1944 words
=(git
-C remove
command -o --opt remove list add
) &&
1945 cword
=${#words[@]} &&
1947 __git_find_on_cmdline
--show-idx "add list remove" >actual
1949 test_cmp expect actual
1952 test_expect_success '__git_get_config_variables
' '
1953 cat >expect
<<-EOF &&
1957 test_config interesting.name-1 good
&&
1958 test_config interesting.name-2 good
&&
1959 test_config subsection.interesting.name-3 bad
&&
1960 __git_get_config_variables interesting
>actual
&&
1961 test_cmp expect actual
1964 test_expect_success '__git_pretty_aliases
' '
1965 cat >expect
<<-EOF &&
1969 test_config pretty.author
"%an %ae" &&
1970 test_config pretty.
hash %H
&&
1971 __git_pretty_aliases
>actual
&&
1972 test_cmp expect actual
1975 test_expect_success 'basic
' '
1976 run_completion
"git " &&
1978 grep -q "^add \$" out
&&
1980 grep -q "^rebase \$" out
&&
1982 ! grep -q "^ls-files \$" out
&&
1984 run_completion
"git r" &&
1985 ! grep -q -v "^r" out
1988 test_expect_success 'double dash
"git" itself
' '
1989 test_completion
"git --" <<-\EOF
2002 --no-replace-objects Z
2007 test_expect_success 'double dash "git checkout"' '
2008 test_completion "git checkout --" <<-\
EOF
2018 --ignore-skip-worktree-bits Z
2019 --ignore-other-worktrees Z
2020 --recurse-submodules Z
2026 --pathspec-file-nul Z
2027 --pathspec-from-file=Z
2031 test_expect_success 'general options' '
2032 test_completion "git --ver" "--version " &&
2033 test_completion "git --hel" "--help " &&
2034 test_completion "git --exe" <<-\EOF &&
2038 test_completion "git --htm" "--html-path " &&
2039 test_completion "git --pag" "--paginate " &&
2040 test_completion "git --no-p" "--no-pager " &&
2041 test_completion "git --git" "--git-dir=" &&
2042 test_completion "git --wor" "--work-tree=" &&
2043 test_completion "git --nam" "--namespace=" &&
2044 test_completion "git --bar" "--bare " &&
2045 test_completion "git --inf" "--info-path " &&
2046 test_completion "git --no-r" "--no-replace-objects "
2049 test_expect_success 'general options plus command' '
2050 test_completion "git --version check" "checkout " &&
2051 test_completion "git --paginate check" "checkout " &&
2052 test_completion "git --git-dir=foo check" "checkout " &&
2053 test_completion "git --bare check" "checkout " &&
2054 test_completion "git --exec-path=foo check" "checkout " &&
2055 test_completion "git --html-path check" "checkout " &&
2056 test_completion "git --no-pager check" "checkout " &&
2057 test_completion "git --work-tree=foo check" "checkout " &&
2058 test_completion "git --namespace=foo check" "checkout " &&
2059 test_completion "git --paginate check" "checkout " &&
2060 test_completion "git --info-path check" "checkout " &&
2061 test_completion "git --no-replace-objects check" "checkout " &&
2062 test_completion "git --git-dir some/path check" "checkout " &&
2063 test_completion "git -c conf.var=value check" "checkout " &&
2064 test_completion "git -C some/path check" "checkout " &&
2065 test_completion "git --work-tree some/path check" "checkout " &&
2066 test_completion "git --namespace name/space check" "checkout "
2069 test_expect_success 'git --help completion' '
2070 test_completion "git --help ad" "add " &&
2071 test_completion "git --help core" "core-tutorial "
2074 test_expect_success 'completion.commands removes multiple commands' '
2075 test_config completion.commands "-cherry -mergetool" &&
2076 git --list-cmds=list-mainporcelain,list-complete,config >out &&
2077 ! grep -E "^(cherry|mergetool)$" out
2080 test_expect_success 'setup for integration tests' '
2081 echo content >file1 &&
2083 git add file1 file2 &&
2084 git commit -m one &&
2085 git branch mybranch &&
2089 test_expect_success 'checkout completes ref names' '
2090 test_completion "git checkout m" <<-\EOF
2097 test_expect_success 'git -C <path> checkout uses the right repo' '
2098 test_completion "git -C subdir -C subsubdir -C .. -C ../otherrepo checkout b" <<-\EOF
2103 test_expect_success 'show completes all refs' '
2104 test_completion "git show m" <<-\EOF
2111 test_expect_success '<ref>: completes paths' '
2112 test_completion "git show mytag:f" <<-\EOF
2118 test_expect_success 'complete tree filename with spaces' '
2119 echo content >"name with spaces" &&
2120 git add "name with spaces" &&
2121 git commit -m spaces &&
2122 test_completion "git show HEAD:nam" <<-\EOF
2127 test_expect_success 'complete tree filename with metacharacters' '
2128 echo content >"name with \${meta}" &&
2129 git add "name with \${meta}" &&
2130 git commit -m meta &&
2131 test_completion "git show HEAD:nam" <<-\EOF
2137 test_expect_success PERL 'send-email' '
2138 test_completion "git send-email --cov" <<-\EOF &&
2139 --cover-from-description=Z
2142 test_completion "git send-email ma" "main "
2145 test_expect_success 'complete files' '
2146 git init tmp && cd tmp &&
2147 test_when_finished "cd .. && rm -rf tmp" &&
2149 echo "expected" > .gitignore &&
2150 echo "out" >> .gitignore &&
2151 echo "out_sorted" >> .gitignore &&
2153 git add .gitignore &&
2154 test_completion "git commit " ".gitignore" &&
2156 git commit -m ignore &&
2159 test_completion "git add " "new" &&
2162 git commit -a -m new &&
2163 test_completion "git add " "" &&
2165 git mv new modified &&
2166 echo modify > modified &&
2167 test_completion "git add " "modified" &&
2169 mkdir -p some/deep &&
2170 touch some/deep/path &&
2171 test_completion "git add some/" "some/deep" &&
2172 git clean -f some &&
2176 : TODO .gitignore should not be here &&
2177 test_completion "git rm " <<-\EOF &&
2182 test_completion "git clean " "untracked" &&
2184 : TODO .gitignore should not be here &&
2185 test_completion "git mv " <<-\EOF &&
2191 touch dir/file-in-dir &&
2192 git add dir/file-in-dir &&
2193 git commit -m dir &&
2195 mkdir untracked-dir &&
2197 : TODO .gitignore should not be here &&
2198 test_completion "git mv modified " <<-\EOF &&
2206 test_completion "git commit " "modified" &&
2208 : TODO .gitignore should not be here &&
2209 test_completion "git ls-files " <<-\EOF &&
2216 test_completion "git add mom" "momified"
2219 test_expect_success "simple alias" '
2220 test_config alias.co checkout &&
2221 test_completion "git co m" <<-\EOF
2228 test_expect_success "recursive alias" '
2229 test_config alias.co checkout &&
2230 test_config alias.cod "co --detached" &&
2231 test_completion "git cod m" <<-\EOF
2238 test_expect_success "completion uses <cmd> completion for alias: !sh -c 'git <cmd> ...'" '
2239 test_config alias.co "!sh -c '"'"'git checkout ...'"'"'" &&
2240 test_completion "git co m" <<-\EOF
2247 test_expect_success 'completion uses <cmd> completion for alias: !f () { VAR=val git <cmd> ... }' '
2248 test_config alias.co "!f () { VAR=val git checkout ... ; } f" &&
2249 test_completion "git co m" <<-\EOF
2256 test_expect_success 'completion used <cmd> completion for alias: !f() { : git <cmd> ; ... }' '
2257 test_config alias.co "!f() { : git checkout ; if ... } f" &&
2258 test_completion "git co m" <<-\EOF
2265 test_expect_success 'completion without explicit _git_xxx function' '
2266 test_completion "git version --" <<-\EOF
2268 --no-build-options Z
2272 test_expect_failure 'complete with tilde expansion' '
2273 git init tmp && cd tmp &&
2274 test_when_finished "cd .. && rm -rf tmp" &&
2278 test_completion "git add ~/tmp/" "~/tmp/file"
2281 test_expect_success 'setup other remote for remote reference completion' '
2282 git remote add other otherrepo &&
2286 for flag in -d --delete
2288 test_expect_success "__git_complete_remote_or_refspec - push
$flag other
" '
2289 sed -e "s
/Z$
//" >expected <<-EOF &&
2293 words=(git push '$flag' other ma) &&
2294 cword=${#words[@]} cur=${words[cword-1]} &&
2296 __git_complete_remote_or_refspec &&
2299 test_cmp expected out
2302 test_expect_failure "__git_complete_remote_or_refspec
- push other
$flag" '
2303 sed -e "s
/Z$
//" >expected <<-EOF &&
2307 words=(git push other '$flag' ma) &&
2308 cword=${#words[@]} cur=${words[cword-1]} &&
2310 __git_complete_remote_or_refspec &&
2313 test_cmp expected out
2317 test_expect_success 'git config - section' '
2318 test_completion "git config br
" <<-\EOF
2324 test_expect_success 'git config - variable name' '
2325 test_completion "git config log.d
" <<-\EOF
2332 test_expect_success 'git config - value' '
2333 test_completion "git config color.pager
" <<-\EOF
2339 test_expect_success 'git -c - section' '
2340 test_completion "git
-c br
" <<-\EOF
2346 test_expect_success 'git -c - variable name' '
2347 test_completion "git
-c log.d
" <<-\EOF
2354 test_expect_success 'git -c - value' '
2355 test_completion "git
-c color.pager
=" <<-\EOF
2361 test_expect_success 'git clone --config= - section' '
2362 test_completion "git clone
--config=br
" <<-\EOF
2368 test_expect_success 'git clone --config= - variable name' '
2369 test_completion "git clone
--config=log.d
" <<-\EOF
2376 test_expect_success 'git clone --config= - value' '
2377 test_completion "git clone
--config=color.pager
=" <<-\EOF
2383 test_expect_success 'sourcing the completion script clears cached commands' '
2384 __git_compute_all_commands &&
2385 verbose test -n "$__git_all_commands" &&
2386 . "$GIT_BUILD_DIR/contrib
/completion
/git-completion.bash
" &&
2387 verbose test -z "$__git_all_commands"
2390 test_expect_success 'sourcing the completion script clears cached merge strategies' '
2391 __git_compute_merge_strategies &&
2392 verbose test -n "$__git_merge_strategies" &&
2393 . "$GIT_BUILD_DIR/contrib
/completion
/git-completion.bash
" &&
2394 verbose test -z "$__git_merge_strategies"
2397 test_expect_success 'sourcing the completion script clears cached --options' '
2398 __gitcomp_builtin checkout &&
2399 verbose test -n "$__gitcomp_builtin_checkout" &&
2400 __gitcomp_builtin notes_edit &&
2401 verbose test -n "$__gitcomp_builtin_notes_edit" &&
2402 . "$GIT_BUILD_DIR/contrib
/completion
/git-completion.bash
" &&
2403 verbose test -z "$__gitcomp_builtin_checkout" &&
2404 verbose test -z "$__gitcomp_builtin_notes_edit"
2407 test_expect_success '__git_complete' '
2408 unset -f __git_wrap__git_main &&
2410 __git_complete foo __git_main &&
2411 __git_have_func __git_wrap__git_main &&
2412 unset -f __git_wrap__git_main &&
2414 __git_complete gf _git_fetch &&
2415 __git_have_func __git_wrap_git_fetch &&
2417 __git_complete foo git &&
2418 __git_have_func __git_wrap__git_main &&
2419 unset -f __git_wrap__git_main &&
2421 __git_complete gd git_diff &&
2422 __git_have_func __git_wrap_git_diff &&
2424 test_must_fail __git_complete ga missing