Code

Fix bash completion in path with spaces
[git.git] / contrib / completion / git-completion.bash
1 #
2 # bash completion support for core Git.
3 #
4 # Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
5 # Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
6 # Distributed under the GNU General Public License, version 2.0.
7 #
8 # The contained completion routines provide support for completing:
9 #
10 #    *) local and remote branch names
11 #    *) local and remote tag names
12 #    *) .git/remotes file names
13 #    *) git 'subcommands'
14 #    *) tree paths within 'ref:path/to/file' expressions
15 #    *) common --long-options
16 #
17 # To use these routines:
18 #
19 #    1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
20 #    2) Added the following line to your .bashrc:
21 #        source ~/.git-completion.sh
22 #
23 #    3) You may want to make sure the git executable is available
24 #       in your PATH before this script is sourced, as some caching
25 #       is performed while the script loads.  If git isn't found
26 #       at source time then all lookups will be done on demand,
27 #       which may be slightly slower.
28 #
29 #    4) Consider changing your PS1 to also show the current branch:
30 #        PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
31 #
32 #       The argument to __git_ps1 will be displayed only if you
33 #       are currently in a git repository.  The %s token will be
34 #       the name of the current branch.
35 #
36 # To submit patches:
37 #
38 #    *) Read Documentation/SubmittingPatches
39 #    *) Send all patches to the current maintainer:
40 #
41 #       "Shawn O. Pearce" <spearce@spearce.org>
42 #
43 #    *) Always CC the Git mailing list:
44 #
45 #       git@vger.kernel.org
46 #
48 case "$COMP_WORDBREAKS" in
49 *:*) : great ;;
50 *)   COMP_WORDBREAKS="$COMP_WORDBREAKS:"
51 esac
53 __gitdir ()
54 {
55         if [ -z "$1" ]; then
56                 if [ -n "$__git_dir" ]; then
57                         echo "$__git_dir"
58                 elif [ -d .git ]; then
59                         echo .git
60                 else
61                         git rev-parse --git-dir 2>/dev/null
62                 fi
63         elif [ -d "$1/.git" ]; then
64                 echo "$1/.git"
65         else
66                 echo "$1"
67         fi
68 }
70 __git_ps1 ()
71 {
72         local g="$(git rev-parse --git-dir 2>/dev/null)"
73         if [ -n "$g" ]; then
74                 local r
75                 local b
76                 if [ -d "$g/rebase-apply" ]
77                 then
78                         if test -f "$g/rebase-apply/rebasing"
79                         then
80                                 r="|REBASE"
81                         elif test -f "$g/rebase-apply/applying"
82                         then
83                                 r="|AM"
84                         else
85                                 r="|AM/REBASE"
86                         fi
87                         b="$(git symbolic-ref HEAD 2>/dev/null)"
88                 elif [ -f "$g/rebase-merge/interactive" ]
89                 then
90                         r="|REBASE-i"
91                         b="$(cat "$g/rebase-merge/head-name")"
92                 elif [ -d "$g/rebase-merge" ]
93                 then
94                         r="|REBASE-m"
95                         b="$(cat "$g/rebase-merge/head-name")"
96                 elif [ -f "$g/MERGE_HEAD" ]
97                 then
98                         r="|MERGING"
99                         b="$(git symbolic-ref HEAD 2>/dev/null)"
100                 else
101                         if [ -f "$g/BISECT_LOG" ]
102                         then
103                                 r="|BISECTING"
104                         fi
105                         if ! b="$(git symbolic-ref HEAD 2>/dev/null)"
106                         then
107                                 if ! b="$(git describe --exact-match HEAD 2>/dev/null)"
108                                 then
109                                         b="$(cut -c1-7 "$g/HEAD")..."
110                                 fi
111                         fi
112                 fi
114                 if [ -n "$1" ]; then
115                         printf "$1" "${b##refs/heads/}$r"
116                 else
117                         printf " (%s)" "${b##refs/heads/}$r"
118                 fi
119         fi
122 __gitcomp_1 ()
124         local c IFS=' '$'\t'$'\n'
125         for c in $1; do
126                 case "$c$2" in
127                 --*=*) printf %s$'\n' "$c$2" ;;
128                 *.)    printf %s$'\n' "$c$2" ;;
129                 *)     printf %s$'\n' "$c$2 " ;;
130                 esac
131         done
134 __gitcomp ()
136         local cur="${COMP_WORDS[COMP_CWORD]}"
137         if [ $# -gt 2 ]; then
138                 cur="$3"
139         fi
140         case "$cur" in
141         --*=)
142                 COMPREPLY=()
143                 ;;
144         *)
145                 local IFS=$'\n'
146                 COMPREPLY=($(compgen -P "$2" \
147                         -W "$(__gitcomp_1 "$1" "$4")" \
148                         -- "$cur"))
149                 ;;
150         esac
153 __git_heads ()
155         local cmd i is_hash=y dir="$(__gitdir "$1")"
156         if [ -d "$dir" ]; then
157                 for i in $(git --git-dir="$dir" \
158                         for-each-ref --format='%(refname)' \
159                         refs/heads ); do
160                         echo "${i#refs/heads/}"
161                 done
162                 return
163         fi
164         for i in $(git ls-remote "$1" 2>/dev/null); do
165                 case "$is_hash,$i" in
166                 y,*) is_hash=n ;;
167                 n,*^{}) is_hash=y ;;
168                 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
169                 n,*) is_hash=y; echo "$i" ;;
170                 esac
171         done
174 __git_tags ()
176         local cmd i is_hash=y dir="$(__gitdir "$1")"
177         if [ -d "$dir" ]; then
178                 for i in $(git --git-dir="$dir" \
179                         for-each-ref --format='%(refname)' \
180                         refs/tags ); do
181                         echo "${i#refs/tags/}"
182                 done
183                 return
184         fi
185         for i in $(git ls-remote "$1" 2>/dev/null); do
186                 case "$is_hash,$i" in
187                 y,*) is_hash=n ;;
188                 n,*^{}) is_hash=y ;;
189                 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
190                 n,*) is_hash=y; echo "$i" ;;
191                 esac
192         done
195 __git_refs ()
197         local cmd i is_hash=y dir="$(__gitdir "$1")"
198         if [ -d "$dir" ]; then
199                 if [ -e "$dir/HEAD" ]; then echo HEAD; fi
200                 for i in $(git --git-dir="$dir" \
201                         for-each-ref --format='%(refname)' \
202                         refs/tags refs/heads refs/remotes); do
203                         case "$i" in
204                                 refs/tags/*)    echo "${i#refs/tags/}" ;;
205                                 refs/heads/*)   echo "${i#refs/heads/}" ;;
206                                 refs/remotes/*) echo "${i#refs/remotes/}" ;;
207                                 *)              echo "$i" ;;
208                         esac
209                 done
210                 return
211         fi
212         for i in $(git ls-remote "$dir" 2>/dev/null); do
213                 case "$is_hash,$i" in
214                 y,*) is_hash=n ;;
215                 n,*^{}) is_hash=y ;;
216                 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
217                 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
218                 n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
219                 n,*) is_hash=y; echo "$i" ;;
220                 esac
221         done
224 __git_refs2 ()
226         local i
227         for i in $(__git_refs "$1"); do
228                 echo "$i:$i"
229         done
232 __git_refs_remotes ()
234         local cmd i is_hash=y
235         for i in $(git ls-remote "$1" 2>/dev/null); do
236                 case "$is_hash,$i" in
237                 n,refs/heads/*)
238                         is_hash=y
239                         echo "$i:refs/remotes/$1/${i#refs/heads/}"
240                         ;;
241                 y,*) is_hash=n ;;
242                 n,*^{}) is_hash=y ;;
243                 n,refs/tags/*) is_hash=y;;
244                 n,*) is_hash=y; ;;
245                 esac
246         done
249 __git_remotes ()
251         local i ngoff IFS=$'\n' d="$(__gitdir)"
252         shopt -q nullglob || ngoff=1
253         shopt -s nullglob
254         for i in "$d/remotes"/*; do
255                 echo ${i#$d/remotes/}
256         done
257         [ "$ngoff" ] && shopt -u nullglob
258         for i in $(git --git-dir="$d" config --list); do
259                 case "$i" in
260                 remote.*.url=*)
261                         i="${i#remote.}"
262                         echo "${i/.url=*/}"
263                         ;;
264                 esac
265         done
268 __git_merge_strategies ()
270         if [ -n "$__git_merge_strategylist" ]; then
271                 echo "$__git_merge_strategylist"
272                 return
273         fi
274         git merge -s help 2>&1 |
275         sed -n -e '/[Aa]vailable strategies are: /,/^$/{
276                 s/\.$//
277                 s/.*://
278                 s/^[    ]*//
279                 s/[     ]*$//
280                 p
281         }'
283 __git_merge_strategylist=
284 __git_merge_strategylist=$(__git_merge_strategies 2>/dev/null)
286 __git_complete_file ()
288         local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
289         case "$cur" in
290         ?*:*)
291                 ref="${cur%%:*}"
292                 cur="${cur#*:}"
293                 case "$cur" in
294                 ?*/*)
295                         pfx="${cur%/*}"
296                         cur="${cur##*/}"
297                         ls="$ref:$pfx"
298                         pfx="$pfx/"
299                         ;;
300                 *)
301                         ls="$ref"
302                         ;;
303             esac
305                 case "$COMP_WORDBREAKS" in
306                 *:*) : great ;;
307                 *)   pfx="$ref:$pfx" ;;
308                 esac
310                 local IFS=$'\n'
311                 COMPREPLY=($(compgen -P "$pfx" \
312                         -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
313                                 | sed '/^100... blob /{
314                                            s,^.*        ,,
315                                            s,$, ,
316                                        }
317                                        /^120000 blob /{
318                                            s,^.*        ,,
319                                            s,$, ,
320                                        }
321                                        /^040000 tree /{
322                                            s,^.*        ,,
323                                            s,$,/,
324                                        }
325                                        s/^.*    //')" \
326                         -- "$cur"))
327                 ;;
328         *)
329                 __gitcomp "$(__git_refs)"
330                 ;;
331         esac
334 __git_complete_revlist ()
336         local pfx cur="${COMP_WORDS[COMP_CWORD]}"
337         case "$cur" in
338         *...*)
339                 pfx="${cur%...*}..."
340                 cur="${cur#*...}"
341                 __gitcomp "$(__git_refs)" "$pfx" "$cur"
342                 ;;
343         *..*)
344                 pfx="${cur%..*}.."
345                 cur="${cur#*..}"
346                 __gitcomp "$(__git_refs)" "$pfx" "$cur"
347                 ;;
348         *)
349                 __gitcomp "$(__git_refs)"
350                 ;;
351         esac
354 __git_all_commands ()
356         if [ -n "$__git_all_commandlist" ]; then
357                 echo "$__git_all_commandlist"
358                 return
359         fi
360         local i IFS=" "$'\n'
361         for i in $(git help -a|egrep '^ ')
362         do
363                 case $i in
364                 *--*)             : helper pattern;;
365                 *) echo $i;;
366                 esac
367         done
369 __git_all_commandlist=
370 __git_all_commandlist="$(__git_all_commands 2>/dev/null)"
372 __git_porcelain_commands ()
374         if [ -n "$__git_porcelain_commandlist" ]; then
375                 echo "$__git_porcelain_commandlist"
376                 return
377         fi
378         local i IFS=" "$'\n'
379         for i in "help" $(__git_all_commands)
380         do
381                 case $i in
382                 *--*)             : helper pattern;;
383                 applymbox)        : ask gittus;;
384                 applypatch)       : ask gittus;;
385                 archimport)       : import;;
386                 cat-file)         : plumbing;;
387                 check-attr)       : plumbing;;
388                 check-ref-format) : plumbing;;
389                 checkout-index)   : plumbing;;
390                 commit-tree)      : plumbing;;
391                 count-objects)    : infrequent;;
392                 cvsexportcommit)  : export;;
393                 cvsimport)        : import;;
394                 cvsserver)        : daemon;;
395                 daemon)           : daemon;;
396                 diff-files)       : plumbing;;
397                 diff-index)       : plumbing;;
398                 diff-tree)        : plumbing;;
399                 fast-import)      : import;;
400                 fast-export)      : export;;
401                 fsck-objects)     : plumbing;;
402                 fetch-pack)       : plumbing;;
403                 fmt-merge-msg)    : plumbing;;
404                 for-each-ref)     : plumbing;;
405                 hash-object)      : plumbing;;
406                 http-*)           : transport;;
407                 index-pack)       : plumbing;;
408                 init-db)          : deprecated;;
409                 local-fetch)      : plumbing;;
410                 lost-found)       : infrequent;;
411                 ls-files)         : plumbing;;
412                 ls-remote)        : plumbing;;
413                 ls-tree)          : plumbing;;
414                 mailinfo)         : plumbing;;
415                 mailsplit)        : plumbing;;
416                 merge-*)          : plumbing;;
417                 mktree)           : plumbing;;
418                 mktag)            : plumbing;;
419                 pack-objects)     : plumbing;;
420                 pack-redundant)   : plumbing;;
421                 pack-refs)        : plumbing;;
422                 parse-remote)     : plumbing;;
423                 patch-id)         : plumbing;;
424                 peek-remote)      : plumbing;;
425                 prune)            : plumbing;;
426                 prune-packed)     : plumbing;;
427                 quiltimport)      : import;;
428                 read-tree)        : plumbing;;
429                 receive-pack)     : plumbing;;
430                 reflog)           : plumbing;;
431                 repo-config)      : deprecated;;
432                 rerere)           : plumbing;;
433                 rev-list)         : plumbing;;
434                 rev-parse)        : plumbing;;
435                 runstatus)        : plumbing;;
436                 sh-setup)         : internal;;
437                 shell)            : daemon;;
438                 show-ref)         : plumbing;;
439                 send-pack)        : plumbing;;
440                 show-index)       : plumbing;;
441                 ssh-*)            : transport;;
442                 stripspace)       : plumbing;;
443                 symbolic-ref)     : plumbing;;
444                 tar-tree)         : deprecated;;
445                 unpack-file)      : plumbing;;
446                 unpack-objects)   : plumbing;;
447                 update-index)     : plumbing;;
448                 update-ref)       : plumbing;;
449                 update-server-info) : daemon;;
450                 upload-archive)   : plumbing;;
451                 upload-pack)      : plumbing;;
452                 write-tree)       : plumbing;;
453                 var)              : infrequent;;
454                 verify-pack)      : infrequent;;
455                 verify-tag)       : plumbing;;
456                 *) echo $i;;
457                 esac
458         done
460 __git_porcelain_commandlist=
461 __git_porcelain_commandlist="$(__git_porcelain_commands 2>/dev/null)"
463 __git_aliases ()
465         local i IFS=$'\n'
466         for i in $(git --git-dir="$(__gitdir)" config --list); do
467                 case "$i" in
468                 alias.*)
469                         i="${i#alias.}"
470                         echo "${i/=*/}"
471                         ;;
472                 esac
473         done
476 __git_aliased_command ()
478         local word cmdline=$(git --git-dir="$(__gitdir)" \
479                 config --get "alias.$1")
480         for word in $cmdline; do
481                 if [ "${word##-*}" ]; then
482                         echo $word
483                         return
484                 fi
485         done
488 __git_find_subcommand ()
490         local word subcommand c=1
492         while [ $c -lt $COMP_CWORD ]; do
493                 word="${COMP_WORDS[c]}"
494                 for subcommand in $1; do
495                         if [ "$subcommand" = "$word" ]; then
496                                 echo "$subcommand"
497                                 return
498                         fi
499                 done
500                 c=$((++c))
501         done
504 __git_has_doubledash ()
506         local c=1
507         while [ $c -lt $COMP_CWORD ]; do
508                 if [ "--" = "${COMP_WORDS[c]}" ]; then
509                         return 0
510                 fi
511                 c=$((++c))
512         done
513         return 1
516 __git_whitespacelist="nowarn warn error error-all fix"
518 _git_am ()
520         local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
521         if [ -d "$dir"/rebase-apply ]; then
522                 __gitcomp "--skip --resolved --abort"
523                 return
524         fi
525         case "$cur" in
526         --whitespace=*)
527                 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
528                 return
529                 ;;
530         --*)
531                 __gitcomp "
532                         --signoff --utf8 --binary --3way --interactive
533                         --whitespace=
534                         "
535                 return
536         esac
537         COMPREPLY=()
540 _git_apply ()
542         local cur="${COMP_WORDS[COMP_CWORD]}"
543         case "$cur" in
544         --whitespace=*)
545                 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
546                 return
547                 ;;
548         --*)
549                 __gitcomp "
550                         --stat --numstat --summary --check --index
551                         --cached --index-info --reverse --reject --unidiff-zero
552                         --apply --no-add --exclude=
553                         --whitespace= --inaccurate-eof --verbose
554                         "
555                 return
556         esac
557         COMPREPLY=()
560 _git_add ()
562         __git_has_doubledash && return
564         local cur="${COMP_WORDS[COMP_CWORD]}"
565         case "$cur" in
566         --*)
567                 __gitcomp "
568                         --interactive --refresh --patch --update --dry-run
569                         --ignore-errors
570                         "
571                 return
572         esac
573         COMPREPLY=()
576 _git_archive ()
578         local cur="${COMP_WORDS[COMP_CWORD]}"
579         case "$cur" in
580         --format=*)
581                 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
582                 return
583                 ;;
584         --remote=*)
585                 __gitcomp "$(__git_remotes)" "" "${cur##--remote=}"
586                 return
587                 ;;
588         --*)
589                 __gitcomp "
590                         --format= --list --verbose
591                         --prefix= --remote= --exec=
592                         "
593                 return
594                 ;;
595         esac
596         __git_complete_file
599 _git_bisect ()
601         __git_has_doubledash && return
603         local subcommands="start bad good skip reset visualize replay log run"
604         local subcommand="$(__git_find_subcommand "$subcommands")"
605         if [ -z "$subcommand" ]; then
606                 __gitcomp "$subcommands"
607                 return
608         fi
610         case "$subcommand" in
611         bad|good|reset|skip)
612                 __gitcomp "$(__git_refs)"
613                 ;;
614         *)
615                 COMPREPLY=()
616                 ;;
617         esac
620 _git_branch ()
622         local i c=1 only_local_ref="n" has_r="n"
624         while [ $c -lt $COMP_CWORD ]; do
625                 i="${COMP_WORDS[c]}"
626                 case "$i" in
627                 -d|-m)  only_local_ref="y" ;;
628                 -r)     has_r="y" ;;
629                 esac
630                 c=$((++c))
631         done
633         case "${COMP_WORDS[COMP_CWORD]}" in
634         --*=*)  COMPREPLY=() ;;
635         --*)
636                 __gitcomp "
637                         --color --no-color --verbose --abbrev= --no-abbrev
638                         --track --no-track --contains --merged --no-merged
639                         "
640                 ;;
641         *)
642                 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
643                         __gitcomp "$(__git_heads)"
644                 else
645                         __gitcomp "$(__git_refs)"
646                 fi
647                 ;;
648         esac
651 _git_bundle ()
653         local cmd="${COMP_WORDS[2]}"
654         case "$COMP_CWORD" in
655         2)
656                 __gitcomp "create list-heads verify unbundle"
657                 ;;
658         3)
659                 # looking for a file
660                 ;;
661         *)
662                 case "$cmd" in
663                         create)
664                                 __git_complete_revlist
665                         ;;
666                 esac
667                 ;;
668         esac
671 _git_checkout ()
673         __git_has_doubledash && return
675         __gitcomp "$(__git_refs)"
678 _git_cherry ()
680         __gitcomp "$(__git_refs)"
683 _git_cherry_pick ()
685         local cur="${COMP_WORDS[COMP_CWORD]}"
686         case "$cur" in
687         --*)
688                 __gitcomp "--edit --no-commit"
689                 ;;
690         *)
691                 __gitcomp "$(__git_refs)"
692                 ;;
693         esac
696 _git_clean ()
698         __git_has_doubledash && return
700         local cur="${COMP_WORDS[COMP_CWORD]}"
701         case "$cur" in
702         --*)
703                 __gitcomp "--dry-run --quiet"
704                 return
705                 ;;
706         esac
707         COMPREPLY=()
710 _git_clone ()
712         local cur="${COMP_WORDS[COMP_CWORD]}"
713         case "$cur" in
714         --*)
715                 __gitcomp "
716                         --local
717                         --no-hardlinks
718                         --shared
719                         --reference
720                         --quiet
721                         --no-checkout
722                         --bare
723                         --mirror
724                         --origin
725                         --upload-pack
726                         --template=
727                         --depth
728                         "
729                 return
730                 ;;
731         esac
732         COMPREPLY=()
735 _git_commit ()
737         __git_has_doubledash && return
739         local cur="${COMP_WORDS[COMP_CWORD]}"
740         case "$cur" in
741         --*)
742                 __gitcomp "
743                         --all --author= --signoff --verify --no-verify
744                         --edit --amend --include --only --interactive
745                         "
746                 return
747         esac
748         COMPREPLY=()
751 _git_describe ()
753         local cur="${COMP_WORDS[COMP_CWORD]}"
754         case "$cur" in
755         --*)
756                 __gitcomp "
757                         --all --tags --contains --abbrev= --candidates=
758                         --exact-match --debug --long --match --always
759                         "
760                 return
761         esac
762         __gitcomp "$(__git_refs)"
765 _git_diff ()
767         __git_has_doubledash && return
769         local cur="${COMP_WORDS[COMP_CWORD]}"
770         case "$cur" in
771         --*)
772                 __gitcomp "--cached --stat --numstat --shortstat --summary
773                         --patch-with-stat --name-only --name-status --color
774                         --no-color --color-words --no-renames --check
775                         --full-index --binary --abbrev --diff-filter=
776                         --find-copies-harder --pickaxe-all --pickaxe-regex
777                         --text --ignore-space-at-eol --ignore-space-change
778                         --ignore-all-space --exit-code --quiet --ext-diff
779                         --no-ext-diff
780                         --no-prefix --src-prefix= --dst-prefix=
781                         --base --ours --theirs
782                         "
783                 return
784                 ;;
785         esac
786         __git_complete_file
789 _git_fetch ()
791         local cur="${COMP_WORDS[COMP_CWORD]}"
793         if [ "$COMP_CWORD" = 2 ]; then
794                 __gitcomp "$(__git_remotes)"
795         else
796                 case "$cur" in
797                 *:*)
798                         local pfx=""
799                         case "$COMP_WORDBREAKS" in
800                         *:*) : great ;;
801                         *)   pfx="${cur%%:*}:" ;;
802                         esac
803                         __gitcomp "$(__git_refs)" "$pfx" "${cur#*:}"
804                         ;;
805                 *)
806                         __gitcomp "$(__git_refs2 "${COMP_WORDS[2]}")"
807                         ;;
808                 esac
809         fi
812 _git_format_patch ()
814         local cur="${COMP_WORDS[COMP_CWORD]}"
815         case "$cur" in
816         --*)
817                 __gitcomp "
818                         --stdout --attach --thread
819                         --output-directory
820                         --numbered --start-number
821                         --numbered-files
822                         --keep-subject
823                         --signoff
824                         --in-reply-to=
825                         --full-index --binary
826                         --not --all
827                         --cover-letter
828                         --no-prefix --src-prefix= --dst-prefix=
829                         "
830                 return
831                 ;;
832         esac
833         __git_complete_revlist
836 _git_gc ()
838         local cur="${COMP_WORDS[COMP_CWORD]}"
839         case "$cur" in
840         --*)
841                 __gitcomp "--prune --aggressive"
842                 return
843                 ;;
844         esac
845         COMPREPLY=()
848 _git_grep ()
850         __git_has_doubledash && return
852         local cur="${COMP_WORDS[COMP_CWORD]}"
853         case "$cur" in
854         --*)
855                 __gitcomp "
856                         --cached
857                         --text --ignore-case --word-regexp --invert-match
858                         --full-name
859                         --extended-regexp --basic-regexp --fixed-strings
860                         --files-with-matches --name-only
861                         --files-without-match
862                         --count
863                         --and --or --not --all-match
864                         "
865                 return
866                 ;;
867         esac
868         COMPREPLY=()
871 _git_help ()
873         local cur="${COMP_WORDS[COMP_CWORD]}"
874         case "$cur" in
875         --*)
876                 __gitcomp "--all --info --man --web"
877                 return
878                 ;;
879         esac
880         __gitcomp "$(__git_all_commands)
881                 attributes cli core-tutorial cvs-migration
882                 diffcore gitk glossary hooks ignore modules
883                 repository-layout tutorial tutorial-2
884                 "
887 _git_init ()
889         local cur="${COMP_WORDS[COMP_CWORD]}"
890         case "$cur" in
891         --shared=*)
892                 __gitcomp "
893                         false true umask group all world everybody
894                         " "" "${cur##--shared=}"
895                 return
896                 ;;
897         --*)
898                 __gitcomp "--quiet --bare --template= --shared --shared="
899                 return
900                 ;;
901         esac
902         COMPREPLY=()
905 _git_ls_files ()
907         __git_has_doubledash && return
909         local cur="${COMP_WORDS[COMP_CWORD]}"
910         case "$cur" in
911         --*)
912                 __gitcomp "--cached --deleted --modified --others --ignored
913                         --stage --directory --no-empty-directory --unmerged
914                         --killed --exclude= --exclude-from=
915                         --exclude-per-directory= --exclude-standard
916                         --error-unmatch --with-tree= --full-name
917                         --abbrev --ignored --exclude-per-directory
918                         "
919                 return
920                 ;;
921         esac
922         COMPREPLY=()
925 _git_ls_remote ()
927         __gitcomp "$(__git_remotes)"
930 _git_ls_tree ()
932         __git_complete_file
935 _git_log ()
937         __git_has_doubledash && return
939         local cur="${COMP_WORDS[COMP_CWORD]}"
940         local g="$(git rev-parse --git-dir 2>/dev/null)"
941         local merge=""
942         if [ -f "$g/MERGE_HEAD" ]; then
943                 merge="--merge"
944         fi
945         case "$cur" in
946         --pretty=*)
947                 __gitcomp "
948                         oneline short medium full fuller email raw
949                         " "" "${cur##--pretty=}"
950                 return
951                 ;;
952         --date=*)
953                 __gitcomp "
954                         relative iso8601 rfc2822 short local default
955                 " "" "${cur##--date=}"
956                 return
957                 ;;
958         --*)
959                 __gitcomp "
960                         --max-count= --max-age= --since= --after=
961                         --min-age= --before= --until=
962                         --root --topo-order --date-order --reverse
963                         --no-merges --follow
964                         --abbrev-commit --abbrev=
965                         --relative-date --date=
966                         --author= --committer= --grep=
967                         --all-match
968                         --pretty= --name-status --name-only --raw
969                         --not --all
970                         --left-right --cherry-pick
971                         --graph
972                         --stat --numstat --shortstat
973                         --decorate --diff-filter=
974                         --color-words --walk-reflogs
975                         --parents --children --full-history
976                         $merge
977                         "
978                 return
979                 ;;
980         esac
981         __git_complete_revlist
984 _git_merge ()
986         local cur="${COMP_WORDS[COMP_CWORD]}"
987         case "${COMP_WORDS[COMP_CWORD-1]}" in
988         -s|--strategy)
989                 __gitcomp "$(__git_merge_strategies)"
990                 return
991         esac
992         case "$cur" in
993         --strategy=*)
994                 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
995                 return
996                 ;;
997         --*)
998                 __gitcomp "
999                         --no-commit --no-stat --log --no-log --squash --strategy
1000                         "
1001                 return
1002         esac
1003         __gitcomp "$(__git_refs)"
1006 _git_mergetool ()
1008         local cur="${COMP_WORDS[COMP_CWORD]}"
1009         case "$cur" in
1010         --tool=*)
1011                 __gitcomp "
1012                         kdiff3 tkdiff meld xxdiff emerge
1013                         vimdiff gvimdiff ecmerge opendiff
1014                         " "" "${cur##--tool=}"
1015                 return
1016                 ;;
1017         --*)
1018                 __gitcomp "--tool="
1019                 return
1020                 ;;
1021         esac
1022         COMPREPLY=()
1025 _git_merge_base ()
1027         __gitcomp "$(__git_refs)"
1030 _git_mv ()
1032         local cur="${COMP_WORDS[COMP_CWORD]}"
1033         case "$cur" in
1034         --*)
1035                 __gitcomp "--dry-run"
1036                 return
1037                 ;;
1038         esac
1039         COMPREPLY=()
1042 _git_name_rev ()
1044         __gitcomp "--tags --all --stdin"
1047 _git_pull ()
1049         local cur="${COMP_WORDS[COMP_CWORD]}"
1051         if [ "$COMP_CWORD" = 2 ]; then
1052                 __gitcomp "$(__git_remotes)"
1053         else
1054                 __gitcomp "$(__git_refs "${COMP_WORDS[2]}")"
1055         fi
1058 _git_push ()
1060         local cur="${COMP_WORDS[COMP_CWORD]}"
1062         if [ "$COMP_CWORD" = 2 ]; then
1063                 __gitcomp "$(__git_remotes)"
1064         else
1065                 case "$cur" in
1066                 *:*)
1067                         local pfx=""
1068                         case "$COMP_WORDBREAKS" in
1069                         *:*) : great ;;
1070                         *)   pfx="${cur%%:*}:" ;;
1071                         esac
1073                         __gitcomp "$(__git_refs "${COMP_WORDS[2]}")" "$pfx" "${cur#*:}"
1074                         ;;
1075                 +*)
1076                         __gitcomp "$(__git_refs)" + "${cur#+}"
1077                         ;;
1078                 *)
1079                         __gitcomp "$(__git_refs)"
1080                         ;;
1081                 esac
1082         fi
1085 _git_rebase ()
1087         local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
1088         if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1089                 __gitcomp "--continue --skip --abort"
1090                 return
1091         fi
1092         case "${COMP_WORDS[COMP_CWORD-1]}" in
1093         -s|--strategy)
1094                 __gitcomp "$(__git_merge_strategies)"
1095                 return
1096         esac
1097         case "$cur" in
1098         --strategy=*)
1099                 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
1100                 return
1101                 ;;
1102         --*)
1103                 __gitcomp "--onto --merge --strategy --interactive"
1104                 return
1105         esac
1106         __gitcomp "$(__git_refs)"
1109 _git_send_email ()
1111         local cur="${COMP_WORDS[COMP_CWORD]}"
1112         case "$cur" in
1113         --*)
1114                 __gitcomp "--bcc --cc --cc-cmd --chain-reply-to --compose
1115                         --dry-run --envelope-sender --from --identity
1116                         --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1117                         --no-suppress-from --no-thread --quiet
1118                         --signed-off-by-cc --smtp-pass --smtp-server
1119                         --smtp-server-port --smtp-ssl --smtp-user --subject
1120                         --suppress-cc --suppress-from --thread --to"
1121                 return
1122                 ;;
1123         esac
1124         COMPREPLY=()
1127 _git_config ()
1129         local cur="${COMP_WORDS[COMP_CWORD]}"
1130         local prv="${COMP_WORDS[COMP_CWORD-1]}"
1131         case "$prv" in
1132         branch.*.remote)
1133                 __gitcomp "$(__git_remotes)"
1134                 return
1135                 ;;
1136         branch.*.merge)
1137                 __gitcomp "$(__git_refs)"
1138                 return
1139                 ;;
1140         remote.*.fetch)
1141                 local remote="${prv#remote.}"
1142                 remote="${remote%.fetch}"
1143                 __gitcomp "$(__git_refs_remotes "$remote")"
1144                 return
1145                 ;;
1146         remote.*.push)
1147                 local remote="${prv#remote.}"
1148                 remote="${remote%.push}"
1149                 __gitcomp "$(git --git-dir="$(__gitdir)" \
1150                         for-each-ref --format='%(refname):%(refname)' \
1151                         refs/heads)"
1152                 return
1153                 ;;
1154         pull.twohead|pull.octopus)
1155                 __gitcomp "$(__git_merge_strategies)"
1156                 return
1157                 ;;
1158         color.branch|color.diff|color.status)
1159                 __gitcomp "always never auto"
1160                 return
1161                 ;;
1162         color.*.*)
1163                 __gitcomp "
1164                         black red green yellow blue magenta cyan white
1165                         bold dim ul blink reverse
1166                         "
1167                 return
1168                 ;;
1169         *.*)
1170                 COMPREPLY=()
1171                 return
1172                 ;;
1173         esac
1174         case "$cur" in
1175         --*)
1176                 __gitcomp "
1177                         --global --system --file=
1178                         --list --replace-all
1179                         --get --get-all --get-regexp
1180                         --add --unset --unset-all
1181                         --remove-section --rename-section
1182                         "
1183                 return
1184                 ;;
1185         branch.*.*)
1186                 local pfx="${cur%.*}."
1187                 cur="${cur##*.}"
1188                 __gitcomp "remote merge" "$pfx" "$cur"
1189                 return
1190                 ;;
1191         branch.*)
1192                 local pfx="${cur%.*}."
1193                 cur="${cur#*.}"
1194                 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
1195                 return
1196                 ;;
1197         remote.*.*)
1198                 local pfx="${cur%.*}."
1199                 cur="${cur##*.}"
1200                 __gitcomp "
1201                         url fetch push skipDefaultUpdate
1202                         receivepack uploadpack tagopt
1203                         " "$pfx" "$cur"
1204                 return
1205                 ;;
1206         remote.*)
1207                 local pfx="${cur%.*}."
1208                 cur="${cur#*.}"
1209                 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
1210                 return
1211                 ;;
1212         esac
1213         __gitcomp "
1214                 apply.whitespace
1215                 core.fileMode
1216                 core.gitProxy
1217                 core.ignoreStat
1218                 core.preferSymlinkRefs
1219                 core.logAllRefUpdates
1220                 core.loosecompression
1221                 core.repositoryFormatVersion
1222                 core.sharedRepository
1223                 core.warnAmbiguousRefs
1224                 core.compression
1225                 core.packedGitWindowSize
1226                 core.packedGitLimit
1227                 clean.requireForce
1228                 color.branch
1229                 color.branch.current
1230                 color.branch.local
1231                 color.branch.remote
1232                 color.branch.plain
1233                 color.diff
1234                 color.diff.plain
1235                 color.diff.meta
1236                 color.diff.frag
1237                 color.diff.old
1238                 color.diff.new
1239                 color.diff.commit
1240                 color.diff.whitespace
1241                 color.pager
1242                 color.status
1243                 color.status.header
1244                 color.status.added
1245                 color.status.changed
1246                 color.status.untracked
1247                 diff.renameLimit
1248                 diff.renames
1249                 fetch.unpackLimit
1250                 format.headers
1251                 format.subjectprefix
1252                 gitcvs.enabled
1253                 gitcvs.logfile
1254                 gitcvs.allbinary
1255                 gitcvs.dbname gitcvs.dbdriver gitcvs.dbuser gitcvs.dbpass
1256                 gitcvs.dbtablenameprefix
1257                 gc.packrefs
1258                 gc.reflogexpire
1259                 gc.reflogexpireunreachable
1260                 gc.rerereresolved
1261                 gc.rerereunresolved
1262                 http.sslVerify
1263                 http.sslCert
1264                 http.sslKey
1265                 http.sslCAInfo
1266                 http.sslCAPath
1267                 http.maxRequests
1268                 http.lowSpeedLimit
1269                 http.lowSpeedTime
1270                 http.noEPSV
1271                 i18n.commitEncoding
1272                 i18n.logOutputEncoding
1273                 log.showroot
1274                 merge.tool
1275                 merge.summary
1276                 merge.verbosity
1277                 pack.window
1278                 pack.depth
1279                 pack.windowMemory
1280                 pack.compression
1281                 pack.deltaCacheSize
1282                 pack.deltaCacheLimit
1283                 pull.octopus
1284                 pull.twohead
1285                 repack.useDeltaBaseOffset
1286                 showbranch.default
1287                 tar.umask
1288                 transfer.unpackLimit
1289                 receive.unpackLimit
1290                 receive.denyNonFastForwards
1291                 user.name
1292                 user.email
1293                 user.signingkey
1294                 branch. remote.
1295         "
1298 _git_remote ()
1300         local subcommands="add rm show prune update"
1301         local subcommand="$(__git_find_subcommand "$subcommands")"
1302         if [ -z "$subcommand" ]; then
1303                 __gitcomp "$subcommands"
1304                 return
1305         fi
1307         case "$subcommand" in
1308         rm|show|prune)
1309                 __gitcomp "$(__git_remotes)"
1310                 ;;
1311         update)
1312                 local i c='' IFS=$'\n'
1313                 for i in $(git --git-dir="$(__gitdir)" config --list); do
1314                         case "$i" in
1315                         remotes.*)
1316                                 i="${i#remotes.}"
1317                                 c="$c ${i/=*/}"
1318                                 ;;
1319                         esac
1320                 done
1321                 __gitcomp "$c"
1322                 ;;
1323         *)
1324                 COMPREPLY=()
1325                 ;;
1326         esac
1329 _git_reset ()
1331         __git_has_doubledash && return
1333         local cur="${COMP_WORDS[COMP_CWORD]}"
1334         case "$cur" in
1335         --*)
1336                 __gitcomp "--mixed --hard --soft"
1337                 return
1338                 ;;
1339         esac
1340         __gitcomp "$(__git_refs)"
1343 _git_revert ()
1345         local cur="${COMP_WORDS[COMP_CWORD]}"
1346         case "$cur" in
1347         --*)
1348                 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
1349                 return
1350                 ;;
1351         esac
1352         __gitcomp "$(__git_refs)"
1355 _git_rm ()
1357         __git_has_doubledash && return
1359         local cur="${COMP_WORDS[COMP_CWORD]}"
1360         case "$cur" in
1361         --*)
1362                 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
1363                 return
1364                 ;;
1365         esac
1366         COMPREPLY=()
1369 _git_shortlog ()
1371         __git_has_doubledash && return
1373         local cur="${COMP_WORDS[COMP_CWORD]}"
1374         case "$cur" in
1375         --*)
1376                 __gitcomp "
1377                         --max-count= --max-age= --since= --after=
1378                         --min-age= --before= --until=
1379                         --no-merges
1380                         --author= --committer= --grep=
1381                         --all-match
1382                         --not --all
1383                         --numbered --summary
1384                         "
1385                 return
1386                 ;;
1387         esac
1388         __git_complete_revlist
1391 _git_show ()
1393         __git_has_doubledash && return
1395         local cur="${COMP_WORDS[COMP_CWORD]}"
1396         case "$cur" in
1397         --pretty=*)
1398                 __gitcomp "
1399                         oneline short medium full fuller email raw
1400                         " "" "${cur##--pretty=}"
1401                 return
1402                 ;;
1403         --*)
1404                 __gitcomp "--pretty="
1405                 return
1406                 ;;
1407         esac
1408         __git_complete_file
1411 _git_show_branch ()
1413         local cur="${COMP_WORDS[COMP_CWORD]}"
1414         case "$cur" in
1415         --*)
1416                 __gitcomp "
1417                         --all --remotes --topo-order --current --more=
1418                         --list --independent --merge-base --no-name
1419                         --sha1-name --topics --reflog
1420                         "
1421                 return
1422                 ;;
1423         esac
1424         __git_complete_revlist
1427 _git_stash ()
1429         local subcommands='save list show apply clear drop pop create branch'
1430         local subcommand="$(__git_find_subcommand "$subcommands")"
1431         if [ -z "$subcommand" ]; then
1432                 __gitcomp "$subcommands"
1433         else
1434                 local cur="${COMP_WORDS[COMP_CWORD]}"
1435                 case "$subcommand,$cur" in
1436                 save,--*)
1437                         __gitcomp "--keep-index"
1438                         ;;
1439                 apply,--*)
1440                         __gitcomp "--index"
1441                         ;;
1442                 show,--*|drop,--*|pop,--*|branch,--*)
1443                         COMPREPLY=()
1444                         ;;
1445                 show,*|apply,*|drop,*|pop,*|branch,*)
1446                         __gitcomp "$(git --git-dir="$(__gitdir)" stash list \
1447                                         | sed -n -e 's/:.*//p')"
1448                         ;;
1449                 *)
1450                         COMPREPLY=()
1451                         ;;
1452                 esac
1453         fi
1456 _git_submodule ()
1458         __git_has_doubledash && return
1460         local subcommands="add status init update"
1461         if [ -z "$(__git_find_subcommand "$subcommands")" ]; then
1462                 local cur="${COMP_WORDS[COMP_CWORD]}"
1463                 case "$cur" in
1464                 --*)
1465                         __gitcomp "--quiet --cached"
1466                         ;;
1467                 *)
1468                         __gitcomp "$subcommands"
1469                         ;;
1470                 esac
1471                 return
1472         fi
1475 _git_svn ()
1477         local subcommands="
1478                 init fetch clone rebase dcommit log find-rev
1479                 set-tree commit-diff info create-ignore propget
1480                 proplist show-ignore show-externals
1481                 "
1482         local subcommand="$(__git_find_subcommand "$subcommands")"
1483         if [ -z "$subcommand" ]; then
1484                 __gitcomp "$subcommands"
1485         else
1486                 local remote_opts="--username= --config-dir= --no-auth-cache"
1487                 local fc_opts="
1488                         --follow-parent --authors-file= --repack=
1489                         --no-metadata --use-svm-props --use-svnsync-props
1490                         --log-window-size= --no-checkout --quiet
1491                         --repack-flags --user-log-author $remote_opts
1492                         "
1493                 local init_opts="
1494                         --template= --shared= --trunk= --tags=
1495                         --branches= --stdlayout --minimize-url
1496                         --no-metadata --use-svm-props --use-svnsync-props
1497                         --rewrite-root= $remote_opts
1498                         "
1499                 local cmt_opts="
1500                         --edit --rmdir --find-copies-harder --copy-similarity=
1501                         "
1503                 local cur="${COMP_WORDS[COMP_CWORD]}"
1504                 case "$subcommand,$cur" in
1505                 fetch,--*)
1506                         __gitcomp "--revision= --fetch-all $fc_opts"
1507                         ;;
1508                 clone,--*)
1509                         __gitcomp "--revision= $fc_opts $init_opts"
1510                         ;;
1511                 init,--*)
1512                         __gitcomp "$init_opts"
1513                         ;;
1514                 dcommit,--*)
1515                         __gitcomp "
1516                                 --merge --strategy= --verbose --dry-run
1517                                 --fetch-all --no-rebase $cmt_opts $fc_opts
1518                                 "
1519                         ;;
1520                 set-tree,--*)
1521                         __gitcomp "--stdin $cmt_opts $fc_opts"
1522                         ;;
1523                 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
1524                 show-externals,--*)
1525                         __gitcomp "--revision="
1526                         ;;
1527                 log,--*)
1528                         __gitcomp "
1529                                 --limit= --revision= --verbose --incremental
1530                                 --oneline --show-commit --non-recursive
1531                                 --authors-file=
1532                                 "
1533                         ;;
1534                 rebase,--*)
1535                         __gitcomp "
1536                                 --merge --verbose --strategy= --local
1537                                 --fetch-all $fc_opts
1538                                 "
1539                         ;;
1540                 commit-diff,--*)
1541                         __gitcomp "--message= --file= --revision= $cmt_opts"
1542                         ;;
1543                 info,--*)
1544                         __gitcomp "--url"
1545                         ;;
1546                 *)
1547                         COMPREPLY=()
1548                         ;;
1549                 esac
1550         fi
1553 _git_tag ()
1555         local i c=1 f=0
1556         while [ $c -lt $COMP_CWORD ]; do
1557                 i="${COMP_WORDS[c]}"
1558                 case "$i" in
1559                 -d|-v)
1560                         __gitcomp "$(__git_tags)"
1561                         return
1562                         ;;
1563                 -f)
1564                         f=1
1565                         ;;
1566                 esac
1567                 c=$((++c))
1568         done
1570         case "${COMP_WORDS[COMP_CWORD-1]}" in
1571         -m|-F)
1572                 COMPREPLY=()
1573                 ;;
1574         -*|tag)
1575                 if [ $f = 1 ]; then
1576                         __gitcomp "$(__git_tags)"
1577                 else
1578                         COMPREPLY=()
1579                 fi
1580                 ;;
1581         *)
1582                 __gitcomp "$(__git_refs)"
1583                 ;;
1584         esac
1587 _git ()
1589         local i c=1 command __git_dir
1591         while [ $c -lt $COMP_CWORD ]; do
1592                 i="${COMP_WORDS[c]}"
1593                 case "$i" in
1594                 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
1595                 --bare)      __git_dir="." ;;
1596                 --version|-p|--paginate) ;;
1597                 --help) command="help"; break ;;
1598                 *) command="$i"; break ;;
1599                 esac
1600                 c=$((++c))
1601         done
1603         if [ -z "$command" ]; then
1604                 case "${COMP_WORDS[COMP_CWORD]}" in
1605                 --*=*) COMPREPLY=() ;;
1606                 --*)   __gitcomp "
1607                         --paginate
1608                         --no-pager
1609                         --git-dir=
1610                         --bare
1611                         --version
1612                         --exec-path
1613                         --work-tree=
1614                         --help
1615                         "
1616                         ;;
1617                 *)     __gitcomp "$(__git_porcelain_commands) $(__git_aliases)" ;;
1618                 esac
1619                 return
1620         fi
1622         local expansion=$(__git_aliased_command "$command")
1623         [ "$expansion" ] && command="$expansion"
1625         case "$command" in
1626         am)          _git_am ;;
1627         add)         _git_add ;;
1628         apply)       _git_apply ;;
1629         archive)     _git_archive ;;
1630         bisect)      _git_bisect ;;
1631         bundle)      _git_bundle ;;
1632         branch)      _git_branch ;;
1633         checkout)    _git_checkout ;;
1634         cherry)      _git_cherry ;;
1635         cherry-pick) _git_cherry_pick ;;
1636         clean)       _git_clean ;;
1637         clone)       _git_clone ;;
1638         commit)      _git_commit ;;
1639         config)      _git_config ;;
1640         describe)    _git_describe ;;
1641         diff)        _git_diff ;;
1642         fetch)       _git_fetch ;;
1643         format-patch) _git_format_patch ;;
1644         gc)          _git_gc ;;
1645         grep)        _git_grep ;;
1646         help)        _git_help ;;
1647         init)        _git_init ;;
1648         log)         _git_log ;;
1649         ls-files)    _git_ls_files ;;
1650         ls-remote)   _git_ls_remote ;;
1651         ls-tree)     _git_ls_tree ;;
1652         merge)       _git_merge;;
1653         mergetool)   _git_mergetool;;
1654         merge-base)  _git_merge_base ;;
1655         mv)          _git_mv ;;
1656         name-rev)    _git_name_rev ;;
1657         pull)        _git_pull ;;
1658         push)        _git_push ;;
1659         rebase)      _git_rebase ;;
1660         remote)      _git_remote ;;
1661         reset)       _git_reset ;;
1662         revert)      _git_revert ;;
1663         rm)          _git_rm ;;
1664         send-email)  _git_send_email ;;
1665         shortlog)    _git_shortlog ;;
1666         show)        _git_show ;;
1667         show-branch) _git_show_branch ;;
1668         stash)       _git_stash ;;
1669         submodule)   _git_submodule ;;
1670         svn)         _git_svn ;;
1671         tag)         _git_tag ;;
1672         whatchanged) _git_log ;;
1673         *)           COMPREPLY=() ;;
1674         esac
1677 _gitk ()
1679         __git_has_doubledash && return
1681         local cur="${COMP_WORDS[COMP_CWORD]}"
1682         local g="$(git rev-parse --git-dir 2>/dev/null)"
1683         local merge=""
1684         if [ -f "$g/MERGE_HEAD" ]; then
1685                 merge="--merge"
1686         fi
1687         case "$cur" in
1688         --*)
1689                 __gitcomp "--not --all $merge"
1690                 return
1691                 ;;
1692         esac
1693         __git_complete_revlist
1696 complete -o default -o nospace -F _git git
1697 complete -o default -o nospace -F _gitk gitk
1699 # The following are necessary only for Cygwin, and only are needed
1700 # when the user has tab-completed the executable name and consequently
1701 # included the '.exe' suffix.
1703 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
1704 complete -o default -o nospace -F _git git.exe
1705 fi