1#!/bin/sh
2#
3# Copyright (c) 2012 Felipe Contreras
4#
5
6test_description='test bash completion'
7
8. ./lib-bash.sh
9
10complete ()
11{
12 # do nothing
13 return 0
14}
15
16# Be careful when updating this list:
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",
31# "filter-branch" and "ls-files" are listed for this.
32
33GIT_TESTING_COMMAND_COMPLETION='add checkout check-attr filter-branch ls-files'
34
35. "$GIT_BUILD_DIR/contrib/completion/git-completion.bash"
36
37# We don't need this function to actually join words or do anything special.
38# Also, it's cleaner to avoid touching bash's internal completion variables.
39# So let's override it with a minimal version for testing purposes.
40_get_comp_words_by_ref ()
41{
42 while [ $# -gt 0 ]; do
43 case "$1" in
44 cur)
45 cur=${_words[_cword]}
46 ;;
47 prev)
48 prev=${_words[_cword-1]}
49 ;;
50 words)
51 words=("${_words[@]}")
52 ;;
53 cword)
54 cword=$_cword
55 ;;
56 esac
57 shift
58 done
59}
60
61print_comp ()
62{
63 local IFS=$'\n'
64 echo "${COMPREPLY[*]}" > out
65}
66
67run_completion ()
68{
69 local -a COMPREPLY _words
70 local _cword
71 _words=( $1 )
72 test "${1: -1}" = ' ' && _words[${#_words[@]}+1]=''
73 (( _cword = ${#_words[@]} - 1 ))
74 __git_wrap__git_main && print_comp
75}
76
77# Test high-level completion
78# Arguments are:
79# 1: typed text so far (cur)
80# 2: expected completion
81test_completion ()
82{
83 if test $# -gt 1
84 then
85 printf '%s\n' "$2" >expected
86 else
87 sed -e 's/Z$//' >expected
88 fi &&
89 run_completion "$1" &&
90 test_cmp expected out
91}
92
93# Test __gitcomp.
94# The first argument is the typed text so far (cur); the rest are
95# passed to __gitcomp. Expected output comes is read from the
96# standard input, like test_completion().
97test_gitcomp ()
98{
99 local -a COMPREPLY &&
100 sed -e 's/Z$//' >expected &&
101 local cur="$1" &&
102 shift &&
103 __gitcomp "$@" &&
104 print_comp &&
105 test_cmp expected out
106}
107
108# Test __gitcomp_nl
109# Arguments are:
110# 1: current word (cur)
111# -: the rest are passed to __gitcomp_nl
112test_gitcomp_nl ()
113{
114 local -a COMPREPLY &&
115 sed -e 's/Z$//' >expected &&
116 local cur="$1" &&
117 shift &&
118 __gitcomp_nl "$@" &&
119 print_comp &&
120 test_cmp expected out
121}
122
123invalid_variable_name='${foo.bar}'
124
125actual="$TRASH_DIRECTORY/actual"
126
127if test_have_prereq MINGW
128then
129 ROOT="$(pwd -W)"
130else
131 ROOT="$(pwd)"
132fi
133
134test_expect_success 'setup for __gitdir tests' '
135 mkdir -p subdir/subsubdir &&
136 git init otherrepo
137'
138
139test_expect_success '__gitdir - from command line (through $__git_dir)' '
140 echo "$ROOT/otherrepo/.git" >expected &&
141 (
142 __git_dir="$ROOT/otherrepo/.git" &&
143 __gitdir >"$actual"
144 ) &&
145 test_cmp expected "$actual"
146'
147
148test_expect_success '__gitdir - repo as argument' '
149 echo "otherrepo/.git" >expected &&
150 __gitdir "otherrepo" >"$actual" &&
151 test_cmp expected "$actual"
152'
153
154test_expect_success '__gitdir - remote as argument' '
155 echo "remote" >expected &&
156 __gitdir "remote" >"$actual" &&
157 test_cmp expected "$actual"
158'
159
160test_expect_success '__gitdir - .git directory in cwd' '
161 echo ".git" >expected &&
162 __gitdir >"$actual" &&
163 test_cmp expected "$actual"
164'
165
166test_expect_success '__gitdir - .git directory in parent' '
167 echo "$ROOT/.git" >expected &&
168 (
169 cd subdir/subsubdir &&
170 __gitdir >"$actual"
171 ) &&
172 test_cmp expected "$actual"
173'
174
175test_expect_success '__gitdir - cwd is a .git directory' '
176 echo "." >expected &&
177 (
178 cd .git &&
179 __gitdir >"$actual"
180 ) &&
181 test_cmp expected "$actual"
182'
183
184test_expect_success '__gitdir - parent is a .git directory' '
185 echo "$ROOT/.git" >expected &&
186 (
187 cd .git/refs/heads &&
188 __gitdir >"$actual"
189 ) &&
190 test_cmp expected "$actual"
191'
192
193test_expect_success '__gitdir - $GIT_DIR set while .git directory in cwd' '
194 echo "$ROOT/otherrepo/.git" >expected &&
195 (
196 GIT_DIR="$ROOT/otherrepo/.git" &&
197 export GIT_DIR &&
198 __gitdir >"$actual"
199 ) &&
200 test_cmp expected "$actual"
201'
202
203test_expect_success '__gitdir - $GIT_DIR set while .git directory in parent' '
204 echo "$ROOT/otherrepo/.git" >expected &&
205 (
206 GIT_DIR="$ROOT/otherrepo/.git" &&
207 export GIT_DIR &&
208 cd subdir &&
209 __gitdir >"$actual"
210 ) &&
211 test_cmp expected "$actual"
212'
213
214test_expect_success '__gitdir - non-existing path in $__git_dir' '
215 (
216 __git_dir="non-existing" &&
217 test_must_fail __gitdir >"$actual"
218 ) &&
219 test_must_be_empty "$actual"
220'
221
222test_expect_success '__gitdir - non-existing $GIT_DIR' '
223 (
224 GIT_DIR="$ROOT/non-existing" &&
225 export GIT_DIR &&
226 test_must_fail __gitdir >"$actual"
227 ) &&
228 test_must_be_empty "$actual"
229'
230
231test_expect_success '__gitdir - gitfile in cwd' '
232 echo "$ROOT/otherrepo/.git" >expected &&
233 echo "gitdir: $ROOT/otherrepo/.git" >subdir/.git &&
234 test_when_finished "rm -f subdir/.git" &&
235 (
236 cd subdir &&
237 __gitdir >"$actual"
238 ) &&
239 test_cmp expected "$actual"
240'
241
242test_expect_success '__gitdir - gitfile in parent' '
243 echo "$ROOT/otherrepo/.git" >expected &&
244 echo "gitdir: $ROOT/otherrepo/.git" >subdir/.git &&
245 test_when_finished "rm -f subdir/.git" &&
246 (
247 cd subdir/subsubdir &&
248 __gitdir >"$actual"
249 ) &&
250 test_cmp expected "$actual"
251'
252
253test_expect_success SYMLINKS '__gitdir - resulting path avoids symlinks' '
254 echo "$ROOT/otherrepo/.git" >expected &&
255 mkdir otherrepo/dir &&
256 test_when_finished "rm -rf otherrepo/dir" &&
257 ln -s otherrepo/dir link &&
258 test_when_finished "rm -f link" &&
259 (
260 cd link &&
261 __gitdir >"$actual"
262 ) &&
263 test_cmp expected "$actual"
264'
265
266test_expect_success '__gitdir - not a git repository' '
267 nongit test_must_fail __gitdir >"$actual" &&
268 test_must_be_empty "$actual"
269'
270
271test_expect_success '__gitcomp - trailing space - options' '
272 test_gitcomp "--re" "--dry-run --reuse-message= --reedit-message=
273 --reset-author" <<-EOF
274 --reuse-message=Z
275 --reedit-message=Z
276 --reset-author Z
277 EOF
278'
279
280test_expect_success '__gitcomp - trailing space - config keys' '
281 test_gitcomp "br" "branch. branch.autosetupmerge
282 branch.autosetuprebase browser." <<-\EOF
283 branch.Z
284 branch.autosetupmerge Z
285 branch.autosetuprebase Z
286 browser.Z
287 EOF
288'
289
290test_expect_success '__gitcomp - option parameter' '
291 test_gitcomp "--strategy=re" "octopus ours recursive resolve subtree" \
292 "" "re" <<-\EOF
293 recursive Z
294 resolve Z
295 EOF
296'
297
298test_expect_success '__gitcomp - prefix' '
299 test_gitcomp "branch.me" "remote merge mergeoptions rebase" \
300 "branch.maint." "me" <<-\EOF
301 branch.maint.merge Z
302 branch.maint.mergeoptions Z
303 EOF
304'
305
306test_expect_success '__gitcomp - suffix' '
307 test_gitcomp "branch.me" "master maint next pu" "branch." \
308 "ma" "." <<-\EOF
309 branch.master.Z
310 branch.maint.Z
311 EOF
312'
313
314test_expect_success '__gitcomp - doesnt fail because of invalid variable name' '
315 __gitcomp "$invalid_variable_name"
316'
317
318read -r -d "" refs <<-\EOF
319maint
320master
321next
322pu
323EOF
324
325test_expect_success '__gitcomp_nl - trailing space' '
326 test_gitcomp_nl "m" "$refs" <<-EOF
327 maint Z
328 master Z
329 EOF
330'
331
332test_expect_success '__gitcomp_nl - prefix' '
333 test_gitcomp_nl "--fixup=m" "$refs" "--fixup=" "m" <<-EOF
334 --fixup=maint Z
335 --fixup=master Z
336 EOF
337'
338
339test_expect_success '__gitcomp_nl - suffix' '
340 test_gitcomp_nl "branch.ma" "$refs" "branch." "ma" "." <<-\EOF
341 branch.maint.Z
342 branch.master.Z
343 EOF
344'
345
346test_expect_success '__gitcomp_nl - no suffix' '
347 test_gitcomp_nl "ma" "$refs" "" "ma" "" <<-\EOF
348 maintZ
349 masterZ
350 EOF
351'
352
353test_expect_success '__gitcomp_nl - doesnt fail because of invalid variable name' '
354 __gitcomp_nl "$invalid_variable_name"
355'
356
357test_expect_success '__git_remotes - list remotes from $GIT_DIR/remotes and from config file' '
358 cat >expect <<-EOF &&
359 remote_from_file_1
360 remote_from_file_2
361 remote_in_config_1
362 remote_in_config_2
363 EOF
364 test_when_finished "rm -rf .git/remotes" &&
365 mkdir -p .git/remotes &&
366 >.git/remotes/remote_from_file_1 &&
367 >.git/remotes/remote_from_file_2 &&
368 test_when_finished "git remote remove remote_in_config_1" &&
369 git remote add remote_in_config_1 git://remote_1 &&
370 test_when_finished "git remote remove remote_in_config_2" &&
371 git remote add remote_in_config_2 git://remote_2 &&
372 __git_remotes >actual &&
373 test_cmp expect actual
374'
375
376test_expect_success 'setup for ref completion' '
377 git commit --allow-empty -m initial &&
378 git branch matching-branch &&
379 git tag matching-tag &&
380 (
381 cd otherrepo &&
382 git commit --allow-empty -m initial &&
383 git branch -m master master-in-other &&
384 git branch branch-in-other &&
385 git tag tag-in-other
386 ) &&
387 git remote add other "$ROOT/otherrepo/.git" &&
388 git fetch --no-tags other &&
389 rm -f .git/FETCH_HEAD &&
390 git init thirdrepo
391'
392
393test_expect_success '__git_refs - simple' '
394 cat >expected <<-EOF &&
395 HEAD
396 master
397 matching-branch
398 other/branch-in-other
399 other/master-in-other
400 matching-tag
401 EOF
402 (
403 cur= &&
404 __git_refs >"$actual"
405 ) &&
406 test_cmp expected "$actual"
407'
408
409test_expect_success '__git_refs - full refs' '
410 cat >expected <<-EOF &&
411 refs/heads/master
412 refs/heads/matching-branch
413 EOF
414 (
415 cur=refs/heads/ &&
416 __git_refs >"$actual"
417 ) &&
418 test_cmp expected "$actual"
419'
420
421test_expect_success '__git_refs - repo given on the command line' '
422 cat >expected <<-EOF &&
423 HEAD
424 branch-in-other
425 master-in-other
426 tag-in-other
427 EOF
428 (
429 __git_dir="$ROOT/otherrepo/.git" &&
430 cur= &&
431 __git_refs >"$actual"
432 ) &&
433 test_cmp expected "$actual"
434'
435
436test_expect_success '__git_refs - remote on local file system' '
437 cat >expected <<-EOF &&
438 HEAD
439 branch-in-other
440 master-in-other
441 tag-in-other
442 EOF
443 (
444 cur= &&
445 __git_refs otherrepo >"$actual"
446 ) &&
447 test_cmp expected "$actual"
448'
449
450test_expect_success '__git_refs - remote on local file system - full refs' '
451 cat >expected <<-EOF &&
452 refs/heads/branch-in-other
453 refs/heads/master-in-other
454 refs/tags/tag-in-other
455 EOF
456 (
457 cur=refs/ &&
458 __git_refs otherrepo >"$actual"
459 ) &&
460 test_cmp expected "$actual"
461'
462
463test_expect_success '__git_refs - configured remote' '
464 cat >expected <<-EOF &&
465 HEAD
466 branch-in-other
467 master-in-other
468 EOF
469 (
470 cur= &&
471 __git_refs other >"$actual"
472 ) &&
473 test_cmp expected "$actual"
474'
475
476test_expect_success '__git_refs - configured remote - full refs' '
477 cat >expected <<-EOF &&
478 refs/heads/branch-in-other
479 refs/heads/master-in-other
480 refs/tags/tag-in-other
481 EOF
482 (
483 cur=refs/ &&
484 __git_refs other >"$actual"
485 ) &&
486 test_cmp expected "$actual"
487'
488
489test_expect_failure '__git_refs - configured remote - repo given on the command line' '
490 cat >expected <<-EOF &&
491 HEAD
492 branch-in-other
493 master-in-other
494 EOF
495 (
496 cd thirdrepo &&
497 __git_dir="$ROOT/.git" &&
498 cur= &&
499 __git_refs other >"$actual"
500 ) &&
501 test_cmp expected "$actual"
502'
503
504test_expect_failure '__git_refs - configured remote - full refs - repo given on the command line' '
505 cat >expected <<-EOF &&
506 refs/heads/branch-in-other
507 refs/heads/master-in-other
508 refs/tags/tag-in-other
509 EOF
510 (
511 cd thirdrepo &&
512 __git_dir="$ROOT/.git" &&
513 cur=refs/ &&
514 __git_refs other >"$actual"
515 ) &&
516 test_cmp expected "$actual"
517'
518
519test_expect_failure '__git_refs - configured remote - remote name matches a directory' '
520 cat >expected <<-EOF &&
521 HEAD
522 branch-in-other
523 master-in-other
524 EOF
525 mkdir other &&
526 test_when_finished "rm -rf other" &&
527 (
528 cur= &&
529 __git_refs other >"$actual"
530 ) &&
531 test_cmp expected "$actual"
532'
533
534test_expect_failure '__git_refs - URL remote' '
535 cat >expected <<-EOF &&
536 HEAD
537 branch-in-other
538 master-in-other
539 tag-in-other
540 EOF
541 (
542 cur= &&
543 __git_refs "file://$ROOT/otherrepo/.git" >"$actual"
544 ) &&
545 test_cmp expected "$actual"
546'
547
548test_expect_success '__git_refs - URL remote - full refs' '
549 cat >expected <<-EOF &&
550 refs/heads/branch-in-other
551 refs/heads/master-in-other
552 refs/tags/tag-in-other
553 EOF
554 (
555 cur=refs/ &&
556 __git_refs "file://$ROOT/otherrepo/.git" >"$actual"
557 ) &&
558 test_cmp expected "$actual"
559'
560
561test_expect_failure '__git_refs - non-existing remote' '
562 (
563 cur= &&
564 __git_refs non-existing >"$actual"
565 ) &&
566 test_must_be_empty "$actual"
567'
568
569test_expect_success '__git_refs - non-existing remote - full refs' '
570 (
571 cur=refs/ &&
572 __git_refs non-existing >"$actual"
573 ) &&
574 test_must_be_empty "$actual"
575'
576
577test_expect_failure '__git_refs - non-existing URL remote' '
578 (
579 cur= &&
580 __git_refs "file://$ROOT/non-existing" >"$actual"
581 ) &&
582 test_must_be_empty "$actual"
583'
584
585test_expect_success '__git_refs - non-existing URL remote - full refs' '
586 (
587 cur=refs/ &&
588 __git_refs "file://$ROOT/non-existing" >"$actual"
589 ) &&
590 test_must_be_empty "$actual"
591'
592
593test_expect_failure '__git_refs - not in a git repository' '
594 (
595 GIT_CEILING_DIRECTORIES="$ROOT" &&
596 export GIT_CEILING_DIRECTORIES &&
597 cd subdir &&
598 cur= &&
599 __git_refs >"$actual"
600 ) &&
601 test_must_be_empty "$actual"
602'
603
604test_expect_success '__git_refs - unique remote branches for git checkout DWIMery' '
605 cat >expected <<-EOF &&
606 HEAD
607 master
608 matching-branch
609 other/ambiguous
610 other/branch-in-other
611 other/master-in-other
612 remote/ambiguous
613 remote/branch-in-remote
614 matching-tag
615 branch-in-other
616 branch-in-remote
617 master-in-other
618 EOF
619 for remote_ref in refs/remotes/other/ambiguous \
620 refs/remotes/remote/ambiguous \
621 refs/remotes/remote/branch-in-remote
622 do
623 git update-ref $remote_ref master &&
624 test_when_finished "git update-ref -d $remote_ref"
625 done &&
626 (
627 cur= &&
628 __git_refs "" 1 >"$actual"
629 ) &&
630 test_cmp expected "$actual"
631'
632
633test_expect_success 'teardown after ref completion' '
634 git branch -d matching-branch &&
635 git tag -d matching-tag &&
636 git remote remove other
637'
638
639test_expect_success '__git_get_config_variables' '
640 cat >expect <<-EOF &&
641 name-1
642 name-2
643 EOF
644 test_config interesting.name-1 good &&
645 test_config interesting.name-2 good &&
646 test_config subsection.interesting.name-3 bad &&
647 __git_get_config_variables interesting >actual &&
648 test_cmp expect actual
649'
650
651test_expect_success '__git_pretty_aliases' '
652 cat >expect <<-EOF &&
653 author
654 hash
655 EOF
656 test_config pretty.author "%an %ae" &&
657 test_config pretty.hash %H &&
658 __git_pretty_aliases >actual &&
659 test_cmp expect actual
660'
661
662test_expect_success '__git_aliases' '
663 cat >expect <<-EOF &&
664 ci
665 co
666 EOF
667 test_config alias.ci commit &&
668 test_config alias.co checkout &&
669 __git_aliases >actual &&
670 test_cmp expect actual
671'
672
673test_expect_success 'basic' '
674 run_completion "git " &&
675 # built-in
676 grep -q "^add \$" out &&
677 # script
678 grep -q "^filter-branch \$" out &&
679 # plumbing
680 ! grep -q "^ls-files \$" out &&
681
682 run_completion "git f" &&
683 ! grep -q -v "^f" out
684'
685
686test_expect_success 'double dash "git" itself' '
687 test_completion "git --" <<-\EOF
688 --paginate Z
689 --no-pager Z
690 --git-dir=
691 --bare Z
692 --version Z
693 --exec-path Z
694 --exec-path=
695 --html-path Z
696 --man-path Z
697 --info-path Z
698 --work-tree=
699 --namespace=
700 --no-replace-objects Z
701 --help Z
702 EOF
703'
704
705test_expect_success 'double dash "git checkout"' '
706 test_completion "git checkout --" <<-\EOF
707 --quiet Z
708 --ours Z
709 --theirs Z
710 --track Z
711 --no-track Z
712 --merge Z
713 --conflict=
714 --orphan Z
715 --patch Z
716 EOF
717'
718
719test_expect_success 'general options' '
720 test_completion "git --ver" "--version " &&
721 test_completion "git --hel" "--help " &&
722 test_completion "git --exe" <<-\EOF &&
723 --exec-path Z
724 --exec-path=
725 EOF
726 test_completion "git --htm" "--html-path " &&
727 test_completion "git --pag" "--paginate " &&
728 test_completion "git --no-p" "--no-pager " &&
729 test_completion "git --git" "--git-dir=" &&
730 test_completion "git --wor" "--work-tree=" &&
731 test_completion "git --nam" "--namespace=" &&
732 test_completion "git --bar" "--bare " &&
733 test_completion "git --inf" "--info-path " &&
734 test_completion "git --no-r" "--no-replace-objects "
735'
736
737test_expect_success 'general options plus command' '
738 test_completion "git --version check" "checkout " &&
739 test_completion "git --paginate check" "checkout " &&
740 test_completion "git --git-dir=foo check" "checkout " &&
741 test_completion "git --bare check" "checkout " &&
742 test_completion "git --exec-path=foo check" "checkout " &&
743 test_completion "git --html-path check" "checkout " &&
744 test_completion "git --no-pager check" "checkout " &&
745 test_completion "git --work-tree=foo check" "checkout " &&
746 test_completion "git --namespace=foo check" "checkout " &&
747 test_completion "git --paginate check" "checkout " &&
748 test_completion "git --info-path check" "checkout " &&
749 test_completion "git --no-replace-objects check" "checkout "
750'
751
752test_expect_success 'git --help completion' '
753 test_completion "git --help ad" "add " &&
754 test_completion "git --help core" "core-tutorial "
755'
756
757test_expect_success 'setup for integration tests' '
758 echo content >file1 &&
759 echo more >file2 &&
760 git add file1 file2 &&
761 git commit -m one &&
762 git branch mybranch &&
763 git tag mytag
764'
765
766test_expect_success 'checkout completes ref names' '
767 test_completion "git checkout m" <<-\EOF
768 master Z
769 mybranch Z
770 mytag Z
771 EOF
772'
773
774test_expect_success 'show completes all refs' '
775 test_completion "git show m" <<-\EOF
776 master Z
777 mybranch Z
778 mytag Z
779 EOF
780'
781
782test_expect_success '<ref>: completes paths' '
783 test_completion "git show mytag:f" <<-\EOF
784 file1 Z
785 file2 Z
786 EOF
787'
788
789test_expect_success 'complete tree filename with spaces' '
790 echo content >"name with spaces" &&
791 git add "name with spaces" &&
792 git commit -m spaces &&
793 test_completion "git show HEAD:nam" <<-\EOF
794 name with spaces Z
795 EOF
796'
797
798test_expect_success 'complete tree filename with metacharacters' '
799 echo content >"name with \${meta}" &&
800 git add "name with \${meta}" &&
801 git commit -m meta &&
802 test_completion "git show HEAD:nam" <<-\EOF
803 name with ${meta} Z
804 name with spaces Z
805 EOF
806'
807
808test_expect_success 'send-email' '
809 test_completion "git send-email --cov" "--cover-letter " &&
810 test_completion "git send-email ma" "master "
811'
812
813test_expect_success 'complete files' '
814 git init tmp && cd tmp &&
815 test_when_finished "cd .. && rm -rf tmp" &&
816
817 echo "expected" > .gitignore &&
818 echo "out" >> .gitignore &&
819
820 git add .gitignore &&
821 test_completion "git commit " ".gitignore" &&
822
823 git commit -m ignore &&
824
825 touch new &&
826 test_completion "git add " "new" &&
827
828 git add new &&
829 git commit -a -m new &&
830 test_completion "git add " "" &&
831
832 git mv new modified &&
833 echo modify > modified &&
834 test_completion "git add " "modified" &&
835
836 touch untracked &&
837
838 : TODO .gitignore should not be here &&
839 test_completion "git rm " <<-\EOF &&
840 .gitignore
841 modified
842 EOF
843
844 test_completion "git clean " "untracked" &&
845
846 : TODO .gitignore should not be here &&
847 test_completion "git mv " <<-\EOF &&
848 .gitignore
849 modified
850 EOF
851
852 mkdir dir &&
853 touch dir/file-in-dir &&
854 git add dir/file-in-dir &&
855 git commit -m dir &&
856
857 mkdir untracked-dir &&
858
859 : TODO .gitignore should not be here &&
860 test_completion "git mv modified " <<-\EOF &&
861 .gitignore
862 dir
863 modified
864 untracked
865 untracked-dir
866 EOF
867
868 test_completion "git commit " "modified" &&
869
870 : TODO .gitignore should not be here &&
871 test_completion "git ls-files " <<-\EOF &&
872 .gitignore
873 dir
874 modified
875 EOF
876
877 touch momified &&
878 test_completion "git add mom" "momified"
879'
880
881test_expect_success "completion uses <cmd> completion for alias: !sh -c 'git <cmd> ...'" '
882 test_config alias.co "!sh -c '"'"'git checkout ...'"'"'" &&
883 test_completion "git co m" <<-\EOF
884 master Z
885 mybranch Z
886 mytag Z
887 EOF
888'
889
890test_expect_success 'completion uses <cmd> completion for alias: !f () { VAR=val git <cmd> ... }' '
891 test_config alias.co "!f () { VAR=val git checkout ... ; } f" &&
892 test_completion "git co m" <<-\EOF
893 master Z
894 mybranch Z
895 mytag Z
896 EOF
897'
898
899test_expect_success 'completion used <cmd> completion for alias: !f() { : git <cmd> ; ... }' '
900 test_config alias.co "!f() { : git checkout ; if ... } f" &&
901 test_completion "git co m" <<-\EOF
902 master Z
903 mybranch Z
904 mytag Z
905 EOF
906'
907
908test_expect_failure 'complete with tilde expansion' '
909 git init tmp && cd tmp &&
910 test_when_finished "cd .. && rm -rf tmp" &&
911
912 touch ~/tmp/file &&
913
914 test_completion "git add ~/tmp/" "~/tmp/file"
915'
916
917test_done