Code

Cache the list of merge strategies and available commands during load.
[git.git] / contrib / completion / git-completion.bash
1 #
2 # bash completion support for core Git.
3 #
4 # Copyright (C) 2006 Shawn Pearce
5 # Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
6 #
7 # The contained completion routines provide support for completing:
8 #
9 #    *) local and remote branch names
10 #    *) local and remote tag names
11 #    *) .git/remotes file names
12 #    *) git 'subcommands'
13 #    *) tree paths within 'ref:path/to/file' expressions
14 #
15 # To use these routines:
16 #
17 #    1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
18 #    2) Added the following line to your .bashrc:
19 #        source ~/.git-completion.sh
20 #
21 #    3) You may want to make sure the git executable is available
22 #       in your PATH before this script is sourced, as some caching
23 #       is performed while the script loads.  If git isn't found
24 #       at source time then all lookups will be done on demand,
25 #       which may be slightly slower.
26 #
27 #    4) Consider changing your PS1 to also show the current branch:
28 #        PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
29 #
30 #       The argument to __git_ps1 will be displayed only if you
31 #       are currently in a git repository.  The %s token will be
32 #       the name of the current branch.
33 #
35 __gitdir ()
36 {
37         echo "${__git_dir:-$(git rev-parse --git-dir 2>/dev/null)}"
38 }
40 __git_ps1 ()
41 {
42         local b="$(git symbolic-ref HEAD 2>/dev/null)"
43         if [ -n "$b" ]; then
44                 if [ -n "$1" ]; then
45                         printf "$1" "${b##refs/heads/}"
46                 else
47                         printf " (%s)" "${b##refs/heads/}"
48                 fi
49         fi
50 }
52 __git_heads ()
53 {
54         local cmd i is_hash=y dir="${1:-$(__gitdir)}"
55         if [ -d "$dir" ]; then
56                 for i in $(git --git-dir="$dir" \
57                         for-each-ref --format='%(refname)' \
58                         refs/heads ); do
59                         echo "${i#refs/heads/}"
60                 done
61                 return
62         fi
63         for i in $(git-ls-remote "$dir" 2>/dev/null); do
64                 case "$is_hash,$i" in
65                 y,*) is_hash=n ;;
66                 n,*^{}) is_hash=y ;;
67                 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
68                 n,*) is_hash=y; echo "$i" ;;
69                 esac
70         done
71 }
73 __git_refs ()
74 {
75         local cmd i is_hash=y dir="${1:-$(__gitdir)}"
76         if [ -d "$dir" ]; then
77                 if [ -e "$dir/HEAD" ]; then echo HEAD; fi
78                 for i in $(git --git-dir="$dir" \
79                         for-each-ref --format='%(refname)' \
80                         refs/tags refs/heads refs/remotes); do
81                         case "$i" in
82                                 refs/tags/*)    echo "${i#refs/tags/}" ;;
83                                 refs/heads/*)   echo "${i#refs/heads/}" ;;
84                                 refs/remotes/*) echo "${i#refs/remotes/}" ;;
85                                 *)              echo "$i" ;;
86                         esac
87                 done
88                 return
89         fi
90         for i in $(git-ls-remote "$dir" 2>/dev/null); do
91                 case "$is_hash,$i" in
92                 y,*) is_hash=n ;;
93                 n,*^{}) is_hash=y ;;
94                 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
95                 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
96                 n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
97                 n,*) is_hash=y; echo "$i" ;;
98                 esac
99         done
102 __git_refs2 ()
104         local cmd i is_hash=y dir="${1:-$(__gitdir)}"
105         if [ -d "$dir" ]; then
106                 cmd=git-peek-remote
107         else
108                 cmd=git-ls-remote
109         fi
110         for i in $($cmd "$dir" 2>/dev/null); do
111                 case "$is_hash,$i" in
112                 y,*) is_hash=n ;;
113                 n,*^{}) is_hash=y ;;
114                 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}:${i#refs/tags/}" ;;
115                 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}:${i#refs/heads/}" ;;
116                 n,*) is_hash=y; echo "$i:$i" ;;
117                 esac
118         done
121 __git_refs_remotes ()
123         local cmd i is_hash=y
124         for i in $(git-ls-remote "$1" 2>/dev/null); do
125                 case "$is_hash,$i" in
126                 n,refs/heads/*)
127                         is_hash=y
128                         echo "$i:refs/remotes/$1/${i#refs/heads/}"
129                         ;;
130                 y,*) is_hash=n ;;
131                 n,*^{}) is_hash=y ;;
132                 n,refs/tags/*) is_hash=y;;
133                 n,*) is_hash=y; ;;
134                 esac
135         done
138 __git_remotes ()
140         local i ngoff IFS=$'\n' d="$(__gitdir)"
141         shopt -q nullglob || ngoff=1
142         shopt -s nullglob
143         for i in "$d/remotes"/*; do
144                 echo ${i#$d/remotes/}
145         done
146         [ "$ngoff" ] && shopt -u nullglob
147         for i in $(git --git-dir="$d" repo-config --list); do
148                 case "$i" in
149                 remote.*.url=*)
150                         i="${i#remote.}"
151                         echo "${i/.url=*/}"
152                         ;;
153                 esac
154         done
157 __git_merge_strategies ()
159         if [ -n "$__git_merge_strategylist" ]; then
160                 echo "$__git_merge_strategylist"
161                 return
162         fi
163         sed -n "/^all_strategies='/{
164                 s/^all_strategies='//
165                 s/'//
166                 p
167                 q
168                 }" "$(git --exec-path)/git-merge"
170 __git_merge_strategylist=
171 __git_merge_strategylist="$(__git_merge_strategies 2>/dev/null)"
173 __git_complete_file ()
175         local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
176         case "$cur" in
177         ?*:*)
178                 ref="${cur%%:*}"
179                 cur="${cur#*:}"
180                 case "$cur" in
181                 ?*/*)
182                         pfx="${cur%/*}"
183                         cur="${cur##*/}"
184                         ls="$ref:$pfx"
185                         pfx="$pfx/"
186                         ;;
187                 *)
188                         ls="$ref"
189                         ;;
190             esac
191                 COMPREPLY=($(compgen -P "$pfx" \
192                         -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
193                                 | sed '/^100... blob /s,^.*     ,,
194                                        /^040000 tree /{
195                                            s,^.*        ,,
196                                            s,$,/,
197                                        }
198                                        s/^.*    //')" \
199                         -- "$cur"))
200                 ;;
201         *)
202                 COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
203                 ;;
204         esac
207 __git_complete_revlist ()
209         local pfx cur="${COMP_WORDS[COMP_CWORD]}"
210         case "$cur" in
211         *...*)
212                 pfx="${cur%...*}..."
213                 cur="${cur#*...}"
214                 COMPREPLY=($(compgen -P "$pfx" -W "$(__git_refs)" -- "$cur"))
215                 ;;
216         *..*)
217                 pfx="${cur%..*}.."
218                 cur="${cur#*..}"
219                 COMPREPLY=($(compgen -P "$pfx" -W "$(__git_refs)" -- "$cur"))
220                 ;;
221         *)
222                 COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
223                 ;;
224         esac
227 __git_commands ()
229         if [ -n "$__git_commandlist" ]; then
230                 echo "$__git_commandlist"
231                 return
232         fi
233         local i IFS=" "$'\n'
234         for i in $(git help -a|egrep '^ ')
235         do
236                 case $i in
237                 check-ref-format) : plumbing;;
238                 commit-tree)      : plumbing;;
239                 convert-objects)  : plumbing;;
240                 cvsserver)        : daemon;;
241                 daemon)           : daemon;;
242                 fetch-pack)       : plumbing;;
243                 hash-object)      : plumbing;;
244                 http-*)           : transport;;
245                 index-pack)       : plumbing;;
246                 local-fetch)      : plumbing;;
247                 mailinfo)         : plumbing;;
248                 mailsplit)        : plumbing;;
249                 merge-*)          : plumbing;;
250                 mktree)           : plumbing;;
251                 mktag)            : plumbing;;
252                 pack-objects)     : plumbing;;
253                 pack-redundant)   : plumbing;;
254                 pack-refs)        : plumbing;;
255                 parse-remote)     : plumbing;;
256                 patch-id)         : plumbing;;
257                 peek-remote)      : plumbing;;
258                 read-tree)        : plumbing;;
259                 receive-pack)     : plumbing;;
260                 rerere)           : plumbing;;
261                 rev-list)         : plumbing;;
262                 rev-parse)        : plumbing;;
263                 runstatus)        : plumbing;;
264                 sh-setup)         : internal;;
265                 shell)            : daemon;;
266                 send-pack)        : plumbing;;
267                 show-index)       : plumbing;;
268                 ssh-*)            : transport;;
269                 stripspace)       : plumbing;;
270                 symbolic-ref)     : plumbing;;
271                 unpack-file)      : plumbing;;
272                 unpack-objects)   : plumbing;;
273                 update-ref)       : plumbing;;
274                 update-server-info) : daemon;;
275                 upload-archive)   : plumbing;;
276                 upload-pack)      : plumbing;;
277                 write-tree)       : plumbing;;
278                 *) echo $i;;
279                 esac
280         done
282 __git_commandlist=
283 __git_commandlist="$(__git_commands 2>/dev/null)"
285 __git_aliases ()
287         local i IFS=$'\n'
288         for i in $(git --git-dir="$(__gitdir)" repo-config --list); do
289                 case "$i" in
290                 alias.*)
291                         i="${i#alias.}"
292                         echo "${i/=*/}"
293                         ;;
294                 esac
295         done
298 __git_aliased_command ()
300         local word cmdline=$(git --git-dir="$(__gitdir)" \
301                 repo-config --get "alias.$1")
302         for word in $cmdline; do
303                 if [ "${word##-*}" ]; then
304                         echo $word
305                         return
306                 fi
307         done
310 _git_branch ()
312         local cur="${COMP_WORDS[COMP_CWORD]}"
313         COMPREPLY=($(compgen -W "-l -f -d -D $(__git_refs)" -- "$cur"))
316 _git_cat_file ()
318         local cur="${COMP_WORDS[COMP_CWORD]}"
319         case "${COMP_WORDS[0]},$COMP_CWORD" in
320         git-cat-file*,1)
321                 COMPREPLY=($(compgen -W "-p -t blob tree commit tag" -- "$cur"))
322                 ;;
323         git,2)
324                 COMPREPLY=($(compgen -W "-p -t blob tree commit tag" -- "$cur"))
325                 ;;
326         *)
327                 __git_complete_file
328                 ;;
329         esac
332 _git_checkout ()
334         local cur="${COMP_WORDS[COMP_CWORD]}"
335         COMPREPLY=($(compgen -W "-l -b $(__git_refs)" -- "$cur"))
338 _git_cherry_pick ()
340         local cur="${COMP_WORDS[COMP_CWORD]}"
341         case "$cur" in
342         --*)
343                 COMPREPLY=($(compgen -W "
344                         --edit --no-commit
345                         " -- "$cur"))
346                 ;;
347         *)
348                 COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
349                 ;;
350         esac
353 _git_diff ()
355         __git_complete_file
358 _git_diff_tree ()
360         local cur="${COMP_WORDS[COMP_CWORD]}"
361         COMPREPLY=($(compgen -W "-r -p -M $(__git_refs)" -- "$cur"))
364 _git_fetch ()
366         local cur="${COMP_WORDS[COMP_CWORD]}"
368         case "${COMP_WORDS[0]},$COMP_CWORD" in
369         git-fetch*,1)
370                 COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
371                 ;;
372         git,2)
373                 COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
374                 ;;
375         *)
376                 case "$cur" in
377                 *:*)
378                         cur="${cur#*:}"
379                         COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
380                         ;;
381                 *)
382                         local remote
383                         case "${COMP_WORDS[0]}" in
384                         git-fetch) remote="${COMP_WORDS[1]}" ;;
385                         git)       remote="${COMP_WORDS[2]}" ;;
386                         esac
387                         COMPREPLY=($(compgen -W "$(__git_refs2 "$remote")" -- "$cur"))
388                         ;;
389                 esac
390                 ;;
391         esac
394 _git_format_patch ()
396         local cur="${COMP_WORDS[COMP_CWORD]}"
397         case "$cur" in
398         --*)
399                 COMPREPLY=($(compgen -W "
400                         --stdout --attach --thread
401                         --output-directory
402                         --numbered --start-number
403                         --keep-subject
404                         --signoff
405                         --in-reply-to=
406                         --full-index --binary
407                         " -- "$cur"))
408                 return
409                 ;;
410         esac
411         __git_complete_revlist
414 _git_ls_remote ()
416         local cur="${COMP_WORDS[COMP_CWORD]}"
417         COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
420 _git_ls_tree ()
422         __git_complete_file
425 _git_log ()
427         local cur="${COMP_WORDS[COMP_CWORD]}"
428         case "$cur" in
429         --pretty=*)
430                 COMPREPLY=($(compgen -W "
431                         oneline short medium full fuller email raw
432                         " -- "${cur##--pretty=}"))
433                 return
434                 ;;
435         --*)
436                 COMPREPLY=($(compgen -W "
437                         --max-count= --max-age= --since= --after=
438                         --min-age= --before= --until=
439                         --root --not --topo-order --date-order
440                         --no-merges
441                         --abbrev-commit --abbrev=
442                         --relative-date
443                         --author= --committer= --grep=
444                         --all-match
445                         --pretty= --name-status --name-only
446                         " -- "$cur"))
447                 return
448                 ;;
449         esac
450         __git_complete_revlist
453 _git_merge ()
455         local cur="${COMP_WORDS[COMP_CWORD]}"
456         case "${COMP_WORDS[COMP_CWORD-1]}" in
457         -s|--strategy)
458                 COMPREPLY=($(compgen -W "$(__git_merge_strategies)" -- "$cur"))
459                 return
460         esac
461         case "$cur" in
462         --strategy=*)
463                 COMPREPLY=($(compgen -W "$(__git_merge_strategies)" \
464                         -- "${cur##--strategy=}"))
465                 return
466                 ;;
467         --*)
468                 COMPREPLY=($(compgen -W "
469                         --no-commit --no-summary --squash --strategy
470                         " -- "$cur"))
471                 return
472         esac
473         COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
476 _git_merge_base ()
478         local cur="${COMP_WORDS[COMP_CWORD]}"
479         COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
482 _git_name_rev ()
484         local cur="${COMP_WORDS[COMP_CWORD]}"
485         COMPREPLY=($(compgen -W "--tags --all --stdin" -- "$cur"))
488 _git_pull ()
490         local cur="${COMP_WORDS[COMP_CWORD]}"
492         case "${COMP_WORDS[0]},$COMP_CWORD" in
493         git-pull*,1)
494                 COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
495                 ;;
496         git,2)
497                 COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
498                 ;;
499         *)
500                 local remote
501                 case "${COMP_WORDS[0]}" in
502                 git-pull)  remote="${COMP_WORDS[1]}" ;;
503                 git)       remote="${COMP_WORDS[2]}" ;;
504                 esac
505                 COMPREPLY=($(compgen -W "$(__git_refs "$remote")" -- "$cur"))
506                 ;;
507         esac
510 _git_push ()
512         local cur="${COMP_WORDS[COMP_CWORD]}"
514         case "${COMP_WORDS[0]},$COMP_CWORD" in
515         git-push*,1)
516                 COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
517                 ;;
518         git,2)
519                 COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
520                 ;;
521         *)
522                 case "$cur" in
523                 *:*)
524                         local remote
525                         case "${COMP_WORDS[0]}" in
526                         git-push)  remote="${COMP_WORDS[1]}" ;;
527                         git)       remote="${COMP_WORDS[2]}" ;;
528                         esac
529                         cur="${cur#*:}"
530                         COMPREPLY=($(compgen -W "$(__git_refs "$remote")" -- "$cur"))
531                         ;;
532                 *)
533                         COMPREPLY=($(compgen -W "$(__git_refs2)" -- "$cur"))
534                         ;;
535                 esac
536                 ;;
537         esac
540 _git_rebase ()
542         local cur="${COMP_WORDS[COMP_CWORD]}"
543         if [ -d .dotest ]; then
544                 COMPREPLY=($(compgen -W "
545                         --continue --skip --abort
546                         " -- "$cur"))
547                 return
548         fi
549         case "${COMP_WORDS[COMP_CWORD-1]}" in
550         -s|--strategy)
551                 COMPREPLY=($(compgen -W "$(__git_merge_strategies)" -- "$cur"))
552                 return
553         esac
554         case "$cur" in
555         --strategy=*)
556                 COMPREPLY=($(compgen -W "$(__git_merge_strategies)" \
557                         -- "${cur##--strategy=}"))
558                 return
559                 ;;
560         --*)
561                 COMPREPLY=($(compgen -W "
562                         --onto --merge --strategy
563                         " -- "$cur"))
564                 return
565         esac
566         COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
569 _git_repo_config ()
571         local cur="${COMP_WORDS[COMP_CWORD]}"
572         local prv="${COMP_WORDS[COMP_CWORD-1]}"
573         case "$prv" in
574         branch.*.remote)
575                 COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
576                 return
577                 ;;
578         branch.*.merge)
579                 COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
580                 return
581                 ;;
582         remote.*.fetch)
583                 local remote="${prv#remote.}"
584                 remote="${remote%.fetch}"
585                 COMPREPLY=($(compgen -W "$(__git_refs_remotes "$remote")" \
586                         -- "$cur"))
587                 return
588                 ;;
589         remote.*.push)
590                 local remote="${prv#remote.}"
591                 remote="${remote%.push}"
592                 COMPREPLY=($(compgen -W "$(git --git-dir="$(__gitdir)" \
593                         for-each-ref --format='%(refname):%(refname)' \
594                         refs/heads)" -- "$cur"))
595                 return
596                 ;;
597         *.*)
598                 COMPREPLY=()
599                 return
600                 ;;
601         esac
602         case "$cur" in
603         --*)
604                 COMPREPLY=($(compgen -W "
605                         --global --list --replace-all
606                         --get --get-all --get-regexp
607                         --unset --unset-all
608                         " -- "$cur"))
609                 return
610                 ;;
611         branch.*.*)
612                 local pfx="${cur%.*}."
613                 cur="${cur##*.}"
614                 COMPREPLY=($(compgen -P "$pfx" -W "remote merge" -- "$cur"))
615                 return
616                 ;;
617         branch.*)
618                 local pfx="${cur%.*}."
619                 cur="${cur#*.}"
620                 COMPREPLY=($(compgen -P "$pfx" -S . \
621                         -W "$(__git_heads)" -- "$cur"))
622                 return
623                 ;;
624         remote.*.*)
625                 local pfx="${cur%.*}."
626                 cur="${cur##*.}"
627                 COMPREPLY=($(compgen -P "$pfx" -W "url fetch push" -- "$cur"))
628                 return
629                 ;;
630         remote.*)
631                 local pfx="${cur%.*}."
632                 cur="${cur#*.}"
633                 COMPREPLY=($(compgen -P "$pfx" -S . \
634                         -W "$(__git_remotes)" -- "$cur"))
635                 return
636                 ;;
637         esac
638         COMPREPLY=($(compgen -W "
639                 apply.whitespace
640                 core.fileMode
641                 core.gitProxy
642                 core.ignoreStat
643                 core.preferSymlinkRefs
644                 core.logAllRefUpdates
645                 core.repositoryFormatVersion
646                 core.sharedRepository
647                 core.warnAmbiguousRefs
648                 core.compression
649                 core.legacyHeaders
650                 i18n.commitEncoding
651                 diff.color
652                 diff.renameLimit
653                 diff.renames
654                 pager.color
655                 status.color
656                 log.showroot
657                 show.difftree
658                 showbranch.default
659                 whatchanged.difftree
660                 http.sslVerify
661                 http.sslCert
662                 http.sslKey
663                 http.sslCAInfo
664                 http.sslCAPath
665                 http.maxRequests
666                 http.lowSpeedLimit http.lowSpeedTime
667                 http.noEPSV
668                 pack.window
669                 repack.useDeltaBaseOffset
670                 pull.octopus pull.twohead
671                 merge.summary
672                 receive.unpackLimit
673                 receive.denyNonFastForwards
674                 user.name user.email
675                 tar.umask
676                 gitcvs.enabled
677                 gitcvs.logfile
678                 branch. remote.
679         " -- "$cur"))
682 _git_reset ()
684         local cur="${COMP_WORDS[COMP_CWORD]}"
685         local opt="--mixed --hard --soft"
686         COMPREPLY=($(compgen -W "$opt $(__git_refs)" -- "$cur"))
689 _git ()
691         local i c=1 command __git_dir
693         while [ $c -lt $COMP_CWORD ]; do
694                 i="${COMP_WORDS[c]}"
695                 case "$i" in
696                 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
697                 --bare)      __git_dir="." ;;
698                 --version|--help|-p|--paginate) ;;
699                 *) command="$i"; break ;;
700                 esac
701                 c=$((++c))
702         done
704         if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
705                 COMPREPLY=($(compgen -W "
706                         --git-dir= --version --exec-path
707                         $(__git_commands)
708                         $(__git_aliases)
709                         " -- "${COMP_WORDS[COMP_CWORD]}"))
710                 return;
711         fi
713         local expansion=$(__git_aliased_command "$command")
714         [ "$expansion" ] && command="$expansion"
716         case "$command" in
717         branch)      _git_branch ;;
718         cat-file)    _git_cat_file ;;
719         checkout)    _git_checkout ;;
720         cherry-pick) _git_cherry_pick ;;
721         diff)        _git_diff ;;
722         diff-tree)   _git_diff_tree ;;
723         fetch)       _git_fetch ;;
724         format-patch) _git_format_patch ;;
725         log)         _git_log ;;
726         ls-remote)   _git_ls_remote ;;
727         ls-tree)     _git_ls_tree ;;
728         merge)       _git_merge;;
729         merge-base)  _git_merge_base ;;
730         name-rev)    _git_name_rev ;;
731         pull)        _git_pull ;;
732         push)        _git_push ;;
733         rebase)      _git_rebase ;;
734         repo-config) _git_repo_config ;;
735         reset)       _git_reset ;;
736         show)        _git_log ;;
737         show-branch) _git_log ;;
738         whatchanged) _git_log ;;
739         *)           COMPREPLY=() ;;
740         esac
743 _gitk ()
745         local cur="${COMP_WORDS[COMP_CWORD]}"
746         COMPREPLY=($(compgen -W "--all $(__git_refs)" -- "$cur"))
749 complete -o default -o nospace -F _git git
750 complete -o default            -F _gitk gitk
751 complete -o default            -F _git_branch git-branch
752 complete -o default -o nospace -F _git_cat_file git-cat-file
753 complete -o default            -F _git_checkout git-checkout
754 complete -o default            -F _git_cherry_pick git-cherry-pick
755 complete -o default -o nospace -F _git_diff git-diff
756 complete -o default            -F _git_diff_tree git-diff-tree
757 complete -o default -o nospace -F _git_fetch git-fetch
758 complete -o default -o nospace -F _git_format_patch git-format-patch
759 complete -o default -o nospace -F _git_log git-log
760 complete -o default            -F _git_ls_remote git-ls-remote
761 complete -o default -o nospace -F _git_ls_tree git-ls-tree
762 complete -o default            -F _git_merge git-merge
763 complete -o default            -F _git_merge_base git-merge-base
764 complete -o default            -F _git_name_rev git-name-rev
765 complete -o default -o nospace -F _git_pull git-pull
766 complete -o default -o nospace -F _git_push git-push
767 complete -o default            -F _git_rebase git-rebase
768 complete -o default            -F _git_repo_config git-repo-config
769 complete -o default            -F _git_reset git-reset
770 complete -o default            -F _git_log git-show
771 complete -o default -o nospace -F _git_log git-show-branch
772 complete -o default -o nospace -F _git_log git-whatchanged
774 # The following are necessary only for Cygwin, and only are needed
775 # when the user has tab-completed the executable name and consequently
776 # included the '.exe' suffix.
778 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
779 complete -o default -o nospace -F _git git.exe
780 complete -o default            -F _git_branch git-branch.exe
781 complete -o default -o nospace -F _git_cat_file git-cat-file.exe
782 complete -o default -o nospace -F _git_diff git-diff.exe
783 complete -o default -o nospace -F _git_diff_tree git-diff-tree.exe
784 complete -o default -o nospace -F _git_format_patch git-format-patch.exe
785 complete -o default -o nospace -F _git_log git-log.exe
786 complete -o default -o nospace -F _git_ls_tree git-ls-tree.exe
787 complete -o default            -F _git_merge_base git-merge-base.exe
788 complete -o default            -F _git_name_rev git-name-rev.exe
789 complete -o default -o nospace -F _git_push git-push.exe
790 complete -o default            -F _git_repo_config git-repo-config
791 complete -o default -o nospace -F _git_log git-show.exe
792 complete -o default -o nospace -F _git_log git-show-branch.exe
793 complete -o default -o nospace -F _git_log git-whatchanged.exe
794 fi