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) You may want to make sure the git executable is available
25 # in your PATH before this script is sourced, as some caching
26 # is performed while the script loads. If git isn't found
27 # at source time then all lookups will be done on demand,
28 # which may be slightly slower.
30 # 4) Consider changing your PS1 to also show the current branch:
31 # PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
33 # The argument to __git_ps1 will be displayed only if you
34 # are currently in a git repository. The %s token will be
35 # the name of the current branch.
37 # In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty
38 # value, unstaged (*) and staged (+) changes will be shown next
39 # to the branch name. You can configure this per-repository
40 # with the bash.showDirtyState variable, which defaults to true
41 # once GIT_PS1_SHOWDIRTYSTATE is enabled.
45 # *) Read Documentation/SubmittingPatches
46 # *) Send all patches to the current maintainer:
48 # "Shawn O. Pearce" <spearce@spearce.org>
50 # *) Always CC the Git mailing list:
55 case "$COMP_WORDBREAKS" in
57 *) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
60 # __gitdir accepts 0 or 1 arguments (i.e., location)
61 # returns location of .git repo
64 if [ -z "${1-}" ]; then
65 if [ -n "$__git_dir" ]; then
67 elif [ -d .git ]; then
70 git rev-parse --git-dir 2>/dev/null
72 elif [ -d "$1/.git" ]; then
79 # __git_ps1 accepts 0 or 1 arguments (i.e., format string)
80 # returns text to add to bash PS1 prompt (includes branch name)
87 if [ -d "$g/rebase-apply" ]; then
88 if [ -f "$g/rebase-apply/rebasing" ]; then
90 elif [ -f "$g/rebase-apply/applying" ]; then
95 b="$(git symbolic-ref HEAD 2>/dev/null)"
96 elif [ -f "$g/rebase-merge/interactive" ]; then
98 b="$(cat "$g/rebase-merge/head-name")"
99 elif [ -d "$g/rebase-merge" ]; then
101 b="$(cat "$g/rebase-merge/head-name")"
102 elif [ -f "$g/MERGE_HEAD" ]; then
104 b="$(git symbolic-ref HEAD 2>/dev/null)"
106 if [ -f "$g/BISECT_LOG" ]; then
109 if ! b="$(git symbolic-ref HEAD 2>/dev/null)"; then
110 if ! b="$(git describe --exact-match HEAD 2>/dev/null)"; then
111 b="$(cut -c1-7 "$g/HEAD")..."
119 if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ]; then
120 if [ "$(git config --bool bash.showDirtyState)" != "false" ]; then
121 git diff --no-ext-diff --ignore-submodules \
122 --quiet --exit-code || w="*"
123 if git rev-parse --quiet --verify HEAD >/dev/null; then
124 git diff-index --cached --quiet \
125 --ignore-submodules HEAD -- || i="+"
132 if [ -n "${1-}" ]; then
133 printf "$1" "${b##refs/heads/}$w$i$r"
135 printf " (%s)" "${b##refs/heads/}$w$i$r"
140 # __gitcomp_1 requires 2 arguments
143 local c IFS=' '$'\t'$'\n'
146 --*=*) printf %s$'\n' "$c$2" ;;
147 *.) printf %s$'\n' "$c$2" ;;
148 *) printf %s$'\n' "$c$2 " ;;
153 # __gitcomp accepts 1, 2, 3, or 4 arguments
154 # generates completion reply with compgen
157 local cur="${COMP_WORDS[COMP_CWORD]}"
158 if [ $# -gt 2 ]; then
167 COMPREPLY=($(compgen -P "${2-}" \
168 -W "$(__gitcomp_1 "${1-}" "${4-}")" \
174 # __git_heads accepts 0 or 1 arguments (to pass to __gitdir)
177 local cmd i is_hash=y dir="$(__gitdir "${1-}")"
178 if [ -d "$dir" ]; then
179 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
183 for i in $(git ls-remote "${1-}" 2>/dev/null); do
184 case "$is_hash,$i" in
187 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
188 n,*) is_hash=y; echo "$i" ;;
193 # __git_tags accepts 0 or 1 arguments (to pass to __gitdir)
196 local cmd i is_hash=y dir="$(__gitdir "${1-}")"
197 if [ -d "$dir" ]; then
198 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
202 for i in $(git ls-remote "${1-}" 2>/dev/null); do
203 case "$is_hash,$i" in
206 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
207 n,*) is_hash=y; echo "$i" ;;
212 # __git_refs accepts 0 or 1 arguments (to pass to __gitdir)
215 local i is_hash=y dir="$(__gitdir "${1-}")"
216 local cur="${COMP_WORDS[COMP_CWORD]}" format refs
217 if [ -d "$dir" ]; then
224 if [ -e "$dir/HEAD" ]; then echo HEAD; fi
225 format="refname:short"
226 refs="refs/tags refs/heads refs/remotes"
229 git --git-dir="$dir" for-each-ref --format="%($format)" \
233 for i in $(git ls-remote "$dir" 2>/dev/null); do
234 case "$is_hash,$i" in
237 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
238 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
239 n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
240 n,*) is_hash=y; echo "$i" ;;
245 # __git_refs2 requires 1 argument (to pass to __git_refs)
249 for i in $(__git_refs "$1"); do
254 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
255 __git_refs_remotes ()
257 local cmd i is_hash=y
258 for i in $(git ls-remote "$1" 2>/dev/null); do
259 case "$is_hash,$i" in
262 echo "$i:refs/remotes/$1/${i#refs/heads/}"
266 n,refs/tags/*) is_hash=y;;
274 local i ngoff IFS=$'\n' d="$(__gitdir)"
275 shopt -q nullglob || ngoff=1
277 for i in "$d/remotes"/*; do
278 echo ${i#$d/remotes/}
280 [ "$ngoff" ] && shopt -u nullglob
281 for i in $(git --git-dir="$d" config --list); do
291 __git_merge_strategies ()
293 if [ -n "$__git_merge_strategylist" ]; then
294 echo "$__git_merge_strategylist"
297 git merge -s help 2>&1 |
298 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
306 __git_merge_strategylist=
307 __git_merge_strategylist=$(__git_merge_strategies 2>/dev/null)
309 __git_complete_file ()
311 local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
328 case "$COMP_WORDBREAKS" in
330 *) pfx="$ref:$pfx" ;;
334 COMPREPLY=($(compgen -P "$pfx" \
335 -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
336 | sed '/^100... blob /{
352 __gitcomp "$(__git_refs)"
357 __git_complete_revlist ()
359 local pfx cur="${COMP_WORDS[COMP_CWORD]}"
364 __gitcomp "$(__git_refs)" "$pfx" "$cur"
369 __gitcomp "$(__git_refs)" "$pfx" "$cur"
372 __gitcomp "$(__git_refs)"
377 __git_all_commands ()
379 if [ -n "$__git_all_commandlist" ]; then
380 echo "$__git_all_commandlist"
384 for i in $(git help -a|egrep '^ ')
387 *--*) : helper pattern;;
392 __git_all_commandlist=
393 __git_all_commandlist="$(__git_all_commands 2>/dev/null)"
395 __git_porcelain_commands ()
397 if [ -n "$__git_porcelain_commandlist" ]; then
398 echo "$__git_porcelain_commandlist"
402 for i in "help" $(__git_all_commands)
405 *--*) : helper pattern;;
406 applymbox) : ask gittus;;
407 applypatch) : ask gittus;;
408 archimport) : import;;
409 cat-file) : plumbing;;
410 check-attr) : plumbing;;
411 check-ref-format) : plumbing;;
412 checkout-index) : plumbing;;
413 commit-tree) : plumbing;;
414 count-objects) : infrequent;;
415 cvsexportcommit) : export;;
416 cvsimport) : import;;
417 cvsserver) : daemon;;
419 diff-files) : plumbing;;
420 diff-index) : plumbing;;
421 diff-tree) : plumbing;;
422 fast-import) : import;;
423 fast-export) : export;;
424 fsck-objects) : plumbing;;
425 fetch-pack) : plumbing;;
426 fmt-merge-msg) : plumbing;;
427 for-each-ref) : plumbing;;
428 hash-object) : plumbing;;
429 http-*) : transport;;
430 index-pack) : plumbing;;
431 init-db) : deprecated;;
432 local-fetch) : plumbing;;
433 lost-found) : infrequent;;
434 ls-files) : plumbing;;
435 ls-remote) : plumbing;;
436 ls-tree) : plumbing;;
437 mailinfo) : plumbing;;
438 mailsplit) : plumbing;;
439 merge-*) : plumbing;;
442 pack-objects) : plumbing;;
443 pack-redundant) : plumbing;;
444 pack-refs) : plumbing;;
445 parse-remote) : plumbing;;
446 patch-id) : plumbing;;
447 peek-remote) : plumbing;;
449 prune-packed) : plumbing;;
450 quiltimport) : import;;
451 read-tree) : plumbing;;
452 receive-pack) : plumbing;;
454 repo-config) : deprecated;;
456 rev-list) : plumbing;;
457 rev-parse) : plumbing;;
458 runstatus) : plumbing;;
459 sh-setup) : internal;;
461 show-ref) : plumbing;;
462 send-pack) : plumbing;;
463 show-index) : plumbing;;
465 stripspace) : plumbing;;
466 symbolic-ref) : plumbing;;
467 tar-tree) : deprecated;;
468 unpack-file) : plumbing;;
469 unpack-objects) : plumbing;;
470 update-index) : plumbing;;
471 update-ref) : plumbing;;
472 update-server-info) : daemon;;
473 upload-archive) : plumbing;;
474 upload-pack) : plumbing;;
475 write-tree) : plumbing;;
477 verify-pack) : infrequent;;
478 verify-tag) : plumbing;;
483 __git_porcelain_commandlist=
484 __git_porcelain_commandlist="$(__git_porcelain_commands 2>/dev/null)"
489 for i in $(git --git-dir="$(__gitdir)" config --list); do
499 # __git_aliased_command requires 1 argument
500 __git_aliased_command ()
502 local word cmdline=$(git --git-dir="$(__gitdir)" \
503 config --get "alias.$1")
504 for word in $cmdline; do
505 if [ "${word##-*}" ]; then
512 # __git_find_subcommand requires 1 argument
513 __git_find_subcommand ()
515 local word subcommand c=1
517 while [ $c -lt $COMP_CWORD ]; do
518 word="${COMP_WORDS[c]}"
519 for subcommand in $1; do
520 if [ "$subcommand" = "$word" ]; then
529 __git_has_doubledash ()
532 while [ $c -lt $COMP_CWORD ]; do
533 if [ "--" = "${COMP_WORDS[c]}" ]; then
541 __git_whitespacelist="nowarn warn error error-all fix"
545 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
546 if [ -d "$dir"/rebase-apply ]; then
547 __gitcomp "--skip --resolved --abort"
552 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
557 --signoff --utf8 --binary --3way --interactive
567 local cur="${COMP_WORDS[COMP_CWORD]}"
570 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
575 --stat --numstat --summary --check --index
576 --cached --index-info --reverse --reject --unidiff-zero
577 --apply --no-add --exclude=
578 --whitespace= --inaccurate-eof --verbose
587 __git_has_doubledash && return
589 local cur="${COMP_WORDS[COMP_CWORD]}"
593 --interactive --refresh --patch --update --dry-run
594 --ignore-errors --intent-to-add
603 local cur="${COMP_WORDS[COMP_CWORD]}"
606 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
610 __gitcomp "$(__git_remotes)" "" "${cur##--remote=}"
615 --format= --list --verbose
616 --prefix= --remote= --exec=
626 __git_has_doubledash && return
628 local subcommands="start bad good skip reset visualize replay log run"
629 local subcommand="$(__git_find_subcommand "$subcommands")"
630 if [ -z "$subcommand" ]; then
631 __gitcomp "$subcommands"
635 case "$subcommand" in
637 __gitcomp "$(__git_refs)"
647 local i c=1 only_local_ref="n" has_r="n"
649 while [ $c -lt $COMP_CWORD ]; do
652 -d|-m) only_local_ref="y" ;;
658 case "${COMP_WORDS[COMP_CWORD]}" in
661 --color --no-color --verbose --abbrev= --no-abbrev
662 --track --no-track --contains --merged --no-merged
666 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
667 __gitcomp "$(__git_heads)"
669 __gitcomp "$(__git_refs)"
677 local cmd="${COMP_WORDS[2]}"
678 case "$COMP_CWORD" in
680 __gitcomp "create list-heads verify unbundle"
688 __git_complete_revlist
697 __git_has_doubledash && return
699 __gitcomp "$(__git_refs)"
704 __gitcomp "$(__git_refs)"
709 local cur="${COMP_WORDS[COMP_CWORD]}"
712 __gitcomp "--edit --no-commit"
715 __gitcomp "$(__git_refs)"
722 __git_has_doubledash && return
724 local cur="${COMP_WORDS[COMP_CWORD]}"
727 __gitcomp "--dry-run --quiet"
736 local cur="${COMP_WORDS[COMP_CWORD]}"
761 __git_has_doubledash && return
763 local cur="${COMP_WORDS[COMP_CWORD]}"
767 --all --author= --signoff --verify --no-verify
768 --edit --amend --include --only --interactive
777 local cur="${COMP_WORDS[COMP_CWORD]}"
781 --all --tags --contains --abbrev= --candidates=
782 --exact-match --debug --long --match --always
786 __gitcomp "$(__git_refs)"
789 __git_diff_common_options="--stat --numstat --shortstat --summary
790 --patch-with-stat --name-only --name-status --color
791 --no-color --color-words --no-renames --check
792 --full-index --binary --abbrev --diff-filter=
794 --text --ignore-space-at-eol --ignore-space-change
795 --ignore-all-space --exit-code --quiet --ext-diff
797 --no-prefix --src-prefix= --dst-prefix=
798 --inter-hunk-context=
805 __git_has_doubledash && return
807 local cur="${COMP_WORDS[COMP_CWORD]}"
810 __gitcomp "--cached --pickaxe-all --pickaxe-regex
811 --base --ours --theirs
812 $__git_diff_common_options
822 local cur="${COMP_WORDS[COMP_CWORD]}"
824 if [ "$COMP_CWORD" = 2 ]; then
825 __gitcomp "$(__git_remotes)"
830 case "$COMP_WORDBREAKS" in
832 *) pfx="${cur%%:*}:" ;;
834 __gitcomp "$(__git_refs)" "$pfx" "${cur#*:}"
837 __gitcomp "$(__git_refs2 "${COMP_WORDS[2]}")"
845 local cur="${COMP_WORDS[COMP_CWORD]}"
849 --stdout --attach --thread
851 --numbered --start-number
856 --full-index --binary
859 --no-prefix --src-prefix= --dst-prefix=
860 --inline --suffix= --ignore-if-in-upstream
866 __git_complete_revlist
871 local cur="${COMP_WORDS[COMP_CWORD]}"
874 __gitcomp "--prune --aggressive"
883 __git_has_doubledash && return
885 local cur="${COMP_WORDS[COMP_CWORD]}"
890 --text --ignore-case --word-regexp --invert-match
892 --extended-regexp --basic-regexp --fixed-strings
893 --files-with-matches --name-only
894 --files-without-match
896 --and --or --not --all-match
906 local cur="${COMP_WORDS[COMP_CWORD]}"
909 __gitcomp "--all --info --man --web"
913 __gitcomp "$(__git_all_commands)
914 attributes cli core-tutorial cvs-migration
915 diffcore gitk glossary hooks ignore modules
916 repository-layout tutorial tutorial-2
923 local cur="${COMP_WORDS[COMP_CWORD]}"
927 false true umask group all world everybody
928 " "" "${cur##--shared=}"
932 __gitcomp "--quiet --bare --template= --shared --shared="
941 __git_has_doubledash && return
943 local cur="${COMP_WORDS[COMP_CWORD]}"
946 __gitcomp "--cached --deleted --modified --others --ignored
947 --stage --directory --no-empty-directory --unmerged
948 --killed --exclude= --exclude-from=
949 --exclude-per-directory= --exclude-standard
950 --error-unmatch --with-tree= --full-name
951 --abbrev --ignored --exclude-per-directory
961 __gitcomp "$(__git_remotes)"
969 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
973 __git_has_doubledash && return
975 local cur="${COMP_WORDS[COMP_CWORD]}"
978 __gitcomp "$__git_log_pretty_formats
979 " "" "${cur##--pretty=}"
984 relative iso8601 rfc2822 short local default
985 " "" "${cur##--date=}"
990 --max-count= --max-age= --since= --after=
991 --min-age= --before= --until=
992 --root --topo-order --date-order --reverse
994 --abbrev-commit --abbrev=
995 --relative-date --date=
996 --author= --committer= --grep=
1000 --left-right --cherry-pick
1004 --parents --children --full-history
1006 $__git_diff_common_options
1007 --pickaxe-all --pickaxe-regex
1012 __git_complete_revlist
1017 local cur="${COMP_WORDS[COMP_CWORD]}"
1018 case "${COMP_WORDS[COMP_CWORD-1]}" in
1020 __gitcomp "$(__git_merge_strategies)"
1025 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
1030 --no-commit --no-stat --log --no-log --squash --strategy
1034 __gitcomp "$(__git_refs)"
1039 local cur="${COMP_WORDS[COMP_CWORD]}"
1043 kdiff3 tkdiff meld xxdiff emerge
1044 vimdiff gvimdiff ecmerge opendiff
1045 " "" "${cur##--tool=}"
1058 __gitcomp "$(__git_refs)"
1063 local cur="${COMP_WORDS[COMP_CWORD]}"
1066 __gitcomp "--dry-run"
1075 __gitcomp "--tags --all --stdin"
1080 local cur="${COMP_WORDS[COMP_CWORD]}"
1082 if [ "$COMP_CWORD" = 2 ]; then
1083 __gitcomp "$(__git_remotes)"
1085 __gitcomp "$(__git_refs "${COMP_WORDS[2]}")"
1091 local cur="${COMP_WORDS[COMP_CWORD]}"
1093 if [ "$COMP_CWORD" = 2 ]; then
1094 __gitcomp "$(__git_remotes)"
1099 case "$COMP_WORDBREAKS" in
1101 *) pfx="${cur%%:*}:" ;;
1104 __gitcomp "$(__git_refs "${COMP_WORDS[2]}")" "$pfx" "${cur#*:}"
1107 __gitcomp "$(__git_refs)" + "${cur#+}"
1110 __gitcomp "$(__git_refs)"
1118 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
1119 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1120 __gitcomp "--continue --skip --abort"
1123 case "${COMP_WORDS[COMP_CWORD-1]}" in
1125 __gitcomp "$(__git_merge_strategies)"
1130 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
1134 __gitcomp "--onto --merge --strategy --interactive"
1137 __gitcomp "$(__git_refs)"
1142 local cur="${COMP_WORDS[COMP_CWORD]}"
1145 __gitcomp "--bcc --cc --cc-cmd --chain-reply-to --compose
1146 --dry-run --envelope-sender --from --identity
1147 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1148 --no-suppress-from --no-thread --quiet
1149 --signed-off-by-cc --smtp-pass --smtp-server
1150 --smtp-server-port --smtp-ssl --smtp-user --subject
1151 --suppress-cc --suppress-from --thread --to
1152 --validate --no-validate"
1161 local cur="${COMP_WORDS[COMP_CWORD]}"
1162 local prv="${COMP_WORDS[COMP_CWORD-1]}"
1165 __gitcomp "$(__git_remotes)"
1169 __gitcomp "$(__git_refs)"
1173 local remote="${prv#remote.}"
1174 remote="${remote%.fetch}"
1175 __gitcomp "$(__git_refs_remotes "$remote")"
1179 local remote="${prv#remote.}"
1180 remote="${remote%.push}"
1181 __gitcomp "$(git --git-dir="$(__gitdir)" \
1182 for-each-ref --format='%(refname):%(refname)' \
1186 pull.twohead|pull.octopus)
1187 __gitcomp "$(__git_merge_strategies)"
1190 color.branch|color.diff|color.status)
1191 __gitcomp "always never auto"
1196 normal black red green yellow blue magenta cyan white
1197 bold dim ul blink reverse
1209 --global --system --file=
1210 --list --replace-all
1211 --get --get-all --get-regexp
1212 --add --unset --unset-all
1213 --remove-section --rename-section
1218 local pfx="${cur%.*}."
1220 __gitcomp "remote merge mergeoptions" "$pfx" "$cur"
1224 local pfx="${cur%.*}."
1226 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
1230 local pfx="${cur%.*}."
1233 url proxy fetch push mirror skipDefaultUpdate
1234 receivepack uploadpack tagopt
1239 local pfx="${cur%.*}."
1241 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
1247 branch.autosetupmerge
1248 branch.autosetuprebase
1251 color.branch.current
1262 color.diff.whitespace
1264 color.interactive.header
1265 color.interactive.help
1266 color.interactive.prompt
1270 color.status.changed
1272 color.status.nobranch
1273 color.status.untracked
1274 color.status.updated
1280 core.deltaBaseCacheLimit
1284 core.fsyncobjectfiles
1286 core.ignoreCygwinFSTricks
1288 core.logAllRefUpdates
1289 core.loosecompression
1291 core.packedGitWindowSize
1293 core.preferSymlinkRefs
1296 core.repositoryFormatVersion
1298 core.sharedRepository
1301 core.warnAmbiguousRefs
1304 diff.autorefreshindex
1321 gc.reflogexpireunreachable
1325 gitcvs.dbTableNamePrefix
1335 gui.copyblamethreshold
1339 gui.matchtrackingbranch
1340 gui.newbranchtemplate
1341 gui.pruneduringfetch
1342 gui.spellingdictionary
1358 i18n.logOutputEncoding
1373 mergetool.keepBackup
1375 pack.deltaCacheLimit
1385 receive.denyCurrentBranch
1387 receive.denyNonFastForwards
1390 repack.usedeltabaseoffset
1394 status.relativePaths
1395 status.showUntrackedFiles
1397 transfer.unpackLimit
1408 local subcommands="add rename rm show prune update"
1409 local subcommand="$(__git_find_subcommand "$subcommands")"
1410 if [ -z "$subcommand" ]; then
1411 __gitcomp "$subcommands"
1415 case "$subcommand" in
1416 rename|rm|show|prune)
1417 __gitcomp "$(__git_remotes)"
1420 local i c='' IFS=$'\n'
1421 for i in $(git --git-dir="$(__gitdir)" config --list); do
1439 __git_has_doubledash && return
1441 local cur="${COMP_WORDS[COMP_CWORD]}"
1444 __gitcomp "--merge --mixed --hard --soft"
1448 __gitcomp "$(__git_refs)"
1453 local cur="${COMP_WORDS[COMP_CWORD]}"
1456 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
1460 __gitcomp "$(__git_refs)"
1465 __git_has_doubledash && return
1467 local cur="${COMP_WORDS[COMP_CWORD]}"
1470 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
1479 __git_has_doubledash && return
1481 local cur="${COMP_WORDS[COMP_CWORD]}"
1485 --max-count= --max-age= --since= --after=
1486 --min-age= --before= --until=
1488 --author= --committer= --grep=
1491 --numbered --summary
1496 __git_complete_revlist
1501 __git_has_doubledash && return
1503 local cur="${COMP_WORDS[COMP_CWORD]}"
1506 __gitcomp "$__git_log_pretty_formats
1507 " "" "${cur##--pretty=}"
1511 __gitcomp "--pretty=
1512 $__git_diff_common_options
1522 local cur="${COMP_WORDS[COMP_CWORD]}"
1526 --all --remotes --topo-order --current --more=
1527 --list --independent --merge-base --no-name
1528 --sha1-name --topics --reflog
1533 __git_complete_revlist
1538 local subcommands='save list show apply clear drop pop create branch'
1539 local subcommand="$(__git_find_subcommand "$subcommands")"
1540 if [ -z "$subcommand" ]; then
1541 __gitcomp "$subcommands"
1543 local cur="${COMP_WORDS[COMP_CWORD]}"
1544 case "$subcommand,$cur" in
1546 __gitcomp "--keep-index"
1551 show,--*|drop,--*|pop,--*|branch,--*)
1554 show,*|apply,*|drop,*|pop,*|branch,*)
1555 __gitcomp "$(git --git-dir="$(__gitdir)" stash list \
1556 | sed -n -e 's/:.*//p')"
1567 __git_has_doubledash && return
1569 local subcommands="add status init update summary foreach sync"
1570 if [ -z "$(__git_find_subcommand "$subcommands")" ]; then
1571 local cur="${COMP_WORDS[COMP_CWORD]}"
1574 __gitcomp "--quiet --cached"
1577 __gitcomp "$subcommands"
1587 init fetch clone rebase dcommit log find-rev
1588 set-tree commit-diff info create-ignore propget
1589 proplist show-ignore show-externals
1591 local subcommand="$(__git_find_subcommand "$subcommands")"
1592 if [ -z "$subcommand" ]; then
1593 __gitcomp "$subcommands"
1595 local remote_opts="--username= --config-dir= --no-auth-cache"
1597 --follow-parent --authors-file= --repack=
1598 --no-metadata --use-svm-props --use-svnsync-props
1599 --log-window-size= --no-checkout --quiet
1600 --repack-flags --user-log-author --localtime $remote_opts
1603 --template= --shared= --trunk= --tags=
1604 --branches= --stdlayout --minimize-url
1605 --no-metadata --use-svm-props --use-svnsync-props
1606 --rewrite-root= $remote_opts
1609 --edit --rmdir --find-copies-harder --copy-similarity=
1612 local cur="${COMP_WORDS[COMP_CWORD]}"
1613 case "$subcommand,$cur" in
1615 __gitcomp "--revision= --fetch-all $fc_opts"
1618 __gitcomp "--revision= $fc_opts $init_opts"
1621 __gitcomp "$init_opts"
1625 --merge --strategy= --verbose --dry-run
1626 --fetch-all --no-rebase $cmt_opts $fc_opts
1630 __gitcomp "--stdin $cmt_opts $fc_opts"
1632 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
1634 __gitcomp "--revision="
1638 --limit= --revision= --verbose --incremental
1639 --oneline --show-commit --non-recursive
1645 --merge --verbose --strategy= --local
1646 --fetch-all $fc_opts
1650 __gitcomp "--message= --file= --revision= $cmt_opts"
1665 while [ $c -lt $COMP_CWORD ]; do
1666 i="${COMP_WORDS[c]}"
1669 __gitcomp "$(__git_tags)"
1679 case "${COMP_WORDS[COMP_CWORD-1]}" in
1685 __gitcomp "$(__git_tags)"
1691 __gitcomp "$(__git_refs)"
1698 local i c=1 command __git_dir
1700 while [ $c -lt $COMP_CWORD ]; do
1701 i="${COMP_WORDS[c]}"
1703 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
1704 --bare) __git_dir="." ;;
1705 --version|-p|--paginate) ;;
1706 --help) command="help"; break ;;
1707 *) command="$i"; break ;;
1712 if [ -z "$command" ]; then
1713 case "${COMP_WORDS[COMP_CWORD]}" in
1725 *) __gitcomp "$(__git_porcelain_commands) $(__git_aliases)" ;;
1730 local expansion=$(__git_aliased_command "$command")
1731 [ "$expansion" ] && command="$expansion"
1736 apply) _git_apply ;;
1737 archive) _git_archive ;;
1738 bisect) _git_bisect ;;
1739 bundle) _git_bundle ;;
1740 branch) _git_branch ;;
1741 checkout) _git_checkout ;;
1742 cherry) _git_cherry ;;
1743 cherry-pick) _git_cherry_pick ;;
1744 clean) _git_clean ;;
1745 clone) _git_clone ;;
1746 commit) _git_commit ;;
1747 config) _git_config ;;
1748 describe) _git_describe ;;
1750 fetch) _git_fetch ;;
1751 format-patch) _git_format_patch ;;
1757 ls-files) _git_ls_files ;;
1758 ls-remote) _git_ls_remote ;;
1759 ls-tree) _git_ls_tree ;;
1761 mergetool) _git_mergetool;;
1762 merge-base) _git_merge_base ;;
1764 name-rev) _git_name_rev ;;
1767 rebase) _git_rebase ;;
1768 remote) _git_remote ;;
1769 reset) _git_reset ;;
1770 revert) _git_revert ;;
1772 send-email) _git_send_email ;;
1773 shortlog) _git_shortlog ;;
1775 show-branch) _git_show_branch ;;
1776 stash) _git_stash ;;
1778 submodule) _git_submodule ;;
1781 whatchanged) _git_log ;;
1788 __git_has_doubledash && return
1790 local cur="${COMP_WORDS[COMP_CWORD]}"
1791 local g="$(__gitdir)"
1793 if [ -f $g/MERGE_HEAD ]; then
1798 __gitcomp "--not --all $merge"
1802 __git_complete_revlist
1805 complete -o bashdefault -o default -o nospace -F _git git 2>/dev/null \
1806 || complete -o default -o nospace -F _git git
1807 complete -o bashdefault -o default -o nospace -F _gitk gitk 2>/dev/null \
1808 || complete -o default -o nospace -F _gitk gitk
1810 # The following are necessary only for Cygwin, and only are needed
1811 # when the user has tab-completed the executable name and consequently
1812 # included the '.exe' suffix.
1814 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
1815 complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \
1816 || complete -o default -o nospace -F _git git.exe