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
22 # Be careful when updating these lists:
24 # (1) The build tree may have build artifact from different branch, or
25 # the user's $PATH may have a random executable that may begin
26 # with "git-check" that are not part of the subcommands this build
27 # will ship, e.g. "check-ignore". The tests for completion for
28 # subcommand names tests how "check" is expanded; we limit the
29 # possible candidates to "checkout" and "check-attr" to make sure
30 # "check-attr", which is known by the filter function as a
31 # subcommand to be thrown out, while excluding other random files
32 # that happen to begin with "check" to avoid letting them get in
35 # (2) A test makes sure that common subcommands are included in the
36 # completion for "git <TAB>", and a plumbing is excluded. "add",
37 # "rebase" and "ls-files" are listed for this.
39 GIT_TESTING_ALL_COMMAND_LIST
='add checkout check-attr rebase ls-files'
40 GIT_TESTING_PORCELAIN_COMMAND_LIST
='add checkout rebase'
42 .
"$GIT_BUILD_DIR/contrib/completion/git-completion.bash"
44 # We don't need this function to actually join words or do anything special.
45 # Also, it's cleaner to avoid touching bash's internal completion variables.
46 # So let's override it with a minimal version for testing purposes.
47 _get_comp_words_by_ref
()
49 while [ $# -gt 0 ]; do
55 prev
=${_words[_cword-1]}
58 words
=("${_words[@]}")
71 echo "${COMPREPLY[*]}" > out
76 local -a COMPREPLY _words
79 test "${1: -1}" = ' ' && _words
[${#_words[@]}+1]=''
80 (( _cword
= ${#_words[@]} - 1 ))
81 __git_wrap__git_main
&& print_comp
84 # Test high-level completion
86 # 1: typed text so far (cur)
87 # 2: expected completion
92 printf '%s\n' "$2" >expected
94 sed -e 's/Z$//' |
sort >expected
96 run_completion
"$1" >"$TRASH_DIRECTORY"/bash-completion-output
2>&1 &&
97 sort out
>out_sorted
&&
98 test_cmp expected out_sorted
&&
99 test_must_be_empty
"$TRASH_DIRECTORY"/bash-completion-output
&&
100 rm "$TRASH_DIRECTORY"/bash-completion-output
104 # The first argument is the typed text so far (cur); the rest are
105 # passed to __gitcomp. Expected output comes is read from the
106 # standard input, like test_completion().
109 local -a COMPREPLY
&&
110 sed -e 's/Z$//' >expected
&&
115 test_cmp expected out
120 # 1: current word (cur)
121 # -: the rest are passed to __gitcomp_nl
124 local -a COMPREPLY
&&
125 sed -e 's/Z$//' >expected
&&
130 test_cmp expected out
133 invalid_variable_name
='${foo.bar}'
135 actual
="$TRASH_DIRECTORY/actual"
137 if test_have_prereq MINGW
144 test_expect_success
'setup for __git_find_repo_path/__gitdir tests' '
145 mkdir -p subdir/subsubdir &&
147 git init -b main otherrepo
150 test_expect_success
'__git_find_repo_path - from command line (through $__git_dir)' '
151 echo "$ROOT/otherrepo/.git" >expected &&
153 __git_dir="$ROOT/otherrepo/.git" &&
154 __git_find_repo_path &&
155 echo "$__git_repo_path" >"$actual"
157 test_cmp expected "$actual"
160 test_expect_success
'__git_find_repo_path - .git directory in cwd' '
161 echo ".git" >expected &&
163 __git_find_repo_path &&
164 echo "$__git_repo_path" >"$actual"
166 test_cmp expected "$actual"
169 test_expect_success
'__git_find_repo_path - .git directory in parent' '
170 echo "$ROOT/.git" >expected &&
172 cd subdir/subsubdir &&
173 __git_find_repo_path &&
174 echo "$__git_repo_path" >"$actual"
176 test_cmp expected "$actual"
179 test_expect_success
'__git_find_repo_path - cwd is a .git directory' '
180 echo "." >expected &&
183 __git_find_repo_path &&
184 echo "$__git_repo_path" >"$actual"
186 test_cmp expected "$actual"
189 test_expect_success
'__git_find_repo_path - parent is a .git directory' '
190 echo "$ROOT/.git" >expected &&
193 __git_find_repo_path &&
194 echo "$__git_repo_path" >"$actual"
196 test_cmp expected "$actual"
199 test_expect_success
'__git_find_repo_path - $GIT_DIR set while .git directory in cwd' '
200 echo "$ROOT/otherrepo/.git" >expected &&
202 GIT_DIR="$ROOT/otherrepo/.git" &&
204 __git_find_repo_path &&
205 echo "$__git_repo_path" >"$actual"
207 test_cmp expected "$actual"
210 test_expect_success
'__git_find_repo_path - $GIT_DIR set while .git directory in parent' '
211 echo "$ROOT/otherrepo/.git" >expected &&
213 GIT_DIR="$ROOT/otherrepo/.git" &&
216 __git_find_repo_path &&
217 echo "$__git_repo_path" >"$actual"
219 test_cmp expected "$actual"
222 test_expect_success
'__git_find_repo_path - from command line while "git -C"' '
223 echo "$ROOT/.git" >expected &&
225 __git_dir="$ROOT/.git" &&
226 __git_C_args=(-C otherrepo) &&
227 __git_find_repo_path &&
228 echo "$__git_repo_path" >"$actual"
230 test_cmp expected "$actual"
233 test_expect_success
'__git_find_repo_path - relative dir from command line and "git -C"' '
234 echo "$ROOT/otherrepo/.git" >expected &&
237 __git_dir="otherrepo/.git" &&
238 __git_C_args=(-C ..) &&
239 __git_find_repo_path &&
240 echo "$__git_repo_path" >"$actual"
242 test_cmp expected "$actual"
245 test_expect_success
'__git_find_repo_path - $GIT_DIR set while "git -C"' '
246 echo "$ROOT/.git" >expected &&
248 GIT_DIR="$ROOT/.git" &&
250 __git_C_args=(-C otherrepo) &&
251 __git_find_repo_path &&
252 echo "$__git_repo_path" >"$actual"
254 test_cmp expected "$actual"
257 test_expect_success
'__git_find_repo_path - relative dir in $GIT_DIR and "git -C"' '
258 echo "$ROOT/otherrepo/.git" >expected &&
261 GIT_DIR="otherrepo/.git" &&
263 __git_C_args=(-C ..) &&
264 __git_find_repo_path &&
265 echo "$__git_repo_path" >"$actual"
267 test_cmp expected "$actual"
270 test_expect_success
'__git_find_repo_path - "git -C" while .git directory in cwd' '
271 echo "$ROOT/otherrepo/.git" >expected &&
273 __git_C_args=(-C otherrepo) &&
274 __git_find_repo_path &&
275 echo "$__git_repo_path" >"$actual"
277 test_cmp expected "$actual"
280 test_expect_success
'__git_find_repo_path - "git -C" while cwd is a .git directory' '
281 echo "$ROOT/otherrepo/.git" >expected &&
284 __git_C_args=(-C .. -C otherrepo) &&
285 __git_find_repo_path &&
286 echo "$__git_repo_path" >"$actual"
288 test_cmp expected "$actual"
291 test_expect_success
'__git_find_repo_path - "git -C" while .git directory in parent' '
292 echo "$ROOT/otherrepo/.git" >expected &&
295 __git_C_args=(-C .. -C otherrepo) &&
296 __git_find_repo_path &&
297 echo "$__git_repo_path" >"$actual"
299 test_cmp expected "$actual"
302 test_expect_success
'__git_find_repo_path - non-existing path in "git -C"' '
304 __git_C_args=(-C non-existing) &&
305 test_must_fail __git_find_repo_path &&
306 printf "$__git_repo_path" >"$actual"
308 test_must_be_empty "$actual"
311 test_expect_success
'__git_find_repo_path - non-existing path in $__git_dir' '
313 __git_dir="non-existing" &&
314 test_must_fail __git_find_repo_path &&
315 printf "$__git_repo_path" >"$actual"
317 test_must_be_empty "$actual"
320 test_expect_success
'__git_find_repo_path - non-existing $GIT_DIR' '
322 GIT_DIR="$ROOT/non-existing" &&
324 test_must_fail __git_find_repo_path &&
325 printf "$__git_repo_path" >"$actual"
327 test_must_be_empty "$actual"
330 test_expect_success
'__git_find_repo_path - gitfile in cwd' '
331 echo "$ROOT/otherrepo/.git" >expected &&
332 echo "gitdir: $ROOT/otherrepo/.git" >subdir/.git &&
333 test_when_finished "rm -f subdir/.git" &&
336 __git_find_repo_path &&
337 echo "$__git_repo_path" >"$actual"
339 test_cmp expected "$actual"
342 test_expect_success
'__git_find_repo_path - gitfile in parent' '
343 echo "$ROOT/otherrepo/.git" >expected &&
344 echo "gitdir: $ROOT/otherrepo/.git" >subdir/.git &&
345 test_when_finished "rm -f subdir/.git" &&
347 cd subdir/subsubdir &&
348 __git_find_repo_path &&
349 echo "$__git_repo_path" >"$actual"
351 test_cmp expected "$actual"
354 test_expect_success SYMLINKS
'__git_find_repo_path - resulting path avoids symlinks' '
355 echo "$ROOT/otherrepo/.git" >expected &&
356 mkdir otherrepo/dir &&
357 test_when_finished "rm -rf otherrepo/dir" &&
358 ln -s otherrepo/dir link &&
359 test_when_finished "rm -f link" &&
362 __git_find_repo_path &&
363 echo "$__git_repo_path" >"$actual"
365 test_cmp expected "$actual"
368 test_expect_success
'__git_find_repo_path - not a git repository' '
371 GIT_CEILING_DIRECTORIES="$ROOT" &&
372 export GIT_CEILING_DIRECTORIES &&
373 test_must_fail __git_find_repo_path &&
374 printf "$__git_repo_path" >"$actual"
376 test_must_be_empty "$actual"
379 test_expect_success
'__gitdir - finds repo' '
380 echo "$ROOT/.git" >expected &&
382 cd subdir/subsubdir &&
385 test_cmp expected "$actual"
389 test_expect_success
'__gitdir - returns error when cannot find repo' '
391 __git_dir="non-existing" &&
392 test_must_fail __gitdir >"$actual"
394 test_must_be_empty "$actual"
397 test_expect_success
'__gitdir - repo as argument' '
398 echo "otherrepo/.git" >expected &&
400 __gitdir "otherrepo" >"$actual"
402 test_cmp expected "$actual"
405 test_expect_success
'__gitdir - remote as argument' '
406 echo "remote" >expected &&
408 __gitdir "remote" >"$actual"
410 test_cmp expected "$actual"
414 test_expect_success
'__git_dequote - plain unquoted word' '
415 __git_dequote unquoted-word &&
416 test unquoted-word = "$dequoted_word"
419 # input: b\a\c\k\'\\\"s\l\a\s\h\es
420 # expected: back'\"slashes
421 test_expect_success
'__git_dequote - backslash escaped' '
422 __git_dequote "b\a\c\k\\'\''\\\\\\\"s\l\a\s\h\es" &&
423 test "back'\''\\\"slashes" = "$dequoted_word"
426 # input: sin'gle\' '"quo'ted
427 # expected: single\ "quoted
428 test_expect_success
'__git_dequote - single quoted' '
429 __git_dequote "'"sin'gle\\\\' '\\\"quo'ted"'" &&
430 test '\''single\ "quoted'\'' = "$dequoted_word"
433 # input: dou"ble\\" "\"\quot"ed
434 # expected: double\ "\quoted
435 test_expect_success
'__git_dequote - double quoted' '
436 __git_dequote '\''dou"ble\\" "\"\quot"ed'\'' &&
437 test '\''double\ "\quoted'\'' = "$dequoted_word"
440 # input: 'open single quote
441 test_expect_success
'__git_dequote - open single quote' '
442 __git_dequote "'\''open single quote" &&
443 test "open single quote" = "$dequoted_word"
446 # input: "open double quote
447 test_expect_success
'__git_dequote - open double quote' '
448 __git_dequote "\"open double quote" &&
449 test "open double quote" = "$dequoted_word"
453 test_expect_success
'__gitcomp_direct - puts everything into COMPREPLY as-is' '
454 sed -e "s/Z$//g" >expected <<-EOF &&
455 with-trailing-space Z
456 without-trailing-spaceZ
459 $invalid_variable_name Z
462 cur=should_be_ignored &&
463 __gitcomp_direct "$(cat expected)" &&
466 test_cmp expected out
469 test_expect_success
'__gitcomp - trailing space - options' '
470 test_gitcomp "--re" "--dry-run --reuse-message= --reedit-message=
471 --reset-author" <<-EOF
478 test_expect_success
'__gitcomp - trailing space - config keys' '
479 test_gitcomp "br" "branch. branch.autosetupmerge
480 branch.autosetuprebase browser." <<-\EOF
482 branch.autosetupmerge Z
483 branch.autosetuprebase Z
488 test_expect_success
'__gitcomp - option parameter' '
489 test_gitcomp "--strategy=re" "octopus ours recursive resolve subtree" \
496 test_expect_success
'__gitcomp - prefix' '
497 test_gitcomp "branch.me" "remote merge mergeoptions rebase" \
498 "branch.maint." "me" <<-\EOF
500 branch.maint.mergeoptions Z
504 test_expect_success
'__gitcomp - suffix' '
505 test_gitcomp "branch.me" "master maint next seen" "branch." \
512 test_expect_success
'__gitcomp - ignore optional negative options' '
513 test_gitcomp "--" "--abc --def --no-one -- --no-two" <<-\EOF
521 test_expect_success
'__gitcomp - ignore/narrow optional negative options' '
522 test_gitcomp "--a" "--abc --abcdef --no-one -- --no-two" <<-\EOF
528 test_expect_success
'__gitcomp - ignore/narrow optional negative options' '
529 test_gitcomp "--n" "--abc --def --no-one -- --no-two" <<-\EOF
535 test_expect_success
'__gitcomp - expand all negative options' '
536 test_gitcomp "--no-" "--abc --def --no-one -- --no-two" <<-\EOF
542 test_expect_success
'__gitcomp - expand/narrow all negative options' '
543 test_gitcomp "--no-o" "--abc --def --no-one -- --no-two" <<-\EOF
548 test_expect_success
'__gitcomp - equal skip' '
549 test_gitcomp "--option=" "--option=" <<-\EOF &&
552 test_gitcomp "option=" "option=" <<-\EOF
557 test_expect_success
'__gitcomp - doesnt fail because of invalid variable name' '
558 __gitcomp "$invalid_variable_name"
561 read -r -d "" refs
<<-\EOF
568 test_expect_success '__gitcomp_nl - trailing space
' '
569 test_gitcomp_nl
"m" "$refs" <<-EOF
575 test_expect_success '__gitcomp_nl
- prefix
' '
576 test_gitcomp_nl
"--fixup=m" "$refs" "--fixup=" "m" <<-EOF
582 test_expect_success '__gitcomp_nl
- suffix
' '
583 test_gitcomp_nl
"branch.ma" "$refs" "branch." "ma" "." <<-\EOF
589 test_expect_success '__gitcomp_nl - no suffix
' '
590 test_gitcomp_nl
"ma" "$refs" "" "ma" "" <<-\EOF
596 test_expect_success '__gitcomp_nl - doesnt fail because of invalid variable name
' '
597 __gitcomp_nl
"$invalid_variable_name"
600 test_expect_success '__git_remotes
- list remotes from
$GIT_DIR/remotes and from config
file' '
601 cat >expect
<<-EOF &&
607 test_when_finished
"rm -rf .git/remotes" &&
608 mkdir
-p .git
/remotes
&&
609 >.git
/remotes
/remote_from_file_1
&&
610 >.git
/remotes
/remote_from_file_2
&&
611 test_when_finished
"git remote remove remote_in_config_1" &&
612 git remote add remote_in_config_1 git
://remote_1
&&
613 test_when_finished
"git remote remove remote_in_config_2" &&
614 git remote add remote_in_config_2 git
://remote_2
&&
616 __git_remotes
>actual
618 test_cmp expect actual
621 test_expect_success '__git_is_configured_remote
' '
622 test_when_finished
"git remote remove remote_1" &&
623 git remote add remote_1 git
://remote_1
&&
624 test_when_finished
"git remote remove remote_2" &&
625 git remote add remote_2 git
://remote_2
&&
627 __git_is_configured_remote remote_2
&&
628 test_must_fail __git_is_configured_remote non-existent
632 test_expect_success 'setup
for ref completion
' '
633 git commit
--allow-empty -m initial
&&
634 git branch
-M main
&&
635 git branch matching-branch
&&
636 git tag matching-tag
&&
639 git commit
--allow-empty -m initial
&&
640 git branch
-m main main-in-other
&&
641 git branch branch-in-other
&&
644 git remote add other
"$ROOT/otherrepo/.git" &&
645 git fetch
--no-tags other
&&
646 rm -f .git
/FETCH_HEAD
&&
650 test_expect_success '__git_refs
- simple
' '
651 cat >expected
<<-EOF &&
655 other/branch-in-other
661 __git_refs
>"$actual"
663 test_cmp expected
"$actual"
666 test_expect_success '__git_refs
- full refs
' '
667 cat >expected
<<-EOF &&
669 refs/heads/matching-branch
670 refs/remotes/other/branch-in-other
671 refs/remotes/other/main-in-other
672 refs/tags/matching-tag
676 __git_refs
>"$actual"
678 test_cmp expected
"$actual"
681 test_expect_success '__git_refs
- repo given on the
command line
' '
682 cat >expected
<<-EOF &&
689 __git_dir
="$ROOT/otherrepo/.git" &&
691 __git_refs
>"$actual"
693 test_cmp expected
"$actual"
696 test_expect_success '__git_refs
- remote on
local file system
' '
697 cat >expected
<<-EOF &&
705 __git_refs otherrepo
>"$actual"
707 test_cmp expected
"$actual"
710 test_expect_success '__git_refs
- remote on
local file system
- full refs
' '
711 cat >expected
<<-EOF &&
712 refs/heads/branch-in-other
713 refs/heads/main-in-other
714 refs/tags/tag-in-other
718 __git_refs otherrepo
>"$actual"
720 test_cmp expected
"$actual"
723 test_expect_success '__git_refs
- configured remote
' '
724 cat >expected
<<-EOF &&
731 __git_refs other
>"$actual"
733 test_cmp expected
"$actual"
736 test_expect_success '__git_refs
- configured remote
- full refs
' '
737 cat >expected
<<-EOF &&
739 refs/heads/branch-in-other
740 refs/heads/main-in-other
741 refs/tags/tag-in-other
745 __git_refs other
>"$actual"
747 test_cmp expected
"$actual"
750 test_expect_success '__git_refs
- configured remote
- repo given on the
command line
' '
751 cat >expected
<<-EOF &&
758 __git_dir
="$ROOT/.git" &&
760 __git_refs other
>"$actual"
762 test_cmp expected
"$actual"
765 test_expect_success '__git_refs
- configured remote
- full refs
- repo given on the
command line
' '
766 cat >expected
<<-EOF &&
768 refs/heads/branch-in-other
769 refs/heads/main-in-other
770 refs/tags/tag-in-other
774 __git_dir
="$ROOT/.git" &&
776 __git_refs other
>"$actual"
778 test_cmp expected
"$actual"
781 test_expect_success '__git_refs
- configured remote
- remote name matches a directory
' '
782 cat >expected
<<-EOF &&
788 test_when_finished
"rm -rf other" &&
791 __git_refs other
>"$actual"
793 test_cmp expected
"$actual"
796 test_expect_success '__git_refs
- URL remote
' '
797 cat >expected
<<-EOF &&
805 __git_refs
"file://$ROOT/otherrepo/.git" >"$actual"
807 test_cmp expected
"$actual"
810 test_expect_success '__git_refs
- URL remote
- full refs
' '
811 cat >expected
<<-EOF &&
813 refs/heads/branch-in-other
814 refs/heads/main-in-other
815 refs/tags/tag-in-other
819 __git_refs
"file://$ROOT/otherrepo/.git" >"$actual"
821 test_cmp expected
"$actual"
824 test_expect_success '__git_refs
- non-existing remote
' '
827 __git_refs non-existing
>"$actual"
829 test_must_be_empty
"$actual"
832 test_expect_success '__git_refs
- non-existing remote
- full refs
' '
835 __git_refs non-existing
>"$actual"
837 test_must_be_empty
"$actual"
840 test_expect_success '__git_refs
- non-existing URL remote
' '
843 __git_refs
"file://$ROOT/non-existing" >"$actual"
845 test_must_be_empty
"$actual"
848 test_expect_success '__git_refs
- non-existing URL remote
- full refs
' '
851 __git_refs
"file://$ROOT/non-existing" >"$actual"
853 test_must_be_empty
"$actual"
856 test_expect_success '__git_refs
- not
in a git repository
' '
858 GIT_CEILING_DIRECTORIES
="$ROOT" &&
859 export GIT_CEILING_DIRECTORIES
&&
862 __git_refs
>"$actual"
864 test_must_be_empty
"$actual"
867 test_expect_success '__git_refs
- unique remote branches
for git checkout DWIMery
' '
868 cat >expected
<<-EOF &&
873 other/branch-in-other
876 remote/branch-in-remote
882 for remote_ref
in refs
/remotes
/other
/ambiguous \
883 refs
/remotes
/remote
/ambiguous \
884 refs
/remotes
/remote
/branch-in-remote
886 git update-ref
$remote_ref main
&&
887 test_when_finished
"git update-ref -d $remote_ref" ||
return 1
891 __git_refs
"" 1 >"$actual"
893 test_cmp expected
"$actual"
896 test_expect_success '__git_refs
- after
--opt=' '
897 cat >expected
<<-EOF &&
901 other/branch-in-other
907 __git_refs
"" "" "" "" >"$actual"
909 test_cmp expected
"$actual"
912 test_expect_success '__git_refs
- after
--opt= - full refs
' '
913 cat >expected
<<-EOF &&
915 refs/heads/matching-branch
916 refs/remotes/other/branch-in-other
917 refs/remotes/other/main-in-other
918 refs/tags/matching-tag
922 __git_refs
"" "" "" refs
/ >"$actual"
924 test_cmp expected
"$actual"
927 test_expect_success '__git refs
- excluding refs
' '
928 cat >expected
<<-EOF &&
932 ^other/branch-in-other
938 __git_refs
>"$actual"
940 test_cmp expected
"$actual"
943 test_expect_success '__git refs
- excluding full refs
' '
944 cat >expected
<<-EOF &&
946 ^refs/heads/matching-branch
947 ^refs/remotes/other/branch-in-other
948 ^refs/remotes/other/main-in-other
949 ^refs/tags/matching-tag
953 __git_refs
>"$actual"
955 test_cmp expected
"$actual"
958 test_expect_success 'setup
for filtering matching refs
' '
959 git branch matching
/branch
&&
960 git tag matching
/tag
&&
961 git
-C otherrepo branch matching
/branch-in-other
&&
962 git fetch
--no-tags other
&&
963 rm -f .git
/FETCH_HEAD
966 test_expect_success '__git_refs
- do not filter refs unless told so
' '
967 cat >expected
<<-EOF &&
972 other/branch-in-other
974 other/matching/branch-in-other
980 __git_refs
>"$actual"
982 test_cmp expected
"$actual"
985 test_expect_success '__git_refs
- only matching refs
' '
986 cat >expected
<<-EOF &&
994 __git_refs
"" "" "" "$cur" >"$actual"
996 test_cmp expected
"$actual"
999 test_expect_success '__git_refs
- only matching refs
- full refs
' '
1000 cat >expected
<<-EOF &&
1001 refs/heads/matching-branch
1002 refs/heads/matching/branch
1005 cur
=refs
/heads
/mat
&&
1006 __git_refs
"" "" "" "$cur" >"$actual"
1008 test_cmp expected
"$actual"
1011 test_expect_success '__git_refs
- only matching refs
- remote on
local file system
' '
1012 cat >expected
<<-EOF &&
1014 matching/branch-in-other
1018 __git_refs otherrepo
"" "" "$cur" >"$actual"
1020 test_cmp expected
"$actual"
1023 test_expect_success '__git_refs
- only matching refs
- configured remote
' '
1024 cat >expected
<<-EOF &&
1026 matching/branch-in-other
1030 __git_refs other
"" "" "$cur" >"$actual"
1032 test_cmp expected
"$actual"
1035 test_expect_success '__git_refs
- only matching refs
- remote
- full refs
' '
1036 cat >expected
<<-EOF &&
1037 refs/heads/main-in-other
1038 refs/heads/matching/branch-in-other
1041 cur
=refs
/heads
/ma
&&
1042 __git_refs other
"" "" "$cur" >"$actual"
1044 test_cmp expected
"$actual"
1047 test_expect_success '__git_refs
- only matching refs
- checkout DWIMery
' '
1048 cat >expected
<<-EOF &&
1053 matching/branch-in-other
1055 for remote_ref
in refs
/remotes
/other
/ambiguous \
1056 refs
/remotes
/remote
/ambiguous \
1057 refs
/remotes
/remote
/branch-in-remote
1059 git update-ref
$remote_ref main
&&
1060 test_when_finished
"git update-ref -d $remote_ref" ||
return 1
1064 __git_refs
"" 1 "" "$cur" >"$actual"
1066 test_cmp expected
"$actual"
1069 test_expect_success 'teardown after filtering matching refs
' '
1070 git branch
-d matching
/branch
&&
1071 git tag
-d matching
/tag
&&
1072 git update-ref
-d refs
/remotes
/other
/matching
/branch-in-other
&&
1073 git
-C otherrepo branch
-D matching
/branch-in-other
1076 test_expect_success '__git_refs
- for-each-ref format specifiers
in prefix
' '
1077 cat >expected
<<-EOF &&
1078 evil-%%-%42-%(refname)..main
1081 cur
="evil-%%-%42-%(refname)..mai" &&
1082 __git_refs
"" "" "evil-%%-%42-%(refname).." mai
>"$actual"
1084 test_cmp expected
"$actual"
1087 test_expect_success '__git_complete_refs
- simple
' '
1088 sed -e "s/Z$//" >expected
<<-EOF &&
1092 other/branch-in-other Z
1093 other/main-in-other Z
1098 __git_complete_refs
&&
1101 test_cmp expected out
1104 test_expect_success '__git_complete_refs
- matching
' '
1105 sed -e "s/Z$//" >expected
<<-EOF &&
1111 __git_complete_refs
&&
1114 test_cmp expected out
1117 test_expect_success '__git_complete_refs
- remote
' '
1118 sed -e "s/Z$//" >expected
<<-EOF &&
1125 __git_complete_refs
--remote=other
&&
1128 test_cmp expected out
1131 test_expect_success '__git_complete_refs
- track
' '
1132 sed -e "s/Z$//" >expected
<<-EOF &&
1136 other/branch-in-other Z
1137 other/main-in-other Z
1144 __git_complete_refs
--track &&
1147 test_cmp expected out
1150 test_expect_success '__git_complete_refs
- current word
' '
1151 sed -e "s/Z$//" >expected
<<-EOF &&
1156 cur
="--option=mat" &&
1157 __git_complete_refs
--cur="${cur#*=}" &&
1160 test_cmp expected out
1163 test_expect_success '__git_complete_refs
- prefix
' '
1164 sed -e "s/Z$//" >expected
<<-EOF &&
1165 v1.0..matching-branch Z
1166 v1.0..matching-tag Z
1170 __git_complete_refs
--pfx=v1.0..
--cur=mat
&&
1173 test_cmp expected out
1176 test_expect_success '__git_complete_refs
- suffix
' '
1177 cat >expected
<<-EOF &&
1181 other/branch-in-other.
1182 other/main-in-other.
1187 __git_complete_refs
--sfx=.
&&
1190 test_cmp expected out
1193 test_expect_success '__git_complete_fetch_refspecs
- simple
' '
1194 sed -e "s/Z$//" >expected
<<-EOF &&
1196 branch-in-other:branch-in-other Z
1197 main-in-other:main-in-other Z
1201 __git_complete_fetch_refspecs other
&&
1204 test_cmp expected out
1207 test_expect_success '__git_complete_fetch_refspecs
- matching
' '
1208 sed -e "s/Z$//" >expected
<<-EOF &&
1209 branch-in-other:branch-in-other Z
1213 __git_complete_fetch_refspecs other
"" br
&&
1216 test_cmp expected out
1219 test_expect_success '__git_complete_fetch_refspecs
- prefix
' '
1220 sed -e "s/Z$//" >expected
<<-EOF &&
1222 +branch-in-other:branch-in-other Z
1223 +main-in-other:main-in-other Z
1227 __git_complete_fetch_refspecs other
"+" "" &&
1230 test_cmp expected out
1233 test_expect_success '__git_complete_fetch_refspecs
- fully qualified
' '
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_complete_fetch_refspecs
- fully qualified
& prefix
' '
1248 sed -e "s/Z$//" >expected
<<-EOF &&
1249 +refs/heads/branch-in-other:refs/heads/branch-in-other Z
1250 +refs/heads/main-in-other:refs/heads/main-in-other Z
1251 +refs/tags/tag-in-other:refs/tags/tag-in-other Z
1255 __git_complete_fetch_refspecs other
+ refs
/ &&
1258 test_cmp expected out
1261 test_expect_success 'git switch
- with no options
, complete
local branches and unique remote branch names
for DWIM logic
' '
1262 test_completion
"git switch " <<-\EOF
1270 test_expect_success 'git checkout - completes refs and unique remote branches
for DWIM
' '
1271 test_completion
"git checkout " <<-\EOF
1278 other/branch-in-other Z
1279 other/main-in-other Z
1283 test_expect_success 'git switch - with
--no-guess, complete only
local branches
' '
1284 test_completion
"git switch --no-guess " <<-\EOF
1290 test_expect_success 'git switch - with GIT_COMPLETION_CHECKOUT_NO_GUESS
=1, complete only
local branches
' '
1291 GIT_COMPLETION_CHECKOUT_NO_GUESS
=1 test_completion
"git switch " <<-\EOF
1297 test_expect_success 'git switch - --guess overrides GIT_COMPLETION_CHECKOUT_NO_GUESS
=1, complete
local branches and unique remote names
for DWIM logic
' '
1298 GIT_COMPLETION_CHECKOUT_NO_GUESS
=1 test_completion
"git switch --guess " <<-\EOF
1306 test_expect_success 'git switch - a later
--guess overrides previous
--no-guess, complete
local and remote unique branches
for DWIM
' '
1307 test_completion
"git switch --no-guess --guess " <<-\EOF
1315 test_expect_success 'git switch - a later
--no-guess overrides previous
--guess, complete only
local branches
' '
1316 test_completion
"git switch --guess --no-guess " <<-\EOF
1322 test_expect_success 'git checkout - with GIT_COMPLETION_NO_GUESS
=1 only completes refs
' '
1323 GIT_COMPLETION_CHECKOUT_NO_GUESS
=1 test_completion
"git checkout " <<-\EOF
1328 other/branch-in-other Z
1329 other/main-in-other Z
1333 test_expect_success 'git checkout - --guess overrides GIT_COMPLETION_NO_GUESS
=1, complete refs and unique remote branches
for DWIM
' '
1334 GIT_COMPLETION_CHECKOUT_NO_GUESS
=1 test_completion
"git checkout --guess " <<-\EOF
1341 other/branch-in-other Z
1342 other/main-in-other Z
1346 test_expect_success 'git checkout - with
--no-guess, only completes refs
' '
1347 test_completion
"git checkout --no-guess " <<-\EOF
1352 other/branch-in-other Z
1353 other/main-in-other Z
1357 test_expect_success 'git checkout - a later
--guess overrides previous
--no-guess, complete refs and unique remote branches
for DWIM
' '
1358 test_completion
"git checkout --no-guess --guess " <<-\EOF
1365 other/branch-in-other Z
1366 other/main-in-other Z
1370 test_expect_success 'git checkout - a later
--no-guess overrides previous
--guess, complete only refs
' '
1371 test_completion
"git checkout --guess --no-guess " <<-\EOF
1376 other/branch-in-other Z
1377 other/main-in-other Z
1381 test_expect_success 'git checkout - with checkout.guess
= false
, only completes refs
' '
1382 test_config checkout.guess false
&&
1383 test_completion
"git checkout " <<-\EOF
1388 other/branch-in-other Z
1389 other/main-in-other Z
1393 test_expect_success 'git checkout - with checkout.guess
= true
, completes refs and unique remote branches
for DWIM
' '
1394 test_config checkout.guess true
&&
1395 test_completion
"git checkout " <<-\EOF
1402 other/branch-in-other Z
1403 other/main-in-other Z
1407 test_expect_success 'git checkout - a later
--guess overrides previous checkout.guess
= false
, complete refs and unique remote branches
for DWIM
' '
1408 test_config checkout.guess false
&&
1409 test_completion
"git checkout --guess " <<-\EOF
1416 other/branch-in-other Z
1417 other/main-in-other Z
1421 test_expect_success 'git checkout - a later
--no-guess overrides previous checkout.guess
= true
, complete only refs
' '
1422 test_config checkout.guess true
&&
1423 test_completion
"git checkout --no-guess " <<-\EOF
1428 other/branch-in-other Z
1429 other/main-in-other Z
1433 test_expect_success 'git switch - with
--detach, complete all references
' '
1434 test_completion
"git switch --detach " <<-\EOF
1439 other/branch-in-other Z
1440 other/main-in-other Z
1444 test_expect_success 'git checkout - with
--detach, complete only references
' '
1445 test_completion
"git checkout --detach " <<-\EOF
1450 other/branch-in-other Z
1451 other/main-in-other Z
1455 test_expect_success 'setup sparse-checkout tests' '
1456 # set up sparse-checkout repo
1457 git init sparse-checkout &&
1459 cd sparse-checkout &&
1460 mkdir -p folder1/0/1 folder2/0 folder3 &&
1461 touch folder1/0/1/t.txt &&
1462 touch folder2/0/t.txt &&
1463 touch folder3/t.txt &&
1465 git commit -am "Initial commit"
1469 test_expect_success 'sparse-checkout completes subcommands' '
1470 test_completion "git sparse-checkout " <<-\
EOF
1480 test_expect_success 'cone mode sparse-checkout completes directory names' '
1481 # initialize sparse-checkout definitions
1482 git -C sparse-checkout sparse-checkout set --cone folder1/0 folder3 &&
1484 # test tab completion
1486 cd sparse-checkout &&
1487 test_completion "git sparse-checkout set f" <<-\EOF
1495 cd sparse-checkout &&
1496 test_completion "git sparse-checkout set folder1/" <<-\EOF
1502 cd sparse-checkout &&
1503 test_completion "git sparse-checkout set folder1/0/" <<-\EOF
1509 cd sparse-checkout/folder1 &&
1510 test_completion "git sparse-checkout add 0" <<-\EOF
1516 test_expect_success 'cone mode sparse-checkout completes directory names with spaces and accents' '
1517 # reset sparse-checkout
1518 git -C sparse-checkout sparse-checkout disable &&
1520 cd sparse-checkout &&
1521 mkdir "directory with spaces" &&
1522 mkdir "directory-with-áccent" &&
1523 >"directory with spaces/randomfile" &&
1524 >"directory-with-áccent/randomfile" &&
1526 git commit -m "Add directory with spaces and directory with accent" &&
1527 git sparse-checkout set --cone "directory with spaces" \
1528 "directory-with-áccent" &&
1529 test_completion "git sparse-checkout add dir" <<-\EOF &&
1530 directory with spaces/
1531 directory-with-áccent/
1533 rm -rf "directory with spaces" &&
1534 rm -rf "directory-with-áccent" &&
1536 git commit -m "Remove directory with spaces and directory with accent"
1540 # use FUNNYNAMES to avoid running on Windows, which doesn't permit tabs in paths
1541 test_expect_success FUNNYNAMES 'cone mode sparse-checkout completes directory names with tabs' '
1542 # reset sparse-checkout
1543 git -C sparse-checkout sparse-checkout disable &&
1545 cd sparse-checkout &&
1546 mkdir "$(printf "directory\twith\ttabs")" &&
1547 >"$(printf "directory\twith\ttabs")/randomfile" &&
1549 git commit -m "Add directory with tabs" &&
1550 git sparse-checkout set --cone \
1551 "$(printf "directory\twith\ttabs")" &&
1552 test_completion "git sparse-checkout add dir" <<-\EOF &&
1553 directory with tabs/
1555 rm -rf "$(printf "directory\twith\ttabs")" &&
1557 git commit -m "Remove directory with tabs"
1561 # use FUNNYNAMES to avoid running on Windows, and !CYGWIN for Cygwin, as neither permit backslashes in paths
1562 test_expect_success FUNNYNAMES,!CYGWIN 'cone mode sparse-checkout completes directory names with backslashes' '
1563 # reset sparse-checkout
1564 git -C sparse-checkout sparse-checkout disable &&
1566 cd sparse-checkout &&
1567 mkdir "directory\with\backslashes" &&
1568 >"directory\with\backslashes/randomfile" &&
1570 git commit -m "Add directory with backslashes" &&
1571 git sparse-checkout set --cone \
1572 "directory\with\backslashes" &&
1573 test_completion "git sparse-checkout add dir" <<-\EOF &&
1574 directory\with\backslashes/
1576 rm -rf "directory\with\backslashes" &&
1578 git commit -m "Remove directory with backslashes"
1582 test_expect_success 'non-cone mode sparse-checkout gives rooted paths' '
1583 # reset sparse-checkout repo to non-cone mode
1584 git -C sparse-checkout sparse-checkout disable &&
1585 git -C sparse-checkout sparse-checkout set --no-cone &&
1588 cd sparse-checkout &&
1589 # expected to be empty since we have not configured
1590 # custom completion for non-cone mode
1591 test_completion "git sparse-checkout set f" <<-\EOF
1592 /folder1/0/1/t.txt Z
1595 /folder1/out_sorted Z
1602 test_expect_success 'git sparse-checkout set --cone completes directory names' '
1603 git -C sparse-checkout sparse-checkout disable &&
1606 cd sparse-checkout &&
1607 test_completion "git sparse-checkout set --cone f" <<-\EOF
1615 test_expect_success 'git switch - with
-d, complete all references
' '
1616 test_completion
"git switch -d " <<-\EOF
1621 other/branch-in-other Z
1622 other/main-in-other Z
1626 test_expect_success 'git checkout - with
-d, complete only references
' '
1627 test_completion
"git checkout -d " <<-\EOF
1632 other/branch-in-other Z
1633 other/main-in-other Z
1637 test_expect_success 'git switch - with
--track, complete only remote branches
' '
1638 test_completion
"git switch --track " <<-\EOF &&
1639 other/branch-in-other Z
1640 other/main-in-other Z
1642 test_completion "git switch -t " <<-\
EOF
1643 other/branch-in-other Z
1644 other/main-in-other Z
1648 test_expect_success 'git checkout - with
--track, complete only remote branches
' '
1649 test_completion
"git checkout --track " <<-\EOF &&
1650 other/branch-in-other Z
1651 other/main-in-other Z
1653 test_completion "git checkout -t " <<-\
EOF
1654 other/branch-in-other Z
1655 other/main-in-other Z
1659 test_expect_success 'git switch - with
--no-track, complete only
local branch names
' '
1660 test_completion
"git switch --no-track " <<-\EOF
1666 test_expect_success 'git checkout - with
--no-track, complete only
local references
' '
1667 test_completion
"git checkout --no-track " <<-\EOF
1672 other/branch-in-other Z
1673 other/main-in-other Z
1677 test_expect_success 'git switch - with
-c, complete all references
' '
1678 test_completion
"git switch -c new-branch " <<-\EOF
1683 other/branch-in-other Z
1684 other/main-in-other Z
1688 test_expect_success 'git switch - with
-C, complete all references
' '
1689 test_completion
"git switch -C new-branch " <<-\EOF
1694 other/branch-in-other Z
1695 other/main-in-other Z
1699 test_expect_success 'git switch - with
-c and
--track, complete all references
' '
1700 test_completion
"git switch -c new-branch --track " <<-EOF
1705 other/branch-in-other Z
1706 other/main-in-other Z
1710 test_expect_success 'git switch
- with
-C and
--track, complete all references
' '
1711 test_completion
"git switch -C new-branch --track " <<-EOF
1716 other/branch-in-other Z
1717 other/main-in-other Z
1721 test_expect_success 'git switch
- with
-c and
--no-track, complete all references
' '
1722 test_completion
"git switch -c new-branch --no-track " <<-\EOF
1727 other/branch-in-other Z
1728 other/main-in-other Z
1732 test_expect_success 'git switch - with
-C and
--no-track, complete all references
' '
1733 test_completion
"git switch -C new-branch --no-track " <<-\EOF
1738 other/branch-in-other Z
1739 other/main-in-other Z
1743 test_expect_success 'git checkout - with
-b, complete all references
' '
1744 test_completion
"git checkout -b new-branch " <<-\EOF
1749 other/branch-in-other Z
1750 other/main-in-other Z
1754 test_expect_success 'git checkout - with
-B, complete all references
' '
1755 test_completion
"git checkout -B new-branch " <<-\EOF
1760 other/branch-in-other Z
1761 other/main-in-other Z
1765 test_expect_success 'git checkout - with
-b and
--track, complete all references
' '
1766 test_completion
"git checkout -b new-branch --track " <<-EOF
1771 other/branch-in-other Z
1772 other/main-in-other Z
1776 test_expect_success 'git checkout
- with
-B and
--track, complete all references
' '
1777 test_completion
"git checkout -B new-branch --track " <<-EOF
1782 other/branch-in-other Z
1783 other/main-in-other Z
1787 test_expect_success 'git checkout
- with
-b and
--no-track, complete all references
' '
1788 test_completion
"git checkout -b new-branch --no-track " <<-\EOF
1793 other/branch-in-other Z
1794 other/main-in-other Z
1798 test_expect_success 'git checkout - with
-B and
--no-track, complete all references
' '
1799 test_completion
"git checkout -B new-branch --no-track " <<-\EOF
1804 other/branch-in-other Z
1805 other/main-in-other Z
1809 test_expect_success 'git switch - for -c, complete
local branches and unique remote branches
' '
1810 test_completion
"git switch -c " <<-\EOF
1818 test_expect_success 'git switch - for -C, complete
local branches and unique remote branches
' '
1819 test_completion
"git switch -C " <<-\EOF
1827 test_expect_success 'git switch - for -c with
--no-guess, complete
local branches only
' '
1828 test_completion
"git switch --no-guess -c " <<-\EOF
1834 test_expect_success 'git switch - for -C with
--no-guess, complete
local branches only
' '
1835 test_completion
"git switch --no-guess -C " <<-\EOF
1841 test_expect_success 'git switch - for -c with
--no-track, complete
local branches only
' '
1842 test_completion
"git switch --no-track -c " <<-\EOF
1848 test_expect_success 'git switch - for -C with
--no-track, complete
local branches only
' '
1849 test_completion
"git switch --no-track -C " <<-\EOF
1855 test_expect_success 'git checkout - for -b, complete
local branches and unique remote branches
' '
1856 test_completion
"git checkout -b " <<-\EOF
1864 test_expect_success 'git checkout - for -B, complete
local branches and unique remote branches
' '
1865 test_completion
"git checkout -B " <<-\EOF
1873 test_expect_success 'git checkout - for -b with
--no-guess, complete
local branches only
' '
1874 test_completion
"git checkout --no-guess -b " <<-\EOF
1880 test_expect_success 'git checkout - for -B with
--no-guess, complete
local branches only
' '
1881 test_completion
"git checkout --no-guess -B " <<-\EOF
1887 test_expect_success 'git checkout - for -b with
--no-track, complete
local branches only
' '
1888 test_completion
"git checkout --no-track -b " <<-\EOF
1894 test_expect_success 'git checkout - for -B with
--no-track, complete
local branches only
' '
1895 test_completion
"git checkout --no-track -B " <<-\EOF
1901 test_expect_success 'git switch - with
--orphan completes
local branch names and unique remote branch names
' '
1902 test_completion
"git switch --orphan " <<-\EOF
1910 test_expect_success 'git switch - --orphan with branch already provided completes nothing
else' '
1911 test_completion
"git switch --orphan main " <<-\EOF
1916 test_expect_success 'git checkout - with
--orphan completes
local branch names and unique remote branch names
' '
1917 test_completion
"git checkout --orphan " <<-\EOF
1925 test_expect_success 'git checkout - --orphan with branch already provided completes
local refs
for a start-point
' '
1926 test_completion
"git checkout --orphan main " <<-\EOF
1931 other/branch-in-other Z
1932 other/main-in-other Z
1936 test_expect_success 'git restore completes modified files' '
1937 test_commit A a.file &&
1939 test_completion "git restore a." <<-\
EOF
1944 test_expect_success 'teardown after ref completion' '
1945 git branch -d matching-branch &&
1946 git tag -d matching-tag &&
1947 git remote remove other
1951 test_path_completion ()
1953 test $# = 2 || BUG "not 2 parameters to test_path_completion"
1955 local cur="$1" expected="$2"
1956 echo "$expected" >expected &&
1958 # In the following tests calling this function we only
1959 # care about how __git_complete_index_file() deals with
1960 # unusual characters in path names. By requesting only
1961 # untracked files we do not have to bother adding any
1962 # paths to the index in those tests.
1963 __git_complete_index_file --others &&
1966 test_cmp expected out
1969 test_expect_success 'setup for path completion tests' '
1973 touch simple-dir/simple-file \
1974 "spaces in dir/spaces in file" \
1975 "árvíztűrő/Сайн яваарай" &&
1976 if test_have_prereq !MINGW &&
1978 '$'separators\034in\035dir'' &&
1979 touch BS\\dir/DQ\"file \
1980 '$'separators\034in\035dir/sep\036in\037file''
1982 test_set_prereq FUNNIERNAMES
1984 rm -rf BS\\dir '$'separators\034in\035dir''
1988 test_expect_success '__git_complete_index_file - simple
' '
1989 test_path_completion simple simple-dir
&& # Bash is supposed to
1990 # add the trailing /.
1991 test_path_completion simple-dir
/simple simple-dir
/simple-file
1994 test_expect_success \
1995 '__git_complete_index_file
- escaped characters on cmdline
' '
1996 test_path_completion spac
"spaces in dir" && # Bash will turn this
1997 # into "spaces\ in\ dir"
1998 test_path_completion
"spaces\\ i" \
2000 test_path_completion
"spaces\\ in\\ dir/s" \
2001 "spaces in dir/spaces in file" &&
2002 test_path_completion
"spaces\\ in\\ dir/spaces\\ i" \
2003 "spaces in dir/spaces in file"
2006 test_expect_success \
2007 '__git_complete_index_file
- quoted characters on cmdline
' '
2008 # Testing with an opening but without a corresponding closing
2009 # double quote is important.
2010 test_path_completion
\"spac
"spaces in dir" &&
2011 test_path_completion
"\"spaces i" \
2013 test_path_completion
"\"spaces in dir/s" \
2014 "spaces in dir/spaces in file" &&
2015 test_path_completion
"\"spaces in dir/spaces i" \
2016 "spaces in dir/spaces in file"
2019 test_expect_success '__git_complete_index_file
- UTF-8
in ls-files output
' '
2020 test_path_completion á árvíztűrő
&&
2021 test_path_completion árvíztűrő
/С
"árvíztűrő/Сайн яваарай"
2024 test_expect_success FUNNIERNAMES \
2025 '__git_complete_index_file
- C-style escapes
in ls-files output
' '
2026 test_path_completion BS \
2028 test_path_completion BS
\\\\d \
2030 test_path_completion BS
\\\\dir
/DQ \
2032 test_path_completion BS
\\\\dir
/DQ
\\\"f \
2036 test_expect_success FUNNIERNAMES \
2037 '__git_complete_index_file
- \nnn
-escaped characters
in ls-files output
' '
2038 test_path_completion sep
'$'separators
\034in\035dir
'' &&
2039 test_path_completion
'$'separators
\034i
'' \
2040 '$'separators
\034in\035dir
'' &&
2041 test_path_completion
'$'separators
\034in\035dir
/sep
'' \
2042 '$'separators
\034in\035dir
/sep
\036in\037file'' &&
2043 test_path_completion
'$'separators
\034in\035dir
/sep
\036i
'' \
2044 '$'separators
\034in\035dir
/sep
\036in\037file''
2047 test_expect_success FUNNYNAMES \
2048 '__git_complete_index_file
- removing repeated quoted path components
' '
2049 test_when_finished
rm -r repeated-quoted
&&
2050 mkdir repeated-quoted
&& # A directory whose name in itself
2051 # would not be quoted ...
2052 >repeated-quoted
/0-file &&
2053 >repeated-quoted
/1\"file && # ... but here the file makes the
2054 # dirname quoted ...
2055 >repeated-quoted
/2-file &&
2056 >repeated-quoted
/3\"file && # ... and here, too.
2058 # Still, we shold only list the directory name only once.
2059 test_path_completion repeated repeated-quoted
2062 test_expect_success 'teardown after path completion tests
' '
2063 rm -rf simple-dir
"spaces in dir" árvíztűrő \
2064 BS
\\dir
'$'separators
\034in\035dir
''
2067 test_expect_success '__git_find_on_cmdline
- single match
' '
2068 echo list
>expect
&&
2070 words
=(git
command --opt list
) &&
2071 cword
=${#words[@]} &&
2073 __git_find_on_cmdline
"add list remove" >actual
2075 test_cmp expect actual
2078 test_expect_success '__git_find_on_cmdline
- multiple matches
' '
2079 echo remove
>expect
&&
2081 words
=(git
command -o --opt remove list add
) &&
2082 cword
=${#words[@]} &&
2084 __git_find_on_cmdline
"add list remove" >actual
2086 test_cmp expect actual
2089 test_expect_success '__git_find_on_cmdline
- no match
' '
2091 words
=(git
command --opt branch
) &&
2092 cword
=${#words[@]} &&
2094 __git_find_on_cmdline
"add list remove" >actual
2096 test_must_be_empty actual
2099 test_expect_success '__git_find_on_cmdline
- single match with index
' '
2100 echo "3 list" >expect
&&
2102 words
=(git
command --opt list
) &&
2103 cword
=${#words[@]} &&
2105 __git_find_on_cmdline
--show-idx "add list remove" >actual
2107 test_cmp expect actual
2110 test_expect_success '__git_find_on_cmdline
- multiple matches with index
' '
2111 echo "4 remove" >expect
&&
2113 words
=(git
command -o --opt remove list add
) &&
2114 cword
=${#words[@]} &&
2116 __git_find_on_cmdline
--show-idx "add list remove" >actual
2118 test_cmp expect actual
2121 test_expect_success '__git_find_on_cmdline
- no match with index
' '
2123 words
=(git
command --opt branch
) &&
2124 cword
=${#words[@]} &&
2126 __git_find_on_cmdline
--show-idx "add list remove" >actual
2128 test_must_be_empty actual
2131 test_expect_success '__git_find_on_cmdline
- ignores matches before
command with index
' '
2132 echo "6 remove" >expect
&&
2134 words
=(git
-C remove
command -o --opt remove list add
) &&
2135 cword
=${#words[@]} &&
2137 __git_find_on_cmdline
--show-idx "add list remove" >actual
2139 test_cmp expect actual
2142 test_expect_success '__git_get_config_variables
' '
2143 cat >expect
<<-EOF &&
2147 test_config interesting.name-1 good
&&
2148 test_config interesting.name-2 good
&&
2149 test_config subsection.interesting.name-3 bad
&&
2150 __git_get_config_variables interesting
>actual
&&
2151 test_cmp expect actual
2154 test_expect_success '__git_pretty_aliases
' '
2155 cat >expect
<<-EOF &&
2159 test_config pretty.author
"%an %ae" &&
2160 test_config pretty.
hash %H
&&
2161 __git_pretty_aliases
>actual
&&
2162 test_cmp expect actual
2165 test_expect_success 'basic
' '
2166 run_completion
"git " &&
2168 grep -q "^add \$" out
&&
2170 grep -q "^rebase \$" out
&&
2172 ! grep -q "^ls-files \$" out
&&
2174 run_completion
"git r" &&
2175 ! grep -q -v "^r" out
2178 test_expect_success 'double dash
"git" itself
' '
2179 test_completion
"git --" <<-\EOF
2192 --no-replace-objects Z
2197 test_expect_success 'double dash "git checkout"' '
2198 test_completion "git checkout --" <<-\
EOF
2208 --ignore-skip-worktree-bits Z
2209 --ignore-other-worktrees Z
2210 --recurse-submodules Z
2216 --pathspec-file-nul Z
2217 --pathspec-from-file=Z
2221 test_expect_success 'general options' '
2222 test_completion "git --ver" "--version " &&
2223 test_completion "git --hel" "--help " &&
2224 test_completion "git --exe" <<-\EOF &&
2228 test_completion "git --htm" "--html-path " &&
2229 test_completion "git --pag" "--paginate " &&
2230 test_completion "git --no-p" "--no-pager " &&
2231 test_completion "git --git" "--git-dir=" &&
2232 test_completion "git --wor" "--work-tree=" &&
2233 test_completion "git --nam" "--namespace=" &&
2234 test_completion "git --bar" "--bare " &&
2235 test_completion "git --inf" "--info-path " &&
2236 test_completion "git --no-r" "--no-replace-objects "
2239 test_expect_success 'general options plus command' '
2240 test_completion "git --version check" "checkout " &&
2241 test_completion "git --paginate check" "checkout " &&
2242 test_completion "git --git-dir=foo check" "checkout " &&
2243 test_completion "git --bare check" "checkout " &&
2244 test_completion "git --exec-path=foo check" "checkout " &&
2245 test_completion "git --html-path check" "checkout " &&
2246 test_completion "git --no-pager check" "checkout " &&
2247 test_completion "git --work-tree=foo check" "checkout " &&
2248 test_completion "git --namespace=foo check" "checkout " &&
2249 test_completion "git --paginate check" "checkout " &&
2250 test_completion "git --info-path check" "checkout " &&
2251 test_completion "git --no-replace-objects check" "checkout " &&
2252 test_completion "git --git-dir some/path check" "checkout " &&
2253 test_completion "git -c conf.var=value check" "checkout " &&
2254 test_completion "git -C some/path check" "checkout " &&
2255 test_completion "git --work-tree some/path check" "checkout " &&
2256 test_completion "git --namespace name/space check" "checkout "
2259 test_expect_success 'git --help completion' '
2260 test_completion "git --help ad" "add " &&
2261 test_completion "git --help core" "core-tutorial "
2264 test_expect_success 'completion.commands removes multiple commands' '
2265 test_config completion.commands "-cherry -mergetool" &&
2266 git --list-cmds=list-mainporcelain,list-complete,config >out &&
2267 ! grep -E "^(cherry|mergetool)$" out
2270 test_expect_success 'setup for integration tests' '
2271 echo content >file1 &&
2273 git add file1 file2 &&
2274 git commit -m one &&
2275 git branch mybranch &&
2279 test_expect_success 'checkout completes ref names' '
2280 test_completion "git checkout m" <<-\EOF
2287 test_expect_success 'checkout does not match ref names of a different case' '
2288 test_completion "git checkout M" ""
2291 test_expect_success 'checkout matches case insensitively with GIT_COMPLETION_IGNORE_CASE' '
2293 GIT_COMPLETION_IGNORE_CASE=1 &&
2294 test_completion "git checkout M" <<-\EOF
2302 test_expect_success 'checkout completes pseudo refs' '
2303 test_completion "git checkout H" <<-\EOF
2308 test_expect_success 'checkout completes pseudo refs case insensitively with GIT_COMPLETION_IGNORE_CASE' '
2310 GIT_COMPLETION_IGNORE_CASE=1 &&
2311 test_completion "git checkout h" <<-\EOF
2317 test_expect_success 'git -C <path> checkout uses the right repo' '
2318 test_completion "git -C subdir -C subsubdir -C .. -C ../otherrepo checkout b" <<-\EOF
2323 test_expect_success 'show completes all refs' '
2324 test_completion "git show m" <<-\EOF
2331 test_expect_success '<ref>: completes paths' '
2332 test_completion "git show mytag:f" <<-\EOF
2338 test_expect_success 'complete tree filename with spaces' '
2339 echo content >"name with spaces" &&
2340 git add "name with spaces" &&
2341 git commit -m spaces &&
2342 test_completion "git show HEAD:nam" <<-\EOF
2347 test_expect_success 'complete tree filename with metacharacters' '
2348 echo content >"name with \${meta}" &&
2349 git add "name with \${meta}" &&
2350 git commit -m meta &&
2351 test_completion "git show HEAD:nam" <<-\EOF
2357 test_expect_success PERL 'send-email' '
2358 test_completion "git send-email --cov" <<-\EOF &&
2359 --cover-from-description=Z
2362 test_completion "git send-email --val" <<-\EOF &&
2365 test_completion "git send-email ma" "main "
2368 test_expect_success 'complete files' '
2369 git init tmp && cd tmp &&
2370 test_when_finished "cd .. && rm -rf tmp" &&
2372 echo "expected" > .gitignore &&
2373 echo "out" >> .gitignore &&
2374 echo "out_sorted" >> .gitignore &&
2376 git add .gitignore &&
2377 test_completion "git commit " ".gitignore" &&
2379 git commit -m ignore &&
2382 test_completion "git add " "new" &&
2385 git commit -a -m new &&
2386 test_completion "git add " "" &&
2388 git mv new modified &&
2389 echo modify > modified &&
2390 test_completion "git add " "modified" &&
2392 mkdir -p some/deep &&
2393 touch some/deep/path &&
2394 test_completion "git add some/" "some/deep" &&
2395 git clean -f some &&
2399 : TODO .gitignore should not be here &&
2400 test_completion "git rm " <<-\EOF &&
2405 test_completion "git clean " "untracked" &&
2407 : TODO .gitignore should not be here &&
2408 test_completion "git mv " <<-\EOF &&
2414 touch dir/file-in-dir &&
2415 git add dir/file-in-dir &&
2416 git commit -m dir &&
2418 mkdir untracked-dir &&
2420 : TODO .gitignore should not be here &&
2421 test_completion "git mv modified " <<-\EOF &&
2429 test_completion "git commit " "modified" &&
2431 : TODO .gitignore should not be here &&
2432 test_completion "git ls-files " <<-\EOF &&
2439 test_completion "git add mom" "momified"
2442 test_expect_success "simple alias" '
2443 test_config alias.co checkout &&
2444 test_completion "git co m" <<-\EOF
2451 test_expect_success "recursive alias" '
2452 test_config alias.co checkout &&
2453 test_config alias.cod "co --detached" &&
2454 test_completion "git cod m" <<-\EOF
2461 test_expect_success "completion uses <cmd> completion for alias: !sh -c 'git <cmd> ...'" '
2462 test_config alias.co "!sh -c '"'"'git checkout ...'"'"'" &&
2463 test_completion "git co m" <<-\EOF
2470 test_expect_success 'completion uses <cmd> completion for alias: !f () { VAR=val git <cmd> ... }' '
2471 test_config alias.co "!f () { VAR=val git checkout ... ; } f" &&
2472 test_completion "git co m" <<-\EOF
2479 test_expect_success 'completion used <cmd> completion for alias: !f() { : git <cmd> ; ... }' '
2480 test_config alias.co "!f() { : git checkout ; if ... } f" &&
2481 test_completion "git co m" <<-\EOF
2488 test_expect_success 'completion used <cmd> completion for alias: !f() { : <cmd> ; ... }' '
2489 test_config alias.co "!f() { : checkout ; if ... } f" &&
2490 test_completion "git co m" <<-\EOF
2497 test_expect_success 'completion used <cmd> completion for alias: !f() { : <cmd>; ... }' '
2498 test_config alias.co "!f() { : checkout; if ... } f" &&
2499 test_completion "git co m" <<-\EOF
2506 test_expect_success 'completion without explicit _git_xxx function' '
2507 test_completion "git version --" <<-\EOF
2509 --no-build-options Z
2513 test_expect_failure 'complete with tilde expansion' '
2514 git init tmp && cd tmp &&
2515 test_when_finished "cd .. && rm -rf tmp" &&
2519 test_completion "git add ~/tmp/" "~/tmp/file"
2522 test_expect_success 'setup other remote for remote reference completion' '
2523 git remote add other otherrepo &&
2527 for flag in -d --delete
2529 test_expect_success "__git_complete_remote_or_refspec - push
$flag other
" '
2530 sed -e "s
/Z$
//" >expected <<-EOF &&
2534 words=(git push '$flag' other ma) &&
2535 cword=${#words[@]} cur=${words[cword-1]} &&
2537 __git_complete_remote_or_refspec &&
2540 test_cmp expected out
2543 test_expect_failure "__git_complete_remote_or_refspec
- push other
$flag" '
2544 sed -e "s
/Z$
//" >expected <<-EOF &&
2548 words=(git push other '$flag' ma) &&
2549 cword=${#words[@]} cur=${words[cword-1]} &&
2551 __git_complete_remote_or_refspec &&
2554 test_cmp expected out
2558 test_expect_success 'git config - section' '
2559 test_completion "git config br
" <<-\EOF
2565 test_expect_success 'git config - section include, includeIf' '
2566 test_completion "git config inclu
" <<-\EOF
2572 test_expect_success 'git config - variable name' '
2573 test_completion "git config log.d
" <<-\EOF
2580 test_expect_success 'git config - variable name include' '
2581 test_completion "git config include.p
" <<-\EOF
2586 test_expect_success 'git config - value' '
2587 test_completion "git config color.pager
" <<-\EOF
2593 test_expect_success 'git -c - section' '
2594 test_completion "git
-c br
" <<-\EOF
2600 test_expect_success 'git -c - variable name' '
2601 test_completion "git
-c log.d
" <<-\EOF
2608 test_expect_success 'git -c - value' '
2609 test_completion "git
-c color.pager
=" <<-\EOF
2615 test_expect_success 'git clone --config= - section' '
2616 test_completion "git clone
--config=br
" <<-\EOF
2622 test_expect_success 'git clone --config= - variable name' '
2623 test_completion "git clone
--config=log.d
" <<-\EOF
2630 test_expect_success 'git clone --config= - value' '
2631 test_completion "git clone
--config=color.pager
=" <<-\EOF
2637 test_expect_success 'options with value' '
2638 test_completion "git merge
-X diff-algorithm
=" <<-\EOF
2643 test_expect_success 'sourcing the completion script clears cached commands' '
2645 __git_compute_all_commands &&
2646 test -n "$__git_all_commands" &&
2647 . "$GIT_BUILD_DIR/contrib
/completion
/git-completion.bash
" &&
2648 test -z "$__git_all_commands"
2652 test_expect_success 'sourcing the completion script clears cached merge strategies' '
2654 __git_compute_merge_strategies &&
2655 test -n "$__git_merge_strategies" &&
2656 . "$GIT_BUILD_DIR/contrib
/completion
/git-completion.bash
" &&
2657 test -z "$__git_merge_strategies"
2661 test_expect_success 'sourcing the completion script clears cached --options' '
2663 __gitcomp_builtin checkout &&
2664 test -n "$__gitcomp_builtin_checkout" &&
2665 __gitcomp_builtin notes_edit &&
2666 test -n "$__gitcomp_builtin_notes_edit" &&
2667 . "$GIT_BUILD_DIR/contrib
/completion
/git-completion.bash
" &&
2668 test -z "$__gitcomp_builtin_checkout" &&
2669 test -z "$__gitcomp_builtin_notes_edit"
2673 test_expect_success 'option aliases are not shown by default' '
2674 test_completion "git clone
--recurs" "--recurse-submodules "
2677 test_expect_success 'option aliases are shown with GIT_COMPLETION_SHOW_ALL' '
2679 . "$GIT_BUILD_DIR/contrib
/completion
/git-completion.bash
" &&
2680 GIT_COMPLETION_SHOW_ALL=1 && export GIT_COMPLETION_SHOW_ALL &&
2681 test_completion "git clone
--recurs" <<-\EOF
2682 --recurse-submodules Z
2688 test_expect_success 'plumbing commands are excluded without GIT_COMPLETION_SHOW_ALL_COMMANDS' '
2690 . "$GIT_BUILD_DIR/contrib
/completion
/git-completion.bash
" &&
2691 sane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST &&
2693 # Just mainporcelain, not plumbing commands
2694 run_completion "git c
" &&
2695 grep checkout out &&
2700 test_expect_success 'all commands are shown with GIT_COMPLETION_SHOW_ALL_COMMANDS (also main non-builtin)' '
2702 . "$GIT_BUILD_DIR/contrib
/completion
/git-completion.bash
" &&
2703 GIT_COMPLETION_SHOW_ALL_COMMANDS=1 &&
2704 export GIT_COMPLETION_SHOW_ALL_COMMANDS &&
2705 sane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST &&
2707 # Both mainporcelain and plumbing commands
2708 run_completion "git c
" &&
2709 grep checkout out &&
2710 grep cat-file out &&
2712 # Check "gitk
", a "main
" command, but not a built-in + more plumbing
2713 run_completion "git g
" &&
2715 grep get-tar-commit-id out
2719 test_expect_success '__git_complete' '
2720 unset -f __git_wrap__git_main &&
2722 __git_complete foo __git_main &&
2723 __git_have_func __git_wrap__git_main &&
2724 unset -f __git_wrap__git_main &&
2726 __git_complete gf _git_fetch &&
2727 __git_have_func __git_wrap_git_fetch &&
2729 __git_complete foo git &&
2730 __git_have_func __git_wrap__git_main &&
2731 unset -f __git_wrap__git_main &&
2733 __git_complete gd git_diff &&
2734 __git_have_func __git_wrap_git_diff &&
2736 test_must_fail __git_complete ga missing
2739 test_expect_success '__git_pseudoref_exists' '
2740 test_when_finished "rm -rf repo
" &&
2744 sane_unset __git_repo_path &&
2746 # HEAD should exist, even if it points to an unborn branch.
2747 __git_pseudoref_exists HEAD >output 2>&1 &&
2748 test_must_be_empty output &&
2750 # HEAD points to an existing branch, so it should exist.
2752 __git_pseudoref_exists HEAD >output 2>&1 &&
2753 test_must_be_empty output &&
2755 # CHERRY_PICK_HEAD does not exist, so the existence check should fail.
2756 ! __git_pseudoref_exists CHERRY_PICK_HEAD >output 2>&1 &&
2757 test_must_be_empty output &&
2759 # CHERRY_PICK_HEAD points to a commit, so it should exist.
2760 git update-ref CHERRY_PICK_HEAD A &&
2761 __git_pseudoref_exists CHERRY_PICK_HEAD >output 2>&1 &&
2762 test_must_be_empty output