completion: add 'symbolic-ref'
[alt-git.git] / t / t9902-completion.sh
blob7773de3469f60cccb5f3e864365621da35137ec8
1 #!/bin/sh
3 # Copyright (c) 2012-2020 Felipe Contreras
6 test_description='test bash completion'
8 # The Bash completion scripts must not print anything to either stdout or
9 # stderr, which we try to verify. When tracing is enabled without support for
10 # BASH_XTRACEFD this assertion will fail, so we have to mark the test as
11 # untraceable with such ancient Bash versions.
12 test_untraceable=UnfortunatelyYes
14 # Override environment and always use master for the default initial branch
15 # name for these tests, so that rev completion candidates are as expected.
16 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
17 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
19 . ./lib-bash.sh
21 complete ()
23 # do nothing
24 return 0
27 # Be careful when updating these lists:
29 # (1) The build tree may have build artifact from different branch, or
30 # the user's $PATH may have a random executable that may begin
31 # with "git-check" that are not part of the subcommands this build
32 # will ship, e.g. "check-ignore". The tests for completion for
33 # subcommand names tests how "check" is expanded; we limit the
34 # possible candidates to "checkout" and "check-attr" to make sure
35 # "check-attr", which is known by the filter function as a
36 # subcommand to be thrown out, while excluding other random files
37 # that happen to begin with "check" to avoid letting them get in
38 # the way.
40 # (2) A test makes sure that common subcommands are included in the
41 # completion for "git <TAB>", and a plumbing is excluded. "add",
42 # "rebase" and "ls-files" are listed for this.
44 GIT_TESTING_ALL_COMMAND_LIST='add checkout check-attr rebase ls-files'
45 GIT_TESTING_PORCELAIN_COMMAND_LIST='add checkout rebase'
47 . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash"
49 # We don't need this function to actually join words or do anything special.
50 # Also, it's cleaner to avoid touching bash's internal completion variables.
51 # So let's override it with a minimal version for testing purposes.
52 _get_comp_words_by_ref ()
54 while [ $# -gt 0 ]; do
55 case "$1" in
56 cur)
57 cur=${_words[_cword]}
59 prev)
60 prev=${_words[_cword-1]}
62 words)
63 words=("${_words[@]}")
65 cword)
66 cword=$_cword
68 esac
69 shift
70 done
73 print_comp ()
75 local IFS=$'\n'
76 echo "${COMPREPLY[*]}" > out
79 run_completion ()
81 local -a COMPREPLY _words
82 local _cword
83 _words=( $1 )
84 test "${1: -1}" = ' ' && _words[${#_words[@]}+1]=''
85 (( _cword = ${#_words[@]} - 1 ))
86 __git_wrap__git_main && print_comp
89 # Test high-level completion
90 # Arguments are:
91 # 1: typed text so far (cur)
92 # 2: expected completion
93 test_completion ()
95 if test $# -gt 1
96 then
97 printf '%s\n' "$2" >expected
98 else
99 sed -e 's/Z$//' |sort >expected
100 fi &&
101 run_completion "$1" >"$TRASH_DIRECTORY"/bash-completion-output 2>&1 &&
102 sort out >out_sorted &&
103 test_cmp expected out_sorted &&
104 test_must_be_empty "$TRASH_DIRECTORY"/bash-completion-output &&
105 rm "$TRASH_DIRECTORY"/bash-completion-output
108 # Test __gitcomp.
109 # The first argument is the typed text so far (cur); the rest are
110 # passed to __gitcomp. Expected output comes is read from the
111 # standard input, like test_completion().
112 test_gitcomp ()
114 local -a COMPREPLY &&
115 sed -e 's/Z$//' >expected &&
116 local cur="$1" &&
117 shift &&
118 __gitcomp "$@" &&
119 print_comp &&
120 test_cmp expected out
123 # Test __gitcomp_nl
124 # Arguments are:
125 # 1: current word (cur)
126 # -: the rest are passed to __gitcomp_nl
127 test_gitcomp_nl ()
129 local -a COMPREPLY &&
130 sed -e 's/Z$//' >expected &&
131 local cur="$1" &&
132 shift &&
133 __gitcomp_nl "$@" &&
134 print_comp &&
135 test_cmp expected out
138 invalid_variable_name='${foo.bar}'
140 actual="$TRASH_DIRECTORY/actual"
142 if test_have_prereq MINGW
143 then
144 ROOT="$(pwd -W)"
145 else
146 ROOT="$(pwd)"
149 test_expect_success 'setup for __git_find_repo_path/__gitdir tests' '
150 mkdir -p subdir/subsubdir &&
151 mkdir -p non-repo &&
152 git init -b main otherrepo
155 test_expect_success '__git_find_repo_path - from command line (through $__git_dir)' '
156 echo "$ROOT/otherrepo/.git" >expected &&
158 __git_dir="$ROOT/otherrepo/.git" &&
159 __git_find_repo_path &&
160 echo "$__git_repo_path" >"$actual"
161 ) &&
162 test_cmp expected "$actual"
165 test_expect_success '__git_find_repo_path - .git directory in cwd' '
166 echo ".git" >expected &&
168 __git_find_repo_path &&
169 echo "$__git_repo_path" >"$actual"
170 ) &&
171 test_cmp expected "$actual"
174 test_expect_success '__git_find_repo_path - .git directory in parent' '
175 echo "$ROOT/.git" >expected &&
177 cd subdir/subsubdir &&
178 __git_find_repo_path &&
179 echo "$__git_repo_path" >"$actual"
180 ) &&
181 test_cmp expected "$actual"
184 test_expect_success '__git_find_repo_path - cwd is a .git directory' '
185 echo "." >expected &&
187 cd .git &&
188 __git_find_repo_path &&
189 echo "$__git_repo_path" >"$actual"
190 ) &&
191 test_cmp expected "$actual"
194 test_expect_success '__git_find_repo_path - parent is a .git directory' '
195 echo "$ROOT/.git" >expected &&
197 cd .git/objects &&
198 __git_find_repo_path &&
199 echo "$__git_repo_path" >"$actual"
200 ) &&
201 test_cmp expected "$actual"
204 test_expect_success '__git_find_repo_path - $GIT_DIR set while .git directory in cwd' '
205 echo "$ROOT/otherrepo/.git" >expected &&
207 GIT_DIR="$ROOT/otherrepo/.git" &&
208 export GIT_DIR &&
209 __git_find_repo_path &&
210 echo "$__git_repo_path" >"$actual"
211 ) &&
212 test_cmp expected "$actual"
215 test_expect_success '__git_find_repo_path - $GIT_DIR set while .git directory in parent' '
216 echo "$ROOT/otherrepo/.git" >expected &&
218 GIT_DIR="$ROOT/otherrepo/.git" &&
219 export GIT_DIR &&
220 cd subdir &&
221 __git_find_repo_path &&
222 echo "$__git_repo_path" >"$actual"
223 ) &&
224 test_cmp expected "$actual"
227 test_expect_success '__git_find_repo_path - from command line while "git -C"' '
228 echo "$ROOT/.git" >expected &&
230 __git_dir="$ROOT/.git" &&
231 __git_C_args=(-C otherrepo) &&
232 __git_find_repo_path &&
233 echo "$__git_repo_path" >"$actual"
234 ) &&
235 test_cmp expected "$actual"
238 test_expect_success '__git_find_repo_path - relative dir from command line and "git -C"' '
239 echo "$ROOT/otherrepo/.git" >expected &&
241 cd subdir &&
242 __git_dir="otherrepo/.git" &&
243 __git_C_args=(-C ..) &&
244 __git_find_repo_path &&
245 echo "$__git_repo_path" >"$actual"
246 ) &&
247 test_cmp expected "$actual"
250 test_expect_success '__git_find_repo_path - $GIT_DIR set while "git -C"' '
251 echo "$ROOT/.git" >expected &&
253 GIT_DIR="$ROOT/.git" &&
254 export GIT_DIR &&
255 __git_C_args=(-C otherrepo) &&
256 __git_find_repo_path &&
257 echo "$__git_repo_path" >"$actual"
258 ) &&
259 test_cmp expected "$actual"
262 test_expect_success '__git_find_repo_path - relative dir in $GIT_DIR and "git -C"' '
263 echo "$ROOT/otherrepo/.git" >expected &&
265 cd subdir &&
266 GIT_DIR="otherrepo/.git" &&
267 export GIT_DIR &&
268 __git_C_args=(-C ..) &&
269 __git_find_repo_path &&
270 echo "$__git_repo_path" >"$actual"
271 ) &&
272 test_cmp expected "$actual"
275 test_expect_success '__git_find_repo_path - "git -C" while .git directory in cwd' '
276 echo "$ROOT/otherrepo/.git" >expected &&
278 __git_C_args=(-C otherrepo) &&
279 __git_find_repo_path &&
280 echo "$__git_repo_path" >"$actual"
281 ) &&
282 test_cmp expected "$actual"
285 test_expect_success '__git_find_repo_path - "git -C" while cwd is a .git directory' '
286 echo "$ROOT/otherrepo/.git" >expected &&
288 cd .git &&
289 __git_C_args=(-C .. -C otherrepo) &&
290 __git_find_repo_path &&
291 echo "$__git_repo_path" >"$actual"
292 ) &&
293 test_cmp expected "$actual"
296 test_expect_success '__git_find_repo_path - "git -C" while .git directory in parent' '
297 echo "$ROOT/otherrepo/.git" >expected &&
299 cd subdir &&
300 __git_C_args=(-C .. -C otherrepo) &&
301 __git_find_repo_path &&
302 echo "$__git_repo_path" >"$actual"
303 ) &&
304 test_cmp expected "$actual"
307 test_expect_success '__git_find_repo_path - non-existing path in "git -C"' '
309 __git_C_args=(-C non-existing) &&
310 test_must_fail __git_find_repo_path &&
311 printf "$__git_repo_path" >"$actual"
312 ) &&
313 test_must_be_empty "$actual"
316 test_expect_success '__git_find_repo_path - non-existing path in $__git_dir' '
318 __git_dir="non-existing" &&
319 test_must_fail __git_find_repo_path &&
320 printf "$__git_repo_path" >"$actual"
321 ) &&
322 test_must_be_empty "$actual"
325 test_expect_success '__git_find_repo_path - non-existing $GIT_DIR' '
327 GIT_DIR="$ROOT/non-existing" &&
328 export GIT_DIR &&
329 test_must_fail __git_find_repo_path &&
330 printf "$__git_repo_path" >"$actual"
331 ) &&
332 test_must_be_empty "$actual"
335 test_expect_success '__git_find_repo_path - gitfile in cwd' '
336 echo "$ROOT/otherrepo/.git" >expected &&
337 echo "gitdir: $ROOT/otherrepo/.git" >subdir/.git &&
338 test_when_finished "rm -f subdir/.git" &&
340 cd subdir &&
341 __git_find_repo_path &&
342 echo "$__git_repo_path" >"$actual"
343 ) &&
344 test_cmp expected "$actual"
347 test_expect_success '__git_find_repo_path - gitfile in parent' '
348 echo "$ROOT/otherrepo/.git" >expected &&
349 echo "gitdir: $ROOT/otherrepo/.git" >subdir/.git &&
350 test_when_finished "rm -f subdir/.git" &&
352 cd subdir/subsubdir &&
353 __git_find_repo_path &&
354 echo "$__git_repo_path" >"$actual"
355 ) &&
356 test_cmp expected "$actual"
359 test_expect_success SYMLINKS '__git_find_repo_path - resulting path avoids symlinks' '
360 echo "$ROOT/otherrepo/.git" >expected &&
361 mkdir otherrepo/dir &&
362 test_when_finished "rm -rf otherrepo/dir" &&
363 ln -s otherrepo/dir link &&
364 test_when_finished "rm -f link" &&
366 cd link &&
367 __git_find_repo_path &&
368 echo "$__git_repo_path" >"$actual"
369 ) &&
370 test_cmp expected "$actual"
373 test_expect_success '__git_find_repo_path - not a git repository' '
375 cd non-repo &&
376 GIT_CEILING_DIRECTORIES="$ROOT" &&
377 export GIT_CEILING_DIRECTORIES &&
378 test_must_fail __git_find_repo_path &&
379 printf "$__git_repo_path" >"$actual"
380 ) &&
381 test_must_be_empty "$actual"
384 test_expect_success '__gitdir - finds repo' '
385 echo "$ROOT/.git" >expected &&
387 cd subdir/subsubdir &&
388 __gitdir >"$actual"
389 ) &&
390 test_cmp expected "$actual"
394 test_expect_success '__gitdir - returns error when cannot find repo' '
396 __git_dir="non-existing" &&
397 test_must_fail __gitdir >"$actual"
398 ) &&
399 test_must_be_empty "$actual"
402 test_expect_success '__gitdir - repo as argument' '
403 echo "otherrepo/.git" >expected &&
405 __gitdir "otherrepo" >"$actual"
406 ) &&
407 test_cmp expected "$actual"
410 test_expect_success '__gitdir - remote as argument' '
411 echo "remote" >expected &&
413 __gitdir "remote" >"$actual"
414 ) &&
415 test_cmp expected "$actual"
419 test_expect_success '__git_dequote - plain unquoted word' '
420 __git_dequote unquoted-word &&
421 test unquoted-word = "$dequoted_word"
424 # input: b\a\c\k\'\\\"s\l\a\s\h\es
425 # expected: back'\"slashes
426 test_expect_success '__git_dequote - backslash escaped' '
427 __git_dequote "b\a\c\k\\'\''\\\\\\\"s\l\a\s\h\es" &&
428 test "back'\''\\\"slashes" = "$dequoted_word"
431 # input: sin'gle\' '"quo'ted
432 # expected: single\ "quoted
433 test_expect_success '__git_dequote - single quoted' '
434 __git_dequote "'"sin'gle\\\\' '\\\"quo'ted"'" &&
435 test '\''single\ "quoted'\'' = "$dequoted_word"
438 # input: dou"ble\\" "\"\quot"ed
439 # expected: double\ "\quoted
440 test_expect_success '__git_dequote - double quoted' '
441 __git_dequote '\''dou"ble\\" "\"\quot"ed'\'' &&
442 test '\''double\ "\quoted'\'' = "$dequoted_word"
445 # input: 'open single quote
446 test_expect_success '__git_dequote - open single quote' '
447 __git_dequote "'\''open single quote" &&
448 test "open single quote" = "$dequoted_word"
451 # input: "open double quote
452 test_expect_success '__git_dequote - open double quote' '
453 __git_dequote "\"open double quote" &&
454 test "open double quote" = "$dequoted_word"
458 test_expect_success '__gitcomp_direct - puts everything into COMPREPLY as-is' '
459 sed -e "s/Z$//g" >expected <<-EOF &&
460 with-trailing-space Z
461 without-trailing-spaceZ
462 --option Z
463 --option=Z
464 $invalid_variable_name Z
467 cur=should_be_ignored &&
468 __gitcomp_direct "$(cat expected)" &&
469 print_comp
470 ) &&
471 test_cmp expected out
474 test_expect_success '__gitcomp - trailing space - options' '
475 test_gitcomp "--re" "--dry-run --reuse-message= --reedit-message=
476 --reset-author" <<-EOF
477 --reuse-message=Z
478 --reedit-message=Z
479 --reset-author Z
483 test_expect_success '__gitcomp - trailing space - config keys' '
484 test_gitcomp "br" "branch. branch.autosetupmerge
485 branch.autosetuprebase browser." <<-\EOF
486 branch.Z
487 branch.autosetupmerge Z
488 branch.autosetuprebase Z
489 browser.Z
493 test_expect_success '__gitcomp - option parameter' '
494 test_gitcomp "--strategy=re" "octopus ours recursive resolve subtree" \
495 "" "re" <<-\EOF
496 recursive Z
497 resolve Z
501 test_expect_success '__gitcomp - prefix' '
502 test_gitcomp "branch.me" "remote merge mergeoptions rebase" \
503 "branch.maint." "me" <<-\EOF
504 branch.maint.merge Z
505 branch.maint.mergeoptions Z
509 test_expect_success '__gitcomp - suffix' '
510 test_gitcomp "branch.me" "master maint next seen" "branch." \
511 "ma" "." <<-\EOF
512 branch.master.Z
513 branch.maint.Z
517 test_expect_success '__gitcomp - ignore optional negative options' '
518 test_gitcomp "--" "--abc --def --no-one -- --no-two" <<-\EOF
519 --abc Z
520 --def Z
521 --no-one Z
522 --no-... Z
526 test_expect_success '__gitcomp - ignore/narrow optional negative options' '
527 test_gitcomp "--a" "--abc --abcdef --no-one -- --no-two" <<-\EOF
528 --abc Z
529 --abcdef Z
533 test_expect_success '__gitcomp - ignore/narrow optional negative options' '
534 test_gitcomp "--n" "--abc --def --no-one -- --no-two" <<-\EOF
535 --no-one Z
536 --no-... Z
540 test_expect_success '__gitcomp - expand all negative options' '
541 test_gitcomp "--no-" "--abc --def --no-one -- --no-two" <<-\EOF
542 --no-one Z
543 --no-two Z
547 test_expect_success '__gitcomp - expand/narrow all negative options' '
548 test_gitcomp "--no-o" "--abc --def --no-one -- --no-two" <<-\EOF
549 --no-one Z
553 test_expect_success '__gitcomp - equal skip' '
554 test_gitcomp "--option=" "--option=" <<-\EOF &&
557 test_gitcomp "option=" "option=" <<-\EOF
562 test_expect_success '__gitcomp - doesnt fail because of invalid variable name' '
563 __gitcomp "$invalid_variable_name"
566 read -r -d "" refs <<-\EOF
567 main
568 maint
569 next
570 seen
573 test_expect_success '__gitcomp_nl - trailing space' '
574 test_gitcomp_nl "m" "$refs" <<-EOF
575 main Z
576 maint Z
580 test_expect_success '__gitcomp_nl - prefix' '
581 test_gitcomp_nl "--fixup=m" "$refs" "--fixup=" "m" <<-EOF
582 --fixup=main Z
583 --fixup=maint Z
587 test_expect_success '__gitcomp_nl - suffix' '
588 test_gitcomp_nl "branch.ma" "$refs" "branch." "ma" "." <<-\EOF
589 branch.main.Z
590 branch.maint.Z
594 test_expect_success '__gitcomp_nl - no suffix' '
595 test_gitcomp_nl "ma" "$refs" "" "ma" "" <<-\EOF
596 mainZ
597 maintZ
601 test_expect_success '__gitcomp_nl - doesnt fail because of invalid variable name' '
602 __gitcomp_nl "$invalid_variable_name"
605 test_expect_success '__git_remotes - list remotes from $GIT_DIR/remotes and from config file' '
606 cat >expect <<-EOF &&
607 remote_from_file_1
608 remote_from_file_2
609 remote_in_config_1
610 remote_in_config_2
612 test_when_finished "rm -rf .git/remotes" &&
613 mkdir -p .git/remotes &&
614 >.git/remotes/remote_from_file_1 &&
615 >.git/remotes/remote_from_file_2 &&
616 test_when_finished "git remote remove remote_in_config_1" &&
617 git remote add remote_in_config_1 git://remote_1 &&
618 test_when_finished "git remote remove remote_in_config_2" &&
619 git remote add remote_in_config_2 git://remote_2 &&
621 __git_remotes >actual
622 ) &&
623 test_cmp expect actual
626 test_expect_success '__git_is_configured_remote' '
627 test_when_finished "git remote remove remote_1" &&
628 git remote add remote_1 git://remote_1 &&
629 test_when_finished "git remote remove remote_2" &&
630 git remote add remote_2 git://remote_2 &&
632 __git_is_configured_remote remote_2 &&
633 test_must_fail __git_is_configured_remote non-existent
637 test_expect_success 'setup for ref completion' '
638 git commit --allow-empty -m initial &&
639 git branch -M main &&
640 git branch matching-branch &&
641 git tag matching-tag &&
643 cd otherrepo &&
644 git commit --allow-empty -m initial &&
645 git branch -m main main-in-other &&
646 git branch branch-in-other &&
647 git tag tag-in-other
648 ) &&
649 git remote add other "$ROOT/otherrepo/.git" &&
650 git fetch --no-tags other &&
651 rm -f .git/FETCH_HEAD &&
652 git init thirdrepo
655 test_expect_success '__git_refs - simple' '
656 cat >expected <<-EOF &&
657 HEAD
658 main
659 matching-branch
660 other/branch-in-other
661 other/main-in-other
662 matching-tag
665 cur= &&
666 __git_refs >"$actual"
667 ) &&
668 test_cmp expected "$actual"
671 test_expect_success '__git_refs - full refs' '
672 cat >expected <<-EOF &&
673 refs/heads/main
674 refs/heads/matching-branch
675 refs/remotes/other/branch-in-other
676 refs/remotes/other/main-in-other
677 refs/tags/matching-tag
680 cur=refs/heads/ &&
681 __git_refs >"$actual"
682 ) &&
683 test_cmp expected "$actual"
686 test_expect_success '__git_refs - repo given on the command line' '
687 cat >expected <<-EOF &&
688 HEAD
689 branch-in-other
690 main-in-other
691 tag-in-other
694 __git_dir="$ROOT/otherrepo/.git" &&
695 cur= &&
696 __git_refs >"$actual"
697 ) &&
698 test_cmp expected "$actual"
701 test_expect_success '__git_refs - remote on local file system' '
702 cat >expected <<-EOF &&
703 HEAD
704 branch-in-other
705 main-in-other
706 tag-in-other
709 cur= &&
710 __git_refs otherrepo >"$actual"
711 ) &&
712 test_cmp expected "$actual"
715 test_expect_success '__git_refs - remote on local file system - full refs' '
716 cat >expected <<-EOF &&
717 refs/heads/branch-in-other
718 refs/heads/main-in-other
719 refs/tags/tag-in-other
722 cur=refs/ &&
723 __git_refs otherrepo >"$actual"
724 ) &&
725 test_cmp expected "$actual"
728 test_expect_success '__git_refs - configured remote' '
729 cat >expected <<-EOF &&
730 HEAD
731 branch-in-other
732 main-in-other
735 cur= &&
736 __git_refs other >"$actual"
737 ) &&
738 test_cmp expected "$actual"
741 test_expect_success '__git_refs - configured remote - full refs' '
742 cat >expected <<-EOF &&
743 HEAD
744 refs/heads/branch-in-other
745 refs/heads/main-in-other
746 refs/tags/tag-in-other
749 cur=refs/ &&
750 __git_refs other >"$actual"
751 ) &&
752 test_cmp expected "$actual"
755 test_expect_success '__git_refs - configured remote - repo given on the command line' '
756 cat >expected <<-EOF &&
757 HEAD
758 branch-in-other
759 main-in-other
762 cd thirdrepo &&
763 __git_dir="$ROOT/.git" &&
764 cur= &&
765 __git_refs other >"$actual"
766 ) &&
767 test_cmp expected "$actual"
770 test_expect_success '__git_refs - configured remote - full refs - repo given on the command line' '
771 cat >expected <<-EOF &&
772 HEAD
773 refs/heads/branch-in-other
774 refs/heads/main-in-other
775 refs/tags/tag-in-other
778 cd thirdrepo &&
779 __git_dir="$ROOT/.git" &&
780 cur=refs/ &&
781 __git_refs other >"$actual"
782 ) &&
783 test_cmp expected "$actual"
786 test_expect_success '__git_refs - configured remote - remote name matches a directory' '
787 cat >expected <<-EOF &&
788 HEAD
789 branch-in-other
790 main-in-other
792 mkdir other &&
793 test_when_finished "rm -rf other" &&
795 cur= &&
796 __git_refs other >"$actual"
797 ) &&
798 test_cmp expected "$actual"
801 test_expect_success '__git_refs - URL remote' '
802 cat >expected <<-EOF &&
803 HEAD
804 branch-in-other
805 main-in-other
806 tag-in-other
809 cur= &&
810 __git_refs "file://$ROOT/otherrepo/.git" >"$actual"
811 ) &&
812 test_cmp expected "$actual"
815 test_expect_success '__git_refs - URL remote - full refs' '
816 cat >expected <<-EOF &&
817 HEAD
818 refs/heads/branch-in-other
819 refs/heads/main-in-other
820 refs/tags/tag-in-other
823 cur=refs/ &&
824 __git_refs "file://$ROOT/otherrepo/.git" >"$actual"
825 ) &&
826 test_cmp expected "$actual"
829 test_expect_success '__git_refs - non-existing remote' '
831 cur= &&
832 __git_refs non-existing >"$actual"
833 ) &&
834 test_must_be_empty "$actual"
837 test_expect_success '__git_refs - non-existing remote - full refs' '
839 cur=refs/ &&
840 __git_refs non-existing >"$actual"
841 ) &&
842 test_must_be_empty "$actual"
845 test_expect_success '__git_refs - non-existing URL remote' '
847 cur= &&
848 __git_refs "file://$ROOT/non-existing" >"$actual"
849 ) &&
850 test_must_be_empty "$actual"
853 test_expect_success '__git_refs - non-existing URL remote - full refs' '
855 cur=refs/ &&
856 __git_refs "file://$ROOT/non-existing" >"$actual"
857 ) &&
858 test_must_be_empty "$actual"
861 test_expect_success '__git_refs - not in a git repository' '
863 GIT_CEILING_DIRECTORIES="$ROOT" &&
864 export GIT_CEILING_DIRECTORIES &&
865 cd subdir &&
866 cur= &&
867 __git_refs >"$actual"
868 ) &&
869 test_must_be_empty "$actual"
872 test_expect_success '__git_refs - unique remote branches for git checkout DWIMery' '
873 cat >expected <<-EOF &&
874 HEAD
875 main
876 matching-branch
877 other/ambiguous
878 other/branch-in-other
879 other/main-in-other
880 remote/ambiguous
881 remote/branch-in-remote
882 matching-tag
883 branch-in-other
884 branch-in-remote
885 main-in-other
887 for remote_ref in refs/remotes/other/ambiguous \
888 refs/remotes/remote/ambiguous \
889 refs/remotes/remote/branch-in-remote
891 git update-ref $remote_ref main &&
892 test_when_finished "git update-ref -d $remote_ref" || return 1
893 done &&
895 cur= &&
896 __git_refs "" 1 >"$actual"
897 ) &&
898 test_cmp expected "$actual"
901 test_expect_success '__git_refs - after --opt=' '
902 cat >expected <<-EOF &&
903 HEAD
904 main
905 matching-branch
906 other/branch-in-other
907 other/main-in-other
908 matching-tag
911 cur="--opt=" &&
912 __git_refs "" "" "" "" >"$actual"
913 ) &&
914 test_cmp expected "$actual"
917 test_expect_success '__git_refs - after --opt= - full refs' '
918 cat >expected <<-EOF &&
919 refs/heads/main
920 refs/heads/matching-branch
921 refs/remotes/other/branch-in-other
922 refs/remotes/other/main-in-other
923 refs/tags/matching-tag
926 cur="--opt=refs/" &&
927 __git_refs "" "" "" refs/ >"$actual"
928 ) &&
929 test_cmp expected "$actual"
932 test_expect_success '__git refs - excluding refs' '
933 cat >expected <<-EOF &&
934 ^HEAD
935 ^main
936 ^matching-branch
937 ^other/branch-in-other
938 ^other/main-in-other
939 ^matching-tag
942 cur=^ &&
943 __git_refs >"$actual"
944 ) &&
945 test_cmp expected "$actual"
948 test_expect_success '__git refs - excluding full refs' '
949 cat >expected <<-EOF &&
950 ^refs/heads/main
951 ^refs/heads/matching-branch
952 ^refs/remotes/other/branch-in-other
953 ^refs/remotes/other/main-in-other
954 ^refs/tags/matching-tag
957 cur=^refs/ &&
958 __git_refs >"$actual"
959 ) &&
960 test_cmp expected "$actual"
963 test_expect_success 'setup for filtering matching refs' '
964 git branch matching/branch &&
965 git tag matching/tag &&
966 git -C otherrepo branch matching/branch-in-other &&
967 git fetch --no-tags other &&
968 rm -f .git/FETCH_HEAD
971 test_expect_success '__git_refs - do not filter refs unless told so' '
972 cat >expected <<-EOF &&
973 HEAD
974 main
975 matching-branch
976 matching/branch
977 other/branch-in-other
978 other/main-in-other
979 other/matching/branch-in-other
980 matching-tag
981 matching/tag
984 cur=main &&
985 __git_refs >"$actual"
986 ) &&
987 test_cmp expected "$actual"
990 test_expect_success '__git_refs - only matching refs' '
991 cat >expected <<-EOF &&
992 matching-branch
993 matching/branch
994 matching-tag
995 matching/tag
998 cur=mat &&
999 __git_refs "" "" "" "$cur" >"$actual"
1000 ) &&
1001 test_cmp expected "$actual"
1004 test_expect_success '__git_refs - only matching refs - full refs' '
1005 cat >expected <<-EOF &&
1006 refs/heads/matching-branch
1007 refs/heads/matching/branch
1010 cur=refs/heads/mat &&
1011 __git_refs "" "" "" "$cur" >"$actual"
1012 ) &&
1013 test_cmp expected "$actual"
1016 test_expect_success '__git_refs - only matching refs - remote on local file system' '
1017 cat >expected <<-EOF &&
1018 main-in-other
1019 matching/branch-in-other
1022 cur=ma &&
1023 __git_refs otherrepo "" "" "$cur" >"$actual"
1024 ) &&
1025 test_cmp expected "$actual"
1028 test_expect_success '__git_refs - only matching refs - configured remote' '
1029 cat >expected <<-EOF &&
1030 main-in-other
1031 matching/branch-in-other
1034 cur=ma &&
1035 __git_refs other "" "" "$cur" >"$actual"
1036 ) &&
1037 test_cmp expected "$actual"
1040 test_expect_success '__git_refs - only matching refs - remote - full refs' '
1041 cat >expected <<-EOF &&
1042 refs/heads/main-in-other
1043 refs/heads/matching/branch-in-other
1046 cur=refs/heads/ma &&
1047 __git_refs other "" "" "$cur" >"$actual"
1048 ) &&
1049 test_cmp expected "$actual"
1052 test_expect_success '__git_refs - only matching refs - checkout DWIMery' '
1053 cat >expected <<-EOF &&
1054 matching-branch
1055 matching/branch
1056 matching-tag
1057 matching/tag
1058 matching/branch-in-other
1060 for remote_ref in refs/remotes/other/ambiguous \
1061 refs/remotes/remote/ambiguous \
1062 refs/remotes/remote/branch-in-remote
1064 git update-ref $remote_ref main &&
1065 test_when_finished "git update-ref -d $remote_ref" || return 1
1066 done &&
1068 cur=mat &&
1069 __git_refs "" 1 "" "$cur" >"$actual"
1070 ) &&
1071 test_cmp expected "$actual"
1074 test_expect_success 'teardown after filtering matching refs' '
1075 git branch -d matching/branch &&
1076 git tag -d matching/tag &&
1077 git update-ref -d refs/remotes/other/matching/branch-in-other &&
1078 git -C otherrepo branch -D matching/branch-in-other
1081 test_expect_success '__git_refs - for-each-ref format specifiers in prefix' '
1082 cat >expected <<-EOF &&
1083 evil-%%-%42-%(refname)..main
1086 cur="evil-%%-%42-%(refname)..mai" &&
1087 __git_refs "" "" "evil-%%-%42-%(refname).." mai >"$actual"
1088 ) &&
1089 test_cmp expected "$actual"
1092 test_expect_success '__git_complete_refs - simple' '
1093 sed -e "s/Z$//" >expected <<-EOF &&
1094 HEAD Z
1095 main Z
1096 matching-branch Z
1097 other/branch-in-other Z
1098 other/main-in-other Z
1099 matching-tag Z
1102 cur= &&
1103 __git_complete_refs &&
1104 print_comp
1105 ) &&
1106 test_cmp expected out
1109 test_expect_success '__git_complete_refs - matching' '
1110 sed -e "s/Z$//" >expected <<-EOF &&
1111 matching-branch Z
1112 matching-tag Z
1115 cur=mat &&
1116 __git_complete_refs &&
1117 print_comp
1118 ) &&
1119 test_cmp expected out
1122 test_expect_success '__git_complete_refs - remote' '
1123 sed -e "s/Z$//" >expected <<-EOF &&
1124 HEAD Z
1125 branch-in-other Z
1126 main-in-other Z
1129 cur= &&
1130 __git_complete_refs --remote=other &&
1131 print_comp
1132 ) &&
1133 test_cmp expected out
1136 test_expect_success '__git_complete_refs - track' '
1137 sed -e "s/Z$//" >expected <<-EOF &&
1138 HEAD Z
1139 main Z
1140 matching-branch Z
1141 other/branch-in-other Z
1142 other/main-in-other Z
1143 matching-tag Z
1144 branch-in-other Z
1145 main-in-other Z
1148 cur= &&
1149 __git_complete_refs --track &&
1150 print_comp
1151 ) &&
1152 test_cmp expected out
1155 test_expect_success '__git_complete_refs - current word' '
1156 sed -e "s/Z$//" >expected <<-EOF &&
1157 matching-branch Z
1158 matching-tag Z
1161 cur="--option=mat" &&
1162 __git_complete_refs --cur="${cur#*=}" &&
1163 print_comp
1164 ) &&
1165 test_cmp expected out
1168 test_expect_success '__git_complete_refs - prefix' '
1169 sed -e "s/Z$//" >expected <<-EOF &&
1170 v1.0..matching-branch Z
1171 v1.0..matching-tag Z
1174 cur=v1.0..mat &&
1175 __git_complete_refs --pfx=v1.0.. --cur=mat &&
1176 print_comp
1177 ) &&
1178 test_cmp expected out
1181 test_expect_success '__git_complete_refs - suffix' '
1182 cat >expected <<-EOF &&
1183 HEAD.
1184 main.
1185 matching-branch.
1186 other/branch-in-other.
1187 other/main-in-other.
1188 matching-tag.
1191 cur= &&
1192 __git_complete_refs --sfx=. &&
1193 print_comp
1194 ) &&
1195 test_cmp expected out
1198 test_expect_success '__git_complete_fetch_refspecs - simple' '
1199 sed -e "s/Z$//" >expected <<-EOF &&
1200 HEAD:HEAD Z
1201 branch-in-other:branch-in-other Z
1202 main-in-other:main-in-other Z
1205 cur= &&
1206 __git_complete_fetch_refspecs other &&
1207 print_comp
1208 ) &&
1209 test_cmp expected out
1212 test_expect_success '__git_complete_fetch_refspecs - matching' '
1213 sed -e "s/Z$//" >expected <<-EOF &&
1214 branch-in-other:branch-in-other Z
1217 cur=br &&
1218 __git_complete_fetch_refspecs other "" br &&
1219 print_comp
1220 ) &&
1221 test_cmp expected out
1224 test_expect_success '__git_complete_fetch_refspecs - prefix' '
1225 sed -e "s/Z$//" >expected <<-EOF &&
1226 +HEAD:HEAD Z
1227 +branch-in-other:branch-in-other Z
1228 +main-in-other:main-in-other Z
1231 cur="+" &&
1232 __git_complete_fetch_refspecs other "+" "" &&
1233 print_comp
1234 ) &&
1235 test_cmp expected out
1238 test_expect_success '__git_complete_fetch_refspecs - fully qualified' '
1239 sed -e "s/Z$//" >expected <<-EOF &&
1240 refs/heads/branch-in-other:refs/heads/branch-in-other Z
1241 refs/heads/main-in-other:refs/heads/main-in-other Z
1242 refs/tags/tag-in-other:refs/tags/tag-in-other Z
1245 cur=refs/ &&
1246 __git_complete_fetch_refspecs other "" refs/ &&
1247 print_comp
1248 ) &&
1249 test_cmp expected out
1252 test_expect_success '__git_complete_fetch_refspecs - fully qualified & prefix' '
1253 sed -e "s/Z$//" >expected <<-EOF &&
1254 +refs/heads/branch-in-other:refs/heads/branch-in-other Z
1255 +refs/heads/main-in-other:refs/heads/main-in-other Z
1256 +refs/tags/tag-in-other:refs/tags/tag-in-other Z
1259 cur=+refs/ &&
1260 __git_complete_fetch_refspecs other + refs/ &&
1261 print_comp
1262 ) &&
1263 test_cmp expected out
1266 test_expect_success 'git switch - with no options, complete local branches and unique remote branch names for DWIM logic' '
1267 test_completion "git switch " <<-\EOF
1268 branch-in-other Z
1269 main Z
1270 main-in-other Z
1271 matching-branch Z
1275 test_expect_success 'git bisect - when not bisecting, complete only replay and start subcommands' '
1276 test_completion "git bisect " <<-\EOF
1277 replay Z
1278 start Z
1282 test_expect_success 'git bisect - complete options to start subcommand' '
1283 test_completion "git bisect start --" <<-\EOF
1284 --term-new Z
1285 --term-bad Z
1286 --term-old Z
1287 --term-good Z
1288 --no-checkout Z
1289 --first-parent Z
1293 test_expect_success 'setup for git-bisect tests requiring a repo' '
1294 git init git-bisect &&
1296 cd git-bisect &&
1297 echo "initial contents" >file &&
1298 git add file &&
1299 git commit -am "Initial commit" &&
1300 git tag initial &&
1301 echo "new line" >>file &&
1302 git commit -am "First change" &&
1303 echo "another new line" >>file &&
1304 git commit -am "Second change" &&
1305 git tag final
1309 test_expect_success 'git bisect - start subcommand arguments before double-dash are completed as revs' '
1311 cd git-bisect &&
1312 test_completion "git bisect start " <<-\EOF
1313 HEAD Z
1314 final Z
1315 initial Z
1316 master Z
1321 # Note that these arguments are <pathspec>s, which in practice the fallback
1322 # completion (not the git completion) later ends up completing as paths.
1323 test_expect_success 'git bisect - start subcommand arguments after double-dash are not completed' '
1325 cd git-bisect &&
1326 test_completion "git bisect start final initial -- " ""
1330 test_expect_success 'setup for git-bisect tests requiring ongoing bisection' '
1332 cd git-bisect &&
1333 git bisect start --term-new=custom_new --term-old=custom_old final initial
1337 test_expect_success 'git-bisect - when bisecting all subcommands are candidates' '
1339 cd git-bisect &&
1340 test_completion "git bisect " <<-\EOF
1341 start Z
1342 bad Z
1343 custom_new Z
1344 custom_old Z
1345 new Z
1346 good Z
1347 old Z
1348 terms Z
1349 skip Z
1350 reset Z
1351 visualize Z
1352 replay Z
1353 log Z
1354 run Z
1355 help Z
1360 test_expect_success 'git-bisect - options to terms subcommand are candidates' '
1362 cd git-bisect &&
1363 test_completion "git bisect terms --" <<-\EOF
1364 --term-bad Z
1365 --term-good Z
1366 --term-new Z
1367 --term-old Z
1372 test_expect_success 'git-bisect - git-log options to visualize subcommand are candidates' '
1374 cd git-bisect &&
1375 # The completion used for git-log and here does not complete
1376 # every git-log option, so rather than hope to stay in sync
1377 # with exactly what it does we will just spot-test here.
1378 test_completion "git bisect visualize --sta" <<-\EOF &&
1379 --stat Z
1381 test_completion "git bisect visualize --summar" <<-\EOF
1382 --summary Z
1387 test_expect_success 'git-bisect - view subcommand is not a candidate' '
1389 cd git-bisect &&
1390 test_completion "git bisect vi" <<-\EOF
1391 visualize Z
1396 test_expect_success 'git-bisect - existing view subcommand is recognized and enables completion of git-log options' '
1398 cd git-bisect &&
1399 # The completion used for git-log and here does not complete
1400 # every git-log option, so rather than hope to stay in sync
1401 # with exactly what it does we will just spot-test here.
1402 test_completion "git bisect view --sta" <<-\EOF &&
1403 --stat Z
1405 test_completion "git bisect view --summar" <<-\EOF
1406 --summary Z
1411 test_expect_success 'git checkout - completes refs and unique remote branches for DWIM' '
1412 test_completion "git checkout " <<-\EOF
1413 HEAD Z
1414 branch-in-other Z
1415 main Z
1416 main-in-other Z
1417 matching-branch Z
1418 matching-tag Z
1419 other/branch-in-other Z
1420 other/main-in-other Z
1424 test_expect_success 'git switch - with --no-guess, complete only local branches' '
1425 test_completion "git switch --no-guess " <<-\EOF
1426 main Z
1427 matching-branch Z
1431 test_expect_success 'git switch - with GIT_COMPLETION_CHECKOUT_NO_GUESS=1, complete only local branches' '
1432 GIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion "git switch " <<-\EOF
1433 main Z
1434 matching-branch Z
1438 test_expect_success 'git switch - --guess overrides GIT_COMPLETION_CHECKOUT_NO_GUESS=1, complete local branches and unique remote names for DWIM logic' '
1439 GIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion "git switch --guess " <<-\EOF
1440 branch-in-other Z
1441 main Z
1442 main-in-other Z
1443 matching-branch Z
1447 test_expect_success 'git switch - a later --guess overrides previous --no-guess, complete local and remote unique branches for DWIM' '
1448 test_completion "git switch --no-guess --guess " <<-\EOF
1449 branch-in-other Z
1450 main Z
1451 main-in-other Z
1452 matching-branch Z
1456 test_expect_success 'git switch - a later --no-guess overrides previous --guess, complete only local branches' '
1457 test_completion "git switch --guess --no-guess " <<-\EOF
1458 main Z
1459 matching-branch Z
1463 test_expect_success 'git checkout - with GIT_COMPLETION_NO_GUESS=1 only completes refs' '
1464 GIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion "git checkout " <<-\EOF
1465 HEAD Z
1466 main Z
1467 matching-branch Z
1468 matching-tag Z
1469 other/branch-in-other Z
1470 other/main-in-other Z
1474 test_expect_success 'git checkout - --guess overrides GIT_COMPLETION_NO_GUESS=1, complete refs and unique remote branches for DWIM' '
1475 GIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion "git checkout --guess " <<-\EOF
1476 HEAD Z
1477 branch-in-other Z
1478 main Z
1479 main-in-other Z
1480 matching-branch Z
1481 matching-tag Z
1482 other/branch-in-other Z
1483 other/main-in-other Z
1487 test_expect_success 'git checkout - with --no-guess, only completes refs' '
1488 test_completion "git checkout --no-guess " <<-\EOF
1489 HEAD Z
1490 main Z
1491 matching-branch Z
1492 matching-tag Z
1493 other/branch-in-other Z
1494 other/main-in-other Z
1498 test_expect_success 'git checkout - a later --guess overrides previous --no-guess, complete refs and unique remote branches for DWIM' '
1499 test_completion "git checkout --no-guess --guess " <<-\EOF
1500 HEAD Z
1501 branch-in-other Z
1502 main Z
1503 main-in-other Z
1504 matching-branch Z
1505 matching-tag Z
1506 other/branch-in-other Z
1507 other/main-in-other Z
1511 test_expect_success 'git checkout - a later --no-guess overrides previous --guess, complete only refs' '
1512 test_completion "git checkout --guess --no-guess " <<-\EOF
1513 HEAD Z
1514 main Z
1515 matching-branch Z
1516 matching-tag Z
1517 other/branch-in-other Z
1518 other/main-in-other Z
1522 test_expect_success 'git checkout - with checkout.guess = false, only completes refs' '
1523 test_config checkout.guess false &&
1524 test_completion "git checkout " <<-\EOF
1525 HEAD Z
1526 main Z
1527 matching-branch Z
1528 matching-tag Z
1529 other/branch-in-other Z
1530 other/main-in-other Z
1534 test_expect_success 'git checkout - with checkout.guess = true, completes refs and unique remote branches for DWIM' '
1535 test_config checkout.guess true &&
1536 test_completion "git checkout " <<-\EOF
1537 HEAD Z
1538 branch-in-other Z
1539 main Z
1540 main-in-other Z
1541 matching-branch Z
1542 matching-tag Z
1543 other/branch-in-other Z
1544 other/main-in-other Z
1548 test_expect_success 'git checkout - a later --guess overrides previous checkout.guess = false, complete refs and unique remote branches for DWIM' '
1549 test_config checkout.guess false &&
1550 test_completion "git checkout --guess " <<-\EOF
1551 HEAD Z
1552 branch-in-other Z
1553 main Z
1554 main-in-other Z
1555 matching-branch Z
1556 matching-tag Z
1557 other/branch-in-other Z
1558 other/main-in-other Z
1562 test_expect_success 'git checkout - a later --no-guess overrides previous checkout.guess = true, complete only refs' '
1563 test_config checkout.guess true &&
1564 test_completion "git checkout --no-guess " <<-\EOF
1565 HEAD Z
1566 main Z
1567 matching-branch Z
1568 matching-tag Z
1569 other/branch-in-other Z
1570 other/main-in-other Z
1574 test_expect_success 'git switch - with --detach, complete all references' '
1575 test_completion "git switch --detach " <<-\EOF
1576 HEAD Z
1577 main Z
1578 matching-branch Z
1579 matching-tag Z
1580 other/branch-in-other Z
1581 other/main-in-other Z
1585 test_expect_success 'git checkout - with --detach, complete only references' '
1586 test_completion "git checkout --detach " <<-\EOF
1587 HEAD Z
1588 main Z
1589 matching-branch Z
1590 matching-tag Z
1591 other/branch-in-other Z
1592 other/main-in-other Z
1596 test_expect_success 'setup sparse-checkout tests' '
1597 # set up sparse-checkout repo
1598 git init sparse-checkout &&
1600 cd sparse-checkout &&
1601 mkdir -p folder1/0/1 folder2/0 folder3 &&
1602 touch folder1/0/1/t.txt &&
1603 touch folder2/0/t.txt &&
1604 touch folder3/t.txt &&
1605 git add . &&
1606 git commit -am "Initial commit"
1610 test_expect_success 'sparse-checkout completes subcommands' '
1611 test_completion "git sparse-checkout " <<-\EOF
1612 list Z
1613 init Z
1614 set Z
1615 add Z
1616 reapply Z
1617 disable Z
1621 test_expect_success 'cone mode sparse-checkout completes directory names' '
1622 # initialize sparse-checkout definitions
1623 git -C sparse-checkout sparse-checkout set --cone folder1/0 folder3 &&
1625 # test tab completion
1627 cd sparse-checkout &&
1628 test_completion "git sparse-checkout set f" <<-\EOF
1629 folder1/
1630 folder2/
1631 folder3/
1633 ) &&
1636 cd sparse-checkout &&
1637 test_completion "git sparse-checkout set folder1/" <<-\EOF
1638 folder1/0/
1640 ) &&
1643 cd sparse-checkout &&
1644 test_completion "git sparse-checkout set folder1/0/" <<-\EOF
1645 folder1/0/1/
1647 ) &&
1650 cd sparse-checkout/folder1 &&
1651 test_completion "git sparse-checkout add 0" <<-\EOF
1657 test_expect_success 'cone mode sparse-checkout completes directory names with spaces and accents' '
1658 # reset sparse-checkout
1659 git -C sparse-checkout sparse-checkout disable &&
1661 cd sparse-checkout &&
1662 mkdir "directory with spaces" &&
1663 mkdir "directory-with-áccent" &&
1664 >"directory with spaces/randomfile" &&
1665 >"directory-with-áccent/randomfile" &&
1666 git add . &&
1667 git commit -m "Add directory with spaces and directory with accent" &&
1668 git sparse-checkout set --cone "directory with spaces" \
1669 "directory-with-áccent" &&
1670 test_completion "git sparse-checkout add dir" <<-\EOF &&
1671 directory with spaces/
1672 directory-with-áccent/
1674 rm -rf "directory with spaces" &&
1675 rm -rf "directory-with-áccent" &&
1676 git add . &&
1677 git commit -m "Remove directory with spaces and directory with accent"
1681 # use FUNNYNAMES to avoid running on Windows, which doesn't permit tabs in paths
1682 test_expect_success FUNNYNAMES 'cone mode sparse-checkout completes directory names with tabs' '
1683 # reset sparse-checkout
1684 git -C sparse-checkout sparse-checkout disable &&
1686 cd sparse-checkout &&
1687 mkdir "$(printf "directory\twith\ttabs")" &&
1688 >"$(printf "directory\twith\ttabs")/randomfile" &&
1689 git add . &&
1690 git commit -m "Add directory with tabs" &&
1691 git sparse-checkout set --cone \
1692 "$(printf "directory\twith\ttabs")" &&
1693 test_completion "git sparse-checkout add dir" <<-\EOF &&
1694 directory with tabs/
1696 rm -rf "$(printf "directory\twith\ttabs")" &&
1697 git add . &&
1698 git commit -m "Remove directory with tabs"
1702 # use FUNNYNAMES to avoid running on Windows, and !CYGWIN for Cygwin, as neither permit backslashes in paths
1703 test_expect_success FUNNYNAMES,!CYGWIN 'cone mode sparse-checkout completes directory names with backslashes' '
1704 # reset sparse-checkout
1705 git -C sparse-checkout sparse-checkout disable &&
1707 cd sparse-checkout &&
1708 mkdir "directory\with\backslashes" &&
1709 >"directory\with\backslashes/randomfile" &&
1710 git add . &&
1711 git commit -m "Add directory with backslashes" &&
1712 git sparse-checkout set --cone \
1713 "directory\with\backslashes" &&
1714 test_completion "git sparse-checkout add dir" <<-\EOF &&
1715 directory\with\backslashes/
1717 rm -rf "directory\with\backslashes" &&
1718 git add . &&
1719 git commit -m "Remove directory with backslashes"
1723 test_expect_success 'non-cone mode sparse-checkout gives rooted paths' '
1724 # reset sparse-checkout repo to non-cone mode
1725 git -C sparse-checkout sparse-checkout disable &&
1726 git -C sparse-checkout sparse-checkout set --no-cone &&
1729 cd sparse-checkout &&
1730 # expected to be empty since we have not configured
1731 # custom completion for non-cone mode
1732 test_completion "git sparse-checkout set f" <<-\EOF
1733 /folder1/0/1/t.txt Z
1734 /folder1/expected Z
1735 /folder1/out Z
1736 /folder1/out_sorted Z
1737 /folder2/0/t.txt Z
1738 /folder3/t.txt Z
1743 test_expect_success 'git sparse-checkout set --cone completes directory names' '
1744 git -C sparse-checkout sparse-checkout disable &&
1747 cd sparse-checkout &&
1748 test_completion "git sparse-checkout set --cone f" <<-\EOF
1749 folder1/
1750 folder2/
1751 folder3/
1756 test_expect_success 'git switch - with -d, complete all references' '
1757 test_completion "git switch -d " <<-\EOF
1758 HEAD Z
1759 main Z
1760 matching-branch Z
1761 matching-tag Z
1762 other/branch-in-other Z
1763 other/main-in-other Z
1767 test_expect_success 'git checkout - with -d, complete only references' '
1768 test_completion "git checkout -d " <<-\EOF
1769 HEAD Z
1770 main Z
1771 matching-branch Z
1772 matching-tag Z
1773 other/branch-in-other Z
1774 other/main-in-other Z
1778 test_expect_success 'git switch - with --track, complete only remote branches' '
1779 test_completion "git switch --track " <<-\EOF &&
1780 other/branch-in-other Z
1781 other/main-in-other Z
1783 test_completion "git switch -t " <<-\EOF
1784 other/branch-in-other Z
1785 other/main-in-other Z
1789 test_expect_success 'git checkout - with --track, complete only remote branches' '
1790 test_completion "git checkout --track " <<-\EOF &&
1791 other/branch-in-other Z
1792 other/main-in-other Z
1794 test_completion "git checkout -t " <<-\EOF
1795 other/branch-in-other Z
1796 other/main-in-other Z
1800 test_expect_success 'git switch - with --no-track, complete only local branch names' '
1801 test_completion "git switch --no-track " <<-\EOF
1802 main Z
1803 matching-branch Z
1807 test_expect_success 'git checkout - with --no-track, complete only local references' '
1808 test_completion "git checkout --no-track " <<-\EOF
1809 HEAD Z
1810 main Z
1811 matching-branch Z
1812 matching-tag Z
1813 other/branch-in-other Z
1814 other/main-in-other Z
1818 test_expect_success 'git switch - with -c, complete all references' '
1819 test_completion "git switch -c new-branch " <<-\EOF
1820 HEAD Z
1821 main Z
1822 matching-branch Z
1823 matching-tag Z
1824 other/branch-in-other Z
1825 other/main-in-other Z
1829 test_expect_success 'git switch - with -C, complete all references' '
1830 test_completion "git switch -C new-branch " <<-\EOF
1831 HEAD Z
1832 main Z
1833 matching-branch Z
1834 matching-tag Z
1835 other/branch-in-other Z
1836 other/main-in-other Z
1840 test_expect_success 'git switch - with -c and --track, complete all references' '
1841 test_completion "git switch -c new-branch --track " <<-EOF
1842 HEAD Z
1843 main Z
1844 matching-branch Z
1845 matching-tag Z
1846 other/branch-in-other Z
1847 other/main-in-other Z
1851 test_expect_success 'git switch - with -C and --track, complete all references' '
1852 test_completion "git switch -C new-branch --track " <<-EOF
1853 HEAD Z
1854 main Z
1855 matching-branch Z
1856 matching-tag Z
1857 other/branch-in-other Z
1858 other/main-in-other Z
1862 test_expect_success 'git switch - with -c and --no-track, complete all references' '
1863 test_completion "git switch -c new-branch --no-track " <<-\EOF
1864 HEAD Z
1865 main Z
1866 matching-branch Z
1867 matching-tag Z
1868 other/branch-in-other Z
1869 other/main-in-other Z
1873 test_expect_success 'git switch - with -C and --no-track, complete all references' '
1874 test_completion "git switch -C new-branch --no-track " <<-\EOF
1875 HEAD Z
1876 main Z
1877 matching-branch Z
1878 matching-tag Z
1879 other/branch-in-other Z
1880 other/main-in-other Z
1884 test_expect_success 'git checkout - with -b, complete all references' '
1885 test_completion "git checkout -b new-branch " <<-\EOF
1886 HEAD Z
1887 main Z
1888 matching-branch Z
1889 matching-tag Z
1890 other/branch-in-other Z
1891 other/main-in-other Z
1895 test_expect_success 'git checkout - with -B, complete all references' '
1896 test_completion "git checkout -B new-branch " <<-\EOF
1897 HEAD Z
1898 main Z
1899 matching-branch Z
1900 matching-tag Z
1901 other/branch-in-other Z
1902 other/main-in-other Z
1906 test_expect_success 'git checkout - with -b and --track, complete all references' '
1907 test_completion "git checkout -b new-branch --track " <<-EOF
1908 HEAD Z
1909 main Z
1910 matching-branch Z
1911 matching-tag Z
1912 other/branch-in-other Z
1913 other/main-in-other Z
1917 test_expect_success 'git checkout - with -B and --track, complete all references' '
1918 test_completion "git checkout -B new-branch --track " <<-EOF
1919 HEAD Z
1920 main Z
1921 matching-branch Z
1922 matching-tag Z
1923 other/branch-in-other Z
1924 other/main-in-other Z
1928 test_expect_success 'git checkout - with -b and --no-track, complete all references' '
1929 test_completion "git checkout -b new-branch --no-track " <<-\EOF
1930 HEAD Z
1931 main Z
1932 matching-branch Z
1933 matching-tag Z
1934 other/branch-in-other Z
1935 other/main-in-other Z
1939 test_expect_success 'git checkout - with -B and --no-track, complete all references' '
1940 test_completion "git checkout -B new-branch --no-track " <<-\EOF
1941 HEAD Z
1942 main Z
1943 matching-branch Z
1944 matching-tag Z
1945 other/branch-in-other Z
1946 other/main-in-other Z
1950 test_expect_success 'git switch - for -c, complete local branches and unique remote branches' '
1951 test_completion "git switch -c " <<-\EOF
1952 branch-in-other Z
1953 main Z
1954 main-in-other Z
1955 matching-branch Z
1959 test_expect_success 'git switch - for -C, complete local branches and unique remote branches' '
1960 test_completion "git switch -C " <<-\EOF
1961 branch-in-other Z
1962 main Z
1963 main-in-other Z
1964 matching-branch Z
1968 test_expect_success 'git switch - for -c with --no-guess, complete local branches only' '
1969 test_completion "git switch --no-guess -c " <<-\EOF
1970 main Z
1971 matching-branch Z
1975 test_expect_success 'git switch - for -C with --no-guess, complete local branches only' '
1976 test_completion "git switch --no-guess -C " <<-\EOF
1977 main Z
1978 matching-branch Z
1982 test_expect_success 'git switch - for -c with --no-track, complete local branches only' '
1983 test_completion "git switch --no-track -c " <<-\EOF
1984 main Z
1985 matching-branch Z
1989 test_expect_success 'git switch - for -C with --no-track, complete local branches only' '
1990 test_completion "git switch --no-track -C " <<-\EOF
1991 main Z
1992 matching-branch Z
1996 test_expect_success 'git checkout - for -b, complete local branches and unique remote branches' '
1997 test_completion "git checkout -b " <<-\EOF
1998 branch-in-other Z
1999 main Z
2000 main-in-other Z
2001 matching-branch Z
2005 test_expect_success 'git checkout - for -B, complete local branches and unique remote branches' '
2006 test_completion "git checkout -B " <<-\EOF
2007 branch-in-other Z
2008 main Z
2009 main-in-other Z
2010 matching-branch Z
2014 test_expect_success 'git checkout - for -b with --no-guess, complete local branches only' '
2015 test_completion "git checkout --no-guess -b " <<-\EOF
2016 main Z
2017 matching-branch Z
2021 test_expect_success 'git checkout - for -B with --no-guess, complete local branches only' '
2022 test_completion "git checkout --no-guess -B " <<-\EOF
2023 main Z
2024 matching-branch Z
2028 test_expect_success 'git checkout - for -b with --no-track, complete local branches only' '
2029 test_completion "git checkout --no-track -b " <<-\EOF
2030 main Z
2031 matching-branch Z
2035 test_expect_success 'git checkout - for -B with --no-track, complete local branches only' '
2036 test_completion "git checkout --no-track -B " <<-\EOF
2037 main Z
2038 matching-branch Z
2042 test_expect_success 'git switch - with --orphan completes local branch names and unique remote branch names' '
2043 test_completion "git switch --orphan " <<-\EOF
2044 branch-in-other Z
2045 main Z
2046 main-in-other Z
2047 matching-branch Z
2051 test_expect_success 'git switch - --orphan with branch already provided completes nothing else' '
2052 test_completion "git switch --orphan main " <<-\EOF
2057 test_expect_success 'git checkout - with --orphan completes local branch names and unique remote branch names' '
2058 test_completion "git checkout --orphan " <<-\EOF
2059 branch-in-other Z
2060 main Z
2061 main-in-other Z
2062 matching-branch Z
2066 test_expect_success 'git checkout - --orphan with branch already provided completes local refs for a start-point' '
2067 test_completion "git checkout --orphan main " <<-\EOF
2068 HEAD Z
2069 main Z
2070 matching-branch Z
2071 matching-tag Z
2072 other/branch-in-other Z
2073 other/main-in-other Z
2077 test_expect_success 'git restore completes modified files' '
2078 test_commit A a.file &&
2079 echo B >a.file &&
2080 test_completion "git restore a." <<-\EOF
2081 a.file
2085 test_expect_success 'teardown after ref completion' '
2086 git branch -d matching-branch &&
2087 git tag -d matching-tag &&
2088 git remote remove other
2092 test_path_completion ()
2094 test $# = 2 || BUG "not 2 parameters to test_path_completion"
2096 local cur="$1" expected="$2"
2097 echo "$expected" >expected &&
2099 # In the following tests calling this function we only
2100 # care about how __git_complete_index_file() deals with
2101 # unusual characters in path names. By requesting only
2102 # untracked files we do not have to bother adding any
2103 # paths to the index in those tests.
2104 __git_complete_index_file --others &&
2105 print_comp
2106 ) &&
2107 test_cmp expected out
2110 test_expect_success 'setup for path completion tests' '
2111 mkdir simple-dir \
2112 "spaces in dir" \
2113 árvíztűrő &&
2114 touch simple-dir/simple-file \
2115 "spaces in dir/spaces in file" \
2116 "árvíztűrő/Сайн яваарай" &&
2117 if test_have_prereq !MINGW &&
2118 mkdir BS\\dir \
2119 '$'separators\034in\035dir'' &&
2120 touch BS\\dir/DQ\"file \
2121 '$'separators\034in\035dir/sep\036in\037file''
2122 then
2123 test_set_prereq FUNNIERNAMES
2124 else
2125 rm -rf BS\\dir '$'separators\034in\035dir''
2129 test_expect_success '__git_complete_index_file - simple' '
2130 test_path_completion simple simple-dir && # Bash is supposed to
2131 # add the trailing /.
2132 test_path_completion simple-dir/simple simple-dir/simple-file
2135 test_expect_success \
2136 '__git_complete_index_file - escaped characters on cmdline' '
2137 test_path_completion spac "spaces in dir" && # Bash will turn this
2138 # into "spaces\ in\ dir"
2139 test_path_completion "spaces\\ i" \
2140 "spaces in dir" &&
2141 test_path_completion "spaces\\ in\\ dir/s" \
2142 "spaces in dir/spaces in file" &&
2143 test_path_completion "spaces\\ in\\ dir/spaces\\ i" \
2144 "spaces in dir/spaces in file"
2147 test_expect_success \
2148 '__git_complete_index_file - quoted characters on cmdline' '
2149 # Testing with an opening but without a corresponding closing
2150 # double quote is important.
2151 test_path_completion \"spac "spaces in dir" &&
2152 test_path_completion "\"spaces i" \
2153 "spaces in dir" &&
2154 test_path_completion "\"spaces in dir/s" \
2155 "spaces in dir/spaces in file" &&
2156 test_path_completion "\"spaces in dir/spaces i" \
2157 "spaces in dir/spaces in file"
2160 test_expect_success '__git_complete_index_file - UTF-8 in ls-files output' '
2161 test_path_completion á árvíztűrő &&
2162 test_path_completion árvíztűrő/С "árvíztűrő/Сайн яваарай"
2165 test_expect_success FUNNIERNAMES \
2166 '__git_complete_index_file - C-style escapes in ls-files output' '
2167 test_path_completion BS \
2168 BS\\dir &&
2169 test_path_completion BS\\\\d \
2170 BS\\dir &&
2171 test_path_completion BS\\\\dir/DQ \
2172 BS\\dir/DQ\"file &&
2173 test_path_completion BS\\\\dir/DQ\\\"f \
2174 BS\\dir/DQ\"file
2177 test_expect_success FUNNIERNAMES \
2178 '__git_complete_index_file - \nnn-escaped characters in ls-files output' '
2179 test_path_completion sep '$'separators\034in\035dir'' &&
2180 test_path_completion '$'separators\034i'' \
2181 '$'separators\034in\035dir'' &&
2182 test_path_completion '$'separators\034in\035dir/sep'' \
2183 '$'separators\034in\035dir/sep\036in\037file'' &&
2184 test_path_completion '$'separators\034in\035dir/sep\036i'' \
2185 '$'separators\034in\035dir/sep\036in\037file''
2188 test_expect_success FUNNYNAMES \
2189 '__git_complete_index_file - removing repeated quoted path components' '
2190 test_when_finished rm -r repeated-quoted &&
2191 mkdir repeated-quoted && # A directory whose name in itself
2192 # would not be quoted ...
2193 >repeated-quoted/0-file &&
2194 >repeated-quoted/1\"file && # ... but here the file makes the
2195 # dirname quoted ...
2196 >repeated-quoted/2-file &&
2197 >repeated-quoted/3\"file && # ... and here, too.
2199 # Still, we shold only list the directory name only once.
2200 test_path_completion repeated repeated-quoted
2203 test_expect_success 'teardown after path completion tests' '
2204 rm -rf simple-dir "spaces in dir" árvíztűrő \
2205 BS\\dir '$'separators\034in\035dir''
2208 test_expect_success '__git_find_on_cmdline - single match' '
2209 echo list >expect &&
2211 words=(git command --opt list) &&
2212 cword=${#words[@]} &&
2213 __git_cmd_idx=1 &&
2214 __git_find_on_cmdline "add list remove" >actual
2215 ) &&
2216 test_cmp expect actual
2219 test_expect_success '__git_find_on_cmdline - multiple matches' '
2220 echo remove >expect &&
2222 words=(git command -o --opt remove list add) &&
2223 cword=${#words[@]} &&
2224 __git_cmd_idx=1 &&
2225 __git_find_on_cmdline "add list remove" >actual
2226 ) &&
2227 test_cmp expect actual
2230 test_expect_success '__git_find_on_cmdline - no match' '
2232 words=(git command --opt branch) &&
2233 cword=${#words[@]} &&
2234 __git_cmd_idx=1 &&
2235 __git_find_on_cmdline "add list remove" >actual
2236 ) &&
2237 test_must_be_empty actual
2240 test_expect_success '__git_find_on_cmdline - single match with index' '
2241 echo "3 list" >expect &&
2243 words=(git command --opt list) &&
2244 cword=${#words[@]} &&
2245 __git_cmd_idx=1 &&
2246 __git_find_on_cmdline --show-idx "add list remove" >actual
2247 ) &&
2248 test_cmp expect actual
2251 test_expect_success '__git_find_on_cmdline - multiple matches with index' '
2252 echo "4 remove" >expect &&
2254 words=(git command -o --opt remove list add) &&
2255 cword=${#words[@]} &&
2256 __git_cmd_idx=1 &&
2257 __git_find_on_cmdline --show-idx "add list remove" >actual
2258 ) &&
2259 test_cmp expect actual
2262 test_expect_success '__git_find_on_cmdline - no match with index' '
2264 words=(git command --opt branch) &&
2265 cword=${#words[@]} &&
2266 __git_cmd_idx=1 &&
2267 __git_find_on_cmdline --show-idx "add list remove" >actual
2268 ) &&
2269 test_must_be_empty actual
2272 test_expect_success '__git_find_on_cmdline - ignores matches before command with index' '
2273 echo "6 remove" >expect &&
2275 words=(git -C remove command -o --opt remove list add) &&
2276 cword=${#words[@]} &&
2277 __git_cmd_idx=3 &&
2278 __git_find_on_cmdline --show-idx "add list remove" >actual
2279 ) &&
2280 test_cmp expect actual
2283 test_expect_success '__git_get_config_variables' '
2284 cat >expect <<-EOF &&
2285 name-1
2286 name-2
2288 test_config interesting.name-1 good &&
2289 test_config interesting.name-2 good &&
2290 test_config subsection.interesting.name-3 bad &&
2291 __git_get_config_variables interesting >actual &&
2292 test_cmp expect actual
2295 test_expect_success '__git_pretty_aliases' '
2296 cat >expect <<-EOF &&
2297 author
2298 hash
2300 test_config pretty.author "%an %ae" &&
2301 test_config pretty.hash %H &&
2302 __git_pretty_aliases >actual &&
2303 test_cmp expect actual
2306 test_expect_success 'basic' '
2307 run_completion "git " &&
2308 # built-in
2309 grep -q "^add \$" out &&
2310 # script
2311 grep -q "^rebase \$" out &&
2312 # plumbing
2313 ! grep -q "^ls-files \$" out &&
2315 run_completion "git r" &&
2316 ! grep -q -v "^r" out
2319 test_expect_success 'double dash "git" itself' '
2320 test_completion "git --" <<-\EOF
2321 --paginate Z
2322 --no-pager Z
2323 --git-dir=
2324 --bare Z
2325 --version Z
2326 --exec-path Z
2327 --exec-path=
2328 --html-path Z
2329 --man-path Z
2330 --info-path Z
2331 --work-tree=
2332 --namespace=
2333 --no-replace-objects Z
2334 --help Z
2338 test_expect_success 'double dash "git checkout"' '
2339 test_completion "git checkout --" <<-\EOF
2340 --quiet Z
2341 --detach Z
2342 --track Z
2343 --orphan=Z
2344 --ours Z
2345 --theirs Z
2346 --merge Z
2347 --conflict=Z
2348 --patch Z
2349 --ignore-skip-worktree-bits Z
2350 --ignore-other-worktrees Z
2351 --recurse-submodules Z
2352 --progress Z
2353 --guess Z
2354 --no-guess Z
2355 --no-... Z
2356 --overlay Z
2357 --pathspec-file-nul Z
2358 --pathspec-from-file=Z
2362 test_expect_success 'general options' '
2363 test_completion "git --ver" "--version " &&
2364 test_completion "git --hel" "--help " &&
2365 test_completion "git --exe" <<-\EOF &&
2366 --exec-path Z
2367 --exec-path=
2369 test_completion "git --htm" "--html-path " &&
2370 test_completion "git --pag" "--paginate " &&
2371 test_completion "git --no-p" "--no-pager " &&
2372 test_completion "git --git" "--git-dir=" &&
2373 test_completion "git --wor" "--work-tree=" &&
2374 test_completion "git --nam" "--namespace=" &&
2375 test_completion "git --bar" "--bare " &&
2376 test_completion "git --inf" "--info-path " &&
2377 test_completion "git --no-r" "--no-replace-objects "
2380 test_expect_success 'general options plus command' '
2381 test_completion "git --version check" "checkout " &&
2382 test_completion "git --paginate check" "checkout " &&
2383 test_completion "git --git-dir=foo check" "checkout " &&
2384 test_completion "git --bare check" "checkout " &&
2385 test_completion "git --exec-path=foo check" "checkout " &&
2386 test_completion "git --html-path check" "checkout " &&
2387 test_completion "git --no-pager check" "checkout " &&
2388 test_completion "git --work-tree=foo check" "checkout " &&
2389 test_completion "git --namespace=foo check" "checkout " &&
2390 test_completion "git --paginate check" "checkout " &&
2391 test_completion "git --info-path check" "checkout " &&
2392 test_completion "git --no-replace-objects check" "checkout " &&
2393 test_completion "git --git-dir some/path check" "checkout " &&
2394 test_completion "git -c conf.var=value check" "checkout " &&
2395 test_completion "git -C some/path check" "checkout " &&
2396 test_completion "git --work-tree some/path check" "checkout " &&
2397 test_completion "git --namespace name/space check" "checkout "
2400 test_expect_success 'git --help completion' '
2401 test_completion "git --help ad" "add " &&
2402 test_completion "git --help core" "core-tutorial "
2405 test_expect_success 'completion.commands removes multiple commands' '
2406 test_config completion.commands "-cherry -mergetool" &&
2407 git --list-cmds=list-mainporcelain,list-complete,config >out &&
2408 ! grep -E "^(cherry|mergetool)$" out
2411 test_expect_success 'setup for integration tests' '
2412 echo content >file1 &&
2413 echo more >file2 &&
2414 git add file1 file2 &&
2415 git commit -m one &&
2416 git branch mybranch &&
2417 git tag mytag
2420 test_expect_success 'checkout completes ref names' '
2421 test_completion "git checkout m" <<-\EOF
2422 main Z
2423 mybranch Z
2424 mytag Z
2428 test_expect_success 'checkout does not match ref names of a different case' '
2429 test_completion "git checkout M" ""
2432 test_expect_success 'checkout matches case insensitively with GIT_COMPLETION_IGNORE_CASE' '
2434 GIT_COMPLETION_IGNORE_CASE=1 &&
2435 test_completion "git checkout M" <<-\EOF
2436 main Z
2437 mybranch Z
2438 mytag Z
2443 test_expect_success 'checkout completes pseudo refs' '
2444 test_completion "git checkout H" <<-\EOF
2445 HEAD Z
2449 test_expect_success 'checkout completes pseudo refs case insensitively with GIT_COMPLETION_IGNORE_CASE' '
2451 GIT_COMPLETION_IGNORE_CASE=1 &&
2452 test_completion "git checkout h" <<-\EOF
2453 HEAD Z
2458 test_expect_success 'git -C <path> checkout uses the right repo' '
2459 test_completion "git -C subdir -C subsubdir -C .. -C ../otherrepo checkout b" <<-\EOF
2460 branch-in-other Z
2464 test_expect_success 'show completes all refs' '
2465 test_completion "git show m" <<-\EOF
2466 main Z
2467 mybranch Z
2468 mytag Z
2472 test_expect_success '<ref>: completes paths' '
2473 test_completion "git show mytag:f" <<-\EOF
2474 file1Z
2475 file2Z
2479 test_expect_success 'complete tree filename with spaces' '
2480 echo content >"name with spaces" &&
2481 git add "name with spaces" &&
2482 git commit -m spaces &&
2483 test_completion "git show HEAD:nam" <<-\EOF
2484 name with spacesZ
2488 test_expect_success 'complete tree filename with metacharacters' '
2489 echo content >"name with \${meta}" &&
2490 git add "name with \${meta}" &&
2491 git commit -m meta &&
2492 test_completion "git show HEAD:nam" <<-\EOF
2493 name with ${meta}Z
2494 name with spacesZ
2498 test_expect_success 'symbolic-ref completes builtin options' '
2499 test_completion "git symbolic-ref --d" <<-\EOF
2500 --delete Z
2504 test_expect_success 'symbolic-ref completes short ref names' '
2505 test_completion "git symbolic-ref foo m" <<-\EOF
2506 main Z
2507 mybranch Z
2508 mytag Z
2512 test_expect_success 'symbolic-ref completes full ref names' '
2513 test_completion "git symbolic-ref foo refs/" <<-\EOF
2514 refs/heads/main Z
2515 refs/heads/mybranch Z
2516 refs/tags/mytag Z
2517 refs/tags/A Z
2521 test_expect_success PERL 'send-email' '
2522 test_completion "git send-email --cov" <<-\EOF &&
2523 --cover-from-description=Z
2524 --cover-letter Z
2526 test_completion "git send-email --val" <<-\EOF &&
2527 --validate Z
2529 test_completion "git send-email ma" "main "
2532 test_expect_success 'complete files' '
2533 git init tmp && cd tmp &&
2534 test_when_finished "cd .. && rm -rf tmp" &&
2536 echo "expected" > .gitignore &&
2537 echo "out" >> .gitignore &&
2538 echo "out_sorted" >> .gitignore &&
2540 git add .gitignore &&
2541 test_completion "git commit " ".gitignore" &&
2543 git commit -m ignore &&
2545 touch new &&
2546 test_completion "git add " "new" &&
2548 git add new &&
2549 git commit -a -m new &&
2550 test_completion "git add " "" &&
2552 git mv new modified &&
2553 echo modify > modified &&
2554 test_completion "git add " "modified" &&
2556 mkdir -p some/deep &&
2557 touch some/deep/path &&
2558 test_completion "git add some/" "some/deep" &&
2559 git clean -f some &&
2561 touch untracked &&
2563 : TODO .gitignore should not be here &&
2564 test_completion "git rm " <<-\EOF &&
2565 .gitignore
2566 modified
2569 test_completion "git clean " "untracked" &&
2571 : TODO .gitignore should not be here &&
2572 test_completion "git mv " <<-\EOF &&
2573 .gitignore
2574 modified
2577 mkdir dir &&
2578 touch dir/file-in-dir &&
2579 git add dir/file-in-dir &&
2580 git commit -m dir &&
2582 mkdir untracked-dir &&
2584 : TODO .gitignore should not be here &&
2585 test_completion "git mv modified " <<-\EOF &&
2586 .gitignore
2588 modified
2589 untracked
2590 untracked-dir
2593 test_completion "git commit " "modified" &&
2595 : TODO .gitignore should not be here &&
2596 test_completion "git ls-files " <<-\EOF &&
2597 .gitignore
2599 modified
2602 touch momified &&
2603 test_completion "git add mom" "momified"
2606 test_expect_success "simple alias" '
2607 test_config alias.co checkout &&
2608 test_completion "git co m" <<-\EOF
2609 main Z
2610 mybranch Z
2611 mytag Z
2615 test_expect_success "recursive alias" '
2616 test_config alias.co checkout &&
2617 test_config alias.cod "co --detached" &&
2618 test_completion "git cod m" <<-\EOF
2619 main Z
2620 mybranch Z
2621 mytag Z
2625 test_expect_success "completion uses <cmd> completion for alias: !sh -c 'git <cmd> ...'" '
2626 test_config alias.co "!sh -c '"'"'git checkout ...'"'"'" &&
2627 test_completion "git co m" <<-\EOF
2628 main Z
2629 mybranch Z
2630 mytag Z
2634 test_expect_success 'completion uses <cmd> completion for alias: !f () { VAR=val git <cmd> ... }' '
2635 test_config alias.co "!f () { VAR=val git checkout ... ; } f" &&
2636 test_completion "git co m" <<-\EOF
2637 main Z
2638 mybranch Z
2639 mytag Z
2643 test_expect_success 'completion used <cmd> completion for alias: !f() { : git <cmd> ; ... }' '
2644 test_config alias.co "!f() { : git checkout ; if ... } f" &&
2645 test_completion "git co m" <<-\EOF
2646 main Z
2647 mybranch Z
2648 mytag Z
2652 test_expect_success 'completion used <cmd> completion for alias: !f() { : <cmd> ; ... }' '
2653 test_config alias.co "!f() { : checkout ; if ... } f" &&
2654 test_completion "git co m" <<-\EOF
2655 main Z
2656 mybranch Z
2657 mytag Z
2661 test_expect_success 'completion used <cmd> completion for alias: !f() { : <cmd>; ... }' '
2662 test_config alias.co "!f() { : checkout; if ... } f" &&
2663 test_completion "git co m" <<-\EOF
2664 main Z
2665 mybranch Z
2666 mytag Z
2670 test_expect_success 'completion without explicit _git_xxx function' '
2671 test_completion "git version --" <<-\EOF
2672 --build-options Z
2673 --no-build-options Z
2677 test_expect_failure 'complete with tilde expansion' '
2678 git init tmp && cd tmp &&
2679 test_when_finished "cd .. && rm -rf tmp" &&
2681 touch ~/tmp/file &&
2683 test_completion "git add ~/tmp/" "~/tmp/file"
2686 test_expect_success 'setup other remote for remote reference completion' '
2687 git remote add other otherrepo &&
2688 git fetch other
2691 for flag in -d --delete
2693 test_expect_success "__git_complete_remote_or_refspec - push $flag other" '
2694 sed -e "s/Z$//" >expected <<-EOF &&
2695 main-in-other Z
2698 words=(git push '$flag' other ma) &&
2699 cword=${#words[@]} cur=${words[cword-1]} &&
2700 __git_cmd_idx=1 &&
2701 __git_complete_remote_or_refspec &&
2702 print_comp
2703 ) &&
2704 test_cmp expected out
2707 test_expect_failure "__git_complete_remote_or_refspec - push other $flag" '
2708 sed -e "s/Z$//" >expected <<-EOF &&
2709 main-in-other Z
2712 words=(git push other '$flag' ma) &&
2713 cword=${#words[@]} cur=${words[cword-1]} &&
2714 __git_cmd_idx=1 &&
2715 __git_complete_remote_or_refspec &&
2716 print_comp
2717 ) &&
2718 test_cmp expected out
2720 done
2722 test_expect_success 'git config - section' '
2723 test_completion "git config br" <<-\EOF
2724 branch.Z
2725 browser.Z
2729 test_expect_success 'git config - section include, includeIf' '
2730 test_completion "git config inclu" <<-\EOF
2731 include.Z
2732 includeIf.Z
2736 test_expect_success 'git config - variable name' '
2737 test_completion "git config log.d" <<-\EOF
2738 log.date Z
2739 log.decorate Z
2740 log.diffMerges Z
2744 test_expect_success 'git config - variable name include' '
2745 test_completion "git config include.p" <<-\EOF
2746 include.path Z
2750 test_expect_success 'setup for git config submodule tests' '
2751 test_create_repo sub &&
2752 test_commit -C sub initial &&
2753 git submodule add ./sub
2756 test_expect_success 'git config - variable name - submodule and __git_compute_first_level_config_vars_for_section' '
2757 test_completion "git config submodule." <<-\EOF
2758 submodule.active Z
2759 submodule.alternateErrorStrategy Z
2760 submodule.alternateLocation Z
2761 submodule.fetchJobs Z
2762 submodule.propagateBranches Z
2763 submodule.recurse Z
2764 submodule.sub.Z
2768 test_expect_success 'git config - variable name - __git_compute_second_level_config_vars_for_section' '
2769 test_completion "git config submodule.sub." <<-\EOF
2770 submodule.sub.url Z
2771 submodule.sub.update Z
2772 submodule.sub.branch Z
2773 submodule.sub.fetchRecurseSubmodules Z
2774 submodule.sub.ignore Z
2775 submodule.sub.active Z
2779 test_expect_success 'git config - value' '
2780 test_completion "git config color.pager " <<-\EOF
2781 false Z
2782 true Z
2786 test_expect_success 'git -c - section' '
2787 test_completion "git -c br" <<-\EOF
2788 branch.Z
2789 browser.Z
2793 test_expect_success 'git -c - variable name' '
2794 test_completion "git -c log.d" <<-\EOF
2795 log.date=Z
2796 log.decorate=Z
2797 log.diffMerges=Z
2801 test_expect_success 'git -c - value' '
2802 test_completion "git -c color.pager=" <<-\EOF
2803 false Z
2804 true Z
2808 test_expect_success 'git clone --config= - section' '
2809 test_completion "git clone --config=br" <<-\EOF
2810 branch.Z
2811 browser.Z
2815 test_expect_success 'git clone --config= - variable name' '
2816 test_completion "git clone --config=log.d" <<-\EOF
2817 log.date=Z
2818 log.decorate=Z
2819 log.diffMerges=Z
2823 test_expect_success 'git clone --config= - value' '
2824 test_completion "git clone --config=color.pager=" <<-\EOF
2825 false Z
2826 true Z
2830 test_expect_success 'options with value' '
2831 test_completion "git merge -X diff-algorithm=" <<-\EOF
2836 test_expect_success 'sourcing the completion script clears cached commands' '
2838 __git_compute_all_commands &&
2839 test -n "$__git_all_commands" &&
2840 . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
2841 test -z "$__git_all_commands"
2845 test_expect_success 'sourcing the completion script clears cached merge strategies' '
2847 __git_compute_merge_strategies &&
2848 test -n "$__git_merge_strategies" &&
2849 . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
2850 test -z "$__git_merge_strategies"
2854 test_expect_success 'sourcing the completion script clears cached --options' '
2856 __gitcomp_builtin checkout &&
2857 test -n "$__gitcomp_builtin_checkout" &&
2858 __gitcomp_builtin notes_edit &&
2859 test -n "$__gitcomp_builtin_notes_edit" &&
2860 . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
2861 test -z "$__gitcomp_builtin_checkout" &&
2862 test -z "$__gitcomp_builtin_notes_edit"
2866 test_expect_success 'option aliases are not shown by default' '
2867 test_completion "git clone --recurs" "--recurse-submodules "
2870 test_expect_success 'option aliases are shown with GIT_COMPLETION_SHOW_ALL' '
2872 . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
2873 GIT_COMPLETION_SHOW_ALL=1 && export GIT_COMPLETION_SHOW_ALL &&
2874 test_completion "git clone --recurs" <<-\EOF
2875 --recurse-submodules Z
2876 --recursive Z
2881 test_expect_success 'plumbing commands are excluded without GIT_COMPLETION_SHOW_ALL_COMMANDS' '
2883 . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
2884 sane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST &&
2886 # Just mainporcelain, not plumbing commands
2887 run_completion "git c" &&
2888 grep checkout out &&
2889 ! grep cat-file out
2893 test_expect_success 'all commands are shown with GIT_COMPLETION_SHOW_ALL_COMMANDS (also main non-builtin)' '
2895 . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
2896 GIT_COMPLETION_SHOW_ALL_COMMANDS=1 &&
2897 export GIT_COMPLETION_SHOW_ALL_COMMANDS &&
2898 sane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST &&
2900 # Both mainporcelain and plumbing commands
2901 run_completion "git c" &&
2902 grep checkout out &&
2903 grep cat-file out &&
2905 # Check "gitk", a "main" command, but not a built-in + more plumbing
2906 run_completion "git g" &&
2907 grep gitk out &&
2908 grep get-tar-commit-id out
2912 test_expect_success '__git_complete' '
2913 unset -f __git_wrap__git_main &&
2915 __git_complete foo __git_main &&
2916 __git_have_func __git_wrap__git_main &&
2917 unset -f __git_wrap__git_main &&
2919 __git_complete gf _git_fetch &&
2920 __git_have_func __git_wrap_git_fetch &&
2922 __git_complete foo git &&
2923 __git_have_func __git_wrap__git_main &&
2924 unset -f __git_wrap__git_main &&
2926 __git_complete gd git_diff &&
2927 __git_have_func __git_wrap_git_diff &&
2929 test_must_fail __git_complete ga missing
2932 test_expect_success '__git_pseudoref_exists' '
2933 test_when_finished "rm -rf repo" &&
2934 git init repo &&
2936 cd repo &&
2937 sane_unset __git_repo_path &&
2939 # HEAD should exist, even if it points to an unborn branch.
2940 __git_pseudoref_exists HEAD >output 2>&1 &&
2941 test_must_be_empty output &&
2943 # HEAD points to an existing branch, so it should exist.
2944 test_commit A &&
2945 __git_pseudoref_exists HEAD >output 2>&1 &&
2946 test_must_be_empty output &&
2948 # CHERRY_PICK_HEAD does not exist, so the existence check should fail.
2949 ! __git_pseudoref_exists CHERRY_PICK_HEAD >output 2>&1 &&
2950 test_must_be_empty output &&
2952 # CHERRY_PICK_HEAD points to a commit, so it should exist.
2953 git update-ref CHERRY_PICK_HEAD A &&
2954 __git_pseudoref_exists CHERRY_PICK_HEAD >output 2>&1 &&
2955 test_must_be_empty output
2959 test_done