bash: support pretty format aliases
[git/git-svn.git] / contrib / completion / git-completion.bash
blob9a6317de69c242ea29271be36a4e3f9878493271
1 #!bash
3 # bash completion support for core Git.
5 # Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
6 # Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
7 # Distributed under the GNU General Public License, version 2.0.
9 # The contained completion routines provide support for completing:
11 # *) local and remote branch names
12 # *) local and remote tag names
13 # *) .git/remotes file names
14 # *) git 'subcommands'
15 # *) tree paths within 'ref:path/to/file' expressions
16 # *) common --long-options
18 # To use these routines:
20 # 1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
21 # 2) Added the following line to your .bashrc:
22 # source ~/.git-completion.sh
24 # 3) Consider changing your PS1 to also show the current branch:
25 # PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
27 # The argument to __git_ps1 will be displayed only if you
28 # are currently in a git repository. The %s token will be
29 # the name of the current branch.
31 # In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty
32 # value, unstaged (*) and staged (+) changes will be shown next
33 # to the branch name. You can configure this per-repository
34 # with the bash.showDirtyState variable, which defaults to true
35 # once GIT_PS1_SHOWDIRTYSTATE is enabled.
37 # You can also see if currently something is stashed, by setting
38 # GIT_PS1_SHOWSTASHSTATE to a nonempty value. If something is stashed,
39 # then a '$' will be shown next to the branch name.
41 # If you would like to see if there're untracked files, then you can
42 # set GIT_PS1_SHOWUNTRACKEDFILES to a nonempty value. If there're
43 # untracked files, then a '%' will be shown next to the branch name.
45 # If you would like to see the difference between HEAD and its
46 # upstream, set GIT_PS1_SHOWUPSTREAM="auto". A "<" indicates
47 # you are behind, ">" indicates you are ahead, and "<>"
48 # indicates you have diverged. You can further control
49 # behaviour by setting GIT_PS1_SHOWUPSTREAM to a space-separated
50 # list of values:
51 # verbose show number of commits ahead/behind (+/-) upstream
52 # legacy don't use the '--count' option available in recent
53 # versions of git-rev-list
54 # git always compare HEAD to @{upstream}
55 # svn always compare HEAD to your SVN upstream
56 # By default, __git_ps1 will compare HEAD to your SVN upstream
57 # if it can find one, or @{upstream} otherwise. Once you have
58 # set GIT_PS1_SHOWUPSTREAM, you can override it on a
59 # per-repository basis by setting the bash.showUpstream config
60 # variable.
63 # To submit patches:
65 # *) Read Documentation/SubmittingPatches
66 # *) Send all patches to the current maintainer:
68 # "Shawn O. Pearce" <spearce@spearce.org>
70 # *) Always CC the Git mailing list:
72 # git@vger.kernel.org
75 case "$COMP_WORDBREAKS" in
76 *:*) : great ;;
77 *) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
78 esac
80 # __gitdir accepts 0 or 1 arguments (i.e., location)
81 # returns location of .git repo
82 __gitdir ()
84 if [ -z "${1-}" ]; then
85 if [ -n "${__git_dir-}" ]; then
86 echo "$__git_dir"
87 elif [ -d .git ]; then
88 echo .git
89 else
90 git rev-parse --git-dir 2>/dev/null
92 elif [ -d "$1/.git" ]; then
93 echo "$1/.git"
94 else
95 echo "$1"
99 # stores the divergence from upstream in $p
100 # used by GIT_PS1_SHOWUPSTREAM
101 __git_ps1_show_upstream ()
103 local key value
104 local svn_remote=() svn_url_pattern count n
105 local upstream=git legacy="" verbose=""
107 # get some config options from git-config
108 while read key value; do
109 case "$key" in
110 bash.showupstream)
111 GIT_PS1_SHOWUPSTREAM="$value"
112 if [[ -z "${GIT_PS1_SHOWUPSTREAM}" ]]; then
113 p=""
114 return
117 svn-remote.*.url)
118 svn_remote[ $((${#svn_remote[@]} + 1)) ]="$value"
119 svn_url_pattern+="\\|$value"
120 upstream=svn+git # default upstream is SVN if available, else git
122 esac
123 done < <(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n ')
125 # parse configuration values
126 for option in ${GIT_PS1_SHOWUPSTREAM}; do
127 case "$option" in
128 git|svn) upstream="$option" ;;
129 verbose) verbose=1 ;;
130 legacy) legacy=1 ;;
131 esac
132 done
134 # Find our upstream
135 case "$upstream" in
136 git) upstream="@{upstream}" ;;
137 svn*)
138 # get the upstream from the "git-svn-id: ..." in a commit message
139 # (git-svn uses essentially the same procedure internally)
140 local svn_upstream=($(git log --first-parent -1 \
141 --grep="^git-svn-id: \(${svn_url_pattern:2}\)" 2>/dev/null))
142 if [[ 0 -ne ${#svn_upstream[@]} ]]; then
143 svn_upstream=${svn_upstream[ ${#svn_upstream[@]} - 2 ]}
144 svn_upstream=${svn_upstream%@*}
145 for ((n=1; "$n" <= "${#svn_remote[@]}"; ++n)); do
146 svn_upstream=${svn_upstream#${svn_remote[$n]}}
147 done
149 if [[ -z "$svn_upstream" ]]; then
150 # default branch name for checkouts with no layout:
151 upstream=${GIT_SVN_ID:-git-svn}
152 else
153 upstream=${svn_upstream#/}
155 elif [[ "svn+git" = "$upstream" ]]; then
156 upstream="@{upstream}"
159 esac
161 # Find how many commits we are ahead/behind our upstream
162 if [[ -z "$legacy" ]]; then
163 count="$(git rev-list --count --left-right \
164 "$upstream"...HEAD 2>/dev/null)"
165 else
166 # produce equivalent output to --count for older versions of git
167 local commits
168 if commits="$(git rev-list --left-right "$upstream"...HEAD 2>/dev/null)"
169 then
170 local commit behind=0 ahead=0
171 for commit in $commits
173 case "$commit" in
174 "<"*) let ++behind
176 *) let ++ahead
178 esac
179 done
180 count="$behind $ahead"
181 else
182 count=""
186 # calculate the result
187 if [[ -z "$verbose" ]]; then
188 case "$count" in
189 "") # no upstream
190 p="" ;;
191 "0 0") # equal to upstream
192 p="=" ;;
193 "0 "*) # ahead of upstream
194 p=">" ;;
195 *" 0") # behind upstream
196 p="<" ;;
197 *) # diverged from upstream
198 p="<>" ;;
199 esac
200 else
201 case "$count" in
202 "") # no upstream
203 p="" ;;
204 "0 0") # equal to upstream
205 p=" u=" ;;
206 "0 "*) # ahead of upstream
207 p=" u+${count#0 }" ;;
208 *" 0") # behind upstream
209 p=" u-${count% 0}" ;;
210 *) # diverged from upstream
211 p=" u+${count#* }-${count% *}" ;;
212 esac
218 # __git_ps1 accepts 0 or 1 arguments (i.e., format string)
219 # returns text to add to bash PS1 prompt (includes branch name)
220 __git_ps1 ()
222 local g="$(__gitdir)"
223 if [ -n "$g" ]; then
224 local r=""
225 local b=""
226 if [ -f "$g/rebase-merge/interactive" ]; then
227 r="|REBASE-i"
228 b="$(cat "$g/rebase-merge/head-name")"
229 elif [ -d "$g/rebase-merge" ]; then
230 r="|REBASE-m"
231 b="$(cat "$g/rebase-merge/head-name")"
232 else
233 if [ -d "$g/rebase-apply" ]; then
234 if [ -f "$g/rebase-apply/rebasing" ]; then
235 r="|REBASE"
236 elif [ -f "$g/rebase-apply/applying" ]; then
237 r="|AM"
238 else
239 r="|AM/REBASE"
241 elif [ -f "$g/MERGE_HEAD" ]; then
242 r="|MERGING"
243 elif [ -f "$g/BISECT_LOG" ]; then
244 r="|BISECTING"
247 b="$(git symbolic-ref HEAD 2>/dev/null)" || {
249 b="$(
250 case "${GIT_PS1_DESCRIBE_STYLE-}" in
251 (contains)
252 git describe --contains HEAD ;;
253 (branch)
254 git describe --contains --all HEAD ;;
255 (describe)
256 git describe HEAD ;;
257 (* | default)
258 git describe --exact-match HEAD ;;
259 esac 2>/dev/null)" ||
261 b="$(cut -c1-7 "$g/HEAD" 2>/dev/null)..." ||
262 b="unknown"
263 b="($b)"
267 local w=""
268 local i=""
269 local s=""
270 local u=""
271 local c=""
272 local p=""
274 if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then
275 if [ "true" = "$(git rev-parse --is-bare-repository 2>/dev/null)" ]; then
276 c="BARE:"
277 else
278 b="GIT_DIR!"
280 elif [ "true" = "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then
281 if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ]; then
282 if [ "$(git config --bool bash.showDirtyState)" != "false" ]; then
283 git diff --no-ext-diff --quiet --exit-code || w="*"
284 if git rev-parse --quiet --verify HEAD >/dev/null; then
285 git diff-index --cached --quiet HEAD -- || i="+"
286 else
287 i="#"
291 if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ]; then
292 git rev-parse --verify refs/stash >/dev/null 2>&1 && s="$"
295 if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ]; then
296 if [ -n "$(git ls-files --others --exclude-standard)" ]; then
297 u="%"
301 if [ -n "${GIT_PS1_SHOWUPSTREAM-}" ]; then
302 __git_ps1_show_upstream
306 local f="$w$i$s$u"
307 printf "${1:- (%s)}" "$c${b##refs/heads/}${f:+ $f}$r$p"
311 # __gitcomp_1 requires 2 arguments
312 __gitcomp_1 ()
314 local c IFS=' '$'\t'$'\n'
315 for c in $1; do
316 case "$c$2" in
317 --*=*) printf %s$'\n' "$c$2" ;;
318 *.) printf %s$'\n' "$c$2" ;;
319 *) printf %s$'\n' "$c$2 " ;;
320 esac
321 done
324 # __gitcomp accepts 1, 2, 3, or 4 arguments
325 # generates completion reply with compgen
326 __gitcomp ()
328 local cur="${COMP_WORDS[COMP_CWORD]}"
329 if [ $# -gt 2 ]; then
330 cur="$3"
332 case "$cur" in
333 --*=)
334 COMPREPLY=()
337 local IFS=$'\n'
338 COMPREPLY=($(compgen -P "${2-}" \
339 -W "$(__gitcomp_1 "${1-}" "${4-}")" \
340 -- "$cur"))
342 esac
345 # __git_heads accepts 0 or 1 arguments (to pass to __gitdir)
346 __git_heads ()
348 local cmd i is_hash=y dir="$(__gitdir "${1-}")"
349 if [ -d "$dir" ]; then
350 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
351 refs/heads
352 return
354 for i in $(git ls-remote "${1-}" 2>/dev/null); do
355 case "$is_hash,$i" in
356 y,*) is_hash=n ;;
357 n,*^{}) is_hash=y ;;
358 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
359 n,*) is_hash=y; echo "$i" ;;
360 esac
361 done
364 # __git_tags accepts 0 or 1 arguments (to pass to __gitdir)
365 __git_tags ()
367 local cmd i is_hash=y dir="$(__gitdir "${1-}")"
368 if [ -d "$dir" ]; then
369 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
370 refs/tags
371 return
373 for i in $(git ls-remote "${1-}" 2>/dev/null); do
374 case "$is_hash,$i" in
375 y,*) is_hash=n ;;
376 n,*^{}) is_hash=y ;;
377 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
378 n,*) is_hash=y; echo "$i" ;;
379 esac
380 done
383 # __git_refs accepts 0 or 1 arguments (to pass to __gitdir)
384 __git_refs ()
386 local i is_hash=y dir="$(__gitdir "${1-}")"
387 local cur="${COMP_WORDS[COMP_CWORD]}" format refs
388 if [ -d "$dir" ]; then
389 case "$cur" in
390 refs|refs/*)
391 format="refname"
392 refs="${cur%/*}"
395 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
396 if [ -e "$dir/$i" ]; then echo $i; fi
397 done
398 format="refname:short"
399 refs="refs/tags refs/heads refs/remotes"
401 esac
402 git --git-dir="$dir" for-each-ref --format="%($format)" \
403 $refs
404 return
406 for i in $(git ls-remote "$dir" 2>/dev/null); do
407 case "$is_hash,$i" in
408 y,*) is_hash=n ;;
409 n,*^{}) is_hash=y ;;
410 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
411 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
412 n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
413 n,*) is_hash=y; echo "$i" ;;
414 esac
415 done
418 # __git_refs2 requires 1 argument (to pass to __git_refs)
419 __git_refs2 ()
421 local i
422 for i in $(__git_refs "$1"); do
423 echo "$i:$i"
424 done
427 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
428 __git_refs_remotes ()
430 local cmd i is_hash=y
431 for i in $(git ls-remote "$1" 2>/dev/null); do
432 case "$is_hash,$i" in
433 n,refs/heads/*)
434 is_hash=y
435 echo "$i:refs/remotes/$1/${i#refs/heads/}"
437 y,*) is_hash=n ;;
438 n,*^{}) is_hash=y ;;
439 n,refs/tags/*) is_hash=y;;
440 n,*) is_hash=y; ;;
441 esac
442 done
445 __git_remotes ()
447 local i ngoff IFS=$'\n' d="$(__gitdir)"
448 shopt -q nullglob || ngoff=1
449 shopt -s nullglob
450 for i in "$d/remotes"/*; do
451 echo ${i#$d/remotes/}
452 done
453 [ "$ngoff" ] && shopt -u nullglob
454 for i in $(git --git-dir="$d" config --get-regexp 'remote\..*\.url' 2>/dev/null); do
455 i="${i#remote.}"
456 echo "${i/.url*/}"
457 done
460 __git_list_merge_strategies ()
462 git merge -s help 2>&1 |
463 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
464 s/\.$//
465 s/.*://
466 s/^[ ]*//
467 s/[ ]*$//
472 __git_merge_strategies=
473 # 'git merge -s help' (and thus detection of the merge strategy
474 # list) fails, unfortunately, if run outside of any git working
475 # tree. __git_merge_strategies is set to the empty string in
476 # that case, and the detection will be repeated the next time it
477 # is needed.
478 __git_compute_merge_strategies ()
480 : ${__git_merge_strategies:=$(__git_list_merge_strategies)}
483 __git_complete_file ()
485 local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
486 case "$cur" in
487 ?*:*)
488 ref="${cur%%:*}"
489 cur="${cur#*:}"
490 case "$cur" in
491 ?*/*)
492 pfx="${cur%/*}"
493 cur="${cur##*/}"
494 ls="$ref:$pfx"
495 pfx="$pfx/"
498 ls="$ref"
500 esac
502 case "$COMP_WORDBREAKS" in
503 *:*) : great ;;
504 *) pfx="$ref:$pfx" ;;
505 esac
507 local IFS=$'\n'
508 COMPREPLY=($(compgen -P "$pfx" \
509 -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
510 | sed '/^100... blob /{
511 s,^.* ,,
512 s,$, ,
514 /^120000 blob /{
515 s,^.* ,,
516 s,$, ,
518 /^040000 tree /{
519 s,^.* ,,
520 s,$,/,
522 s/^.* //')" \
523 -- "$cur"))
526 __gitcomp "$(__git_refs)"
528 esac
531 __git_complete_revlist ()
533 local pfx cur="${COMP_WORDS[COMP_CWORD]}"
534 case "$cur" in
535 *...*)
536 pfx="${cur%...*}..."
537 cur="${cur#*...}"
538 __gitcomp "$(__git_refs)" "$pfx" "$cur"
540 *..*)
541 pfx="${cur%..*}.."
542 cur="${cur#*..}"
543 __gitcomp "$(__git_refs)" "$pfx" "$cur"
546 __gitcomp "$(__git_refs)"
548 esac
551 __git_complete_remote_or_refspec ()
553 local cmd="${COMP_WORDS[1]}"
554 local cur="${COMP_WORDS[COMP_CWORD]}"
555 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
556 while [ $c -lt $COMP_CWORD ]; do
557 i="${COMP_WORDS[c]}"
558 case "$i" in
559 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
560 --all)
561 case "$cmd" in
562 push) no_complete_refspec=1 ;;
563 fetch)
564 COMPREPLY=()
565 return
567 *) ;;
568 esac
570 -*) ;;
571 *) remote="$i"; break ;;
572 esac
573 c=$((++c))
574 done
575 if [ -z "$remote" ]; then
576 __gitcomp "$(__git_remotes)"
577 return
579 if [ $no_complete_refspec = 1 ]; then
580 COMPREPLY=()
581 return
583 [ "$remote" = "." ] && remote=
584 case "$cur" in
585 *:*)
586 case "$COMP_WORDBREAKS" in
587 *:*) : great ;;
588 *) pfx="${cur%%:*}:" ;;
589 esac
590 cur="${cur#*:}"
591 lhs=0
594 pfx="+"
595 cur="${cur#+}"
597 esac
598 case "$cmd" in
599 fetch)
600 if [ $lhs = 1 ]; then
601 __gitcomp "$(__git_refs2 "$remote")" "$pfx" "$cur"
602 else
603 __gitcomp "$(__git_refs)" "$pfx" "$cur"
606 pull)
607 if [ $lhs = 1 ]; then
608 __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
609 else
610 __gitcomp "$(__git_refs)" "$pfx" "$cur"
613 push)
614 if [ $lhs = 1 ]; then
615 __gitcomp "$(__git_refs)" "$pfx" "$cur"
616 else
617 __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
620 esac
623 __git_complete_strategy ()
625 __git_compute_merge_strategies
626 case "${COMP_WORDS[COMP_CWORD-1]}" in
627 -s|--strategy)
628 __gitcomp "$__git_merge_strategies"
629 return 0
630 esac
631 local cur="${COMP_WORDS[COMP_CWORD]}"
632 case "$cur" in
633 --strategy=*)
634 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
635 return 0
637 esac
638 return 1
641 __git_list_all_commands ()
643 local i IFS=" "$'\n'
644 for i in $(git help -a|egrep '^ [a-zA-Z0-9]')
646 case $i in
647 *--*) : helper pattern;;
648 *) echo $i;;
649 esac
650 done
653 __git_all_commands=
654 __git_compute_all_commands ()
656 : ${__git_all_commands:=$(__git_list_all_commands)}
659 __git_list_porcelain_commands ()
661 local i IFS=" "$'\n'
662 __git_compute_all_commands
663 for i in "help" $__git_all_commands
665 case $i in
666 *--*) : helper pattern;;
667 applymbox) : ask gittus;;
668 applypatch) : ask gittus;;
669 archimport) : import;;
670 cat-file) : plumbing;;
671 check-attr) : plumbing;;
672 check-ref-format) : plumbing;;
673 checkout-index) : plumbing;;
674 commit-tree) : plumbing;;
675 count-objects) : infrequent;;
676 cvsexportcommit) : export;;
677 cvsimport) : import;;
678 cvsserver) : daemon;;
679 daemon) : daemon;;
680 diff-files) : plumbing;;
681 diff-index) : plumbing;;
682 diff-tree) : plumbing;;
683 fast-import) : import;;
684 fast-export) : export;;
685 fsck-objects) : plumbing;;
686 fetch-pack) : plumbing;;
687 fmt-merge-msg) : plumbing;;
688 for-each-ref) : plumbing;;
689 hash-object) : plumbing;;
690 http-*) : transport;;
691 index-pack) : plumbing;;
692 init-db) : deprecated;;
693 local-fetch) : plumbing;;
694 lost-found) : infrequent;;
695 ls-files) : plumbing;;
696 ls-remote) : plumbing;;
697 ls-tree) : plumbing;;
698 mailinfo) : plumbing;;
699 mailsplit) : plumbing;;
700 merge-*) : plumbing;;
701 mktree) : plumbing;;
702 mktag) : plumbing;;
703 pack-objects) : plumbing;;
704 pack-redundant) : plumbing;;
705 pack-refs) : plumbing;;
706 parse-remote) : plumbing;;
707 patch-id) : plumbing;;
708 peek-remote) : plumbing;;
709 prune) : plumbing;;
710 prune-packed) : plumbing;;
711 quiltimport) : import;;
712 read-tree) : plumbing;;
713 receive-pack) : plumbing;;
714 reflog) : plumbing;;
715 remote-*) : transport;;
716 repo-config) : deprecated;;
717 rerere) : plumbing;;
718 rev-list) : plumbing;;
719 rev-parse) : plumbing;;
720 runstatus) : plumbing;;
721 sh-setup) : internal;;
722 shell) : daemon;;
723 show-ref) : plumbing;;
724 send-pack) : plumbing;;
725 show-index) : plumbing;;
726 ssh-*) : transport;;
727 stripspace) : plumbing;;
728 symbolic-ref) : plumbing;;
729 tar-tree) : deprecated;;
730 unpack-file) : plumbing;;
731 unpack-objects) : plumbing;;
732 update-index) : plumbing;;
733 update-ref) : plumbing;;
734 update-server-info) : daemon;;
735 upload-archive) : plumbing;;
736 upload-pack) : plumbing;;
737 write-tree) : plumbing;;
738 var) : infrequent;;
739 verify-pack) : infrequent;;
740 verify-tag) : plumbing;;
741 *) echo $i;;
742 esac
743 done
746 __git_porcelain_commands=
747 __git_compute_porcelain_commands ()
749 __git_compute_all_commands
750 : ${__git_porcelain_commands:=$(__git_list_porcelain_commands)}
753 __git_pretty_aliases ()
755 local i IFS=$'\n'
756 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "pretty\..*" 2>/dev/null); do
757 case "$i" in
758 pretty.*)
759 i="${i#pretty.}"
760 echo "${i/ */}"
762 esac
763 done
766 __git_aliases ()
768 local i IFS=$'\n'
769 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do
770 case "$i" in
771 alias.*)
772 i="${i#alias.}"
773 echo "${i/ */}"
775 esac
776 done
779 # __git_aliased_command requires 1 argument
780 __git_aliased_command ()
782 local word cmdline=$(git --git-dir="$(__gitdir)" \
783 config --get "alias.$1")
784 for word in $cmdline; do
785 case "$word" in
786 \!gitk|gitk)
787 echo "gitk"
788 return
790 \!*) : shell command alias ;;
791 -*) : option ;;
792 *=*) : setting env ;;
793 git) : git itself ;;
795 echo "$word"
796 return
797 esac
798 done
801 # __git_find_on_cmdline requires 1 argument
802 __git_find_on_cmdline ()
804 local word subcommand c=1
806 while [ $c -lt $COMP_CWORD ]; do
807 word="${COMP_WORDS[c]}"
808 for subcommand in $1; do
809 if [ "$subcommand" = "$word" ]; then
810 echo "$subcommand"
811 return
813 done
814 c=$((++c))
815 done
818 __git_has_doubledash ()
820 local c=1
821 while [ $c -lt $COMP_CWORD ]; do
822 if [ "--" = "${COMP_WORDS[c]}" ]; then
823 return 0
825 c=$((++c))
826 done
827 return 1
830 __git_whitespacelist="nowarn warn error error-all fix"
832 _git_am ()
834 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
835 if [ -d "$dir"/rebase-apply ]; then
836 __gitcomp "--skip --continue --resolved --abort"
837 return
839 case "$cur" in
840 --whitespace=*)
841 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
842 return
844 --*)
845 __gitcomp "
846 --3way --committer-date-is-author-date --ignore-date
847 --ignore-whitespace --ignore-space-change
848 --interactive --keep --no-utf8 --signoff --utf8
849 --whitespace= --scissors
851 return
852 esac
853 COMPREPLY=()
856 _git_apply ()
858 local cur="${COMP_WORDS[COMP_CWORD]}"
859 case "$cur" in
860 --whitespace=*)
861 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
862 return
864 --*)
865 __gitcomp "
866 --stat --numstat --summary --check --index
867 --cached --index-info --reverse --reject --unidiff-zero
868 --apply --no-add --exclude=
869 --ignore-whitespace --ignore-space-change
870 --whitespace= --inaccurate-eof --verbose
872 return
873 esac
874 COMPREPLY=()
877 _git_add ()
879 __git_has_doubledash && return
881 local cur="${COMP_WORDS[COMP_CWORD]}"
882 case "$cur" in
883 --*)
884 __gitcomp "
885 --interactive --refresh --patch --update --dry-run
886 --ignore-errors --intent-to-add
888 return
889 esac
890 COMPREPLY=()
893 _git_archive ()
895 local cur="${COMP_WORDS[COMP_CWORD]}"
896 case "$cur" in
897 --format=*)
898 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
899 return
901 --remote=*)
902 __gitcomp "$(__git_remotes)" "" "${cur##--remote=}"
903 return
905 --*)
906 __gitcomp "
907 --format= --list --verbose
908 --prefix= --remote= --exec=
910 return
912 esac
913 __git_complete_file
916 _git_bisect ()
918 __git_has_doubledash && return
920 local subcommands="start bad good skip reset visualize replay log run"
921 local subcommand="$(__git_find_on_cmdline "$subcommands")"
922 if [ -z "$subcommand" ]; then
923 if [ -f "$(__gitdir)"/BISECT_START ]; then
924 __gitcomp "$subcommands"
925 else
926 __gitcomp "replay start"
928 return
931 case "$subcommand" in
932 bad|good|reset|skip|start)
933 __gitcomp "$(__git_refs)"
936 COMPREPLY=()
938 esac
941 _git_branch ()
943 local i c=1 only_local_ref="n" has_r="n"
945 while [ $c -lt $COMP_CWORD ]; do
946 i="${COMP_WORDS[c]}"
947 case "$i" in
948 -d|-m) only_local_ref="y" ;;
949 -r) has_r="y" ;;
950 esac
951 c=$((++c))
952 done
954 case "${COMP_WORDS[COMP_CWORD]}" in
955 --*)
956 __gitcomp "
957 --color --no-color --verbose --abbrev= --no-abbrev
958 --track --no-track --contains --merged --no-merged
959 --set-upstream
963 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
964 __gitcomp "$(__git_heads)"
965 else
966 __gitcomp "$(__git_refs)"
969 esac
972 _git_bundle ()
974 local cmd="${COMP_WORDS[2]}"
975 case "$COMP_CWORD" in
977 __gitcomp "create list-heads verify unbundle"
980 # looking for a file
983 case "$cmd" in
984 create)
985 __git_complete_revlist
987 esac
989 esac
992 _git_checkout ()
994 __git_has_doubledash && return
996 local cur="${COMP_WORDS[COMP_CWORD]}"
997 case "$cur" in
998 --conflict=*)
999 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
1001 --*)
1002 __gitcomp "
1003 --quiet --ours --theirs --track --no-track --merge
1004 --conflict= --orphan --patch
1008 __gitcomp "$(__git_refs)"
1010 esac
1013 _git_cherry ()
1015 __gitcomp "$(__git_refs)"
1018 _git_cherry_pick ()
1020 local cur="${COMP_WORDS[COMP_CWORD]}"
1021 case "$cur" in
1022 --*)
1023 __gitcomp "--edit --no-commit"
1026 __gitcomp "$(__git_refs)"
1028 esac
1031 _git_clean ()
1033 __git_has_doubledash && return
1035 local cur="${COMP_WORDS[COMP_CWORD]}"
1036 case "$cur" in
1037 --*)
1038 __gitcomp "--dry-run --quiet"
1039 return
1041 esac
1042 COMPREPLY=()
1045 _git_clone ()
1047 local cur="${COMP_WORDS[COMP_CWORD]}"
1048 case "$cur" in
1049 --*)
1050 __gitcomp "
1051 --local
1052 --no-hardlinks
1053 --shared
1054 --reference
1055 --quiet
1056 --no-checkout
1057 --bare
1058 --mirror
1059 --origin
1060 --upload-pack
1061 --template=
1062 --depth
1064 return
1066 esac
1067 COMPREPLY=()
1070 _git_commit ()
1072 __git_has_doubledash && return
1074 local cur="${COMP_WORDS[COMP_CWORD]}"
1075 case "$cur" in
1076 --cleanup=*)
1077 __gitcomp "default strip verbatim whitespace
1078 " "" "${cur##--cleanup=}"
1079 return
1081 --reuse-message=*)
1082 __gitcomp "$(__git_refs)" "" "${cur##--reuse-message=}"
1083 return
1085 --reedit-message=*)
1086 __gitcomp "$(__git_refs)" "" "${cur##--reedit-message=}"
1087 return
1089 --untracked-files=*)
1090 __gitcomp "all no normal" "" "${cur##--untracked-files=}"
1091 return
1093 --*)
1094 __gitcomp "
1095 --all --author= --signoff --verify --no-verify
1096 --edit --amend --include --only --interactive
1097 --dry-run --reuse-message= --reedit-message=
1098 --reset-author --file= --message= --template=
1099 --cleanup= --untracked-files --untracked-files=
1100 --verbose --quiet
1102 return
1103 esac
1104 COMPREPLY=()
1107 _git_describe ()
1109 local cur="${COMP_WORDS[COMP_CWORD]}"
1110 case "$cur" in
1111 --*)
1112 __gitcomp "
1113 --all --tags --contains --abbrev= --candidates=
1114 --exact-match --debug --long --match --always
1116 return
1117 esac
1118 __gitcomp "$(__git_refs)"
1121 __git_diff_common_options="--stat --numstat --shortstat --summary
1122 --patch-with-stat --name-only --name-status --color
1123 --no-color --color-words --no-renames --check
1124 --full-index --binary --abbrev --diff-filter=
1125 --find-copies-harder
1126 --text --ignore-space-at-eol --ignore-space-change
1127 --ignore-all-space --exit-code --quiet --ext-diff
1128 --no-ext-diff
1129 --no-prefix --src-prefix= --dst-prefix=
1130 --inter-hunk-context=
1131 --patience
1132 --raw
1133 --dirstat --dirstat= --dirstat-by-file
1134 --dirstat-by-file= --cumulative
1137 _git_diff ()
1139 __git_has_doubledash && return
1141 local cur="${COMP_WORDS[COMP_CWORD]}"
1142 case "$cur" in
1143 --*)
1144 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1145 --base --ours --theirs --no-index
1146 $__git_diff_common_options
1148 return
1150 esac
1151 __git_complete_file
1154 __git_mergetools_common="diffuse ecmerge emerge kdiff3 meld opendiff
1155 tkdiff vimdiff gvimdiff xxdiff araxis p4merge
1158 _git_difftool ()
1160 __git_has_doubledash && return
1162 local cur="${COMP_WORDS[COMP_CWORD]}"
1163 case "$cur" in
1164 --tool=*)
1165 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1166 return
1168 --*)
1169 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1170 --base --ours --theirs
1171 --no-renames --diff-filter= --find-copies-harder
1172 --relative --ignore-submodules
1173 --tool="
1174 return
1176 esac
1177 __git_complete_file
1180 __git_fetch_options="
1181 --quiet --verbose --append --upload-pack --force --keep --depth=
1182 --tags --no-tags --all --prune --dry-run
1185 _git_fetch ()
1187 local cur="${COMP_WORDS[COMP_CWORD]}"
1188 case "$cur" in
1189 --*)
1190 __gitcomp "$__git_fetch_options"
1191 return
1193 esac
1194 __git_complete_remote_or_refspec
1197 _git_format_patch ()
1199 local cur="${COMP_WORDS[COMP_CWORD]}"
1200 case "$cur" in
1201 --thread=*)
1202 __gitcomp "
1203 deep shallow
1204 " "" "${cur##--thread=}"
1205 return
1207 --*)
1208 __gitcomp "
1209 --stdout --attach --no-attach --thread --thread=
1210 --output-directory
1211 --numbered --start-number
1212 --numbered-files
1213 --keep-subject
1214 --signoff --signature --no-signature
1215 --in-reply-to= --cc=
1216 --full-index --binary
1217 --not --all
1218 --cover-letter
1219 --no-prefix --src-prefix= --dst-prefix=
1220 --inline --suffix= --ignore-if-in-upstream
1221 --subject-prefix=
1223 return
1225 esac
1226 __git_complete_revlist
1229 _git_fsck ()
1231 local cur="${COMP_WORDS[COMP_CWORD]}"
1232 case "$cur" in
1233 --*)
1234 __gitcomp "
1235 --tags --root --unreachable --cache --no-reflogs --full
1236 --strict --verbose --lost-found
1238 return
1240 esac
1241 COMPREPLY=()
1244 _git_gc ()
1246 local cur="${COMP_WORDS[COMP_CWORD]}"
1247 case "$cur" in
1248 --*)
1249 __gitcomp "--prune --aggressive"
1250 return
1252 esac
1253 COMPREPLY=()
1256 _git_gitk ()
1258 _gitk
1261 _git_grep ()
1263 __git_has_doubledash && return
1265 local cur="${COMP_WORDS[COMP_CWORD]}"
1266 case "$cur" in
1267 --*)
1268 __gitcomp "
1269 --cached
1270 --text --ignore-case --word-regexp --invert-match
1271 --full-name
1272 --extended-regexp --basic-regexp --fixed-strings
1273 --files-with-matches --name-only
1274 --files-without-match
1275 --max-depth
1276 --count
1277 --and --or --not --all-match
1279 return
1281 esac
1283 __gitcomp "$(__git_refs)"
1286 _git_help ()
1288 local cur="${COMP_WORDS[COMP_CWORD]}"
1289 case "$cur" in
1290 --*)
1291 __gitcomp "--all --info --man --web"
1292 return
1294 esac
1295 __git_compute_all_commands
1296 __gitcomp "$__git_all_commands
1297 attributes cli core-tutorial cvs-migration
1298 diffcore gitk glossary hooks ignore modules
1299 repository-layout tutorial tutorial-2
1300 workflows
1304 _git_init ()
1306 local cur="${COMP_WORDS[COMP_CWORD]}"
1307 case "$cur" in
1308 --shared=*)
1309 __gitcomp "
1310 false true umask group all world everybody
1311 " "" "${cur##--shared=}"
1312 return
1314 --*)
1315 __gitcomp "--quiet --bare --template= --shared --shared="
1316 return
1318 esac
1319 COMPREPLY=()
1322 _git_ls_files ()
1324 __git_has_doubledash && return
1326 local cur="${COMP_WORDS[COMP_CWORD]}"
1327 case "$cur" in
1328 --*)
1329 __gitcomp "--cached --deleted --modified --others --ignored
1330 --stage --directory --no-empty-directory --unmerged
1331 --killed --exclude= --exclude-from=
1332 --exclude-per-directory= --exclude-standard
1333 --error-unmatch --with-tree= --full-name
1334 --abbrev --ignored --exclude-per-directory
1336 return
1338 esac
1339 COMPREPLY=()
1342 _git_ls_remote ()
1344 __gitcomp "$(__git_remotes)"
1347 _git_ls_tree ()
1349 __git_complete_file
1352 # Options that go well for log, shortlog and gitk
1353 __git_log_common_options="
1354 --not --all
1355 --branches --tags --remotes
1356 --first-parent --merges --no-merges
1357 --max-count=
1358 --max-age= --since= --after=
1359 --min-age= --until= --before=
1361 # Options that go well for log and gitk (not shortlog)
1362 __git_log_gitk_options="
1363 --dense --sparse --full-history
1364 --simplify-merges --simplify-by-decoration
1365 --left-right
1367 # Options that go well for log and shortlog (not gitk)
1368 __git_log_shortlog_options="
1369 --author= --committer= --grep=
1370 --all-match
1373 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1374 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1376 _git_log ()
1378 __git_has_doubledash && return
1380 local cur="${COMP_WORDS[COMP_CWORD]}"
1381 local g="$(git rev-parse --git-dir 2>/dev/null)"
1382 local merge=""
1383 if [ -f "$g/MERGE_HEAD" ]; then
1384 merge="--merge"
1386 case "$cur" in
1387 --pretty=*)
1388 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
1389 " "" "${cur##--pretty=}"
1390 return
1392 --format=*)
1393 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
1394 " "" "${cur##--format=}"
1395 return
1397 --date=*)
1398 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1399 return
1401 --decorate=*)
1402 __gitcomp "long short" "" "${cur##--decorate=}"
1403 return
1405 --*)
1406 __gitcomp "
1407 $__git_log_common_options
1408 $__git_log_shortlog_options
1409 $__git_log_gitk_options
1410 --root --topo-order --date-order --reverse
1411 --follow --full-diff
1412 --abbrev-commit --abbrev=
1413 --relative-date --date=
1414 --pretty= --format= --oneline
1415 --cherry-pick
1416 --graph
1417 --decorate --decorate=
1418 --walk-reflogs
1419 --parents --children
1420 $merge
1421 $__git_diff_common_options
1422 --pickaxe-all --pickaxe-regex
1424 return
1426 esac
1427 __git_complete_revlist
1430 __git_merge_options="
1431 --no-commit --no-stat --log --no-log --squash --strategy
1432 --commit --stat --no-squash --ff --no-ff --ff-only
1435 _git_merge ()
1437 __git_complete_strategy && return
1439 local cur="${COMP_WORDS[COMP_CWORD]}"
1440 case "$cur" in
1441 --*)
1442 __gitcomp "$__git_merge_options"
1443 return
1444 esac
1445 __gitcomp "$(__git_refs)"
1448 _git_mergetool ()
1450 local cur="${COMP_WORDS[COMP_CWORD]}"
1451 case "$cur" in
1452 --tool=*)
1453 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1454 return
1456 --*)
1457 __gitcomp "--tool="
1458 return
1460 esac
1461 COMPREPLY=()
1464 _git_merge_base ()
1466 __gitcomp "$(__git_refs)"
1469 _git_mv ()
1471 local cur="${COMP_WORDS[COMP_CWORD]}"
1472 case "$cur" in
1473 --*)
1474 __gitcomp "--dry-run"
1475 return
1477 esac
1478 COMPREPLY=()
1481 _git_name_rev ()
1483 __gitcomp "--tags --all --stdin"
1486 _git_notes ()
1488 local subcommands='add append copy edit list prune remove show'
1489 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1490 local cur="${COMP_WORDS[COMP_CWORD]}"
1492 case "$subcommand,$cur" in
1493 ,--*)
1494 __gitcomp '--ref'
1497 case "${COMP_WORDS[COMP_CWORD-1]}" in
1498 --ref)
1499 __gitcomp "$(__git_refs)"
1502 __gitcomp "$subcommands --ref"
1504 esac
1506 add,--reuse-message=*|append,--reuse-message=*)
1507 __gitcomp "$(__git_refs)" "" "${cur##--reuse-message=}"
1509 add,--reedit-message=*|append,--reedit-message=*)
1510 __gitcomp "$(__git_refs)" "" "${cur##--reedit-message=}"
1512 add,--*|append,--*)
1513 __gitcomp '--file= --message= --reedit-message=
1514 --reuse-message='
1516 copy,--*)
1517 __gitcomp '--stdin'
1519 prune,--*)
1520 __gitcomp '--dry-run --verbose'
1522 prune,*)
1525 case "${COMP_WORDS[COMP_CWORD-1]}" in
1526 -m|-F)
1529 __gitcomp "$(__git_refs)"
1531 esac
1533 esac
1536 _git_pull ()
1538 __git_complete_strategy && return
1540 local cur="${COMP_WORDS[COMP_CWORD]}"
1541 case "$cur" in
1542 --*)
1543 __gitcomp "
1544 --rebase --no-rebase
1545 $__git_merge_options
1546 $__git_fetch_options
1548 return
1550 esac
1551 __git_complete_remote_or_refspec
1554 _git_push ()
1556 local cur="${COMP_WORDS[COMP_CWORD]}"
1557 case "${COMP_WORDS[COMP_CWORD-1]}" in
1558 --repo)
1559 __gitcomp "$(__git_remotes)"
1560 return
1561 esac
1562 case "$cur" in
1563 --repo=*)
1564 __gitcomp "$(__git_remotes)" "" "${cur##--repo=}"
1565 return
1567 --*)
1568 __gitcomp "
1569 --all --mirror --tags --dry-run --force --verbose
1570 --receive-pack= --repo=
1572 return
1574 esac
1575 __git_complete_remote_or_refspec
1578 _git_rebase ()
1580 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
1581 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1582 __gitcomp "--continue --skip --abort"
1583 return
1585 __git_complete_strategy && return
1586 case "$cur" in
1587 --whitespace=*)
1588 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1589 return
1591 --*)
1592 __gitcomp "
1593 --onto --merge --strategy --interactive
1594 --preserve-merges --stat --no-stat
1595 --committer-date-is-author-date --ignore-date
1596 --ignore-whitespace --whitespace=
1597 --autosquash
1600 return
1601 esac
1602 __gitcomp "$(__git_refs)"
1605 __git_send_email_confirm_options="always never auto cc compose"
1606 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1608 _git_send_email ()
1610 local cur="${COMP_WORDS[COMP_CWORD]}"
1611 case "$cur" in
1612 --confirm=*)
1613 __gitcomp "
1614 $__git_send_email_confirm_options
1615 " "" "${cur##--confirm=}"
1616 return
1618 --suppress-cc=*)
1619 __gitcomp "
1620 $__git_send_email_suppresscc_options
1621 " "" "${cur##--suppress-cc=}"
1623 return
1625 --smtp-encryption=*)
1626 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1627 return
1629 --*)
1630 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1631 --compose --confirm= --dry-run --envelope-sender
1632 --from --identity
1633 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1634 --no-suppress-from --no-thread --quiet
1635 --signed-off-by-cc --smtp-pass --smtp-server
1636 --smtp-server-port --smtp-encryption= --smtp-user
1637 --subject --suppress-cc= --suppress-from --thread --to
1638 --validate --no-validate"
1639 return
1641 esac
1642 COMPREPLY=()
1645 _git_stage ()
1647 _git_add
1650 __git_config_get_set_variables ()
1652 local prevword word config_file= c=$COMP_CWORD
1653 while [ $c -gt 1 ]; do
1654 word="${COMP_WORDS[c]}"
1655 case "$word" in
1656 --global|--system|--file=*)
1657 config_file="$word"
1658 break
1660 -f|--file)
1661 config_file="$word $prevword"
1662 break
1664 esac
1665 prevword=$word
1666 c=$((--c))
1667 done
1669 git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
1670 while read line
1672 case "$line" in
1673 *.*=*)
1674 echo "${line/=*/}"
1676 esac
1677 done
1680 _git_config ()
1682 local cur="${COMP_WORDS[COMP_CWORD]}"
1683 local prv="${COMP_WORDS[COMP_CWORD-1]}"
1684 case "$prv" in
1685 branch.*.remote)
1686 __gitcomp "$(__git_remotes)"
1687 return
1689 branch.*.merge)
1690 __gitcomp "$(__git_refs)"
1691 return
1693 remote.*.fetch)
1694 local remote="${prv#remote.}"
1695 remote="${remote%.fetch}"
1696 __gitcomp "$(__git_refs_remotes "$remote")"
1697 return
1699 remote.*.push)
1700 local remote="${prv#remote.}"
1701 remote="${remote%.push}"
1702 __gitcomp "$(git --git-dir="$(__gitdir)" \
1703 for-each-ref --format='%(refname):%(refname)' \
1704 refs/heads)"
1705 return
1707 pull.twohead|pull.octopus)
1708 __git_compute_merge_strategies
1709 __gitcomp "$__git_merge_strategies"
1710 return
1712 color.branch|color.diff|color.interactive|\
1713 color.showbranch|color.status|color.ui)
1714 __gitcomp "always never auto"
1715 return
1717 color.pager)
1718 __gitcomp "false true"
1719 return
1721 color.*.*)
1722 __gitcomp "
1723 normal black red green yellow blue magenta cyan white
1724 bold dim ul blink reverse
1726 return
1728 help.format)
1729 __gitcomp "man info web html"
1730 return
1732 log.date)
1733 __gitcomp "$__git_log_date_formats"
1734 return
1736 sendemail.aliasesfiletype)
1737 __gitcomp "mutt mailrc pine elm gnus"
1738 return
1740 sendemail.confirm)
1741 __gitcomp "$__git_send_email_confirm_options"
1742 return
1744 sendemail.suppresscc)
1745 __gitcomp "$__git_send_email_suppresscc_options"
1746 return
1748 --get|--get-all|--unset|--unset-all)
1749 __gitcomp "$(__git_config_get_set_variables)"
1750 return
1752 *.*)
1753 COMPREPLY=()
1754 return
1756 esac
1757 case "$cur" in
1758 --*)
1759 __gitcomp "
1760 --global --system --file=
1761 --list --replace-all
1762 --get --get-all --get-regexp
1763 --add --unset --unset-all
1764 --remove-section --rename-section
1766 return
1768 branch.*.*)
1769 local pfx="${cur%.*}."
1770 cur="${cur##*.}"
1771 __gitcomp "remote merge mergeoptions rebase" "$pfx" "$cur"
1772 return
1774 branch.*)
1775 local pfx="${cur%.*}."
1776 cur="${cur#*.}"
1777 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
1778 return
1780 guitool.*.*)
1781 local pfx="${cur%.*}."
1782 cur="${cur##*.}"
1783 __gitcomp "
1784 argprompt cmd confirm needsfile noconsole norescan
1785 prompt revprompt revunmerged title
1786 " "$pfx" "$cur"
1787 return
1789 difftool.*.*)
1790 local pfx="${cur%.*}."
1791 cur="${cur##*.}"
1792 __gitcomp "cmd path" "$pfx" "$cur"
1793 return
1795 man.*.*)
1796 local pfx="${cur%.*}."
1797 cur="${cur##*.}"
1798 __gitcomp "cmd path" "$pfx" "$cur"
1799 return
1801 mergetool.*.*)
1802 local pfx="${cur%.*}."
1803 cur="${cur##*.}"
1804 __gitcomp "cmd path trustExitCode" "$pfx" "$cur"
1805 return
1807 pager.*)
1808 local pfx="${cur%.*}."
1809 cur="${cur#*.}"
1810 __git_compute_all_commands
1811 __gitcomp "$__git_all_commands" "$pfx" "$cur"
1812 return
1814 remote.*.*)
1815 local pfx="${cur%.*}."
1816 cur="${cur##*.}"
1817 __gitcomp "
1818 url proxy fetch push mirror skipDefaultUpdate
1819 receivepack uploadpack tagopt pushurl
1820 " "$pfx" "$cur"
1821 return
1823 remote.*)
1824 local pfx="${cur%.*}."
1825 cur="${cur#*.}"
1826 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
1827 return
1829 url.*.*)
1830 local pfx="${cur%.*}."
1831 cur="${cur##*.}"
1832 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur"
1833 return
1835 esac
1836 __gitcomp "
1837 add.ignore-errors
1838 alias.
1839 apply.ignorewhitespace
1840 apply.whitespace
1841 branch.autosetupmerge
1842 branch.autosetuprebase
1843 clean.requireForce
1844 color.branch
1845 color.branch.current
1846 color.branch.local
1847 color.branch.plain
1848 color.branch.remote
1849 color.diff
1850 color.diff.commit
1851 color.diff.frag
1852 color.diff.meta
1853 color.diff.new
1854 color.diff.old
1855 color.diff.plain
1856 color.diff.whitespace
1857 color.grep
1858 color.grep.external
1859 color.grep.match
1860 color.interactive
1861 color.interactive.header
1862 color.interactive.help
1863 color.interactive.prompt
1864 color.pager
1865 color.showbranch
1866 color.status
1867 color.status.added
1868 color.status.changed
1869 color.status.header
1870 color.status.nobranch
1871 color.status.untracked
1872 color.status.updated
1873 color.ui
1874 commit.template
1875 core.autocrlf
1876 core.bare
1877 core.compression
1878 core.createObject
1879 core.deltaBaseCacheLimit
1880 core.editor
1881 core.excludesfile
1882 core.fileMode
1883 core.fsyncobjectfiles
1884 core.gitProxy
1885 core.ignoreCygwinFSTricks
1886 core.ignoreStat
1887 core.logAllRefUpdates
1888 core.loosecompression
1889 core.packedGitLimit
1890 core.packedGitWindowSize
1891 core.pager
1892 core.preferSymlinkRefs
1893 core.preloadindex
1894 core.quotepath
1895 core.repositoryFormatVersion
1896 core.safecrlf
1897 core.sharedRepository
1898 core.symlinks
1899 core.trustctime
1900 core.warnAmbiguousRefs
1901 core.whitespace
1902 core.worktree
1903 diff.autorefreshindex
1904 diff.external
1905 diff.mnemonicprefix
1906 diff.renameLimit
1907 diff.renameLimit.
1908 diff.renames
1909 diff.suppressBlankEmpty
1910 diff.tool
1911 diff.wordRegex
1912 difftool.
1913 difftool.prompt
1914 fetch.unpackLimit
1915 format.attach
1916 format.cc
1917 format.headers
1918 format.numbered
1919 format.pretty
1920 format.signature
1921 format.signoff
1922 format.subjectprefix
1923 format.suffix
1924 format.thread
1925 gc.aggressiveWindow
1926 gc.auto
1927 gc.autopacklimit
1928 gc.packrefs
1929 gc.pruneexpire
1930 gc.reflogexpire
1931 gc.reflogexpireunreachable
1932 gc.rerereresolved
1933 gc.rerereunresolved
1934 gitcvs.allbinary
1935 gitcvs.commitmsgannotation
1936 gitcvs.dbTableNamePrefix
1937 gitcvs.dbdriver
1938 gitcvs.dbname
1939 gitcvs.dbpass
1940 gitcvs.dbuser
1941 gitcvs.enabled
1942 gitcvs.logfile
1943 gitcvs.usecrlfattr
1944 guitool.
1945 gui.blamehistoryctx
1946 gui.commitmsgwidth
1947 gui.copyblamethreshold
1948 gui.diffcontext
1949 gui.encoding
1950 gui.fastcopyblame
1951 gui.matchtrackingbranch
1952 gui.newbranchtemplate
1953 gui.pruneduringfetch
1954 gui.spellingdictionary
1955 gui.trustmtime
1956 help.autocorrect
1957 help.browser
1958 help.format
1959 http.lowSpeedLimit
1960 http.lowSpeedTime
1961 http.maxRequests
1962 http.noEPSV
1963 http.proxy
1964 http.sslCAInfo
1965 http.sslCAPath
1966 http.sslCert
1967 http.sslKey
1968 http.sslVerify
1969 i18n.commitEncoding
1970 i18n.logOutputEncoding
1971 imap.folder
1972 imap.host
1973 imap.pass
1974 imap.port
1975 imap.preformattedHTML
1976 imap.sslverify
1977 imap.tunnel
1978 imap.user
1979 instaweb.browser
1980 instaweb.httpd
1981 instaweb.local
1982 instaweb.modulepath
1983 instaweb.port
1984 interactive.singlekey
1985 log.date
1986 log.showroot
1987 mailmap.file
1988 man.
1989 man.viewer
1990 merge.conflictstyle
1991 merge.log
1992 merge.renameLimit
1993 merge.stat
1994 merge.tool
1995 merge.verbosity
1996 mergetool.
1997 mergetool.keepBackup
1998 mergetool.prompt
1999 pack.compression
2000 pack.deltaCacheLimit
2001 pack.deltaCacheSize
2002 pack.depth
2003 pack.indexVersion
2004 pack.packSizeLimit
2005 pack.threads
2006 pack.window
2007 pack.windowMemory
2008 pager.
2009 pull.octopus
2010 pull.twohead
2011 push.default
2012 rebase.stat
2013 receive.denyCurrentBranch
2014 receive.denyDeletes
2015 receive.denyNonFastForwards
2016 receive.fsckObjects
2017 receive.unpackLimit
2018 repack.usedeltabaseoffset
2019 rerere.autoupdate
2020 rerere.enabled
2021 sendemail.aliasesfile
2022 sendemail.aliasesfiletype
2023 sendemail.bcc
2024 sendemail.cc
2025 sendemail.cccmd
2026 sendemail.chainreplyto
2027 sendemail.confirm
2028 sendemail.envelopesender
2029 sendemail.multiedit
2030 sendemail.signedoffbycc
2031 sendemail.smtpencryption
2032 sendemail.smtppass
2033 sendemail.smtpserver
2034 sendemail.smtpserverport
2035 sendemail.smtpuser
2036 sendemail.suppresscc
2037 sendemail.suppressfrom
2038 sendemail.thread
2039 sendemail.to
2040 sendemail.validate
2041 showbranch.default
2042 status.relativePaths
2043 status.showUntrackedFiles
2044 tar.umask
2045 transfer.unpackLimit
2046 url.
2047 user.email
2048 user.name
2049 user.signingkey
2050 web.browser
2051 branch. remote.
2055 _git_remote ()
2057 local subcommands="add rename rm show prune update set-head"
2058 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2059 if [ -z "$subcommand" ]; then
2060 __gitcomp "$subcommands"
2061 return
2064 case "$subcommand" in
2065 rename|rm|show|prune)
2066 __gitcomp "$(__git_remotes)"
2068 update)
2069 local i c='' IFS=$'\n'
2070 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do
2071 i="${i#remotes.}"
2072 c="$c ${i/ */}"
2073 done
2074 __gitcomp "$c"
2077 COMPREPLY=()
2079 esac
2082 _git_replace ()
2084 __gitcomp "$(__git_refs)"
2087 _git_reset ()
2089 __git_has_doubledash && return
2091 local cur="${COMP_WORDS[COMP_CWORD]}"
2092 case "$cur" in
2093 --*)
2094 __gitcomp "--merge --mixed --hard --soft --patch"
2095 return
2097 esac
2098 __gitcomp "$(__git_refs)"
2101 _git_revert ()
2103 local cur="${COMP_WORDS[COMP_CWORD]}"
2104 case "$cur" in
2105 --*)
2106 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
2107 return
2109 esac
2110 __gitcomp "$(__git_refs)"
2113 _git_rm ()
2115 __git_has_doubledash && return
2117 local cur="${COMP_WORDS[COMP_CWORD]}"
2118 case "$cur" in
2119 --*)
2120 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
2121 return
2123 esac
2124 COMPREPLY=()
2127 _git_shortlog ()
2129 __git_has_doubledash && return
2131 local cur="${COMP_WORDS[COMP_CWORD]}"
2132 case "$cur" in
2133 --*)
2134 __gitcomp "
2135 $__git_log_common_options
2136 $__git_log_shortlog_options
2137 --numbered --summary
2139 return
2141 esac
2142 __git_complete_revlist
2145 _git_show ()
2147 __git_has_doubledash && return
2149 local cur="${COMP_WORDS[COMP_CWORD]}"
2150 case "$cur" in
2151 --pretty=*)
2152 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2153 " "" "${cur##--pretty=}"
2154 return
2156 --format=*)
2157 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2158 " "" "${cur##--format=}"
2159 return
2161 --*)
2162 __gitcomp "--pretty= --format= --abbrev-commit --oneline
2163 $__git_diff_common_options
2165 return
2167 esac
2168 __git_complete_file
2171 _git_show_branch ()
2173 local cur="${COMP_WORDS[COMP_CWORD]}"
2174 case "$cur" in
2175 --*)
2176 __gitcomp "
2177 --all --remotes --topo-order --current --more=
2178 --list --independent --merge-base --no-name
2179 --color --no-color
2180 --sha1-name --sparse --topics --reflog
2182 return
2184 esac
2185 __git_complete_revlist
2188 _git_stash ()
2190 local cur="${COMP_WORDS[COMP_CWORD]}"
2191 local save_opts='--keep-index --no-keep-index --quiet --patch'
2192 local subcommands='save list show apply clear drop pop create branch'
2193 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2194 if [ -z "$subcommand" ]; then
2195 case "$cur" in
2196 --*)
2197 __gitcomp "$save_opts"
2200 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2201 __gitcomp "$subcommands"
2202 else
2203 COMPREPLY=()
2206 esac
2207 else
2208 case "$subcommand,$cur" in
2209 save,--*)
2210 __gitcomp "$save_opts"
2212 apply,--*|pop,--*)
2213 __gitcomp "--index --quiet"
2215 show,--*|drop,--*|branch,--*)
2216 COMPREPLY=()
2218 show,*|apply,*|drop,*|pop,*|branch,*)
2219 __gitcomp "$(git --git-dir="$(__gitdir)" stash list \
2220 | sed -n -e 's/:.*//p')"
2223 COMPREPLY=()
2225 esac
2229 _git_submodule ()
2231 __git_has_doubledash && return
2233 local subcommands="add status init update summary foreach sync"
2234 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2235 local cur="${COMP_WORDS[COMP_CWORD]}"
2236 case "$cur" in
2237 --*)
2238 __gitcomp "--quiet --cached"
2241 __gitcomp "$subcommands"
2243 esac
2244 return
2248 _git_svn ()
2250 local subcommands="
2251 init fetch clone rebase dcommit log find-rev
2252 set-tree commit-diff info create-ignore propget
2253 proplist show-ignore show-externals branch tag blame
2254 migrate mkdirs reset gc
2256 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2257 if [ -z "$subcommand" ]; then
2258 __gitcomp "$subcommands"
2259 else
2260 local remote_opts="--username= --config-dir= --no-auth-cache"
2261 local fc_opts="
2262 --follow-parent --authors-file= --repack=
2263 --no-metadata --use-svm-props --use-svnsync-props
2264 --log-window-size= --no-checkout --quiet
2265 --repack-flags --use-log-author --localtime
2266 --ignore-paths= $remote_opts
2268 local init_opts="
2269 --template= --shared= --trunk= --tags=
2270 --branches= --stdlayout --minimize-url
2271 --no-metadata --use-svm-props --use-svnsync-props
2272 --rewrite-root= --prefix= --use-log-author
2273 --add-author-from $remote_opts
2275 local cmt_opts="
2276 --edit --rmdir --find-copies-harder --copy-similarity=
2279 local cur="${COMP_WORDS[COMP_CWORD]}"
2280 case "$subcommand,$cur" in
2281 fetch,--*)
2282 __gitcomp "--revision= --fetch-all $fc_opts"
2284 clone,--*)
2285 __gitcomp "--revision= $fc_opts $init_opts"
2287 init,--*)
2288 __gitcomp "$init_opts"
2290 dcommit,--*)
2291 __gitcomp "
2292 --merge --strategy= --verbose --dry-run
2293 --fetch-all --no-rebase --commit-url
2294 --revision $cmt_opts $fc_opts
2297 set-tree,--*)
2298 __gitcomp "--stdin $cmt_opts $fc_opts"
2300 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2301 show-externals,--*|mkdirs,--*)
2302 __gitcomp "--revision="
2304 log,--*)
2305 __gitcomp "
2306 --limit= --revision= --verbose --incremental
2307 --oneline --show-commit --non-recursive
2308 --authors-file= --color
2311 rebase,--*)
2312 __gitcomp "
2313 --merge --verbose --strategy= --local
2314 --fetch-all --dry-run $fc_opts
2317 commit-diff,--*)
2318 __gitcomp "--message= --file= --revision= $cmt_opts"
2320 info,--*)
2321 __gitcomp "--url"
2323 branch,--*)
2324 __gitcomp "--dry-run --message --tag"
2326 tag,--*)
2327 __gitcomp "--dry-run --message"
2329 blame,--*)
2330 __gitcomp "--git-format"
2332 migrate,--*)
2333 __gitcomp "
2334 --config-dir= --ignore-paths= --minimize
2335 --no-auth-cache --username=
2338 reset,--*)
2339 __gitcomp "--revision= --parent"
2342 COMPREPLY=()
2344 esac
2348 _git_tag ()
2350 local i c=1 f=0
2351 while [ $c -lt $COMP_CWORD ]; do
2352 i="${COMP_WORDS[c]}"
2353 case "$i" in
2354 -d|-v)
2355 __gitcomp "$(__git_tags)"
2356 return
2361 esac
2362 c=$((++c))
2363 done
2365 case "${COMP_WORDS[COMP_CWORD-1]}" in
2366 -m|-F)
2367 COMPREPLY=()
2369 -*|tag)
2370 if [ $f = 1 ]; then
2371 __gitcomp "$(__git_tags)"
2372 else
2373 COMPREPLY=()
2377 __gitcomp "$(__git_refs)"
2379 esac
2382 _git_whatchanged ()
2384 _git_log
2387 _git ()
2389 local i c=1 command __git_dir
2391 while [ $c -lt $COMP_CWORD ]; do
2392 i="${COMP_WORDS[c]}"
2393 case "$i" in
2394 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2395 --bare) __git_dir="." ;;
2396 --version|-p|--paginate) ;;
2397 --help) command="help"; break ;;
2398 *) command="$i"; break ;;
2399 esac
2400 c=$((++c))
2401 done
2403 if [ -z "$command" ]; then
2404 case "${COMP_WORDS[COMP_CWORD]}" in
2405 --*) __gitcomp "
2406 --paginate
2407 --no-pager
2408 --git-dir=
2409 --bare
2410 --version
2411 --exec-path
2412 --html-path
2413 --work-tree=
2414 --help
2417 *) __git_compute_porcelain_commands
2418 __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
2419 esac
2420 return
2423 local completion_func="_git_${command//-/_}"
2424 declare -F $completion_func >/dev/null && $completion_func && return
2426 local expansion=$(__git_aliased_command "$command")
2427 if [ -n "$expansion" ]; then
2428 completion_func="_git_${expansion//-/_}"
2429 declare -F $completion_func >/dev/null && $completion_func
2433 _gitk ()
2435 __git_has_doubledash && return
2437 local cur="${COMP_WORDS[COMP_CWORD]}"
2438 local g="$(__gitdir)"
2439 local merge=""
2440 if [ -f "$g/MERGE_HEAD" ]; then
2441 merge="--merge"
2443 case "$cur" in
2444 --*)
2445 __gitcomp "
2446 $__git_log_common_options
2447 $__git_log_gitk_options
2448 $merge
2450 return
2452 esac
2453 __git_complete_revlist
2456 complete -o bashdefault -o default -o nospace -F _git git 2>/dev/null \
2457 || complete -o default -o nospace -F _git git
2458 complete -o bashdefault -o default -o nospace -F _gitk gitk 2>/dev/null \
2459 || complete -o default -o nospace -F _gitk gitk
2461 # The following are necessary only for Cygwin, and only are needed
2462 # when the user has tab-completed the executable name and consequently
2463 # included the '.exe' suffix.
2465 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
2466 complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \
2467 || complete -o default -o nospace -F _git git.exe