]> git.ipfire.org Git - thirdparty/git.git/blame - t/t9902-completion.sh
completion: reflog with implicit "show"
[thirdparty/git.git] / t / t9902-completion.sh
CommitLineData
5c293a6b
FC
1#!/bin/sh
2#
af806a2c 3# Copyright (c) 2012-2020 Felipe Contreras
5c293a6b
FC
4#
5
5c293a6b
FC
6test_description='test bash completion'
7
f8891cfa 8. ./lib-bash.sh
5c293a6b
FC
9
10complete ()
11{
12 # do nothing
13 return 0
14}
15
84a97131 16# Be careful when updating these lists:
50478223
JH
17#
18# (1) The build tree may have build artifact from different branch, or
19# the user's $PATH may have a random executable that may begin
20# with "git-check" that are not part of the subcommands this build
21# will ship, e.g. "check-ignore". The tests for completion for
22# subcommand names tests how "check" is expanded; we limit the
23# possible candidates to "checkout" and "check-attr" to make sure
24# "check-attr", which is known by the filter function as a
25# subcommand to be thrown out, while excluding other random files
26# that happen to begin with "check" to avoid letting them get in
27# the way.
28#
29# (2) A test makes sure that common subcommands are included in the
30# completion for "git <TAB>", and a plumbing is excluded. "add",
483e8611 31# "rebase" and "ls-files" are listed for this.
50478223 32
483e8611
EN
33GIT_TESTING_ALL_COMMAND_LIST='add checkout check-attr rebase ls-files'
34GIT_TESTING_PORCELAIN_COMMAND_LIST='add checkout rebase'
50478223 35
5c293a6b
FC
36. "$GIT_BUILD_DIR/contrib/completion/git-completion.bash"
37
38# We don't need this function to actually join words or do anything special.
39# Also, it's cleaner to avoid touching bash's internal completion variables.
40# So let's override it with a minimal version for testing purposes.
41_get_comp_words_by_ref ()
42{
43 while [ $# -gt 0 ]; do
44 case "$1" in
45 cur)
46 cur=${_words[_cword]}
47 ;;
48 prev)
49 prev=${_words[_cword-1]}
50 ;;
51 words)
52 words=("${_words[@]}")
53 ;;
54 cword)
55 cword=$_cword
56 ;;
57 esac
58 shift
59 done
60}
61
62print_comp ()
63{
64 local IFS=$'\n'
65 echo "${COMPREPLY[*]}" > out
66}
67
68run_completion ()
69{
70 local -a COMPREPLY _words
71 local _cword
72 _words=( $1 )
0ef09702 73 test "${1: -1}" = ' ' && _words[${#_words[@]}+1]=''
5c293a6b 74 (( _cword = ${#_words[@]} - 1 ))
93b291e0 75 __git_wrap__git_main && print_comp
5c293a6b
FC
76}
77
701ecdf1
FC
78# Test high-level completion
79# Arguments are:
80# 1: typed text so far (cur)
81# 2: expected completion
5c293a6b
FC
82test_completion ()
83{
2fbaf813
FC
84 if test $# -gt 1
85 then
86 printf '%s\n' "$2" >expected
87 else
9703797c 88 sed -e 's/Z$//' |sort >expected
2fbaf813 89 fi &&
701ecdf1 90 run_completion "$1" &&
9703797c
SG
91 sort out >out_sorted &&
92 test_cmp expected out_sorted
5c293a6b
FC
93}
94
e4615238
FC
95# Test __gitcomp.
96# The first argument is the typed text so far (cur); the rest are
97# passed to __gitcomp. Expected output comes is read from the
98# standard input, like test_completion().
99test_gitcomp ()
49ba92b4 100{
17393033 101 local -a COMPREPLY &&
e4615238 102 sed -e 's/Z$//' >expected &&
eac90623 103 local cur="$1" &&
17393033
FC
104 shift &&
105 __gitcomp "$@" &&
106 print_comp &&
74a8c849 107 test_cmp expected out
49ba92b4
JK
108}
109
43369a22
FC
110# Test __gitcomp_nl
111# Arguments are:
112# 1: current word (cur)
113# -: the rest are passed to __gitcomp_nl
114test_gitcomp_nl ()
115{
116 local -a COMPREPLY &&
117 sed -e 's/Z$//' >expected &&
eac90623 118 local cur="$1" &&
43369a22
FC
119 shift &&
120 __gitcomp_nl "$@" &&
121 print_comp &&
122 test_cmp expected out
123}
124
125invalid_variable_name='${foo.bar}'
126
c9a102e8
SG
127actual="$TRASH_DIRECTORY/actual"
128
f6114408
SG
129if test_have_prereq MINGW
130then
131 ROOT="$(pwd -W)"
132else
133 ROOT="$(pwd)"
134fi
135
fad9484f 136test_expect_success 'setup for __git_find_repo_path/__gitdir tests' '
c9a102e8 137 mkdir -p subdir/subsubdir &&
fad9484f 138 mkdir -p non-repo &&
00076181 139 git init -b main otherrepo
c9a102e8
SG
140'
141
fad9484f 142test_expect_success '__git_find_repo_path - from command line (through $__git_dir)' '
f6114408 143 echo "$ROOT/otherrepo/.git" >expected &&
c9a102e8 144 (
f6114408 145 __git_dir="$ROOT/otherrepo/.git" &&
fad9484f
SG
146 __git_find_repo_path &&
147 echo "$__git_repo_path" >"$actual"
beb6ee71 148 ) &&
c9a102e8
SG
149 test_cmp expected "$actual"
150'
151
fad9484f 152test_expect_success '__git_find_repo_path - .git directory in cwd' '
c9a102e8 153 echo ".git" >expected &&
beb6ee71 154 (
fad9484f
SG
155 __git_find_repo_path &&
156 echo "$__git_repo_path" >"$actual"
beb6ee71 157 ) &&
c9a102e8
SG
158 test_cmp expected "$actual"
159'
160
fad9484f 161test_expect_success '__git_find_repo_path - .git directory in parent' '
f6114408 162 echo "$ROOT/.git" >expected &&
c9a102e8
SG
163 (
164 cd subdir/subsubdir &&
fad9484f
SG
165 __git_find_repo_path &&
166 echo "$__git_repo_path" >"$actual"
c9a102e8
SG
167 ) &&
168 test_cmp expected "$actual"
169'
170
fad9484f 171test_expect_success '__git_find_repo_path - cwd is a .git directory' '
c9a102e8
SG
172 echo "." >expected &&
173 (
174 cd .git &&
fad9484f
SG
175 __git_find_repo_path &&
176 echo "$__git_repo_path" >"$actual"
c9a102e8
SG
177 ) &&
178 test_cmp expected "$actual"
179'
180
fad9484f 181test_expect_success '__git_find_repo_path - parent is a .git directory' '
f6114408 182 echo "$ROOT/.git" >expected &&
c9a102e8 183 (
5340d471 184 cd .git/objects &&
fad9484f
SG
185 __git_find_repo_path &&
186 echo "$__git_repo_path" >"$actual"
c9a102e8
SG
187 ) &&
188 test_cmp expected "$actual"
189'
190
fad9484f 191test_expect_success '__git_find_repo_path - $GIT_DIR set while .git directory in cwd' '
f6114408 192 echo "$ROOT/otherrepo/.git" >expected &&
c9a102e8 193 (
f6114408 194 GIT_DIR="$ROOT/otherrepo/.git" &&
c9a102e8 195 export GIT_DIR &&
fad9484f
SG
196 __git_find_repo_path &&
197 echo "$__git_repo_path" >"$actual"
c9a102e8
SG
198 ) &&
199 test_cmp expected "$actual"
200'
201
fad9484f 202test_expect_success '__git_find_repo_path - $GIT_DIR set while .git directory in parent' '
f6114408 203 echo "$ROOT/otherrepo/.git" >expected &&
c9a102e8 204 (
f6114408 205 GIT_DIR="$ROOT/otherrepo/.git" &&
c9a102e8
SG
206 export GIT_DIR &&
207 cd subdir &&
fad9484f
SG
208 __git_find_repo_path &&
209 echo "$__git_repo_path" >"$actual"
c9a102e8
SG
210 ) &&
211 test_cmp expected "$actual"
212'
213
fad9484f 214test_expect_success '__git_find_repo_path - from command line while "git -C"' '
80ac0744
SG
215 echo "$ROOT/.git" >expected &&
216 (
217 __git_dir="$ROOT/.git" &&
218 __git_C_args=(-C otherrepo) &&
fad9484f
SG
219 __git_find_repo_path &&
220 echo "$__git_repo_path" >"$actual"
80ac0744
SG
221 ) &&
222 test_cmp expected "$actual"
223'
224
fad9484f 225test_expect_success '__git_find_repo_path - relative dir from command line and "git -C"' '
80ac0744
SG
226 echo "$ROOT/otherrepo/.git" >expected &&
227 (
228 cd subdir &&
229 __git_dir="otherrepo/.git" &&
230 __git_C_args=(-C ..) &&
fad9484f
SG
231 __git_find_repo_path &&
232 echo "$__git_repo_path" >"$actual"
80ac0744
SG
233 ) &&
234 test_cmp expected "$actual"
235'
236
fad9484f 237test_expect_success '__git_find_repo_path - $GIT_DIR set while "git -C"' '
80ac0744
SG
238 echo "$ROOT/.git" >expected &&
239 (
240 GIT_DIR="$ROOT/.git" &&
241 export GIT_DIR &&
242 __git_C_args=(-C otherrepo) &&
fad9484f
SG
243 __git_find_repo_path &&
244 echo "$__git_repo_path" >"$actual"
80ac0744
SG
245 ) &&
246 test_cmp expected "$actual"
247'
248
fad9484f 249test_expect_success '__git_find_repo_path - relative dir in $GIT_DIR and "git -C"' '
80ac0744
SG
250 echo "$ROOT/otherrepo/.git" >expected &&
251 (
252 cd subdir &&
253 GIT_DIR="otherrepo/.git" &&
254 export GIT_DIR &&
255 __git_C_args=(-C ..) &&
fad9484f
SG
256 __git_find_repo_path &&
257 echo "$__git_repo_path" >"$actual"
80ac0744
SG
258 ) &&
259 test_cmp expected "$actual"
260'
261
fad9484f 262test_expect_success '__git_find_repo_path - "git -C" while .git directory in cwd' '
80ac0744
SG
263 echo "$ROOT/otherrepo/.git" >expected &&
264 (
265 __git_C_args=(-C otherrepo) &&
fad9484f
SG
266 __git_find_repo_path &&
267 echo "$__git_repo_path" >"$actual"
80ac0744
SG
268 ) &&
269 test_cmp expected "$actual"
270'
271
fad9484f 272test_expect_success '__git_find_repo_path - "git -C" while cwd is a .git directory' '
80ac0744
SG
273 echo "$ROOT/otherrepo/.git" >expected &&
274 (
275 cd .git &&
276 __git_C_args=(-C .. -C otherrepo) &&
fad9484f
SG
277 __git_find_repo_path &&
278 echo "$__git_repo_path" >"$actual"
80ac0744
SG
279 ) &&
280 test_cmp expected "$actual"
281'
282
fad9484f 283test_expect_success '__git_find_repo_path - "git -C" while .git directory in parent' '
80ac0744
SG
284 echo "$ROOT/otherrepo/.git" >expected &&
285 (
286 cd subdir &&
287 __git_C_args=(-C .. -C otherrepo) &&
fad9484f
SG
288 __git_find_repo_path &&
289 echo "$__git_repo_path" >"$actual"
80ac0744
SG
290 ) &&
291 test_cmp expected "$actual"
292'
293
fad9484f 294test_expect_success '__git_find_repo_path - non-existing path in "git -C"' '
80ac0744
SG
295 (
296 __git_C_args=(-C non-existing) &&
fad9484f
SG
297 test_must_fail __git_find_repo_path &&
298 printf "$__git_repo_path" >"$actual"
80ac0744
SG
299 ) &&
300 test_must_be_empty "$actual"
301'
302
fad9484f 303test_expect_success '__git_find_repo_path - non-existing path in $__git_dir' '
a2f03b0e
SG
304 (
305 __git_dir="non-existing" &&
fad9484f
SG
306 test_must_fail __git_find_repo_path &&
307 printf "$__git_repo_path" >"$actual"
a2f03b0e
SG
308 ) &&
309 test_must_be_empty "$actual"
310'
311
fad9484f 312test_expect_success '__git_find_repo_path - non-existing $GIT_DIR' '
c9a102e8 313 (
f6114408 314 GIT_DIR="$ROOT/non-existing" &&
c9a102e8 315 export GIT_DIR &&
fad9484f
SG
316 test_must_fail __git_find_repo_path &&
317 printf "$__git_repo_path" >"$actual"
8f0fa85d
SG
318 ) &&
319 test_must_be_empty "$actual"
c9a102e8
SG
320'
321
fad9484f 322test_expect_success '__git_find_repo_path - gitfile in cwd' '
f6114408
SG
323 echo "$ROOT/otherrepo/.git" >expected &&
324 echo "gitdir: $ROOT/otherrepo/.git" >subdir/.git &&
c9a102e8
SG
325 test_when_finished "rm -f subdir/.git" &&
326 (
327 cd subdir &&
fad9484f
SG
328 __git_find_repo_path &&
329 echo "$__git_repo_path" >"$actual"
c9a102e8
SG
330 ) &&
331 test_cmp expected "$actual"
332'
333
fad9484f 334test_expect_success '__git_find_repo_path - gitfile in parent' '
f6114408
SG
335 echo "$ROOT/otherrepo/.git" >expected &&
336 echo "gitdir: $ROOT/otherrepo/.git" >subdir/.git &&
c9a102e8
SG
337 test_when_finished "rm -f subdir/.git" &&
338 (
339 cd subdir/subsubdir &&
fad9484f
SG
340 __git_find_repo_path &&
341 echo "$__git_repo_path" >"$actual"
c9a102e8
SG
342 ) &&
343 test_cmp expected "$actual"
344'
345
fad9484f 346test_expect_success SYMLINKS '__git_find_repo_path - resulting path avoids symlinks' '
f6114408 347 echo "$ROOT/otherrepo/.git" >expected &&
c9a102e8
SG
348 mkdir otherrepo/dir &&
349 test_when_finished "rm -rf otherrepo/dir" &&
350 ln -s otherrepo/dir link &&
351 test_when_finished "rm -f link" &&
352 (
353 cd link &&
fad9484f
SG
354 __git_find_repo_path &&
355 echo "$__git_repo_path" >"$actual"
356 ) &&
357 test_cmp expected "$actual"
358'
359
360test_expect_success '__git_find_repo_path - not a git repository' '
361 (
362 cd non-repo &&
363 GIT_CEILING_DIRECTORIES="$ROOT" &&
364 export GIT_CEILING_DIRECTORIES &&
365 test_must_fail __git_find_repo_path &&
366 printf "$__git_repo_path" >"$actual"
367 ) &&
368 test_must_be_empty "$actual"
369'
370
371test_expect_success '__gitdir - finds repo' '
372 echo "$ROOT/.git" >expected &&
373 (
374 cd subdir/subsubdir &&
c9a102e8
SG
375 __gitdir >"$actual"
376 ) &&
377 test_cmp expected "$actual"
378'
379
fad9484f 380
4dc8b1c1 381test_expect_success '__gitdir - returns error when cannot find repo' '
fad9484f
SG
382 (
383 __git_dir="non-existing" &&
384 test_must_fail __gitdir >"$actual"
385 ) &&
8f0fa85d 386 test_must_be_empty "$actual"
c9a102e8
SG
387'
388
fad9484f
SG
389test_expect_success '__gitdir - repo as argument' '
390 echo "otherrepo/.git" >expected &&
391 (
392 __gitdir "otherrepo" >"$actual"
393 ) &&
394 test_cmp expected "$actual"
395'
396
397test_expect_success '__gitdir - remote as argument' '
398 echo "remote" >expected &&
399 (
400 __gitdir "remote" >"$actual"
401 ) &&
402 test_cmp expected "$actual"
403'
404
f12785a3
SG
405
406test_expect_success '__git_dequote - plain unquoted word' '
407 __git_dequote unquoted-word &&
8ddfce71 408 test unquoted-word = "$dequoted_word"
f12785a3
SG
409'
410
411# input: b\a\c\k\'\\\"s\l\a\s\h\es
412# expected: back'\"slashes
413test_expect_success '__git_dequote - backslash escaped' '
414 __git_dequote "b\a\c\k\\'\''\\\\\\\"s\l\a\s\h\es" &&
8ddfce71 415 test "back'\''\\\"slashes" = "$dequoted_word"
f12785a3
SG
416'
417
418# input: sin'gle\' '"quo'ted
419# expected: single\ "quoted
420test_expect_success '__git_dequote - single quoted' '
421 __git_dequote "'"sin'gle\\\\' '\\\"quo'ted"'" &&
8ddfce71 422 test '\''single\ "quoted'\'' = "$dequoted_word"
f12785a3
SG
423'
424
425# input: dou"ble\\" "\"\quot"ed
426# expected: double\ "\quoted
427test_expect_success '__git_dequote - double quoted' '
428 __git_dequote '\''dou"ble\\" "\"\quot"ed'\'' &&
8ddfce71 429 test '\''double\ "\quoted'\'' = "$dequoted_word"
f12785a3
SG
430'
431
432# input: 'open single quote
433test_expect_success '__git_dequote - open single quote' '
434 __git_dequote "'\''open single quote" &&
8ddfce71 435 test "open single quote" = "$dequoted_word"
f12785a3
SG
436'
437
438# input: "open double quote
439test_expect_success '__git_dequote - open double quote' '
440 __git_dequote "\"open double quote" &&
8ddfce71 441 test "open double quote" = "$dequoted_word"
f12785a3
SG
442'
443
444
fef56eb0
SG
445test_expect_success '__gitcomp_direct - puts everything into COMPREPLY as-is' '
446 sed -e "s/Z$//g" >expected <<-EOF &&
447 with-trailing-space Z
448 without-trailing-spaceZ
449 --option Z
450 --option=Z
451 $invalid_variable_name Z
452 EOF
453 (
454 cur=should_be_ignored &&
455 __gitcomp_direct "$(cat expected)" &&
456 print_comp
457 ) &&
458 test_cmp expected out
459'
460
74a8c849 461test_expect_success '__gitcomp - trailing space - options' '
e4615238
FC
462 test_gitcomp "--re" "--dry-run --reuse-message= --reedit-message=
463 --reset-author" <<-EOF
74a8c849
SG
464 --reuse-message=Z
465 --reedit-message=Z
466 --reset-author Z
467 EOF
74a8c849
SG
468'
469
470test_expect_success '__gitcomp - trailing space - config keys' '
e4615238
FC
471 test_gitcomp "br" "branch. branch.autosetupmerge
472 branch.autosetuprebase browser." <<-\EOF
74a8c849
SG
473 branch.Z
474 branch.autosetupmerge Z
475 branch.autosetuprebase Z
476 browser.Z
477 EOF
74a8c849
SG
478'
479
480test_expect_success '__gitcomp - option parameter' '
e4615238
FC
481 test_gitcomp "--strategy=re" "octopus ours recursive resolve subtree" \
482 "" "re" <<-\EOF
74a8c849
SG
483 recursive Z
484 resolve Z
485 EOF
74a8c849
SG
486'
487
488test_expect_success '__gitcomp - prefix' '
e4615238
FC
489 test_gitcomp "branch.me" "remote merge mergeoptions rebase" \
490 "branch.maint." "me" <<-\EOF
74a8c849
SG
491 branch.maint.merge Z
492 branch.maint.mergeoptions Z
493 EOF
74a8c849
SG
494'
495
496test_expect_success '__gitcomp - suffix' '
6dca5dbf 497 test_gitcomp "branch.me" "master maint next seen" "branch." \
e4615238 498 "ma" "." <<-\EOF
74a8c849
SG
499 branch.master.Z
500 branch.maint.Z
501 EOF
74a8c849
SG
502'
503
b221b5ab
NTND
504test_expect_success '__gitcomp - ignore optional negative options' '
505 test_gitcomp "--" "--abc --def --no-one -- --no-two" <<-\EOF
506 --abc Z
507 --def Z
508 --no-one Z
509 --no-... Z
510 EOF
511'
512
513test_expect_success '__gitcomp - ignore/narrow optional negative options' '
514 test_gitcomp "--a" "--abc --abcdef --no-one -- --no-two" <<-\EOF
515 --abc Z
516 --abcdef Z
517 EOF
518'
519
520test_expect_success '__gitcomp - ignore/narrow optional negative options' '
521 test_gitcomp "--n" "--abc --def --no-one -- --no-two" <<-\EOF
522 --no-one Z
523 --no-... Z
524 EOF
525'
526
527test_expect_success '__gitcomp - expand all negative options' '
528 test_gitcomp "--no-" "--abc --def --no-one -- --no-two" <<-\EOF
529 --no-one Z
530 --no-two Z
531 EOF
532'
533
534test_expect_success '__gitcomp - expand/narrow all negative options' '
535 test_gitcomp "--no-o" "--abc --def --no-one -- --no-two" <<-\EOF
536 --no-one Z
537 EOF
538'
539
e9f2118d
FC
540test_expect_success '__gitcomp - equal skip' '
541 test_gitcomp "--option=" "--option=" <<-\EOF &&
542
543 EOF
544 test_gitcomp "option=" "option=" <<-\EOF
545
546 EOF
547'
548
7d13e0a3 549test_expect_success '__gitcomp - doesnt fail because of invalid variable name' '
43369a22
FC
550 __gitcomp "$invalid_variable_name"
551'
552
553read -r -d "" refs <<-\EOF
f33f2d3d 554main
43369a22 555maint
43369a22 556next
6dca5dbf 557seen
43369a22
FC
558EOF
559
560test_expect_success '__gitcomp_nl - trailing space' '
561 test_gitcomp_nl "m" "$refs" <<-EOF
f33f2d3d 562 main Z
43369a22 563 maint Z
43369a22
FC
564 EOF
565'
566
567test_expect_success '__gitcomp_nl - prefix' '
568 test_gitcomp_nl "--fixup=m" "$refs" "--fixup=" "m" <<-EOF
f33f2d3d 569 --fixup=main Z
43369a22 570 --fixup=maint Z
43369a22
FC
571 EOF
572'
573
574test_expect_success '__gitcomp_nl - suffix' '
575 test_gitcomp_nl "branch.ma" "$refs" "branch." "ma" "." <<-\EOF
f33f2d3d 576 branch.main.Z
43369a22 577 branch.maint.Z
43369a22
FC
578 EOF
579'
580
581test_expect_success '__gitcomp_nl - no suffix' '
582 test_gitcomp_nl "ma" "$refs" "" "ma" "" <<-\EOF
f33f2d3d 583 mainZ
43369a22 584 maintZ
43369a22
FC
585 EOF
586'
587
7d13e0a3 588test_expect_success '__gitcomp_nl - doesnt fail because of invalid variable name' '
43369a22
FC
589 __gitcomp_nl "$invalid_variable_name"
590'
591
2acc1940
SG
592test_expect_success '__git_remotes - list remotes from $GIT_DIR/remotes and from config file' '
593 cat >expect <<-EOF &&
594 remote_from_file_1
595 remote_from_file_2
596 remote_in_config_1
597 remote_in_config_2
598 EOF
599 test_when_finished "rm -rf .git/remotes" &&
600 mkdir -p .git/remotes &&
601 >.git/remotes/remote_from_file_1 &&
602 >.git/remotes/remote_from_file_2 &&
603 test_when_finished "git remote remove remote_in_config_1" &&
604 git remote add remote_in_config_1 git://remote_1 &&
605 test_when_finished "git remote remove remote_in_config_2" &&
606 git remote add remote_in_config_2 git://remote_2 &&
beb6ee71
SG
607 (
608 __git_remotes >actual
609 ) &&
2acc1940
SG
610 test_cmp expect actual
611'
612
69a77596
SG
613test_expect_success '__git_is_configured_remote' '
614 test_when_finished "git remote remove remote_1" &&
615 git remote add remote_1 git://remote_1 &&
616 test_when_finished "git remote remove remote_2" &&
617 git remote add remote_2 git://remote_2 &&
beb6ee71 618 (
8ddfce71 619 __git_is_configured_remote remote_2 &&
beb6ee71
SG
620 test_must_fail __git_is_configured_remote non-existent
621 )
69a77596
SG
622'
623
fb9cd420
SG
624test_expect_success 'setup for ref completion' '
625 git commit --allow-empty -m initial &&
00076181 626 git branch -M main &&
fb9cd420
SG
627 git branch matching-branch &&
628 git tag matching-tag &&
629 (
630 cd otherrepo &&
631 git commit --allow-empty -m initial &&
00076181 632 git branch -m main main-in-other &&
fb9cd420
SG
633 git branch branch-in-other &&
634 git tag tag-in-other
635 ) &&
636 git remote add other "$ROOT/otherrepo/.git" &&
637 git fetch --no-tags other &&
638 rm -f .git/FETCH_HEAD &&
639 git init thirdrepo
640'
641
642test_expect_success '__git_refs - simple' '
643 cat >expected <<-EOF &&
644 HEAD
00076181 645 main
fb9cd420
SG
646 matching-branch
647 other/branch-in-other
00076181 648 other/main-in-other
fb9cd420
SG
649 matching-tag
650 EOF
651 (
652 cur= &&
653 __git_refs >"$actual"
654 ) &&
655 test_cmp expected "$actual"
656'
657
658test_expect_success '__git_refs - full refs' '
659 cat >expected <<-EOF &&
00076181 660 refs/heads/main
fb9cd420 661 refs/heads/matching-branch
e896369b 662 refs/remotes/other/branch-in-other
00076181 663 refs/remotes/other/main-in-other
e896369b 664 refs/tags/matching-tag
fb9cd420
SG
665 EOF
666 (
667 cur=refs/heads/ &&
668 __git_refs >"$actual"
669 ) &&
670 test_cmp expected "$actual"
671'
672
673test_expect_success '__git_refs - repo given on the command line' '
674 cat >expected <<-EOF &&
675 HEAD
676 branch-in-other
00076181 677 main-in-other
fb9cd420
SG
678 tag-in-other
679 EOF
680 (
681 __git_dir="$ROOT/otherrepo/.git" &&
682 cur= &&
683 __git_refs >"$actual"
684 ) &&
685 test_cmp expected "$actual"
686'
687
688test_expect_success '__git_refs - remote on local file system' '
689 cat >expected <<-EOF &&
690 HEAD
691 branch-in-other
00076181 692 main-in-other
fb9cd420
SG
693 tag-in-other
694 EOF
695 (
696 cur= &&
697 __git_refs otherrepo >"$actual"
698 ) &&
699 test_cmp expected "$actual"
700'
701
702test_expect_success '__git_refs - remote on local file system - full refs' '
703 cat >expected <<-EOF &&
704 refs/heads/branch-in-other
00076181 705 refs/heads/main-in-other
fb9cd420
SG
706 refs/tags/tag-in-other
707 EOF
708 (
709 cur=refs/ &&
710 __git_refs otherrepo >"$actual"
711 ) &&
712 test_cmp expected "$actual"
713'
714
715test_expect_success '__git_refs - configured remote' '
716 cat >expected <<-EOF &&
717 HEAD
718 branch-in-other
00076181 719 main-in-other
fb9cd420
SG
720 EOF
721 (
722 cur= &&
723 __git_refs other >"$actual"
724 ) &&
725 test_cmp expected "$actual"
726'
727
728test_expect_success '__git_refs - configured remote - full refs' '
729 cat >expected <<-EOF &&
e896369b 730 HEAD
fb9cd420 731 refs/heads/branch-in-other
00076181 732 refs/heads/main-in-other
fb9cd420
SG
733 refs/tags/tag-in-other
734 EOF
735 (
736 cur=refs/ &&
737 __git_refs other >"$actual"
738 ) &&
739 test_cmp expected "$actual"
740'
741
5c12f642 742test_expect_success '__git_refs - configured remote - repo given on the command line' '
fb9cd420
SG
743 cat >expected <<-EOF &&
744 HEAD
745 branch-in-other
00076181 746 main-in-other
fb9cd420
SG
747 EOF
748 (
749 cd thirdrepo &&
750 __git_dir="$ROOT/.git" &&
751 cur= &&
752 __git_refs other >"$actual"
753 ) &&
754 test_cmp expected "$actual"
755'
756
5c12f642 757test_expect_success '__git_refs - configured remote - full refs - repo given on the command line' '
fb9cd420 758 cat >expected <<-EOF &&
e896369b 759 HEAD
fb9cd420 760 refs/heads/branch-in-other
00076181 761 refs/heads/main-in-other
fb9cd420
SG
762 refs/tags/tag-in-other
763 EOF
764 (
765 cd thirdrepo &&
766 __git_dir="$ROOT/.git" &&
767 cur=refs/ &&
768 __git_refs other >"$actual"
769 ) &&
770 test_cmp expected "$actual"
771'
772
69a77596 773test_expect_success '__git_refs - configured remote - remote name matches a directory' '
fb9cd420
SG
774 cat >expected <<-EOF &&
775 HEAD
776 branch-in-other
00076181 777 main-in-other
fb9cd420
SG
778 EOF
779 mkdir other &&
780 test_when_finished "rm -rf other" &&
781 (
782 cur= &&
783 __git_refs other >"$actual"
784 ) &&
785 test_cmp expected "$actual"
786'
787
91b7ea81 788test_expect_success '__git_refs - URL remote' '
fb9cd420
SG
789 cat >expected <<-EOF &&
790 HEAD
791 branch-in-other
00076181 792 main-in-other
fb9cd420
SG
793 tag-in-other
794 EOF
795 (
796 cur= &&
797 __git_refs "file://$ROOT/otherrepo/.git" >"$actual"
798 ) &&
799 test_cmp expected "$actual"
800'
801
802test_expect_success '__git_refs - URL remote - full refs' '
803 cat >expected <<-EOF &&
e896369b 804 HEAD
fb9cd420 805 refs/heads/branch-in-other
00076181 806 refs/heads/main-in-other
fb9cd420
SG
807 refs/tags/tag-in-other
808 EOF
809 (
810 cur=refs/ &&
811 __git_refs "file://$ROOT/otherrepo/.git" >"$actual"
812 ) &&
813 test_cmp expected "$actual"
814'
815
91b7ea81 816test_expect_success '__git_refs - non-existing remote' '
fb9cd420
SG
817 (
818 cur= &&
819 __git_refs non-existing >"$actual"
820 ) &&
821 test_must_be_empty "$actual"
822'
823
824test_expect_success '__git_refs - non-existing remote - full refs' '
825 (
826 cur=refs/ &&
827 __git_refs non-existing >"$actual"
828 ) &&
829 test_must_be_empty "$actual"
830'
831
91b7ea81 832test_expect_success '__git_refs - non-existing URL remote' '
fb9cd420
SG
833 (
834 cur= &&
835 __git_refs "file://$ROOT/non-existing" >"$actual"
836 ) &&
837 test_must_be_empty "$actual"
838'
839
840test_expect_success '__git_refs - non-existing URL remote - full refs' '
841 (
842 cur=refs/ &&
843 __git_refs "file://$ROOT/non-existing" >"$actual"
844 ) &&
845 test_must_be_empty "$actual"
846'
847
62a1b732 848test_expect_success '__git_refs - not in a git repository' '
fb9cd420
SG
849 (
850 GIT_CEILING_DIRECTORIES="$ROOT" &&
851 export GIT_CEILING_DIRECTORIES &&
852 cd subdir &&
853 cur= &&
854 __git_refs >"$actual"
855 ) &&
856 test_must_be_empty "$actual"
857'
858
859test_expect_success '__git_refs - unique remote branches for git checkout DWIMery' '
860 cat >expected <<-EOF &&
861 HEAD
00076181 862 main
fb9cd420
SG
863 matching-branch
864 other/ambiguous
865 other/branch-in-other
00076181 866 other/main-in-other
fb9cd420
SG
867 remote/ambiguous
868 remote/branch-in-remote
869 matching-tag
870 branch-in-other
871 branch-in-remote
00076181 872 main-in-other
fb9cd420
SG
873 EOF
874 for remote_ref in refs/remotes/other/ambiguous \
875 refs/remotes/remote/ambiguous \
876 refs/remotes/remote/branch-in-remote
877 do
00076181 878 git update-ref $remote_ref main &&
0c51d6b4 879 test_when_finished "git update-ref -d $remote_ref" || return 1
fb9cd420
SG
880 done &&
881 (
882 cur= &&
883 __git_refs "" 1 >"$actual"
884 ) &&
885 test_cmp expected "$actual"
886'
887
2ea328a1
SG
888test_expect_success '__git_refs - after --opt=' '
889 cat >expected <<-EOF &&
890 HEAD
00076181 891 main
2ea328a1
SG
892 matching-branch
893 other/branch-in-other
00076181 894 other/main-in-other
2ea328a1
SG
895 matching-tag
896 EOF
897 (
898 cur="--opt=" &&
899 __git_refs "" "" "" "" >"$actual"
900 ) &&
901 test_cmp expected "$actual"
902'
903
904test_expect_success '__git_refs - after --opt= - full refs' '
905 cat >expected <<-EOF &&
00076181 906 refs/heads/main
2ea328a1
SG
907 refs/heads/matching-branch
908 refs/remotes/other/branch-in-other
00076181 909 refs/remotes/other/main-in-other
2ea328a1
SG
910 refs/tags/matching-tag
911 EOF
912 (
913 cur="--opt=refs/" &&
914 __git_refs "" "" "" refs/ >"$actual"
915 ) &&
916 test_cmp expected "$actual"
917'
918
b64b43d2 919test_expect_success '__git refs - excluding refs' '
aed38813
SG
920 cat >expected <<-EOF &&
921 ^HEAD
00076181 922 ^main
aed38813
SG
923 ^matching-branch
924 ^other/branch-in-other
00076181 925 ^other/main-in-other
aed38813
SG
926 ^matching-tag
927 EOF
928 (
929 cur=^ &&
930 __git_refs >"$actual"
931 ) &&
932 test_cmp expected "$actual"
933'
934
b64b43d2 935test_expect_success '__git refs - excluding full refs' '
aed38813 936 cat >expected <<-EOF &&
00076181 937 ^refs/heads/main
aed38813
SG
938 ^refs/heads/matching-branch
939 ^refs/remotes/other/branch-in-other
00076181 940 ^refs/remotes/other/main-in-other
aed38813
SG
941 ^refs/tags/matching-tag
942 EOF
943 (
944 cur=^refs/ &&
945 __git_refs >"$actual"
946 ) &&
947 test_cmp expected "$actual"
948'
949
e896369b
SG
950test_expect_success 'setup for filtering matching refs' '
951 git branch matching/branch &&
952 git tag matching/tag &&
953 git -C otherrepo branch matching/branch-in-other &&
954 git fetch --no-tags other &&
955 rm -f .git/FETCH_HEAD
956'
957
4dc8b1c1 958test_expect_success '__git_refs - do not filter refs unless told so' '
e896369b
SG
959 cat >expected <<-EOF &&
960 HEAD
00076181 961 main
e896369b
SG
962 matching-branch
963 matching/branch
964 other/branch-in-other
00076181 965 other/main-in-other
e896369b
SG
966 other/matching/branch-in-other
967 matching-tag
968 matching/tag
969 EOF
970 (
00076181 971 cur=main &&
e896369b
SG
972 __git_refs >"$actual"
973 ) &&
974 test_cmp expected "$actual"
975'
976
977test_expect_success '__git_refs - only matching refs' '
978 cat >expected <<-EOF &&
979 matching-branch
980 matching/branch
981 matching-tag
982 matching/tag
983 EOF
984 (
985 cur=mat &&
986 __git_refs "" "" "" "$cur" >"$actual"
987 ) &&
988 test_cmp expected "$actual"
989'
990
991test_expect_success '__git_refs - only matching refs - full refs' '
992 cat >expected <<-EOF &&
993 refs/heads/matching-branch
994 refs/heads/matching/branch
995 EOF
996 (
997 cur=refs/heads/mat &&
998 __git_refs "" "" "" "$cur" >"$actual"
999 ) &&
1000 test_cmp expected "$actual"
1001'
1002
1003test_expect_success '__git_refs - only matching refs - remote on local file system' '
1004 cat >expected <<-EOF &&
00076181 1005 main-in-other
e896369b
SG
1006 matching/branch-in-other
1007 EOF
1008 (
1009 cur=ma &&
1010 __git_refs otherrepo "" "" "$cur" >"$actual"
1011 ) &&
1012 test_cmp expected "$actual"
1013'
1014
1015test_expect_success '__git_refs - only matching refs - configured remote' '
1016 cat >expected <<-EOF &&
00076181 1017 main-in-other
e896369b
SG
1018 matching/branch-in-other
1019 EOF
1020 (
1021 cur=ma &&
1022 __git_refs other "" "" "$cur" >"$actual"
1023 ) &&
1024 test_cmp expected "$actual"
1025'
1026
1027test_expect_success '__git_refs - only matching refs - remote - full refs' '
1028 cat >expected <<-EOF &&
00076181 1029 refs/heads/main-in-other
e896369b
SG
1030 refs/heads/matching/branch-in-other
1031 EOF
1032 (
1033 cur=refs/heads/ma &&
1034 __git_refs other "" "" "$cur" >"$actual"
1035 ) &&
1036 test_cmp expected "$actual"
1037'
1038
1039test_expect_success '__git_refs - only matching refs - checkout DWIMery' '
1040 cat >expected <<-EOF &&
1041 matching-branch
1042 matching/branch
1043 matching-tag
1044 matching/tag
1045 matching/branch-in-other
1046 EOF
1047 for remote_ref in refs/remotes/other/ambiguous \
1048 refs/remotes/remote/ambiguous \
1049 refs/remotes/remote/branch-in-remote
1050 do
00076181 1051 git update-ref $remote_ref main &&
0c51d6b4 1052 test_when_finished "git update-ref -d $remote_ref" || return 1
e896369b
SG
1053 done &&
1054 (
1055 cur=mat &&
1056 __git_refs "" 1 "" "$cur" >"$actual"
1057 ) &&
1058 test_cmp expected "$actual"
1059'
1060
1061test_expect_success 'teardown after filtering matching refs' '
1062 git branch -d matching/branch &&
1063 git tag -d matching/tag &&
1064 git update-ref -d refs/remotes/other/matching/branch-in-other &&
1065 git -C otherrepo branch -D matching/branch-in-other
1066'
1067
00076181 1068test_expect_success '__git_refs - for-each-ref format specifiers in prefix' '
fef56eb0 1069 cat >expected <<-EOF &&
00076181 1070 evil-%%-%42-%(refname)..main
fef56eb0
SG
1071 EOF
1072 (
8164360f
JS
1073 cur="evil-%%-%42-%(refname)..mai" &&
1074 __git_refs "" "" "evil-%%-%42-%(refname).." mai >"$actual"
fef56eb0
SG
1075 ) &&
1076 test_cmp expected "$actual"
1077'
1078
15b4a163
SG
1079test_expect_success '__git_complete_refs - simple' '
1080 sed -e "s/Z$//" >expected <<-EOF &&
1081 HEAD Z
00076181 1082 main Z
15b4a163
SG
1083 matching-branch Z
1084 other/branch-in-other Z
00076181 1085 other/main-in-other Z
15b4a163
SG
1086 matching-tag Z
1087 EOF
1088 (
1089 cur= &&
1090 __git_complete_refs &&
1091 print_comp
1092 ) &&
1093 test_cmp expected out
1094'
1095
1096test_expect_success '__git_complete_refs - matching' '
1097 sed -e "s/Z$//" >expected <<-EOF &&
1098 matching-branch Z
1099 matching-tag Z
1100 EOF
1101 (
1102 cur=mat &&
1103 __git_complete_refs &&
1104 print_comp
1105 ) &&
1106 test_cmp expected out
1107'
1108
1109test_expect_success '__git_complete_refs - remote' '
1110 sed -e "s/Z$//" >expected <<-EOF &&
1111 HEAD Z
1112 branch-in-other Z
00076181 1113 main-in-other Z
15b4a163
SG
1114 EOF
1115 (
cff4243d 1116 cur= &&
15b4a163
SG
1117 __git_complete_refs --remote=other &&
1118 print_comp
1119 ) &&
1120 test_cmp expected out
1121'
1122
1123test_expect_success '__git_complete_refs - track' '
1124 sed -e "s/Z$//" >expected <<-EOF &&
1125 HEAD Z
00076181 1126 main Z
15b4a163
SG
1127 matching-branch Z
1128 other/branch-in-other Z
00076181 1129 other/main-in-other Z
15b4a163
SG
1130 matching-tag Z
1131 branch-in-other Z
00076181 1132 main-in-other Z
15b4a163
SG
1133 EOF
1134 (
cff4243d 1135 cur= &&
15b4a163
SG
1136 __git_complete_refs --track &&
1137 print_comp
1138 ) &&
1139 test_cmp expected out
1140'
1141
1142test_expect_success '__git_complete_refs - current word' '
1143 sed -e "s/Z$//" >expected <<-EOF &&
1144 matching-branch Z
1145 matching-tag Z
1146 EOF
1147 (
1148 cur="--option=mat" &&
1149 __git_complete_refs --cur="${cur#*=}" &&
1150 print_comp
1151 ) &&
1152 test_cmp expected out
1153'
1154
1155test_expect_success '__git_complete_refs - prefix' '
1156 sed -e "s/Z$//" >expected <<-EOF &&
1157 v1.0..matching-branch Z
1158 v1.0..matching-tag Z
1159 EOF
1160 (
1161 cur=v1.0..mat &&
1162 __git_complete_refs --pfx=v1.0.. --cur=mat &&
1163 print_comp
1164 ) &&
1165 test_cmp expected out
1166'
1167
1168test_expect_success '__git_complete_refs - suffix' '
1169 cat >expected <<-EOF &&
1170 HEAD.
00076181 1171 main.
15b4a163
SG
1172 matching-branch.
1173 other/branch-in-other.
00076181 1174 other/main-in-other.
15b4a163
SG
1175 matching-tag.
1176 EOF
1177 (
1178 cur= &&
1179 __git_complete_refs --sfx=. &&
1180 print_comp
1181 ) &&
1182 test_cmp expected out
1183'
1184
aa0644f7
SG
1185test_expect_success '__git_complete_fetch_refspecs - simple' '
1186 sed -e "s/Z$//" >expected <<-EOF &&
1187 HEAD:HEAD Z
1188 branch-in-other:branch-in-other Z
00076181 1189 main-in-other:main-in-other Z
aa0644f7
SG
1190 EOF
1191 (
1192 cur= &&
1193 __git_complete_fetch_refspecs other &&
1194 print_comp
1195 ) &&
1196 test_cmp expected out
1197'
1198
1199test_expect_success '__git_complete_fetch_refspecs - matching' '
1200 sed -e "s/Z$//" >expected <<-EOF &&
1201 branch-in-other:branch-in-other Z
1202 EOF
1203 (
1204 cur=br &&
1205 __git_complete_fetch_refspecs other "" br &&
1206 print_comp
1207 ) &&
1208 test_cmp expected out
1209'
1210
1211test_expect_success '__git_complete_fetch_refspecs - prefix' '
1212 sed -e "s/Z$//" >expected <<-EOF &&
1213 +HEAD:HEAD Z
1214 +branch-in-other:branch-in-other Z
00076181 1215 +main-in-other:main-in-other Z
aa0644f7
SG
1216 EOF
1217 (
1218 cur="+" &&
1219 __git_complete_fetch_refspecs other "+" "" &&
1220 print_comp
1221 ) &&
1222 test_cmp expected out
1223'
1224
1225test_expect_success '__git_complete_fetch_refspecs - fully qualified' '
1226 sed -e "s/Z$//" >expected <<-EOF &&
1227 refs/heads/branch-in-other:refs/heads/branch-in-other Z
00076181 1228 refs/heads/main-in-other:refs/heads/main-in-other Z
aa0644f7
SG
1229 refs/tags/tag-in-other:refs/tags/tag-in-other Z
1230 EOF
1231 (
1232 cur=refs/ &&
1233 __git_complete_fetch_refspecs other "" refs/ &&
1234 print_comp
1235 ) &&
1236 test_cmp expected out
1237'
1238
1239test_expect_success '__git_complete_fetch_refspecs - fully qualified & prefix' '
1240 sed -e "s/Z$//" >expected <<-EOF &&
1241 +refs/heads/branch-in-other:refs/heads/branch-in-other Z
00076181 1242 +refs/heads/main-in-other:refs/heads/main-in-other Z
aa0644f7
SG
1243 +refs/tags/tag-in-other:refs/tags/tag-in-other Z
1244 EOF
1245 (
1246 cur=+refs/ &&
1247 __git_complete_fetch_refspecs other + refs/ &&
1248 print_comp
1249 ) &&
1250 test_cmp expected out
1251'
1252
68d97c7f 1253test_expect_success 'git switch - with no options, complete local branches and unique remote branch names for DWIM logic' '
fab466f9
JK
1254 test_completion "git switch " <<-\EOF
1255 branch-in-other Z
00076181
JS
1256 main Z
1257 main-in-other Z
fab466f9
JK
1258 matching-branch Z
1259 EOF
1260'
1261
1262test_expect_success 'git checkout - completes refs and unique remote branches for DWIM' '
1263 test_completion "git checkout " <<-\EOF
1264 HEAD Z
1265 branch-in-other Z
00076181
JS
1266 main Z
1267 main-in-other Z
fab466f9
JK
1268 matching-branch Z
1269 matching-tag Z
1270 other/branch-in-other Z
00076181 1271 other/main-in-other Z
fab466f9
JK
1272 EOF
1273'
1274
ab58e90f
JK
1275test_expect_success 'git switch - with --no-guess, complete only local branches' '
1276 test_completion "git switch --no-guess " <<-\EOF
00076181 1277 main Z
ab58e90f
JK
1278 matching-branch Z
1279 EOF
1280'
1281
1282test_expect_success 'git switch - with GIT_COMPLETION_CHECKOUT_NO_GUESS=1, complete only local branches' '
1283 GIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion "git switch " <<-\EOF
00076181 1284 main Z
ab58e90f
JK
1285 matching-branch Z
1286 EOF
1287'
1288
68d97c7f 1289test_expect_success 'git switch - --guess overrides GIT_COMPLETION_CHECKOUT_NO_GUESS=1, complete local branches and unique remote names for DWIM logic' '
ab58e90f
JK
1290 GIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion "git switch --guess " <<-\EOF
1291 branch-in-other Z
00076181
JS
1292 main Z
1293 main-in-other Z
ab58e90f
JK
1294 matching-branch Z
1295 EOF
1296'
1297
68d97c7f 1298test_expect_success 'git switch - a later --guess overrides previous --no-guess, complete local and remote unique branches for DWIM' '
ab58e90f
JK
1299 test_completion "git switch --no-guess --guess " <<-\EOF
1300 branch-in-other Z
00076181
JS
1301 main Z
1302 main-in-other Z
ab58e90f
JK
1303 matching-branch Z
1304 EOF
1305'
1306
4e79adf4 1307test_expect_success 'git switch - a later --no-guess overrides previous --guess, complete only local branches' '
ab58e90f 1308 test_completion "git switch --guess --no-guess " <<-\EOF
00076181 1309 main Z
ab58e90f
JK
1310 matching-branch Z
1311 EOF
1312'
1313
1314test_expect_success 'git checkout - with GIT_COMPLETION_NO_GUESS=1 only completes refs' '
1315 GIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion "git checkout " <<-\EOF
1316 HEAD Z
00076181 1317 main Z
ab58e90f
JK
1318 matching-branch Z
1319 matching-tag Z
1320 other/branch-in-other Z
00076181 1321 other/main-in-other Z
ab58e90f
JK
1322 EOF
1323'
1324
4e79adf4 1325test_expect_success 'git checkout - --guess overrides GIT_COMPLETION_NO_GUESS=1, complete refs and unique remote branches for DWIM' '
ab58e90f
JK
1326 GIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion "git checkout --guess " <<-\EOF
1327 HEAD Z
1328 branch-in-other Z
00076181
JS
1329 main Z
1330 main-in-other Z
ab58e90f
JK
1331 matching-branch Z
1332 matching-tag Z
1333 other/branch-in-other Z
00076181 1334 other/main-in-other Z
ab58e90f
JK
1335 EOF
1336'
1337
1338test_expect_success 'git checkout - with --no-guess, only completes refs' '
1339 test_completion "git checkout --no-guess " <<-\EOF
1340 HEAD Z
00076181 1341 main Z
ab58e90f
JK
1342 matching-branch Z
1343 matching-tag Z
1344 other/branch-in-other Z
00076181 1345 other/main-in-other Z
ab58e90f
JK
1346 EOF
1347'
1348
4e79adf4 1349test_expect_success 'git checkout - a later --guess overrides previous --no-guess, complete refs and unique remote branches for DWIM' '
ab58e90f
JK
1350 test_completion "git checkout --no-guess --guess " <<-\EOF
1351 HEAD Z
1352 branch-in-other Z
00076181
JS
1353 main Z
1354 main-in-other Z
ab58e90f
JK
1355 matching-branch Z
1356 matching-tag Z
1357 other/branch-in-other Z
00076181 1358 other/main-in-other Z
ab58e90f
JK
1359 EOF
1360'
1361
1362test_expect_success 'git checkout - a later --no-guess overrides previous --guess, complete only refs' '
1363 test_completion "git checkout --guess --no-guess " <<-\EOF
1364 HEAD Z
00076181 1365 main Z
ab58e90f
JK
1366 matching-branch Z
1367 matching-tag Z
1368 other/branch-in-other Z
00076181 1369 other/main-in-other Z
ab58e90f
JK
1370 EOF
1371'
1372
64f1f58f
DL
1373test_expect_success 'git checkout - with checkout.guess = false, only completes refs' '
1374 test_config checkout.guess false &&
1375 test_completion "git checkout " <<-\EOF
1376 HEAD Z
00076181 1377 main Z
64f1f58f
DL
1378 matching-branch Z
1379 matching-tag Z
1380 other/branch-in-other Z
00076181 1381 other/main-in-other Z
64f1f58f
DL
1382 EOF
1383'
1384
1385test_expect_success 'git checkout - with checkout.guess = true, completes refs and unique remote branches for DWIM' '
1386 test_config checkout.guess true &&
1387 test_completion "git checkout " <<-\EOF
1388 HEAD Z
1389 branch-in-other Z
00076181
JS
1390 main Z
1391 main-in-other Z
64f1f58f
DL
1392 matching-branch Z
1393 matching-tag Z
1394 other/branch-in-other Z
00076181 1395 other/main-in-other Z
64f1f58f
DL
1396 EOF
1397'
1398
1399test_expect_success 'git checkout - a later --guess overrides previous checkout.guess = false, complete refs and unique remote branches for DWIM' '
1400 test_config checkout.guess false &&
1401 test_completion "git checkout --guess " <<-\EOF
1402 HEAD Z
1403 branch-in-other Z
00076181
JS
1404 main Z
1405 main-in-other Z
64f1f58f
DL
1406 matching-branch Z
1407 matching-tag Z
1408 other/branch-in-other Z
00076181 1409 other/main-in-other Z
64f1f58f
DL
1410 EOF
1411'
1412
1413test_expect_success 'git checkout - a later --no-guess overrides previous checkout.guess = true, complete only refs' '
1414 test_config checkout.guess true &&
1415 test_completion "git checkout --no-guess " <<-\EOF
1416 HEAD Z
00076181 1417 main Z
64f1f58f
DL
1418 matching-branch Z
1419 matching-tag Z
1420 other/branch-in-other Z
00076181 1421 other/main-in-other Z
64f1f58f
DL
1422 EOF
1423'
1424
e69fb0a1
JK
1425test_expect_success 'git switch - with --detach, complete all references' '
1426 test_completion "git switch --detach " <<-\EOF
1427 HEAD Z
00076181 1428 main Z
e69fb0a1
JK
1429 matching-branch Z
1430 matching-tag Z
1431 other/branch-in-other Z
00076181 1432 other/main-in-other Z
e69fb0a1
JK
1433 EOF
1434'
1435
6d76a5cc 1436test_expect_success 'git checkout - with --detach, complete only references' '
e69fb0a1
JK
1437 test_completion "git checkout --detach " <<-\EOF
1438 HEAD Z
00076181 1439 main Z
e69fb0a1
JK
1440 matching-branch Z
1441 matching-tag Z
1442 other/branch-in-other Z
00076181 1443 other/main-in-other Z
e69fb0a1
JK
1444 EOF
1445'
1446
fd6d9bec
LD
1447test_expect_success 'setup sparse-checkout tests' '
1448 # set up sparse-checkout repo
1449 git init sparse-checkout &&
1450 (
1451 cd sparse-checkout &&
1452 mkdir -p folder1/0/1 folder2/0 folder3 &&
1453 touch folder1/0/1/t.txt &&
1454 touch folder2/0/t.txt &&
1455 touch folder3/t.txt &&
1456 git add . &&
1457 git commit -am "Initial commit"
1458 )
1459'
1460
1461test_expect_success 'sparse-checkout completes subcommands' '
1462 test_completion "git sparse-checkout " <<-\EOF
1463 list Z
1464 init Z
1465 set Z
1466 add Z
1467 reapply Z
1468 disable Z
1469 EOF
1470'
1471
1472test_expect_success 'cone mode sparse-checkout completes directory names' '
1473 # initialize sparse-checkout definitions
1474 git -C sparse-checkout sparse-checkout set --cone folder1/0 folder3 &&
1475
1476 # test tab completion
1477 (
1478 cd sparse-checkout &&
1479 test_completion "git sparse-checkout set f" <<-\EOF
c5f5c508
LD
1480 folder1/
1481 folder2/
1482 folder3/
1483 EOF
1484 ) &&
1485
1486 (
1487 cd sparse-checkout &&
1488 test_completion "git sparse-checkout set folder1/" <<-\EOF
1489 folder1/0/
1490 EOF
1491 ) &&
1492
1493 (
1494 cd sparse-checkout &&
1495 test_completion "git sparse-checkout set folder1/0/" <<-\EOF
1496 folder1/0/1/
fd6d9bec
LD
1497 EOF
1498 ) &&
1499
1500 (
1501 cd sparse-checkout/folder1 &&
c5f5c508
LD
1502 test_completion "git sparse-checkout add 0" <<-\EOF
1503 0/
fd6d9bec
LD
1504 EOF
1505 )
1506'
1507
48803821
LD
1508test_expect_success 'cone mode sparse-checkout completes directory names with spaces and accents' '
1509 # reset sparse-checkout
1510 git -C sparse-checkout sparse-checkout disable &&
1511 (
1512 cd sparse-checkout &&
1513 mkdir "directory with spaces" &&
1514 mkdir "directory-with-áccent" &&
1515 >"directory with spaces/randomfile" &&
1516 >"directory-with-áccent/randomfile" &&
1517 git add . &&
1518 git commit -m "Add directory with spaces and directory with accent" &&
1519 git sparse-checkout set --cone "directory with spaces" \
1520 "directory-with-áccent" &&
1521 test_completion "git sparse-checkout add dir" <<-\EOF &&
1522 directory with spaces/
1523 directory-with-áccent/
1524 EOF
1525 rm -rf "directory with spaces" &&
1526 rm -rf "directory-with-áccent" &&
1527 git add . &&
1528 git commit -m "Remove directory with spaces and directory with accent"
1529 )
1530'
1531
6d340dfa
AD
1532# use FUNNYNAMES to avoid running on Windows, which doesn't permit tabs in paths
1533test_expect_success FUNNYNAMES 'cone mode sparse-checkout completes directory names with tabs' '
48803821
LD
1534 # reset sparse-checkout
1535 git -C sparse-checkout sparse-checkout disable &&
1536 (
1537 cd sparse-checkout &&
48803821 1538 mkdir "$(printf "directory\twith\ttabs")" &&
48803821
LD
1539 >"$(printf "directory\twith\ttabs")/randomfile" &&
1540 git add . &&
6d340dfa
AD
1541 git commit -m "Add directory with tabs" &&
1542 git sparse-checkout set --cone \
48803821
LD
1543 "$(printf "directory\twith\ttabs")" &&
1544 test_completion "git sparse-checkout add dir" <<-\EOF &&
48803821
LD
1545 directory with tabs/
1546 EOF
48803821
LD
1547 rm -rf "$(printf "directory\twith\ttabs")" &&
1548 git add . &&
6d340dfa
AD
1549 git commit -m "Remove directory with tabs"
1550 )
1551'
1552
1553# use FUNNYNAMES to avoid running on Windows, and !CYGWIN for Cygwin, as neither permit backslashes in paths
1554test_expect_success FUNNYNAMES,!CYGWIN 'cone mode sparse-checkout completes directory names with backslashes' '
1555 # reset sparse-checkout
1556 git -C sparse-checkout sparse-checkout disable &&
1557 (
1558 cd sparse-checkout &&
1559 mkdir "directory\with\backslashes" &&
1560 >"directory\with\backslashes/randomfile" &&
1561 git add . &&
1562 git commit -m "Add directory with backslashes" &&
1563 git sparse-checkout set --cone \
1564 "directory\with\backslashes" &&
1565 test_completion "git sparse-checkout add dir" <<-\EOF &&
1566 directory\with\backslashes/
1567 EOF
1568 rm -rf "directory\with\backslashes" &&
1569 git add . &&
1570 git commit -m "Remove directory with backslashes"
48803821
LD
1571 )
1572'
1573
a1fbe26a 1574test_expect_success 'non-cone mode sparse-checkout gives rooted paths' '
fd6d9bec
LD
1575 # reset sparse-checkout repo to non-cone mode
1576 git -C sparse-checkout sparse-checkout disable &&
1577 git -C sparse-checkout sparse-checkout set --no-cone &&
1578
1579 (
1580 cd sparse-checkout &&
1581 # expected to be empty since we have not configured
1582 # custom completion for non-cone mode
1583 test_completion "git sparse-checkout set f" <<-\EOF
a1fbe26a
EN
1584 /folder1/0/1/t.txt Z
1585 /folder1/expected Z
1586 /folder1/out Z
1587 /folder1/out_sorted Z
1588 /folder2/0/t.txt Z
1589 /folder3/t.txt Z
fd6d9bec
LD
1590 EOF
1591 )
1592'
1593
1594test_expect_success 'git sparse-checkout set --cone completes directory names' '
1595 git -C sparse-checkout sparse-checkout disable &&
1596
1597 (
1598 cd sparse-checkout &&
1599 test_completion "git sparse-checkout set --cone f" <<-\EOF
c5f5c508
LD
1600 folder1/
1601 folder2/
1602 folder3/
fd6d9bec
LD
1603 EOF
1604 )
1605'
1606
e69fb0a1
JK
1607test_expect_success 'git switch - with -d, complete all references' '
1608 test_completion "git switch -d " <<-\EOF
1609 HEAD Z
00076181 1610 main Z
e69fb0a1
JK
1611 matching-branch Z
1612 matching-tag Z
1613 other/branch-in-other Z
00076181 1614 other/main-in-other Z
e69fb0a1
JK
1615 EOF
1616'
1617
6d76a5cc 1618test_expect_success 'git checkout - with -d, complete only references' '
e69fb0a1
JK
1619 test_completion "git checkout -d " <<-\EOF
1620 HEAD Z
00076181 1621 main Z
e69fb0a1
JK
1622 matching-branch Z
1623 matching-tag Z
1624 other/branch-in-other Z
00076181 1625 other/main-in-other Z
e69fb0a1
JK
1626 EOF
1627'
1628
00e7bd2b 1629test_expect_success 'git switch - with --track, complete only remote branches' '
9f892830
JS
1630 test_completion "git switch --track " <<-\EOF &&
1631 other/branch-in-other Z
1632 other/main-in-other Z
1633 EOF
1634 test_completion "git switch -t " <<-\EOF
c55b99c3 1635 other/branch-in-other Z
00076181 1636 other/main-in-other Z
c55b99c3
JK
1637 EOF
1638'
1639
00e7bd2b 1640test_expect_success 'git checkout - with --track, complete only remote branches' '
9f892830
JS
1641 test_completion "git checkout --track " <<-\EOF &&
1642 other/branch-in-other Z
1643 other/main-in-other Z
1644 EOF
1645 test_completion "git checkout -t " <<-\EOF
c55b99c3 1646 other/branch-in-other Z
00076181 1647 other/main-in-other Z
c55b99c3
JK
1648 EOF
1649'
1650
1651test_expect_success 'git switch - with --no-track, complete only local branch names' '
1652 test_completion "git switch --no-track " <<-\EOF
00076181 1653 main Z
c55b99c3
JK
1654 matching-branch Z
1655 EOF
1656'
1657
1658test_expect_success 'git checkout - with --no-track, complete only local references' '
1659 test_completion "git checkout --no-track " <<-\EOF
1660 HEAD Z
00076181 1661 main Z
c55b99c3
JK
1662 matching-branch Z
1663 matching-tag Z
1664 other/branch-in-other Z
00076181 1665 other/main-in-other Z
c55b99c3
JK
1666 EOF
1667'
1668
acb658fe 1669test_expect_success 'git switch - with -c, complete all references' '
b07d77a2
JK
1670 test_completion "git switch -c new-branch " <<-\EOF
1671 HEAD Z
00076181 1672 main Z
b07d77a2
JK
1673 matching-branch Z
1674 matching-tag Z
1675 other/branch-in-other Z
00076181 1676 other/main-in-other Z
b07d77a2
JK
1677 EOF
1678'
1679
acb658fe 1680test_expect_success 'git switch - with -C, complete all references' '
b07d77a2
JK
1681 test_completion "git switch -C new-branch " <<-\EOF
1682 HEAD Z
00076181 1683 main Z
b07d77a2
JK
1684 matching-branch Z
1685 matching-tag Z
1686 other/branch-in-other Z
00076181 1687 other/main-in-other Z
b07d77a2
JK
1688 EOF
1689'
1690
acb658fe 1691test_expect_success 'git switch - with -c and --track, complete all references' '
b07d77a2
JK
1692 test_completion "git switch -c new-branch --track " <<-EOF
1693 HEAD Z
00076181 1694 main Z
b07d77a2
JK
1695 matching-branch Z
1696 matching-tag Z
1697 other/branch-in-other Z
00076181 1698 other/main-in-other Z
b07d77a2
JK
1699 EOF
1700'
1701
acb658fe 1702test_expect_success 'git switch - with -C and --track, complete all references' '
b07d77a2
JK
1703 test_completion "git switch -C new-branch --track " <<-EOF
1704 HEAD Z
00076181 1705 main Z
b07d77a2
JK
1706 matching-branch Z
1707 matching-tag Z
1708 other/branch-in-other Z
00076181 1709 other/main-in-other Z
b07d77a2
JK
1710 EOF
1711'
1712
acb658fe 1713test_expect_success 'git switch - with -c and --no-track, complete all references' '
b07d77a2
JK
1714 test_completion "git switch -c new-branch --no-track " <<-\EOF
1715 HEAD Z
00076181 1716 main Z
b07d77a2
JK
1717 matching-branch Z
1718 matching-tag Z
1719 other/branch-in-other Z
00076181 1720 other/main-in-other Z
b07d77a2
JK
1721 EOF
1722'
1723
acb658fe 1724test_expect_success 'git switch - with -C and --no-track, complete all references' '
b07d77a2
JK
1725 test_completion "git switch -C new-branch --no-track " <<-\EOF
1726 HEAD Z
00076181 1727 main Z
b07d77a2
JK
1728 matching-branch Z
1729 matching-tag Z
1730 other/branch-in-other Z
00076181 1731 other/main-in-other Z
b07d77a2
JK
1732 EOF
1733'
1734
acb658fe 1735test_expect_success 'git checkout - with -b, complete all references' '
b07d77a2
JK
1736 test_completion "git checkout -b new-branch " <<-\EOF
1737 HEAD Z
00076181 1738 main Z
b07d77a2
JK
1739 matching-branch Z
1740 matching-tag Z
1741 other/branch-in-other Z
00076181 1742 other/main-in-other Z
b07d77a2
JK
1743 EOF
1744'
1745
acb658fe 1746test_expect_success 'git checkout - with -B, complete all references' '
b07d77a2
JK
1747 test_completion "git checkout -B new-branch " <<-\EOF
1748 HEAD Z
00076181 1749 main Z
b07d77a2
JK
1750 matching-branch Z
1751 matching-tag Z
1752 other/branch-in-other Z
00076181 1753 other/main-in-other Z
b07d77a2
JK
1754 EOF
1755'
1756
acb658fe 1757test_expect_success 'git checkout - with -b and --track, complete all references' '
b07d77a2
JK
1758 test_completion "git checkout -b new-branch --track " <<-EOF
1759 HEAD Z
00076181 1760 main Z
b07d77a2
JK
1761 matching-branch Z
1762 matching-tag Z
1763 other/branch-in-other Z
00076181 1764 other/main-in-other Z
b07d77a2
JK
1765 EOF
1766'
1767
acb658fe 1768test_expect_success 'git checkout - with -B and --track, complete all references' '
b07d77a2
JK
1769 test_completion "git checkout -B new-branch --track " <<-EOF
1770 HEAD Z
00076181 1771 main Z
b07d77a2
JK
1772 matching-branch Z
1773 matching-tag Z
1774 other/branch-in-other Z
00076181 1775 other/main-in-other Z
b07d77a2
JK
1776 EOF
1777'
1778
1779test_expect_success 'git checkout - with -b and --no-track, complete all references' '
1780 test_completion "git checkout -b new-branch --no-track " <<-\EOF
1781 HEAD Z
00076181 1782 main Z
b07d77a2
JK
1783 matching-branch Z
1784 matching-tag Z
1785 other/branch-in-other Z
00076181 1786 other/main-in-other Z
b07d77a2
JK
1787 EOF
1788'
1789
1790test_expect_success 'git checkout - with -B and --no-track, complete all references' '
1791 test_completion "git checkout -B new-branch --no-track " <<-\EOF
1792 HEAD Z
00076181 1793 main Z
b07d77a2
JK
1794 matching-branch Z
1795 matching-tag Z
1796 other/branch-in-other Z
00076181 1797 other/main-in-other Z
b07d77a2
JK
1798 EOF
1799'
1800
68d97c7f 1801test_expect_success 'git switch - for -c, complete local branches and unique remote branches' '
7f59d604
JK
1802 test_completion "git switch -c " <<-\EOF
1803 branch-in-other Z
00076181
JS
1804 main Z
1805 main-in-other Z
7f59d604
JK
1806 matching-branch Z
1807 EOF
1808'
1809
68d97c7f 1810test_expect_success 'git switch - for -C, complete local branches and unique remote branches' '
7f59d604
JK
1811 test_completion "git switch -C " <<-\EOF
1812 branch-in-other Z
00076181
JS
1813 main Z
1814 main-in-other Z
7f59d604
JK
1815 matching-branch Z
1816 EOF
1817'
1818
1819test_expect_success 'git switch - for -c with --no-guess, complete local branches only' '
1820 test_completion "git switch --no-guess -c " <<-\EOF
00076181 1821 main Z
7f59d604
JK
1822 matching-branch Z
1823 EOF
1824'
1825
1826test_expect_success 'git switch - for -C with --no-guess, complete local branches only' '
1827 test_completion "git switch --no-guess -C " <<-\EOF
00076181 1828 main Z
7f59d604
JK
1829 matching-branch Z
1830 EOF
1831'
1832
1833test_expect_success 'git switch - for -c with --no-track, complete local branches only' '
1834 test_completion "git switch --no-track -c " <<-\EOF
00076181 1835 main Z
7f59d604
JK
1836 matching-branch Z
1837 EOF
1838'
1839
1840test_expect_success 'git switch - for -C with --no-track, complete local branches only' '
1841 test_completion "git switch --no-track -C " <<-\EOF
00076181 1842 main Z
7f59d604
JK
1843 matching-branch Z
1844 EOF
1845'
1846
acb658fe 1847test_expect_success 'git checkout - for -b, complete local branches and unique remote branches' '
7f59d604
JK
1848 test_completion "git checkout -b " <<-\EOF
1849 branch-in-other Z
00076181
JS
1850 main Z
1851 main-in-other Z
7f59d604
JK
1852 matching-branch Z
1853 EOF
1854'
1855
acb658fe 1856test_expect_success 'git checkout - for -B, complete local branches and unique remote branches' '
7f59d604
JK
1857 test_completion "git checkout -B " <<-\EOF
1858 branch-in-other Z
00076181
JS
1859 main Z
1860 main-in-other Z
7f59d604
JK
1861 matching-branch Z
1862 EOF
1863'
1864
acb658fe 1865test_expect_success 'git checkout - for -b with --no-guess, complete local branches only' '
7f59d604 1866 test_completion "git checkout --no-guess -b " <<-\EOF
00076181 1867 main Z
7f59d604
JK
1868 matching-branch Z
1869 EOF
1870'
1871
acb658fe 1872test_expect_success 'git checkout - for -B with --no-guess, complete local branches only' '
7f59d604 1873 test_completion "git checkout --no-guess -B " <<-\EOF
00076181 1874 main Z
7f59d604
JK
1875 matching-branch Z
1876 EOF
1877'
1878
acb658fe 1879test_expect_success 'git checkout - for -b with --no-track, complete local branches only' '
7f59d604 1880 test_completion "git checkout --no-track -b " <<-\EOF
00076181 1881 main Z
7f59d604
JK
1882 matching-branch Z
1883 EOF
1884'
1885
acb658fe 1886test_expect_success 'git checkout - for -B with --no-track, complete local branches only' '
7f59d604 1887 test_completion "git checkout --no-track -B " <<-\EOF
00076181 1888 main Z
7f59d604
JK
1889 matching-branch Z
1890 EOF
1891'
1892
68d97c7f 1893test_expect_success 'git switch - with --orphan completes local branch names and unique remote branch names' '
c81ca56b
JK
1894 test_completion "git switch --orphan " <<-\EOF
1895 branch-in-other Z
00076181
JS
1896 main Z
1897 main-in-other Z
c81ca56b
JK
1898 matching-branch Z
1899 EOF
1900'
1901
91439928 1902test_expect_success 'git switch - --orphan with branch already provided completes nothing else' '
00076181 1903 test_completion "git switch --orphan main " <<-\EOF
c81ca56b
JK
1904
1905 EOF
1906'
1907
91439928 1908test_expect_success 'git checkout - with --orphan completes local branch names and unique remote branch names' '
c81ca56b
JK
1909 test_completion "git checkout --orphan " <<-\EOF
1910 branch-in-other Z
00076181
JS
1911 main Z
1912 main-in-other Z
c81ca56b
JK
1913 matching-branch Z
1914 EOF
1915'
1916
91439928 1917test_expect_success 'git checkout - --orphan with branch already provided completes local refs for a start-point' '
00076181 1918 test_completion "git checkout --orphan main " <<-\EOF
c81ca56b 1919 HEAD Z
00076181 1920 main Z
c81ca56b
JK
1921 matching-branch Z
1922 matching-tag Z
1923 other/branch-in-other Z
00076181 1924 other/main-in-other Z
c81ca56b
JK
1925 EOF
1926'
1927
fb9cd420
SG
1928test_expect_success 'teardown after ref completion' '
1929 git branch -d matching-branch &&
1930 git tag -d matching-tag &&
1931 git remote remove other
1932'
1933
7d314073
SG
1934
1935test_path_completion ()
1936{
165293af 1937 test $# = 2 || BUG "not 2 parameters to test_path_completion"
7d314073
SG
1938
1939 local cur="$1" expected="$2"
1940 echo "$expected" >expected &&
1941 (
1942 # In the following tests calling this function we only
1943 # care about how __git_complete_index_file() deals with
1944 # unusual characters in path names. By requesting only
7a40cf15 1945 # untracked files we do not have to bother adding any
7d314073
SG
1946 # paths to the index in those tests.
1947 __git_complete_index_file --others &&
1948 print_comp
1949 ) &&
1950 test_cmp expected out
1951}
1952
1953test_expect_success 'setup for path completion tests' '
1954 mkdir simple-dir \
1955 "spaces in dir" \
1956 árvíztűrő &&
1957 touch simple-dir/simple-file \
1958 "spaces in dir/spaces in file" \
1959 "árvíztűrő/Сайн яваарай" &&
1960 if test_have_prereq !MINGW &&
1961 mkdir BS\\dir \
1962 '$'separators\034in\035dir'' &&
1963 touch BS\\dir/DQ\"file \
1964 '$'separators\034in\035dir/sep\036in\037file''
1965 then
6ec63305 1966 test_set_prereq FUNNIERNAMES
7d314073
SG
1967 else
1968 rm -rf BS\\dir '$'separators\034in\035dir''
1969 fi
1970'
1971
1972test_expect_success '__git_complete_index_file - simple' '
1973 test_path_completion simple simple-dir && # Bash is supposed to
1974 # add the trailing /.
1975 test_path_completion simple-dir/simple simple-dir/simple-file
1976'
1977
1978test_expect_success \
1979 '__git_complete_index_file - escaped characters on cmdline' '
1980 test_path_completion spac "spaces in dir" && # Bash will turn this
1981 # into "spaces\ in\ dir"
1982 test_path_completion "spaces\\ i" \
1983 "spaces in dir" &&
1984 test_path_completion "spaces\\ in\\ dir/s" \
1985 "spaces in dir/spaces in file" &&
1986 test_path_completion "spaces\\ in\\ dir/spaces\\ i" \
1987 "spaces in dir/spaces in file"
1988'
1989
1990test_expect_success \
1991 '__git_complete_index_file - quoted characters on cmdline' '
1992 # Testing with an opening but without a corresponding closing
1993 # double quote is important.
1994 test_path_completion \"spac "spaces in dir" &&
1995 test_path_completion "\"spaces i" \
1996 "spaces in dir" &&
1997 test_path_completion "\"spaces in dir/s" \
1998 "spaces in dir/spaces in file" &&
1999 test_path_completion "\"spaces in dir/spaces i" \
2000 "spaces in dir/spaces in file"
2001'
2002
2003test_expect_success '__git_complete_index_file - UTF-8 in ls-files output' '
2004 test_path_completion á árvíztűrő &&
2005 test_path_completion árvíztűrő/С "árvíztűrő/Сайн яваарай"
2006'
2007
6ec63305 2008test_expect_success FUNNIERNAMES \
7d314073
SG
2009 '__git_complete_index_file - C-style escapes in ls-files output' '
2010 test_path_completion BS \
2011 BS\\dir &&
2012 test_path_completion BS\\\\d \
2013 BS\\dir &&
2014 test_path_completion BS\\\\dir/DQ \
2015 BS\\dir/DQ\"file &&
2016 test_path_completion BS\\\\dir/DQ\\\"f \
2017 BS\\dir/DQ\"file
2018'
2019
6ec63305 2020test_expect_success FUNNIERNAMES \
7d314073
SG
2021 '__git_complete_index_file - \nnn-escaped characters in ls-files output' '
2022 test_path_completion sep '$'separators\034in\035dir'' &&
2023 test_path_completion '$'separators\034i'' \
2024 '$'separators\034in\035dir'' &&
2025 test_path_completion '$'separators\034in\035dir/sep'' \
2026 '$'separators\034in\035dir/sep\036in\037file'' &&
2027 test_path_completion '$'separators\034in\035dir/sep\036i'' \
2028 '$'separators\034in\035dir/sep\036in\037file''
2029'
2030
2031test_expect_success FUNNYNAMES \
2032 '__git_complete_index_file - removing repeated quoted path components' '
2033 test_when_finished rm -r repeated-quoted &&
2034 mkdir repeated-quoted && # A directory whose name in itself
2035 # would not be quoted ...
2036 >repeated-quoted/0-file &&
2037 >repeated-quoted/1\"file && # ... but here the file makes the
2038 # dirname quoted ...
2039 >repeated-quoted/2-file &&
2040 >repeated-quoted/3\"file && # ... and here, too.
2041
2042 # Still, we shold only list the directory name only once.
2043 test_path_completion repeated repeated-quoted
2044'
2045
2046test_expect_success 'teardown after path completion tests' '
2047 rm -rf simple-dir "spaces in dir" árvíztűrő \
2048 BS\\dir '$'separators\034in\035dir''
2049'
2050
2712e915
SG
2051test_expect_success '__git_find_on_cmdline - single match' '
2052 echo list >expect &&
2053 (
2054 words=(git command --opt list) &&
2055 cword=${#words[@]} &&
59d85a2a 2056 __git_cmd_idx=1 &&
2712e915
SG
2057 __git_find_on_cmdline "add list remove" >actual
2058 ) &&
2059 test_cmp expect actual
2060'
2061
2062test_expect_success '__git_find_on_cmdline - multiple matches' '
2063 echo remove >expect &&
2064 (
2065 words=(git command -o --opt remove list add) &&
2066 cword=${#words[@]} &&
59d85a2a 2067 __git_cmd_idx=1 &&
2712e915
SG
2068 __git_find_on_cmdline "add list remove" >actual
2069 ) &&
2070 test_cmp expect actual
2071'
2072
2073test_expect_success '__git_find_on_cmdline - no match' '
2074 (
2075 words=(git command --opt branch) &&
2076 cword=${#words[@]} &&
59d85a2a 2077 __git_cmd_idx=1 &&
2712e915
SG
2078 __git_find_on_cmdline "add list remove" >actual
2079 ) &&
2080 test_must_be_empty actual
2081'
7d314073 2082
367efd54
SG
2083test_expect_success '__git_find_on_cmdline - single match with index' '
2084 echo "3 list" >expect &&
2085 (
2086 words=(git command --opt list) &&
2087 cword=${#words[@]} &&
59d85a2a 2088 __git_cmd_idx=1 &&
367efd54
SG
2089 __git_find_on_cmdline --show-idx "add list remove" >actual
2090 ) &&
2091 test_cmp expect actual
2092'
2093
2094test_expect_success '__git_find_on_cmdline - multiple matches with index' '
2095 echo "4 remove" >expect &&
2096 (
2097 words=(git command -o --opt remove list add) &&
2098 cword=${#words[@]} &&
59d85a2a 2099 __git_cmd_idx=1 &&
367efd54
SG
2100 __git_find_on_cmdline --show-idx "add list remove" >actual
2101 ) &&
2102 test_cmp expect actual
2103'
2104
2105test_expect_success '__git_find_on_cmdline - no match with index' '
2106 (
2107 words=(git command --opt branch) &&
2108 cword=${#words[@]} &&
59d85a2a 2109 __git_cmd_idx=1 &&
367efd54
SG
2110 __git_find_on_cmdline --show-idx "add list remove" >actual
2111 ) &&
2112 test_must_be_empty actual
2113'
7d314073 2114
59d85a2a
DL
2115test_expect_success '__git_find_on_cmdline - ignores matches before command with index' '
2116 echo "6 remove" >expect &&
2117 (
2118 words=(git -C remove command -o --opt remove list add) &&
2119 cword=${#words[@]} &&
2120 __git_cmd_idx=3 &&
2121 __git_find_on_cmdline --show-idx "add list remove" >actual
2122 ) &&
2123 test_cmp expect actual
2124'
2125
12bdc880
SG
2126test_expect_success '__git_get_config_variables' '
2127 cat >expect <<-EOF &&
2128 name-1
2129 name-2
2130 EOF
2131 test_config interesting.name-1 good &&
2132 test_config interesting.name-2 good &&
2133 test_config subsection.interesting.name-3 bad &&
2134 __git_get_config_variables interesting >actual &&
2135 test_cmp expect actual
2136'
2137
e8f9e428
SG
2138test_expect_success '__git_pretty_aliases' '
2139 cat >expect <<-EOF &&
2140 author
2141 hash
2142 EOF
2143 test_config pretty.author "%an %ae" &&
2144 test_config pretty.hash %H &&
2145 __git_pretty_aliases >actual &&
2146 test_cmp expect actual
2147'
2148
5c293a6b 2149test_expect_success 'basic' '
cdbff7d6 2150 run_completion "git " &&
5c293a6b
FC
2151 # built-in
2152 grep -q "^add \$" out &&
2153 # script
483e8611 2154 grep -q "^rebase \$" out &&
5c293a6b
FC
2155 # plumbing
2156 ! grep -q "^ls-files \$" out &&
2157
483e8611
EN
2158 run_completion "git r" &&
2159 ! grep -q -v "^r" out
5c293a6b
FC
2160'
2161
2162test_expect_success 'double dash "git" itself' '
2fbaf813 2163 test_completion "git --" <<-\EOF
5c293a6b
FC
2164 --paginate Z
2165 --no-pager Z
2166 --git-dir=
2167 --bare Z
2168 --version Z
2169 --exec-path Z
3ffcd086 2170 --exec-path=
5c293a6b 2171 --html-path Z
66fb37d0 2172 --man-path Z
69ef3c02 2173 --info-path Z
5c293a6b
FC
2174 --work-tree=
2175 --namespace=
69ef3c02 2176 --no-replace-objects Z
5c293a6b
FC
2177 --help Z
2178 EOF
5c293a6b
FC
2179'
2180
2181test_expect_success 'double dash "git checkout"' '
2fbaf813 2182 test_completion "git checkout --" <<-\EOF
5c293a6b 2183 --quiet Z
77afafb2
NTND
2184 --detach Z
2185 --track Z
2186 --orphan=Z
5c293a6b
FC
2187 --ours Z
2188 --theirs Z
5c293a6b 2189 --merge Z
77afafb2 2190 --conflict=Z
5c293a6b 2191 --patch Z
6357d9d0 2192 --ignore-skip-worktree-bits Z
77afafb2 2193 --ignore-other-worktrees Z
6357d9d0 2194 --recurse-submodules Z
77afafb2 2195 --progress Z
be4908f1
NTND
2196 --guess Z
2197 --no-guess Z
b221b5ab 2198 --no-... Z
091e04bc 2199 --overlay Z
a9aecc7a
AM
2200 --pathspec-file-nul Z
2201 --pathspec-from-file=Z
5c293a6b 2202 EOF
5c293a6b
FC
2203'
2204
69ef3c02
FC
2205test_expect_success 'general options' '
2206 test_completion "git --ver" "--version " &&
2207 test_completion "git --hel" "--help " &&
2fbaf813 2208 test_completion "git --exe" <<-\EOF &&
3ffcd086
JN
2209 --exec-path Z
2210 --exec-path=
2211 EOF
69ef3c02
FC
2212 test_completion "git --htm" "--html-path " &&
2213 test_completion "git --pag" "--paginate " &&
2214 test_completion "git --no-p" "--no-pager " &&
2215 test_completion "git --git" "--git-dir=" &&
2216 test_completion "git --wor" "--work-tree=" &&
2217 test_completion "git --nam" "--namespace=" &&
2218 test_completion "git --bar" "--bare " &&
2219 test_completion "git --inf" "--info-path " &&
2220 test_completion "git --no-r" "--no-replace-objects "
2221'
911d5da6
SG
2222
2223test_expect_success 'general options plus command' '
2224 test_completion "git --version check" "checkout " &&
2225 test_completion "git --paginate check" "checkout " &&
2226 test_completion "git --git-dir=foo check" "checkout " &&
2227 test_completion "git --bare check" "checkout " &&
911d5da6
SG
2228 test_completion "git --exec-path=foo check" "checkout " &&
2229 test_completion "git --html-path check" "checkout " &&
2230 test_completion "git --no-pager check" "checkout " &&
2231 test_completion "git --work-tree=foo check" "checkout " &&
2232 test_completion "git --namespace=foo check" "checkout " &&
2233 test_completion "git --paginate check" "checkout " &&
2234 test_completion "git --info-path check" "checkout " &&
336d694c
SG
2235 test_completion "git --no-replace-objects check" "checkout " &&
2236 test_completion "git --git-dir some/path check" "checkout " &&
2237 test_completion "git -c conf.var=value check" "checkout " &&
2238 test_completion "git -C some/path check" "checkout " &&
2239 test_completion "git --work-tree some/path check" "checkout " &&
2240 test_completion "git --namespace name/space check" "checkout "
911d5da6
SG
2241'
2242
50478223
JH
2243test_expect_success 'git --help completion' '
2244 test_completion "git --help ad" "add " &&
2245 test_completion "git --help core" "core-tutorial "
2246'
2247
057ab54b 2248test_expect_success 'completion.commands removes multiple commands' '
402e3e15
TZ
2249 test_config completion.commands "-cherry -mergetool" &&
2250 git --list-cmds=list-mainporcelain,list-complete,config >out &&
2251 ! grep -E "^(cherry|mergetool)$" out
2252'
2253
fb9cd420 2254test_expect_success 'setup for integration tests' '
49ba92b4
JK
2255 echo content >file1 &&
2256 echo more >file2 &&
e5edbef4 2257 git add file1 file2 &&
49ba92b4
JK
2258 git commit -m one &&
2259 git branch mybranch &&
2260 git tag mytag
2261'
2262
2263test_expect_success 'checkout completes ref names' '
2fbaf813 2264 test_completion "git checkout m" <<-\EOF
00076181 2265 main Z
43ea0812
FC
2266 mybranch Z
2267 mytag Z
49ba92b4
JK
2268 EOF
2269'
2270
9bab766f
AW
2271test_expect_success 'checkout does not match ref names of a different case' '
2272 test_completion "git checkout M" ""
2273'
2274
2275test_expect_success 'checkout matches case insensitively with GIT_COMPLETION_IGNORE_CASE' '
2276 (
2277 GIT_COMPLETION_IGNORE_CASE=1 &&
2278 test_completion "git checkout M" <<-\EOF
2279 main Z
2280 mybranch Z
2281 mytag Z
2282 EOF
2283 )
2284'
2285
9de31f7b
AW
2286test_expect_success 'checkout completes pseudo refs' '
2287 test_completion "git checkout H" <<-\EOF
2288 HEAD Z
2289 EOF
2290'
2291
2292test_expect_success 'checkout completes pseudo refs case insensitively with GIT_COMPLETION_IGNORE_CASE' '
2293 (
2294 GIT_COMPLETION_IGNORE_CASE=1 &&
2295 test_completion "git checkout h" <<-\EOF
2296 HEAD Z
2297 EOF
2298 )
2299'
2300
80ac0744
SG
2301test_expect_success 'git -C <path> checkout uses the right repo' '
2302 test_completion "git -C subdir -C subsubdir -C .. -C ../otherrepo checkout b" <<-\EOF
2303 branch-in-other Z
2304 EOF
2305'
2306
49ba92b4 2307test_expect_success 'show completes all refs' '
2fbaf813 2308 test_completion "git show m" <<-\EOF
00076181 2309 main Z
43ea0812
FC
2310 mybranch Z
2311 mytag Z
49ba92b4
JK
2312 EOF
2313'
2314
2315test_expect_success '<ref>: completes paths' '
2fbaf813 2316 test_completion "git show mytag:f" <<-\EOF
6d54f528
CY
2317 file1Z
2318 file2Z
49ba92b4
JK
2319 EOF
2320'
2321
bafed0df
JK
2322test_expect_success 'complete tree filename with spaces' '
2323 echo content >"name with spaces" &&
e5edbef4 2324 git add "name with spaces" &&
bafed0df 2325 git commit -m spaces &&
2fbaf813 2326 test_completion "git show HEAD:nam" <<-\EOF
6d54f528 2327 name with spacesZ
bafed0df
JK
2328 EOF
2329'
2330
7d13e0a3 2331test_expect_success 'complete tree filename with metacharacters' '
bafed0df 2332 echo content >"name with \${meta}" &&
e5edbef4 2333 git add "name with \${meta}" &&
bafed0df 2334 git commit -m meta &&
2fbaf813 2335 test_completion "git show HEAD:nam" <<-\EOF
6d54f528
CY
2336 name with ${meta}Z
2337 name with spacesZ
bafed0df
JK
2338 EOF
2339'
2340
0365b9ec 2341test_expect_success PERL 'send-email' '
bf8e65b3
DL
2342 test_completion "git send-email --cov" <<-\EOF &&
2343 --cover-from-description=Z
2344 --cover-letter Z
2345 EOF
2b7b7585
TP
2346 test_completion "git send-email --val" <<-\EOF &&
2347 --validate Z
2348 EOF
00076181 2349 test_completion "git send-email ma" "main "
2f65494d
FC
2350'
2351
ddf07bdd
FC
2352test_expect_success 'complete files' '
2353 git init tmp && cd tmp &&
2354 test_when_finished "cd .. && rm -rf tmp" &&
2355
2356 echo "expected" > .gitignore &&
2357 echo "out" >> .gitignore &&
9703797c 2358 echo "out_sorted" >> .gitignore &&
ddf07bdd
FC
2359
2360 git add .gitignore &&
2361 test_completion "git commit " ".gitignore" &&
2362
2363 git commit -m ignore &&
2364
2365 touch new &&
2366 test_completion "git add " "new" &&
2367
2368 git add new &&
2369 git commit -a -m new &&
2370 test_completion "git add " "" &&
2371
2372 git mv new modified &&
2373 echo modify > modified &&
2374 test_completion "git add " "modified" &&
2375
c0af173a
EN
2376 mkdir -p some/deep &&
2377 touch some/deep/path &&
2378 test_completion "git add some/" "some/deep" &&
2379 git clean -f some &&
2380
ddf07bdd
FC
2381 touch untracked &&
2382
2383 : TODO .gitignore should not be here &&
2384 test_completion "git rm " <<-\EOF &&
2385 .gitignore
2386 modified
2387 EOF
2388
2389 test_completion "git clean " "untracked" &&
2390
2391 : TODO .gitignore should not be here &&
2392 test_completion "git mv " <<-\EOF &&
2393 .gitignore
2394 modified
2395 EOF
2396
2397 mkdir dir &&
2398 touch dir/file-in-dir &&
2399 git add dir/file-in-dir &&
2400 git commit -m dir &&
2401
2402 mkdir untracked-dir &&
2403
2404 : TODO .gitignore should not be here &&
2405 test_completion "git mv modified " <<-\EOF &&
2406 .gitignore
2407 dir
2408 modified
2409 untracked
2410 untracked-dir
2411 EOF
2412
2413 test_completion "git commit " "modified" &&
2414
2415 : TODO .gitignore should not be here &&
8fb26872 2416 test_completion "git ls-files " <<-\EOF &&
ddf07bdd
FC
2417 .gitignore
2418 dir
2419 modified
2420 EOF
2421
2422 touch momified &&
2423 test_completion "git add mom" "momified"
2424'
2425
9414938c
FC
2426test_expect_success "simple alias" '
2427 test_config alias.co checkout &&
2428 test_completion "git co m" <<-\EOF
00076181 2429 main Z
9414938c
FC
2430 mybranch Z
2431 mytag Z
2432 EOF
2433'
2434
2435test_expect_success "recursive alias" '
2436 test_config alias.co checkout &&
2437 test_config alias.cod "co --detached" &&
2438 test_completion "git cod m" <<-\EOF
00076181 2439 main Z
9414938c
FC
2440 mybranch Z
2441 mytag Z
2442 EOF
2443'
2444
56f24e80
SP
2445test_expect_success "completion uses <cmd> completion for alias: !sh -c 'git <cmd> ...'" '
2446 test_config alias.co "!sh -c '"'"'git checkout ...'"'"'" &&
2447 test_completion "git co m" <<-\EOF
00076181 2448 main Z
56f24e80
SP
2449 mybranch Z
2450 mytag Z
2451 EOF
2452'
2453
2454test_expect_success 'completion uses <cmd> completion for alias: !f () { VAR=val git <cmd> ... }' '
2455 test_config alias.co "!f () { VAR=val git checkout ... ; } f" &&
2456 test_completion "git co m" <<-\EOF
00076181 2457 main Z
56f24e80
SP
2458 mybranch Z
2459 mytag Z
2460 EOF
2461'
2462
2463test_expect_success 'completion used <cmd> completion for alias: !f() { : git <cmd> ; ... }' '
2464 test_config alias.co "!f() { : git checkout ; if ... } f" &&
2465 test_completion "git co m" <<-\EOF
00076181 2466 main Z
56f24e80
SP
2467 mybranch Z
2468 mytag Z
2469 EOF
2470'
2471
8d73a2cc
JH
2472test_expect_success 'completion used <cmd> completion for alias: !f() { : <cmd> ; ... }' '
2473 test_config alias.co "!f() { : checkout ; if ... } f" &&
2474 test_completion "git co m" <<-\EOF
2475 main Z
2476 mybranch Z
2477 mytag Z
2478 EOF
2479'
2480
2481test_expect_success 'completion used <cmd> completion for alias: !f() { : <cmd>; ... }' '
2482 test_config alias.co "!f() { : checkout; if ... } f" &&
2483 test_completion "git co m" <<-\EOF
2484 main Z
2485 mybranch Z
2486 mytag Z
2487 EOF
2488'
2489
9f642a71
NTND
2490test_expect_success 'completion without explicit _git_xxx function' '
2491 test_completion "git version --" <<-\EOF
2492 --build-options Z
2b1c01d2 2493 --no-build-options Z
9f642a71
NTND
2494 EOF
2495'
2496
f03efba4
FC
2497test_expect_failure 'complete with tilde expansion' '
2498 git init tmp && cd tmp &&
2499 test_when_finished "cd .. && rm -rf tmp" &&
2500
2501 touch ~/tmp/file &&
2502
2503 test_completion "git add ~/tmp/" "~/tmp/file"
2504'
2505
723c1d52
ÆAB
2506test_expect_success 'setup other remote for remote reference completion' '
2507 git remote add other otherrepo &&
2508 git fetch other
2509'
2510
2511for flag in -d --delete
2512do
2513 test_expect_success "__git_complete_remote_or_refspec - push $flag other" '
2514 sed -e "s/Z$//" >expected <<-EOF &&
00076181 2515 main-in-other Z
723c1d52
ÆAB
2516 EOF
2517 (
2518 words=(git push '$flag' other ma) &&
2519 cword=${#words[@]} cur=${words[cword-1]} &&
59d85a2a 2520 __git_cmd_idx=1 &&
723c1d52
ÆAB
2521 __git_complete_remote_or_refspec &&
2522 print_comp
2523 ) &&
2524 test_cmp expected out
2525 '
2526
2527 test_expect_failure "__git_complete_remote_or_refspec - push other $flag" '
2528 sed -e "s/Z$//" >expected <<-EOF &&
00076181 2529 main-in-other Z
723c1d52
ÆAB
2530 EOF
2531 (
2532 words=(git push other '$flag' ma) &&
2533 cword=${#words[@]} cur=${words[cword-1]} &&
59d85a2a 2534 __git_cmd_idx=1 &&
723c1d52
ÆAB
2535 __git_complete_remote_or_refspec &&
2536 print_comp
2537 ) &&
2538 test_cmp expected out
2539 '
2540done
2541
d9438873 2542test_expect_success 'git config - section' '
7a09a8f0
SG
2543 test_completion "git config br" <<-\EOF
2544 branch.Z
2545 browser.Z
2546 EOF
2547'
2548
07aed580
MB
2549test_expect_success 'git config - section include, includeIf' '
2550 test_completion "git config inclu" <<-\EOF
2551 include.Z
2552 includeIf.Z
2553 EOF
2554'
2555
7a09a8f0
SG
2556test_expect_success 'git config - variable name' '
2557 test_completion "git config log.d" <<-\EOF
2558 log.date Z
2559 log.decorate Z
17c13e60 2560 log.diffMerges Z
7a09a8f0
SG
2561 EOF
2562'
2563
07aed580
MB
2564test_expect_success 'git config - variable name include' '
2565 test_completion "git config include.p" <<-\EOF
2566 include.path Z
2567 EOF
2568'
2569
7a09a8f0
SG
2570test_expect_success 'git config - value' '
2571 test_completion "git config color.pager " <<-\EOF
2572 false Z
2573 true Z
2574 EOF
2575'
2576
e1e00089
SG
2577test_expect_success 'git -c - section' '
2578 test_completion "git -c br" <<-\EOF
2579 branch.Z
2580 browser.Z
2581 EOF
2582'
2583
2584test_expect_success 'git -c - variable name' '
2585 test_completion "git -c log.d" <<-\EOF
2586 log.date=Z
2587 log.decorate=Z
17c13e60 2588 log.diffMerges=Z
e1e00089
SG
2589 EOF
2590'
2591
dd334728
SG
2592test_expect_success 'git -c - value' '
2593 test_completion "git -c color.pager=" <<-\EOF
5af9d5f6
SG
2594 false Z
2595 true Z
2596 EOF
2597'
2598
2599test_expect_success 'git clone --config= - section' '
2600 test_completion "git clone --config=br" <<-\EOF
2601 branch.Z
2602 browser.Z
2603 EOF
2604'
2605
2606test_expect_success 'git clone --config= - variable name' '
2607 test_completion "git clone --config=log.d" <<-\EOF
2608 log.date=Z
2609 log.decorate=Z
17c13e60 2610 log.diffMerges=Z
5af9d5f6
SG
2611 EOF
2612'
2613
2614test_expect_success 'git clone --config= - value' '
2615 test_completion "git clone --config=color.pager=" <<-\EOF
dd334728
SG
2616 false Z
2617 true Z
2618 EOF
2619'
2620
85452a1d
RJ
2621test_expect_success 'git reflog show' '
2622 test_when_finished "git checkout - && git branch -d shown" &&
2623 git checkout -b shown &&
2624 test_completion "git reflog sho" <<-\EOF &&
2625 show Z
2626 shown Z
2627 EOF
2628 test_completion "git reflog show sho" "shown " &&
2629 test_completion "git reflog shown sho" "shown "
2630'
2631
e9f2118d
FC
2632test_expect_success 'options with value' '
2633 test_completion "git merge -X diff-algorithm=" <<-\EOF
2634
2635 EOF
2636'
2637
8b0eaa41 2638test_expect_success 'sourcing the completion script clears cached commands' '
59d9442f
ÆAB
2639 (
2640 __git_compute_all_commands &&
8ddfce71 2641 test -n "$__git_all_commands" &&
59d9442f 2642 . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
8ddfce71 2643 test -z "$__git_all_commands"
59d9442f 2644 )
8b0eaa41
SG
2645'
2646
6cdccfce 2647test_expect_success 'sourcing the completion script clears cached merge strategies' '
59d9442f
ÆAB
2648 (
2649 __git_compute_merge_strategies &&
8ddfce71 2650 test -n "$__git_merge_strategies" &&
59d9442f 2651 . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
8ddfce71 2652 test -z "$__git_merge_strategies"
59d9442f 2653 )
8b0eaa41
SG
2654'
2655
2656test_expect_success 'sourcing the completion script clears cached --options' '
59d9442f
ÆAB
2657 (
2658 __gitcomp_builtin checkout &&
8ddfce71 2659 test -n "$__gitcomp_builtin_checkout" &&
59d9442f 2660 __gitcomp_builtin notes_edit &&
8ddfce71 2661 test -n "$__gitcomp_builtin_notes_edit" &&
59d9442f 2662 . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
8ddfce71
JK
2663 test -z "$__gitcomp_builtin_checkout" &&
2664 test -z "$__gitcomp_builtin_notes_edit"
59d9442f 2665 )
8b0eaa41
SG
2666'
2667
ca2d62b7
PB
2668test_expect_success 'option aliases are not shown by default' '
2669 test_completion "git clone --recurs" "--recurse-submodules "
2670'
2671
2672test_expect_success 'option aliases are shown with GIT_COMPLETION_SHOW_ALL' '
59d9442f
ÆAB
2673 (
2674 . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
2675 GIT_COMPLETION_SHOW_ALL=1 && export GIT_COMPLETION_SHOW_ALL &&
2676 test_completion "git clone --recurs" <<-\EOF
2677 --recurse-submodules Z
2678 --recursive Z
2679 EOF
2680 )
ca2d62b7
PB
2681'
2682
d9f88dd8
ÆAB
2683test_expect_success 'plumbing commands are excluded without GIT_COMPLETION_SHOW_ALL_COMMANDS' '
2684 (
2685 . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
2686 sane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST &&
2687
2688 # Just mainporcelain, not plumbing commands
2689 run_completion "git c" &&
2690 grep checkout out &&
2691 ! grep cat-file out
2692 )
2693'
2694
2695test_expect_success 'all commands are shown with GIT_COMPLETION_SHOW_ALL_COMMANDS (also main non-builtin)' '
2696 (
2697 . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
2698 GIT_COMPLETION_SHOW_ALL_COMMANDS=1 &&
2699 export GIT_COMPLETION_SHOW_ALL_COMMANDS &&
2700 sane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST &&
2701
2702 # Both mainporcelain and plumbing commands
2703 run_completion "git c" &&
2704 grep checkout out &&
2705 grep cat-file out &&
2706
2707 # Check "gitk", a "main" command, but not a built-in + more plumbing
2708 run_completion "git g" &&
2709 grep gitk out &&
2710 grep get-tar-commit-id out
2711 )
ca2d62b7
PB
2712'
2713
0e02bdc1
FC
2714test_expect_success '__git_complete' '
2715 unset -f __git_wrap__git_main &&
5a067ba9 2716
0e02bdc1
FC
2717 __git_complete foo __git_main &&
2718 __git_have_func __git_wrap__git_main &&
5a067ba9
FC
2719 unset -f __git_wrap__git_main &&
2720
0e02bdc1 2721 __git_complete gf _git_fetch &&
5a067ba9
FC
2722 __git_have_func __git_wrap_git_fetch &&
2723
2724 __git_complete foo git &&
2725 __git_have_func __git_wrap__git_main &&
2726 unset -f __git_wrap__git_main &&
2727
2728 __git_complete gd git_diff &&
2729 __git_have_func __git_wrap_git_diff &&
2730
2731 test_must_fail __git_complete ga missing
0e02bdc1
FC
2732'
2733
5c293a6b 2734test_done