Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

finally using real git prompt/completion

  • Loading branch information...
commit 2c4eaf26f5c0b580b1c04f6884be260dec3c277a 1 parent 00bc2fe
Jordan Bach authored July 18, 2012
2,480  config/bash/git-completion.bash
... ...
@@ -0,0 +1,2480 @@
  1
+#!bash
  2
+#
  3
+# https://raw.github.com/git/git/master/contrib/completion/git-completion.bash
  4
+#
  5
+# bash/zsh completion support for core Git.
  6
+#
  7
+# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
  8
+# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
  9
+# Distributed under the GNU General Public License, version 2.0.
  10
+#
  11
+# The contained completion routines provide support for completing:
  12
+#
  13
+#    *) local and remote branch names
  14
+#    *) local and remote tag names
  15
+#    *) .git/remotes file names
  16
+#    *) git 'subcommands'
  17
+#    *) tree paths within 'ref:path/to/file' expressions
  18
+#    *) common --long-options
  19
+#
  20
+# To use these routines:
  21
+#
  22
+#    1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
  23
+#    2) Add the following line to your .bashrc/.zshrc:
  24
+#        source ~/.git-completion.sh
  25
+#    3) Consider changing your PS1 to also show the current branch,
  26
+#       see git-prompt.sh for details.
  27
+
  28
+if [[ -n ${ZSH_VERSION-} ]]; then
  29
+	autoload -U +X bashcompinit && bashcompinit
  30
+fi
  31
+
  32
+case "$COMP_WORDBREAKS" in
  33
+*:*) : great ;;
  34
+*)   COMP_WORDBREAKS="$COMP_WORDBREAKS:"
  35
+esac
  36
+
  37
+# __gitdir accepts 0 or 1 arguments (i.e., location)
  38
+# returns location of .git repo
  39
+__gitdir ()
  40
+{
  41
+	# Note: this function is duplicated in git-prompt.sh
  42
+	# When updating it, make sure you update the other one to match.
  43
+	if [ -z "${1-}" ]; then
  44
+		if [ -n "${__git_dir-}" ]; then
  45
+			echo "$__git_dir"
  46
+		elif [ -n "${GIT_DIR-}" ]; then
  47
+			test -d "${GIT_DIR-}" || return 1
  48
+			echo "$GIT_DIR"
  49
+		elif [ -d .git ]; then
  50
+			echo .git
  51
+		else
  52
+			git rev-parse --git-dir 2>/dev/null
  53
+		fi
  54
+	elif [ -d "$1/.git" ]; then
  55
+		echo "$1/.git"
  56
+	else
  57
+		echo "$1"
  58
+	fi
  59
+}
  60
+
  61
+__gitcomp_1 ()
  62
+{
  63
+	local c IFS=$' \t\n'
  64
+	for c in $1; do
  65
+		c="$c$2"
  66
+		case $c in
  67
+		--*=*|*.) ;;
  68
+		*) c="$c " ;;
  69
+		esac
  70
+		printf '%s\n' "$c"
  71
+	done
  72
+}
  73
+
  74
+# The following function is based on code from:
  75
+#
  76
+#   bash_completion - programmable completion functions for bash 3.2+
  77
+#
  78
+#   Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
  79
+#             © 2009-2010, Bash Completion Maintainers
  80
+#                     <bash-completion-devel@lists.alioth.debian.org>
  81
+#
  82
+#   This program is free software; you can redistribute it and/or modify
  83
+#   it under the terms of the GNU General Public License as published by
  84
+#   the Free Software Foundation; either version 2, or (at your option)
  85
+#   any later version.
  86
+#
  87
+#   This program is distributed in the hope that it will be useful,
  88
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of
  89
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  90
+#   GNU General Public License for more details.
  91
+#
  92
+#   You should have received a copy of the GNU General Public License
  93
+#   along with this program; if not, write to the Free Software Foundation,
  94
+#   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  95
+#
  96
+#   The latest version of this software can be obtained here:
  97
+#
  98
+#   http://bash-completion.alioth.debian.org/
  99
+#
  100
+#   RELEASE: 2.x
  101
+
  102
+# This function can be used to access a tokenized list of words
  103
+# on the command line:
  104
+#
  105
+#	__git_reassemble_comp_words_by_ref '=:'
  106
+#	if test "${words_[cword_-1]}" = -w
  107
+#	then
  108
+#		...
  109
+#	fi
  110
+#
  111
+# The argument should be a collection of characters from the list of
  112
+# word completion separators (COMP_WORDBREAKS) to treat as ordinary
  113
+# characters.
  114
+#
  115
+# This is roughly equivalent to going back in time and setting
  116
+# COMP_WORDBREAKS to exclude those characters.  The intent is to
  117
+# make option types like --date=<type> and <rev>:<path> easy to
  118
+# recognize by treating each shell word as a single token.
  119
+#
  120
+# It is best not to set COMP_WORDBREAKS directly because the value is
  121
+# shared with other completion scripts.  By the time the completion
  122
+# function gets called, COMP_WORDS has already been populated so local
  123
+# changes to COMP_WORDBREAKS have no effect.
  124
+#
  125
+# Output: words_, cword_, cur_.
  126
+
  127
+__git_reassemble_comp_words_by_ref()
  128
+{
  129
+	local exclude i j first
  130
+	# Which word separators to exclude?
  131
+	exclude="${1//[^$COMP_WORDBREAKS]}"
  132
+	cword_=$COMP_CWORD
  133
+	if [ -z "$exclude" ]; then
  134
+		words_=("${COMP_WORDS[@]}")
  135
+		return
  136
+	fi
  137
+	# List of word completion separators has shrunk;
  138
+	# re-assemble words to complete.
  139
+	for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
  140
+		# Append each nonempty word consisting of just
  141
+		# word separator characters to the current word.
  142
+		first=t
  143
+		while
  144
+			[ $i -gt 0 ] &&
  145
+			[ -n "${COMP_WORDS[$i]}" ] &&
  146
+			# word consists of excluded word separators
  147
+			[ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
  148
+		do
  149
+			# Attach to the previous token,
  150
+			# unless the previous token is the command name.
  151
+			if [ $j -ge 2 ] && [ -n "$first" ]; then
  152
+				((j--))
  153
+			fi
  154
+			first=
  155
+			words_[$j]=${words_[j]}${COMP_WORDS[i]}
  156
+			if [ $i = $COMP_CWORD ]; then
  157
+				cword_=$j
  158
+			fi
  159
+			if (($i < ${#COMP_WORDS[@]} - 1)); then
  160
+				((i++))
  161
+			else
  162
+				# Done.
  163
+				return
  164
+			fi
  165
+		done
  166
+		words_[$j]=${words_[j]}${COMP_WORDS[i]}
  167
+		if [ $i = $COMP_CWORD ]; then
  168
+			cword_=$j
  169
+		fi
  170
+	done
  171
+}
  172
+
  173
+if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
  174
+if [[ -z ${ZSH_VERSION:+set} ]]; then
  175
+_get_comp_words_by_ref ()
  176
+{
  177
+	local exclude cur_ words_ cword_
  178
+	if [ "$1" = "-n" ]; then
  179
+		exclude=$2
  180
+		shift 2
  181
+	fi
  182
+	__git_reassemble_comp_words_by_ref "$exclude"
  183
+	cur_=${words_[cword_]}
  184
+	while [ $# -gt 0 ]; do
  185
+		case "$1" in
  186
+		cur)
  187
+			cur=$cur_
  188
+			;;
  189
+		prev)
  190
+			prev=${words_[$cword_-1]}
  191
+			;;
  192
+		words)
  193
+			words=("${words_[@]}")
  194
+			;;
  195
+		cword)
  196
+			cword=$cword_
  197
+			;;
  198
+		esac
  199
+		shift
  200
+	done
  201
+}
  202
+else
  203
+_get_comp_words_by_ref ()
  204
+{
  205
+	while [ $# -gt 0 ]; do
  206
+		case "$1" in
  207
+		cur)
  208
+			cur=${COMP_WORDS[COMP_CWORD]}
  209
+			;;
  210
+		prev)
  211
+			prev=${COMP_WORDS[COMP_CWORD-1]}
  212
+			;;
  213
+		words)
  214
+			words=("${COMP_WORDS[@]}")
  215
+			;;
  216
+		cword)
  217
+			cword=$COMP_CWORD
  218
+			;;
  219
+		-n)
  220
+			# assume COMP_WORDBREAKS is already set sanely
  221
+			shift
  222
+			;;
  223
+		esac
  224
+		shift
  225
+	done
  226
+}
  227
+fi
  228
+fi
  229
+
  230
+# Generates completion reply with compgen, appending a space to possible
  231
+# completion words, if necessary.
  232
+# It accepts 1 to 4 arguments:
  233
+# 1: List of possible completion words.
  234
+# 2: A prefix to be added to each possible completion word (optional).
  235
+# 3: Generate possible completion matches for this word (optional).
  236
+# 4: A suffix to be appended to each possible completion word (optional).
  237
+__gitcomp ()
  238
+{
  239
+	local cur_="${3-$cur}"
  240
+
  241
+	case "$cur_" in
  242
+	--*=)
  243
+		COMPREPLY=()
  244
+		;;
  245
+	*)
  246
+		local IFS=$'\n'
  247
+		COMPREPLY=($(compgen -P "${2-}" \
  248
+			-W "$(__gitcomp_1 "${1-}" "${4-}")" \
  249
+			-- "$cur_"))
  250
+		;;
  251
+	esac
  252
+}
  253
+
  254
+# Generates completion reply with compgen from newline-separated possible
  255
+# completion words by appending a space to all of them.
  256
+# It accepts 1 to 4 arguments:
  257
+# 1: List of possible completion words, separated by a single newline.
  258
+# 2: A prefix to be added to each possible completion word (optional).
  259
+# 3: Generate possible completion matches for this word (optional).
  260
+# 4: A suffix to be appended to each possible completion word instead of
  261
+#    the default space (optional).  If specified but empty, nothing is
  262
+#    appended.
  263
+__gitcomp_nl ()
  264
+{
  265
+	local IFS=$'\n'
  266
+	COMPREPLY=($(compgen -P "${2-}" -S "${4- }" -W "$1" -- "${3-$cur}"))
  267
+}
  268
+
  269
+__git_heads ()
  270
+{
  271
+	local dir="$(__gitdir)"
  272
+	if [ -d "$dir" ]; then
  273
+		git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
  274
+			refs/heads
  275
+		return
  276
+	fi
  277
+}
  278
+
  279
+__git_tags ()
  280
+{
  281
+	local dir="$(__gitdir)"
  282
+	if [ -d "$dir" ]; then
  283
+		git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
  284
+			refs/tags
  285
+		return
  286
+	fi
  287
+}
  288
+
  289
+# __git_refs accepts 0, 1 (to pass to __gitdir), or 2 arguments
  290
+# presence of 2nd argument means use the guess heuristic employed
  291
+# by checkout for tracking branches
  292
+__git_refs ()
  293
+{
  294
+	local i hash dir="$(__gitdir "${1-}")" track="${2-}"
  295
+	local format refs
  296
+	if [ -d "$dir" ]; then
  297
+		case "$cur" in
  298
+		refs|refs/*)
  299
+			format="refname"
  300
+			refs="${cur%/*}"
  301
+			track=""
  302
+			;;
  303
+		*)
  304
+			for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
  305
+				if [ -e "$dir/$i" ]; then echo $i; fi
  306
+			done
  307
+			format="refname:short"
  308
+			refs="refs/tags refs/heads refs/remotes"
  309
+			;;
  310
+		esac
  311
+		git --git-dir="$dir" for-each-ref --format="%($format)" \
  312
+			$refs
  313
+		if [ -n "$track" ]; then
  314
+			# employ the heuristic used by git checkout
  315
+			# Try to find a remote branch that matches the completion word
  316
+			# but only output if the branch name is unique
  317
+			local ref entry
  318
+			git --git-dir="$dir" for-each-ref --shell --format="ref=%(refname:short)" \
  319
+				"refs/remotes/" | \
  320
+			while read -r entry; do
  321
+				eval "$entry"
  322
+				ref="${ref#*/}"
  323
+				if [[ "$ref" == "$cur"* ]]; then
  324
+					echo "$ref"
  325
+				fi
  326
+			done | uniq -u
  327
+		fi
  328
+		return
  329
+	fi
  330
+	case "$cur" in
  331
+	refs|refs/*)
  332
+		git ls-remote "$dir" "$cur*" 2>/dev/null | \
  333
+		while read -r hash i; do
  334
+			case "$i" in
  335
+			*^{}) ;;
  336
+			*) echo "$i" ;;
  337
+			esac
  338
+		done
  339
+		;;
  340
+	*)
  341
+		git ls-remote "$dir" HEAD ORIG_HEAD 'refs/tags/*' 'refs/heads/*' 'refs/remotes/*' 2>/dev/null | \
  342
+		while read -r hash i; do
  343
+			case "$i" in
  344
+			*^{}) ;;
  345
+			refs/*) echo "${i#refs/*/}" ;;
  346
+			*) echo "$i" ;;
  347
+			esac
  348
+		done
  349
+		;;
  350
+	esac
  351
+}
  352
+
  353
+# __git_refs2 requires 1 argument (to pass to __git_refs)
  354
+__git_refs2 ()
  355
+{
  356
+	local i
  357
+	for i in $(__git_refs "$1"); do
  358
+		echo "$i:$i"
  359
+	done
  360
+}
  361
+
  362
+# __git_refs_remotes requires 1 argument (to pass to ls-remote)
  363
+__git_refs_remotes ()
  364
+{
  365
+	local i hash
  366
+	git ls-remote "$1" 'refs/heads/*' 2>/dev/null | \
  367
+	while read -r hash i; do
  368
+		echo "$i:refs/remotes/$1/${i#refs/heads/}"
  369
+	done
  370
+}
  371
+
  372
+__git_remotes ()
  373
+{
  374
+	local i IFS=$'\n' d="$(__gitdir)"
  375
+	test -d "$d/remotes" && ls -1 "$d/remotes"
  376
+	for i in $(git --git-dir="$d" config --get-regexp 'remote\..*\.url' 2>/dev/null); do
  377
+		i="${i#remote.}"
  378
+		echo "${i/.url*/}"
  379
+	done
  380
+}
  381
+
  382
+__git_list_merge_strategies ()
  383
+{
  384
+	git merge -s help 2>&1 |
  385
+	sed -n -e '/[Aa]vailable strategies are: /,/^$/{
  386
+		s/\.$//
  387
+		s/.*://
  388
+		s/^[ 	]*//
  389
+		s/[ 	]*$//
  390
+		p
  391
+	}'
  392
+}
  393
+
  394
+__git_merge_strategies=
  395
+# 'git merge -s help' (and thus detection of the merge strategy
  396
+# list) fails, unfortunately, if run outside of any git working
  397
+# tree.  __git_merge_strategies is set to the empty string in
  398
+# that case, and the detection will be repeated the next time it
  399
+# is needed.
  400
+__git_compute_merge_strategies ()
  401
+{
  402
+	test -n "$__git_merge_strategies" ||
  403
+	__git_merge_strategies=$(__git_list_merge_strategies)
  404
+}
  405
+
  406
+__git_complete_revlist_file ()
  407
+{
  408
+	local pfx ls ref cur_="$cur"
  409
+	case "$cur_" in
  410
+	*..?*:*)
  411
+		return
  412
+		;;
  413
+	?*:*)
  414
+		ref="${cur_%%:*}"
  415
+		cur_="${cur_#*:}"
  416
+		case "$cur_" in
  417
+		?*/*)
  418
+			pfx="${cur_%/*}"
  419
+			cur_="${cur_##*/}"
  420
+			ls="$ref:$pfx"
  421
+			pfx="$pfx/"
  422
+			;;
  423
+		*)
  424
+			ls="$ref"
  425
+			;;
  426
+		esac
  427
+
  428
+		case "$COMP_WORDBREAKS" in
  429
+		*:*) : great ;;
  430
+		*)   pfx="$ref:$pfx" ;;
  431
+		esac
  432
+
  433
+		__gitcomp_nl "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
  434
+				| sed '/^100... blob /{
  435
+				           s,^.*	,,
  436
+				           s,$, ,
  437
+				       }
  438
+				       /^120000 blob /{
  439
+				           s,^.*	,,
  440
+				           s,$, ,
  441
+				       }
  442
+				       /^040000 tree /{
  443
+				           s,^.*	,,
  444
+				           s,$,/,
  445
+				       }
  446
+				       s/^.*	//')" \
  447
+			"$pfx" "$cur_" ""
  448
+		;;
  449
+	*...*)
  450
+		pfx="${cur_%...*}..."
  451
+		cur_="${cur_#*...}"
  452
+		__gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
  453
+		;;
  454
+	*..*)
  455
+		pfx="${cur_%..*}.."
  456
+		cur_="${cur_#*..}"
  457
+		__gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
  458
+		;;
  459
+	*)
  460
+		__gitcomp_nl "$(__git_refs)"
  461
+		;;
  462
+	esac
  463
+}
  464
+
  465
+
  466
+__git_complete_file ()
  467
+{
  468
+	__git_complete_revlist_file
  469
+}
  470
+
  471
+__git_complete_revlist ()
  472
+{
  473
+	__git_complete_revlist_file
  474
+}
  475
+
  476
+__git_complete_remote_or_refspec ()
  477
+{
  478
+	local cur_="$cur" cmd="${words[1]}"
  479
+	local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
  480
+	if [ "$cmd" = "remote" ]; then
  481
+		((c++))
  482
+	fi
  483
+	while [ $c -lt $cword ]; do
  484
+		i="${words[c]}"
  485
+		case "$i" in
  486
+		--mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
  487
+		--all)
  488
+			case "$cmd" in
  489
+			push) no_complete_refspec=1 ;;
  490
+			fetch)
  491
+				COMPREPLY=()
  492
+				return
  493
+				;;
  494
+			*) ;;
  495
+			esac
  496
+			;;
  497
+		-*) ;;
  498
+		*) remote="$i"; break ;;
  499
+		esac
  500
+		((c++))
  501
+	done
  502
+	if [ -z "$remote" ]; then
  503
+		__gitcomp_nl "$(__git_remotes)"
  504
+		return
  505
+	fi
  506
+	if [ $no_complete_refspec = 1 ]; then
  507
+		COMPREPLY=()
  508
+		return
  509
+	fi
  510
+	[ "$remote" = "." ] && remote=
  511
+	case "$cur_" in
  512
+	*:*)
  513
+		case "$COMP_WORDBREAKS" in
  514
+		*:*) : great ;;
  515
+		*)   pfx="${cur_%%:*}:" ;;
  516
+		esac
  517
+		cur_="${cur_#*:}"
  518
+		lhs=0
  519
+		;;
  520
+	+*)
  521
+		pfx="+"
  522
+		cur_="${cur_#+}"
  523
+		;;
  524
+	esac
  525
+	case "$cmd" in
  526
+	fetch)
  527
+		if [ $lhs = 1 ]; then
  528
+			__gitcomp_nl "$(__git_refs2 "$remote")" "$pfx" "$cur_"
  529
+		else
  530
+			__gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
  531
+		fi
  532
+		;;
  533
+	pull|remote)
  534
+		if [ $lhs = 1 ]; then
  535
+			__gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
  536
+		else
  537
+			__gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
  538
+		fi
  539
+		;;
  540
+	push)
  541
+		if [ $lhs = 1 ]; then
  542
+			__gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
  543
+		else
  544
+			__gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
  545
+		fi
  546
+		;;
  547
+	esac
  548
+}
  549
+
  550
+__git_complete_strategy ()
  551
+{
  552
+	__git_compute_merge_strategies
  553
+	case "$prev" in
  554
+	-s|--strategy)
  555
+		__gitcomp "$__git_merge_strategies"
  556
+		return 0
  557
+	esac
  558
+	case "$cur" in
  559
+	--strategy=*)
  560
+		__gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
  561
+		return 0
  562
+		;;
  563
+	esac
  564
+	return 1
  565
+}
  566
+
  567
+__git_list_all_commands ()
  568
+{
  569
+	local i IFS=" "$'\n'
  570
+	for i in $(git help -a|egrep '^  [a-zA-Z0-9]')
  571
+	do
  572
+		case $i in
  573
+		*--*)             : helper pattern;;
  574
+		*) echo $i;;
  575
+		esac
  576
+	done
  577
+}
  578
+
  579
+__git_all_commands=
  580
+__git_compute_all_commands ()
  581
+{
  582
+	test -n "$__git_all_commands" ||
  583
+	__git_all_commands=$(__git_list_all_commands)
  584
+}
  585
+
  586
+__git_list_porcelain_commands ()
  587
+{
  588
+	local i IFS=" "$'\n'
  589
+	__git_compute_all_commands
  590
+	for i in "help" $__git_all_commands
  591
+	do
  592
+		case $i in
  593
+		*--*)             : helper pattern;;
  594
+		applymbox)        : ask gittus;;
  595
+		applypatch)       : ask gittus;;
  596
+		archimport)       : import;;
  597
+		cat-file)         : plumbing;;
  598
+		check-attr)       : plumbing;;
  599
+		check-ref-format) : plumbing;;
  600
+		checkout-index)   : plumbing;;
  601
+		commit-tree)      : plumbing;;
  602
+		count-objects)    : infrequent;;
  603
+		credential-cache) : credentials helper;;
  604
+		credential-store) : credentials helper;;
  605
+		cvsexportcommit)  : export;;
  606
+		cvsimport)        : import;;
  607
+		cvsserver)        : daemon;;
  608
+		daemon)           : daemon;;
  609
+		diff-files)       : plumbing;;
  610
+		diff-index)       : plumbing;;
  611
+		diff-tree)        : plumbing;;
  612
+		fast-import)      : import;;
  613
+		fast-export)      : export;;
  614
+		fsck-objects)     : plumbing;;
  615
+		fetch-pack)       : plumbing;;
  616
+		fmt-merge-msg)    : plumbing;;
  617
+		for-each-ref)     : plumbing;;
  618
+		hash-object)      : plumbing;;
  619
+		http-*)           : transport;;
  620
+		index-pack)       : plumbing;;
  621
+		init-db)          : deprecated;;
  622
+		local-fetch)      : plumbing;;
  623
+		lost-found)       : infrequent;;
  624
+		ls-files)         : plumbing;;
  625
+		ls-remote)        : plumbing;;
  626
+		ls-tree)          : plumbing;;
  627
+		mailinfo)         : plumbing;;
  628
+		mailsplit)        : plumbing;;
  629
+		merge-*)          : plumbing;;
  630
+		mktree)           : plumbing;;
  631
+		mktag)            : plumbing;;
  632
+		pack-objects)     : plumbing;;
  633
+		pack-redundant)   : plumbing;;
  634
+		pack-refs)        : plumbing;;
  635
+		parse-remote)     : plumbing;;
  636
+		patch-id)         : plumbing;;
  637
+		peek-remote)      : plumbing;;
  638
+		prune)            : plumbing;;
  639
+		prune-packed)     : plumbing;;
  640
+		quiltimport)      : import;;
  641
+		read-tree)        : plumbing;;
  642
+		receive-pack)     : plumbing;;
  643
+		remote-*)         : transport;;
  644
+		repo-config)      : deprecated;;
  645
+		rerere)           : plumbing;;
  646
+		rev-list)         : plumbing;;
  647
+		rev-parse)        : plumbing;;
  648
+		runstatus)        : plumbing;;
  649
+		sh-setup)         : internal;;
  650
+		shell)            : daemon;;
  651
+		show-ref)         : plumbing;;
  652
+		send-pack)        : plumbing;;
  653
+		show-index)       : plumbing;;
  654
+		ssh-*)            : transport;;
  655
+		stripspace)       : plumbing;;
  656
+		symbolic-ref)     : plumbing;;
  657
+		tar-tree)         : deprecated;;
  658
+		unpack-file)      : plumbing;;
  659
+		unpack-objects)   : plumbing;;
  660
+		update-index)     : plumbing;;
  661
+		update-ref)       : plumbing;;
  662
+		update-server-info) : daemon;;
  663
+		upload-archive)   : plumbing;;
  664
+		upload-pack)      : plumbing;;
  665
+		write-tree)       : plumbing;;
  666
+		var)              : infrequent;;
  667
+		verify-pack)      : infrequent;;
  668
+		verify-tag)       : plumbing;;
  669
+		*) echo $i;;
  670
+		esac
  671
+	done
  672
+}
  673
+
  674
+__git_porcelain_commands=
  675
+__git_compute_porcelain_commands ()
  676
+{
  677
+	__git_compute_all_commands
  678
+	test -n "$__git_porcelain_commands" ||
  679
+	__git_porcelain_commands=$(__git_list_porcelain_commands)
  680
+}
  681
+
  682
+__git_pretty_aliases ()
  683
+{
  684
+	local i IFS=$'\n'
  685
+	for i in $(git --git-dir="$(__gitdir)" config --get-regexp "pretty\..*" 2>/dev/null); do
  686
+		case "$i" in
  687
+		pretty.*)
  688
+			i="${i#pretty.}"
  689
+			echo "${i/ */}"
  690
+			;;
  691
+		esac
  692
+	done
  693
+}
  694
+
  695
+__git_aliases ()
  696
+{
  697
+	local i IFS=$'\n'
  698
+	for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do
  699
+		case "$i" in
  700
+		alias.*)
  701
+			i="${i#alias.}"
  702
+			echo "${i/ */}"
  703
+			;;
  704
+		esac
  705
+	done
  706
+}
  707
+
  708
+# __git_aliased_command requires 1 argument
  709
+__git_aliased_command ()
  710
+{
  711
+	local word cmdline=$(git --git-dir="$(__gitdir)" \
  712
+		config --get "alias.$1")
  713
+	for word in $cmdline; do
  714
+		case "$word" in
  715
+		\!gitk|gitk)
  716
+			echo "gitk"
  717
+			return
  718
+			;;
  719
+		\!*)	: shell command alias ;;
  720
+		-*)	: option ;;
  721
+		*=*)	: setting env ;;
  722
+		git)	: git itself ;;
  723
+		*)
  724
+			echo "$word"
  725
+			return
  726
+		esac
  727
+	done
  728
+}
  729
+
  730
+# __git_find_on_cmdline requires 1 argument
  731
+__git_find_on_cmdline ()
  732
+{
  733
+	local word subcommand c=1
  734
+	while [ $c -lt $cword ]; do
  735
+		word="${words[c]}"
  736
+		for subcommand in $1; do
  737
+			if [ "$subcommand" = "$word" ]; then
  738
+				echo "$subcommand"
  739
+				return
  740
+			fi
  741
+		done
  742
+		((c++))
  743
+	done
  744
+}
  745
+
  746
+__git_has_doubledash ()
  747
+{
  748
+	local c=1
  749
+	while [ $c -lt $cword ]; do
  750
+		if [ "--" = "${words[c]}" ]; then
  751
+			return 0
  752
+		fi
  753
+		((c++))
  754
+	done
  755
+	return 1
  756
+}
  757
+
  758
+__git_whitespacelist="nowarn warn error error-all fix"
  759
+
  760
+_git_am ()
  761
+{
  762
+	local dir="$(__gitdir)"
  763
+	if [ -d "$dir"/rebase-apply ]; then
  764
+		__gitcomp "--skip --continue --resolved --abort"
  765
+		return
  766
+	fi
  767
+	case "$cur" in
  768
+	--whitespace=*)
  769
+		__gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
  770
+		return
  771
+		;;
  772
+	--*)
  773
+		__gitcomp "
  774
+			--3way --committer-date-is-author-date --ignore-date
  775
+			--ignore-whitespace --ignore-space-change
  776
+			--interactive --keep --no-utf8 --signoff --utf8
  777
+			--whitespace= --scissors
  778
+			"
  779
+		return
  780
+	esac
  781
+	COMPREPLY=()
  782
+}
  783
+
  784
+_git_apply ()
  785
+{
  786
+	case "$cur" in
  787
+	--whitespace=*)
  788
+		__gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
  789
+		return
  790
+		;;
  791
+	--*)
  792
+		__gitcomp "
  793
+			--stat --numstat --summary --check --index
  794
+			--cached --index-info --reverse --reject --unidiff-zero
  795
+			--apply --no-add --exclude=
  796
+			--ignore-whitespace --ignore-space-change
  797
+			--whitespace= --inaccurate-eof --verbose
  798
+			"
  799
+		return
  800
+	esac
  801
+	COMPREPLY=()
  802
+}
  803
+
  804
+_git_add ()
  805
+{
  806
+	__git_has_doubledash && return
  807
+
  808
+	case "$cur" in
  809
+	--*)
  810
+		__gitcomp "
  811
+			--interactive --refresh --patch --update --dry-run
  812
+			--ignore-errors --intent-to-add
  813
+			"
  814
+		return
  815
+	esac
  816
+	COMPREPLY=()
  817
+}
  818
+
  819
+_git_archive ()
  820
+{
  821
+	case "$cur" in
  822
+	--format=*)
  823
+		__gitcomp "$(git archive --list)" "" "${cur##--format=}"
  824
+		return
  825
+		;;
  826
+	--remote=*)
  827
+		__gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
  828
+		return
  829
+		;;
  830
+	--*)
  831
+		__gitcomp "
  832
+			--format= --list --verbose
  833
+			--prefix= --remote= --exec=
  834
+			"
  835
+		return
  836
+		;;
  837
+	esac
  838
+	__git_complete_file
  839
+}
  840
+
  841
+_git_bisect ()
  842
+{
  843
+	__git_has_doubledash && return
  844
+
  845
+	local subcommands="start bad good skip reset visualize replay log run"
  846
+	local subcommand="$(__git_find_on_cmdline "$subcommands")"
  847
+	if [ -z "$subcommand" ]; then
  848
+		if [ -f "$(__gitdir)"/BISECT_START ]; then
  849
+			__gitcomp "$subcommands"
  850
+		else
  851
+			__gitcomp "replay start"
  852
+		fi
  853
+		return
  854
+	fi
  855
+
  856
+	case "$subcommand" in
  857
+	bad|good|reset|skip|start)
  858
+		__gitcomp_nl "$(__git_refs)"
  859
+		;;
  860
+	*)
  861
+		COMPREPLY=()
  862
+		;;
  863
+	esac
  864
+}
  865
+
  866
+_git_branch ()
  867
+{
  868
+	local i c=1 only_local_ref="n" has_r="n"
  869
+
  870
+	while [ $c -lt $cword ]; do
  871
+		i="${words[c]}"
  872
+		case "$i" in
  873
+		-d|-m)	only_local_ref="y" ;;
  874
+		-r)	has_r="y" ;;
  875
+		esac
  876
+		((c++))
  877
+	done
  878
+
  879
+	case "$cur" in
  880
+	--*)
  881
+		__gitcomp "
  882
+			--color --no-color --verbose --abbrev= --no-abbrev
  883
+			--track --no-track --contains --merged --no-merged
  884
+			--set-upstream --edit-description --list
  885
+			"
  886
+		;;
  887
+	*)
  888
+		if [ $only_local_ref = "y" -a $has_r = "n" ]; then
  889
+			__gitcomp_nl "$(__git_heads)"
  890
+		else
  891
+			__gitcomp_nl "$(__git_refs)"
  892
+		fi
  893
+		;;
  894
+	esac
  895
+}
  896
+
  897
+_git_bundle ()
  898
+{
  899
+	local cmd="${words[2]}"
  900
+	case "$cword" in
  901
+	2)
  902
+		__gitcomp "create list-heads verify unbundle"
  903
+		;;
  904
+	3)
  905
+		# looking for a file
  906
+		;;
  907
+	*)
  908
+		case "$cmd" in
  909
+			create)
  910
+				__git_complete_revlist
  911
+			;;
  912
+		esac
  913
+		;;
  914
+	esac
  915
+}
  916
+
  917
+_git_checkout ()
  918
+{
  919
+	__git_has_doubledash && return
  920
+
  921
+	case "$cur" in
  922
+	--conflict=*)
  923
+		__gitcomp "diff3 merge" "" "${cur##--conflict=}"
  924
+		;;
  925
+	--*)
  926
+		__gitcomp "
  927
+			--quiet --ours --theirs --track --no-track --merge
  928
+			--conflict= --orphan --patch
  929
+			"
  930
+		;;
  931
+	*)
  932
+		# check if --track, --no-track, or --no-guess was specified
  933
+		# if so, disable DWIM mode
  934
+		local flags="--track --no-track --no-guess" track=1
  935
+		if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
  936
+			track=''
  937
+		fi
  938
+		__gitcomp_nl "$(__git_refs '' $track)"
  939
+		;;
  940
+	esac
  941
+}
  942
+
  943
+_git_cherry ()
  944
+{
  945
+	__gitcomp "$(__git_refs)"
  946
+}
  947
+
  948
+_git_cherry_pick ()
  949
+{
  950
+	case "$cur" in
  951
+	--*)
  952
+		__gitcomp "--edit --no-commit"
  953
+		;;
  954
+	*)
  955
+		__gitcomp_nl "$(__git_refs)"
  956
+		;;
  957
+	esac
  958
+}
  959
+
  960
+_git_clean ()
  961
+{
  962
+	__git_has_doubledash && return
  963
+
  964
+	case "$cur" in
  965
+	--*)
  966
+		__gitcomp "--dry-run --quiet"
  967
+		return
  968
+		;;
  969
+	esac
  970
+	COMPREPLY=()
  971
+}
  972
+
  973
+_git_clone ()
  974
+{
  975
+	case "$cur" in
  976
+	--*)
  977
+		__gitcomp "
  978
+			--local
  979
+			--no-hardlinks
  980
+			--shared
  981
+			--reference
  982
+			--quiet
  983
+			--no-checkout
  984
+			--bare
  985
+			--mirror
  986
+			--origin
  987
+			--upload-pack
  988
+			--template=
  989
+			--depth
  990
+			"
  991
+		return
  992
+		;;
  993
+	esac
  994
+	COMPREPLY=()
  995
+}
  996
+
  997
+_git_commit ()
  998
+{
  999
+	__git_has_doubledash && return
  1000
+
  1001
+	case "$cur" in
  1002
+	--cleanup=*)
  1003
+		__gitcomp "default strip verbatim whitespace
  1004
+			" "" "${cur##--cleanup=}"
  1005
+		return
  1006
+		;;
  1007
+	--reuse-message=*|--reedit-message=*|\
  1008
+	--fixup=*|--squash=*)
  1009
+		__gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
  1010
+		return
  1011
+		;;
  1012
+	--untracked-files=*)
  1013
+		__gitcomp "all no normal" "" "${cur##--untracked-files=}"
  1014
+		return
  1015
+		;;
  1016
+	--*)
  1017
+		__gitcomp "
  1018
+			--all --author= --signoff --verify --no-verify
  1019
+			--edit --amend --include --only --interactive
  1020
+			--dry-run --reuse-message= --reedit-message=
  1021
+			--reset-author --file= --message= --template=
  1022
+			--cleanup= --untracked-files --untracked-files=
  1023
+			--verbose --quiet --fixup= --squash=
  1024
+			"
  1025
+		return
  1026
+	esac
  1027
+	COMPREPLY=()
  1028
+}
  1029
+
  1030
+_git_describe ()
  1031
+{
  1032
+	case "$cur" in
  1033
+	--*)
  1034
+		__gitcomp "
  1035
+			--all --tags --contains --abbrev= --candidates=
  1036
+			--exact-match --debug --long --match --always
  1037
+			"
  1038
+		return
  1039
+	esac
  1040
+	__gitcomp_nl "$(__git_refs)"
  1041
+}
  1042
+
  1043
+__git_diff_common_options="--stat --numstat --shortstat --summary
  1044
+			--patch-with-stat --name-only --name-status --color
  1045
+			--no-color --color-words --no-renames --check
  1046
+			--full-index --binary --abbrev --diff-filter=
  1047
+			--find-copies-harder
  1048
+			--text --ignore-space-at-eol --ignore-space-change
  1049
+			--ignore-all-space --exit-code --quiet --ext-diff
  1050
+			--no-ext-diff
  1051
+			--no-prefix --src-prefix= --dst-prefix=
  1052
+			--inter-hunk-context=
  1053
+			--patience
  1054
+			--raw
  1055
+			--dirstat --dirstat= --dirstat-by-file
  1056
+			--dirstat-by-file= --cumulative
  1057
+"
  1058
+
  1059
+_git_diff ()
  1060
+{
  1061
+	__git_has_doubledash && return
  1062
+
  1063
+	case "$cur" in
  1064
+	--*)
  1065
+		__gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
  1066
+			--base --ours --theirs --no-index
  1067
+			$__git_diff_common_options
  1068
+			"
  1069
+		return
  1070
+		;;
  1071
+	esac
  1072
+	__git_complete_revlist_file
  1073
+}
  1074
+
  1075
+__git_mergetools_common="diffuse ecmerge emerge kdiff3 meld opendiff
  1076
+			tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc3
  1077
+"
  1078
+
  1079
+_git_difftool ()
  1080
+{
  1081
+	__git_has_doubledash && return
  1082
+
  1083
+	case "$cur" in
  1084
+	--tool=*)
  1085
+		__gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
  1086
+		return
  1087
+		;;
  1088
+	--*)
  1089
+		__gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
  1090
+			--base --ours --theirs
  1091
+			--no-renames --diff-filter= --find-copies-harder
  1092
+			--relative --ignore-submodules
  1093
+			--tool="
  1094
+		return
  1095
+		;;
  1096
+	esac
  1097
+	__git_complete_file
  1098
+}
  1099
+
  1100
+__git_fetch_options="
  1101
+	--quiet --verbose --append --upload-pack --force --keep --depth=
  1102
+	--tags --no-tags --all --prune --dry-run
  1103
+"
  1104
+
  1105
+_git_fetch ()
  1106
+{
  1107
+	case "$cur" in
  1108
+	--*)
  1109
+		__gitcomp "$__git_fetch_options"
  1110
+		return
  1111
+		;;
  1112
+	esac
  1113
+	__git_complete_remote_or_refspec
  1114
+}
  1115
+
  1116
+_git_format_patch ()
  1117
+{
  1118
+	case "$cur" in
  1119
+	--thread=*)
  1120
+		__gitcomp "
  1121
+			deep shallow
  1122
+			" "" "${cur##--thread=}"
  1123
+		return
  1124
+		;;
  1125
+	--*)
  1126
+		__gitcomp "
  1127
+			--stdout --attach --no-attach --thread --thread=
  1128
+			--output-directory
  1129
+			--numbered --start-number
  1130
+			--numbered-files
  1131
+			--keep-subject
  1132
+			--signoff --signature --no-signature
  1133
+			--in-reply-to= --cc=
  1134
+			--full-index --binary
  1135
+			--not --all
  1136
+			--cover-letter
  1137
+			--no-prefix --src-prefix= --dst-prefix=
  1138
+			--inline --suffix= --ignore-if-in-upstream
  1139
+			--subject-prefix=
  1140
+			"
  1141
+		return
  1142
+		;;
  1143
+	esac
  1144
+	__git_complete_revlist
  1145
+}
  1146
+
  1147
+_git_fsck ()
  1148
+{
  1149
+	case "$cur" in
  1150
+	--*)
  1151
+		__gitcomp "
  1152
+			--tags --root --unreachable --cache --no-reflogs --full
  1153
+			--strict --verbose --lost-found
  1154
+			"
  1155
+		return
  1156
+		;;
  1157
+	esac
  1158
+	COMPREPLY=()
  1159
+}
  1160
+
  1161
+_git_gc ()
  1162
+{
  1163
+	case "$cur" in
  1164
+	--*)
  1165
+		__gitcomp "--prune --aggressive"
  1166
+		return