git-completion.bash 45.3 KB
Newer Older
1
#!bash
2 3 4
#
# 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.
8 9 10 11 12 13 14 15
#
# The contained completion routines provide support for completing:
#
#    *) local and remote branch names
#    *) local and remote tag names
#    *) .git/remotes file names
#    *) git 'subcommands'
#    *) tree paths within 'ref:path/to/file' expressions
16
#    *) common --long-options
17 18 19 20 21 22 23
#
# To use these routines:
#
#    1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
#    2) Added the following line to your .bashrc:
#        source ~/.git-completion.sh
#
J
Jonathan Nieder 已提交
24
#    3) Consider changing your PS1 to also show the current branch:
25 26 27 28 29 30
#        PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
#
#       The argument to __git_ps1 will be displayed only if you
#       are currently in a git repository.  The %s token will be
#       the name of the current branch.
#
31 32 33 34 35
#       In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty
#       value, unstaged (*) and staged (+) changes will be shown next
#       to the branch name.  You can configure this per-repository
#       with the bash.showDirtyState variable, which defaults to true
#       once GIT_PS1_SHOWDIRTYSTATE is enabled.
36
#
37 38 39 40
#       You can also see if currently something is stashed, by setting
#       GIT_PS1_SHOWSTASHSTATE to a nonempty value. If something is stashed,
#       then a '$' will be shown next to the branch name.
#
41 42 43 44
#       If you would like to see if there're untracked files, then you can
#       set GIT_PS1_SHOWUNTRACKEDFILES to a nonempty value. If there're
#       untracked files, then a '%' will be shown next to the branch name.
#
45 46 47 48 49 50 51 52 53 54 55
# To submit patches:
#
#    *) Read Documentation/SubmittingPatches
#    *) Send all patches to the current maintainer:
#
#       "Shawn O. Pearce" <spearce@spearce.org>
#
#    *) Always CC the Git mailing list:
#
#       git@vger.kernel.org
#
56

57 58 59 60 61
case "$COMP_WORDBREAKS" in
*:*) : great ;;
*)   COMP_WORDBREAKS="$COMP_WORDBREAKS:"
esac

62 63
# __gitdir accepts 0 or 1 arguments (i.e., location)
# returns location of .git repo
64 65
__gitdir ()
{
66
	if [ -z "${1-}" ]; then
67
		if [ -n "${__git_dir-}" ]; then
68 69 70 71 72 73 74 75 76 77 78
			echo "$__git_dir"
		elif [ -d .git ]; then
			echo .git
		else
			git rev-parse --git-dir 2>/dev/null
		fi
	elif [ -d "$1/.git" ]; then
		echo "$1/.git"
	else
		echo "$1"
	fi
79 80
}

81 82
# __git_ps1 accepts 0 or 1 arguments (i.e., format string)
# returns text to add to bash PS1 prompt (includes branch name)
83 84
__git_ps1 ()
{
85
	local g="$(__gitdir)"
86 87 88
	if [ -n "$g" ]; then
		local r
		local b
89
		if [ -f "$g/rebase-merge/interactive" ]; then
90
			r="|REBASE-i"
91
			b="$(cat "$g/rebase-merge/head-name")"
92
		elif [ -d "$g/rebase-merge" ]; then
93
			r="|REBASE-m"
94
			b="$(cat "$g/rebase-merge/head-name")"
95
		else
96 97 98 99 100 101 102 103 104
			if [ -d "$g/rebase-apply" ]; then
				if [ -f "$g/rebase-apply/rebasing" ]; then
					r="|REBASE"
				elif [ -f "$g/rebase-apply/applying" ]; then
					r="|AM"
				else
					r="|AM/REBASE"
				fi
			elif [ -f "$g/MERGE_HEAD" ]; then
105
				r="|MERGING"
106
			elif [ -f "$g/BISECT_LOG" ]; then
107 108
				r="|BISECTING"
			fi
109 110

			b="$(git symbolic-ref HEAD 2>/dev/null)" || {
111 112 113 114 115 116 117 118 119 120 121 122 123

				b="$(
				case "${GIT_PS1_DESCRIBE_STYLE-}" in
				(contains)
					git describe --contains HEAD ;;
				(branch)
					git describe --contains --all HEAD ;;
				(describe)
					git describe HEAD ;;
				(* | default)
					git describe --exact-match HEAD ;;
				esac 2>/dev/null)" ||

124 125 126 127
				b="$(cut -c1-7 "$g/HEAD" 2>/dev/null)..." ||
				b="unknown"
				b="($b)"
			}
128 129
		fi

130 131
		local w
		local i
132
		local s
133
		local u
134
		local c
135

136
		if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then
137
			if [ "true" = "$(git rev-parse --is-bare-repository 2>/dev/null)" ]; then
138 139 140 141
				c="BARE:"
			else
				b="GIT_DIR!"
			fi
142 143 144
		elif [ "true" = "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then
			if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ]; then
				if [ "$(git config --bool bash.showDirtyState)" != "false" ]; then
145
					git diff --no-ext-diff --quiet --exit-code || w="*"
146
					if git rev-parse --quiet --verify HEAD >/dev/null; then
147
						git diff-index --cached --quiet HEAD -- || i="+"
148 149 150
					else
						i="#"
					fi
151 152
				fi
			fi
153 154 155
			if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ]; then
			        git rev-parse --verify refs/stash >/dev/null 2>&1 && s="$"
			fi
156 157 158 159 160 161

			if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ]; then
			   if [ -n "$(git ls-files --others --exclude-standard)" ]; then
			      u="%"
			   fi
			fi
162 163
		fi

164 165
		local f="$w$i$s$u"
		printf "${1:- (%s)}" "$c${b##refs/heads/}${f:+ $f}$r"
166 167 168
	fi
}

169
# __gitcomp_1 requires 2 arguments
170 171 172 173 174 175 176 177 178 179 180 181
__gitcomp_1 ()
{
	local c IFS=' '$'\t'$'\n'
	for c in $1; do
		case "$c$2" in
		--*=*) printf %s$'\n' "$c$2" ;;
		*.)    printf %s$'\n' "$c$2" ;;
		*)     printf %s$'\n' "$c$2 " ;;
		esac
	done
}

182 183
# __gitcomp accepts 1, 2, 3, or 4 arguments
# generates completion reply with compgen
184 185
__gitcomp ()
{
186
	local cur="${COMP_WORDS[COMP_CWORD]}"
187
	if [ $# -gt 2 ]; then
188 189
		cur="$3"
	fi
190 191 192 193 194
	case "$cur" in
	--*=)
		COMPREPLY=()
		;;
	*)
195
		local IFS=$'\n'
196 197
		COMPREPLY=($(compgen -P "${2-}" \
			-W "$(__gitcomp_1 "${1-}" "${4-}")" \
198
			-- "$cur"))
199 200
		;;
	esac
201 202
}

203
# __git_heads accepts 0 or 1 arguments (to pass to __gitdir)
204 205
__git_heads ()
{
206
	local cmd i is_hash=y dir="$(__gitdir "${1-}")"
207
	if [ -d "$dir" ]; then
208 209
		git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
			refs/heads
210 211
		return
	fi
212
	for i in $(git ls-remote "${1-}" 2>/dev/null); do
213 214 215 216 217 218 219 220 221
		case "$is_hash,$i" in
		y,*) is_hash=n ;;
		n,*^{}) is_hash=y ;;
		n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
		n,*) is_hash=y; echo "$i" ;;
		esac
	done
}

222
# __git_tags accepts 0 or 1 arguments (to pass to __gitdir)
223 224
__git_tags ()
{
225
	local cmd i is_hash=y dir="$(__gitdir "${1-}")"
226
	if [ -d "$dir" ]; then
227 228
		git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
			refs/tags
229 230
		return
	fi
231
	for i in $(git ls-remote "${1-}" 2>/dev/null); do
232 233 234 235 236 237 238 239 240
		case "$is_hash,$i" in
		y,*) is_hash=n ;;
		n,*^{}) is_hash=y ;;
		n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
		n,*) is_hash=y; echo "$i" ;;
		esac
	done
}

241
# __git_refs accepts 0 or 1 arguments (to pass to __gitdir)
242 243
__git_refs ()
{
244
	local i is_hash=y dir="$(__gitdir "${1-}")"
S
SZEDER Gábor 已提交
245
	local cur="${COMP_WORDS[COMP_CWORD]}" format refs
246
	if [ -d "$dir" ]; then
S
SZEDER Gábor 已提交
247 248 249 250 251 252 253 254 255 256 257 258 259
		case "$cur" in
		refs|refs/*)
			format="refname"
			refs="${cur%/*}"
			;;
		*)
			if [ -e "$dir/HEAD" ]; then echo HEAD; fi
			format="refname:short"
			refs="refs/tags refs/heads refs/remotes"
			;;
		esac
		git --git-dir="$dir" for-each-ref --format="%($format)" \
			$refs
260
		return
261
	fi
262
	for i in $(git ls-remote "$dir" 2>/dev/null); do
263 264 265 266 267
		case "$is_hash,$i" in
		y,*) is_hash=n ;;
		n,*^{}) is_hash=y ;;
		n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
		n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
268
		n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
269 270 271 272 273
		n,*) is_hash=y; echo "$i" ;;
		esac
	done
}

274
# __git_refs2 requires 1 argument (to pass to __git_refs)
275 276
__git_refs2 ()
{
277 278 279
	local i
	for i in $(__git_refs "$1"); do
		echo "$i:$i"
280 281 282
	done
}

283
# __git_refs_remotes requires 1 argument (to pass to ls-remote)
284 285 286
__git_refs_remotes ()
{
	local cmd i is_hash=y
287
	for i in $(git ls-remote "$1" 2>/dev/null); do
288 289 290 291 292 293 294 295 296 297 298 299 300
		case "$is_hash,$i" in
		n,refs/heads/*)
			is_hash=y
			echo "$i:refs/remotes/$1/${i#refs/heads/}"
			;;
		y,*) is_hash=n ;;
		n,*^{}) is_hash=y ;;
		n,refs/tags/*) is_hash=y;;
		n,*) is_hash=y; ;;
		esac
	done
}

301 302
__git_remotes ()
{
303
	local i ngoff IFS=$'\n' d="$(__gitdir)"
304
	shopt -q nullglob || ngoff=1
305
	shopt -s nullglob
306 307
	for i in "$d/remotes"/*; do
		echo ${i#$d/remotes/}
308
	done
309
	[ "$ngoff" ] && shopt -u nullglob
310 311 312
	for i in $(git --git-dir="$d" config --get-regexp 'remote\..*\.url' 2>/dev/null); do
		i="${i#remote.}"
		echo "${i/.url*/}"
313
	done
314 315
}

J
Jonathan Nieder 已提交
316
__git_list_merge_strategies ()
317
{
318 319 320 321 322 323
	git merge -s help 2>&1 |
	sed -n -e '/[Aa]vailable strategies are: /,/^$/{
		s/\.$//
		s/.*://
		s/^[ 	]*//
		s/[ 	]*$//
324
		p
325
	}'
326
}
J
Jonathan Nieder 已提交
327 328 329 330 331 332 333 334 335 336 337

__git_merge_strategies=
# 'git merge -s help' (and thus detection of the merge strategy
# list) fails, unfortunately, if run outside of any git working
# tree.  __git_merge_strategies is set to the empty string in
# that case, and the detection will be repeated the next time it
# is needed.
__git_compute_merge_strategies ()
{
	: ${__git_merge_strategies:=$(__git_list_merge_strategies)}
}
338

339 340
__git_complete_file ()
{
341
	local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
342 343
	case "$cur" in
	?*:*)
344 345
		ref="${cur%%:*}"
		cur="${cur#*:}"
346 347
		case "$cur" in
		?*/*)
348 349
			pfx="${cur%/*}"
			cur="${cur##*/}"
350 351 352 353 354 355 356
			ls="$ref:$pfx"
			pfx="$pfx/"
			;;
		*)
			ls="$ref"
			;;
	    esac
357 358 359 360 361 362

		case "$COMP_WORDBREAKS" in
		*:*) : great ;;
		*)   pfx="$ref:$pfx" ;;
		esac

363
		local IFS=$'\n'
364
		COMPREPLY=($(compgen -P "$pfx" \
365
			-W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
366 367 368 369 370 371 372 373
				| sed '/^100... blob /{
				           s,^.*	,,
				           s,$, ,
				       }
				       /^120000 blob /{
				           s,^.*	,,
				           s,$, ,
				       }
374 375 376 377 378 379 380 381
				       /^040000 tree /{
				           s,^.*	,,
				           s,$,/,
				       }
				       s/^.*	//')" \
			-- "$cur"))
		;;
	*)
382
		__gitcomp "$(__git_refs)"
383 384 385 386
		;;
	esac
}

387 388 389 390 391 392 393
__git_complete_revlist ()
{
	local pfx cur="${COMP_WORDS[COMP_CWORD]}"
	case "$cur" in
	*...*)
		pfx="${cur%...*}..."
		cur="${cur#*...}"
394
		__gitcomp "$(__git_refs)" "$pfx" "$cur"
395 396 397 398
		;;
	*..*)
		pfx="${cur%..*}.."
		cur="${cur#*..}"
399 400
		__gitcomp "$(__git_refs)" "$pfx" "$cur"
		;;
401
	*)
402
		__gitcomp "$(__git_refs)"
403 404 405 406
		;;
	esac
}

407 408 409 410
__git_complete_remote_or_refspec ()
{
	local cmd="${COMP_WORDS[1]}"
	local cur="${COMP_WORDS[COMP_CWORD]}"
411
	local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
412 413 414
	while [ $c -lt $COMP_CWORD ]; do
		i="${COMP_WORDS[c]}"
		case "$i" in
415 416 417 418 419 420 421 422 423 424 425
		--mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
		--all)
			case "$cmd" in
			push) no_complete_refspec=1 ;;
			fetch)
				COMPREPLY=()
				return
				;;
			*) ;;
			esac
			;;
426 427 428 429 430 431 432 433 434
		-*) ;;
		*) remote="$i"; break ;;
		esac
		c=$((++c))
	done
	if [ -z "$remote" ]; then
		__gitcomp "$(__git_remotes)"
		return
	fi
435 436 437 438
	if [ $no_complete_refspec = 1 ]; then
		COMPREPLY=()
		return
	fi
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478
	[ "$remote" = "." ] && remote=
	case "$cur" in
	*:*)
		case "$COMP_WORDBREAKS" in
		*:*) : great ;;
		*)   pfx="${cur%%:*}:" ;;
		esac
		cur="${cur#*:}"
		lhs=0
		;;
	+*)
		pfx="+"
		cur="${cur#+}"
		;;
	esac
	case "$cmd" in
	fetch)
		if [ $lhs = 1 ]; then
			__gitcomp "$(__git_refs2 "$remote")" "$pfx" "$cur"
		else
			__gitcomp "$(__git_refs)" "$pfx" "$cur"
		fi
		;;
	pull)
		if [ $lhs = 1 ]; then
			__gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
		else
			__gitcomp "$(__git_refs)" "$pfx" "$cur"
		fi
		;;
	push)
		if [ $lhs = 1 ]; then
			__gitcomp "$(__git_refs)" "$pfx" "$cur"
		else
			__gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
		fi
		;;
	esac
}

479 480
__git_complete_strategy ()
{
J
Jonathan Nieder 已提交
481
	__git_compute_merge_strategies
482 483
	case "${COMP_WORDS[COMP_CWORD-1]}" in
	-s|--strategy)
J
Jonathan Nieder 已提交
484
		__gitcomp "$__git_merge_strategies"
485 486 487 488 489
		return 0
	esac
	local cur="${COMP_WORDS[COMP_CWORD]}"
	case "$cur" in
	--strategy=*)
J
Jonathan Nieder 已提交
490
		__gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
491 492 493 494 495 496
		return 0
		;;
	esac
	return 1
}

J
Jonathan Nieder 已提交
497
__git_list_all_commands ()
498 499
{
	local i IFS=" "$'\n'
500
	for i in $(git help -a|egrep '^  [a-zA-Z0-9]')
501 502 503 504 505 506 507 508
	do
		case $i in
		*--*)             : helper pattern;;
		*) echo $i;;
		esac
	done
}

J
Jonathan Nieder 已提交
509 510 511 512 513 514 515
__git_all_commands=
__git_compute_all_commands ()
{
	: ${__git_all_commands:=$(__git_list_all_commands)}
}

__git_list_porcelain_commands ()
516 517
{
	local i IFS=" "$'\n'
J
Jonathan Nieder 已提交
518 519
	__git_compute_all_commands
	for i in "help" $__git_all_commands
520 521
	do
		case $i in
522
		*--*)             : helper pattern;;
523 524 525
		applymbox)        : ask gittus;;
		applypatch)       : ask gittus;;
		archimport)       : import;;
526
		cat-file)         : plumbing;;
527
		check-attr)       : plumbing;;
528
		check-ref-format) : plumbing;;
529
		checkout-index)   : plumbing;;
530
		commit-tree)      : plumbing;;
531
		count-objects)    : infrequent;;
532 533
		cvsexportcommit)  : export;;
		cvsimport)        : import;;
534 535
		cvsserver)        : daemon;;
		daemon)           : daemon;;
536 537 538
		diff-files)       : plumbing;;
		diff-index)       : plumbing;;
		diff-tree)        : plumbing;;
S
Shawn O. Pearce 已提交
539
		fast-import)      : import;;
540
		fast-export)      : export;;
541
		fsck-objects)     : plumbing;;
542
		fetch-pack)       : plumbing;;
543
		fmt-merge-msg)    : plumbing;;
544
		for-each-ref)     : plumbing;;
545 546 547
		hash-object)      : plumbing;;
		http-*)           : transport;;
		index-pack)       : plumbing;;
548
		init-db)          : deprecated;;
549
		local-fetch)      : plumbing;;
550 551 552 553
		lost-found)       : infrequent;;
		ls-files)         : plumbing;;
		ls-remote)        : plumbing;;
		ls-tree)          : plumbing;;
554 555 556 557 558 559 560 561 562 563 564
		mailinfo)         : plumbing;;
		mailsplit)        : plumbing;;
		merge-*)          : plumbing;;
		mktree)           : plumbing;;
		mktag)            : plumbing;;
		pack-objects)     : plumbing;;
		pack-redundant)   : plumbing;;
		pack-refs)        : plumbing;;
		parse-remote)     : plumbing;;
		patch-id)         : plumbing;;
		peek-remote)      : plumbing;;
565 566 567
		prune)            : plumbing;;
		prune-packed)     : plumbing;;
		quiltimport)      : import;;
568 569
		read-tree)        : plumbing;;
		receive-pack)     : plumbing;;
570
		reflog)           : plumbing;;
571
		remote-*)         : transport;;
572
		repo-config)      : deprecated;;
573 574 575 576 577 578
		rerere)           : plumbing;;
		rev-list)         : plumbing;;
		rev-parse)        : plumbing;;
		runstatus)        : plumbing;;
		sh-setup)         : internal;;
		shell)            : daemon;;
579
		show-ref)         : plumbing;;
580 581 582 583 584
		send-pack)        : plumbing;;
		show-index)       : plumbing;;
		ssh-*)            : transport;;
		stripspace)       : plumbing;;
		symbolic-ref)     : plumbing;;
585
		tar-tree)         : deprecated;;
586 587
		unpack-file)      : plumbing;;
		unpack-objects)   : plumbing;;
588
		update-index)     : plumbing;;
589 590 591 592 593
		update-ref)       : plumbing;;
		update-server-info) : daemon;;
		upload-archive)   : plumbing;;
		upload-pack)      : plumbing;;
		write-tree)       : plumbing;;
594 595
		var)              : infrequent;;
		verify-pack)      : infrequent;;
596
		verify-tag)       : plumbing;;
597 598 599 600
		*) echo $i;;
		esac
	done
}
J
Jonathan Nieder 已提交
601 602 603 604 605 606 607

__git_porcelain_commands=
__git_compute_porcelain_commands ()
{
	__git_compute_all_commands
	: ${__git_porcelain_commands:=$(__git_list_porcelain_commands)}
}
608

609 610
__git_aliases ()
{
611
	local i IFS=$'\n'
612
	for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do
613 614 615 616 617 618
		case "$i" in
		alias.*)
			i="${i#alias.}"
			echo "${i/ */}"
			;;
		esac
619
	done
620 621
}

622
# __git_aliased_command requires 1 argument
623 624
__git_aliased_command ()
{
625
	local word cmdline=$(git --git-dir="$(__gitdir)" \
626
		config --get "alias.$1")
627 628 629 630 631 632 633 634
	for word in $cmdline; do
		if [ "${word##-*}" ]; then
			echo $word
			return
		fi
	done
}

635 636
# __git_find_on_cmdline requires 1 argument
__git_find_on_cmdline ()
637 638 639 640 641 642 643 644 645 646 647 648 649 650 651
{
	local word subcommand c=1

	while [ $c -lt $COMP_CWORD ]; do
		word="${COMP_WORDS[c]}"
		for subcommand in $1; do
			if [ "$subcommand" = "$word" ]; then
				echo "$subcommand"
				return
			fi
		done
		c=$((++c))
	done
}

652 653 654 655 656 657 658 659 660 661 662 663
__git_has_doubledash ()
{
	local c=1
	while [ $c -lt $COMP_CWORD ]; do
		if [ "--" = "${COMP_WORDS[c]}" ]; then
			return 0
		fi
		c=$((++c))
	done
	return 1
}

664
__git_whitespacelist="nowarn warn error error-all fix"
665 666 667

_git_am ()
{
668
	local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
669
	if [ -d "$dir"/rebase-apply ]; then
670
		__gitcomp "--skip --continue --resolved --abort"
671 672 673 674
		return
	fi
	case "$cur" in
	--whitespace=*)
675
		__gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
676 677 678
		return
		;;
	--*)
679
		__gitcomp "
680
			--3way --committer-date-is-author-date --ignore-date
681
			--ignore-whitespace --ignore-space-change
682
			--interactive --keep --no-utf8 --signoff --utf8
683
			--whitespace= --scissors
684
			"
685 686 687 688 689 690 691 692 693 694
		return
	esac
	COMPREPLY=()
}

_git_apply ()
{
	local cur="${COMP_WORDS[COMP_CWORD]}"
	case "$cur" in
	--whitespace=*)
695
		__gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
696 697 698
		return
		;;
	--*)
699
		__gitcomp "
700 701 702
			--stat --numstat --summary --check --index
			--cached --index-info --reverse --reject --unidiff-zero
			--apply --no-add --exclude=
703
			--ignore-whitespace --ignore-space-change
704
			--whitespace= --inaccurate-eof --verbose
705
			"
706 707 708 709 710
		return
	esac
	COMPREPLY=()
}

711 712
_git_add ()
{
713 714
	__git_has_doubledash && return

715 716 717
	local cur="${COMP_WORDS[COMP_CWORD]}"
	case "$cur" in
	--*)
718 719
		__gitcomp "
			--interactive --refresh --patch --update --dry-run
720
			--ignore-errors --intent-to-add
721
			"
722 723 724 725 726
		return
	esac
	COMPREPLY=()
}

727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749
_git_archive ()
{
	local cur="${COMP_WORDS[COMP_CWORD]}"
	case "$cur" in
	--format=*)
		__gitcomp "$(git archive --list)" "" "${cur##--format=}"
		return
		;;
	--remote=*)
		__gitcomp "$(__git_remotes)" "" "${cur##--remote=}"
		return
		;;
	--*)
		__gitcomp "
			--format= --list --verbose
			--prefix= --remote= --exec=
			"
		return
		;;
	esac
	__git_complete_file
}

750 751
_git_bisect ()
{
752 753
	__git_has_doubledash && return

754
	local subcommands="start bad good skip reset visualize replay log run"
755
	local subcommand="$(__git_find_on_cmdline "$subcommands")"
756 757
	if [ -z "$subcommand" ]; then
		__gitcomp "$subcommands"
758 759 760
		return
	fi

761
	case "$subcommand" in
762
	bad|good|reset|skip)
763 764 765 766 767 768 769 770
		__gitcomp "$(__git_refs)"
		;;
	*)
		COMPREPLY=()
		;;
	esac
}

771 772
_git_branch ()
{
773 774 775 776 777 778 779 780 781 782 783
	local i c=1 only_local_ref="n" has_r="n"

	while [ $c -lt $COMP_CWORD ]; do
		i="${COMP_WORDS[c]}"
		case "$i" in
		-d|-m)	only_local_ref="y" ;;
		-r)	has_r="y" ;;
		esac
		c=$((++c))
	done

S
SZEDER Gábor 已提交
784 785 786 787
	case "${COMP_WORDS[COMP_CWORD]}" in
	--*)
		__gitcomp "
			--color --no-color --verbose --abbrev= --no-abbrev
788
			--track --no-track --contains --merged --no-merged
S
SZEDER Gábor 已提交
789 790
			"
		;;
791 792 793 794 795 796 797
	*)
		if [ $only_local_ref = "y" -a $has_r = "n" ]; then
			__gitcomp "$(__git_heads)"
		else
			__gitcomp "$(__git_refs)"
		fi
		;;
S
SZEDER Gábor 已提交
798
	esac
799 800
}

801 802
_git_bundle ()
{
803 804 805
	local cmd="${COMP_WORDS[2]}"
	case "$COMP_CWORD" in
	2)
806 807
		__gitcomp "create list-heads verify unbundle"
		;;
808
	3)
809 810 811 812 813 814 815 816 817 818 819 820
		# looking for a file
		;;
	*)
		case "$cmd" in
			create)
				__git_complete_revlist
			;;
		esac
		;;
	esac
}

821 822
_git_checkout ()
{
823 824
	__git_has_doubledash && return

825 826 827 828 829 830 831 832 833 834 835 836 837 838 839
	local cur="${COMP_WORDS[COMP_CWORD]}"
	case "$cur" in
	--conflict=*)
		__gitcomp "diff3 merge" "" "${cur##--conflict=}"
		;;
	--*)
		__gitcomp "
			--quiet --ours --theirs --track --no-track --merge
			--conflict= --patch
			"
		;;
	*)
		__gitcomp "$(__git_refs)"
		;;
	esac
840 841
}

842 843 844 845 846
_git_cherry ()
{
	__gitcomp "$(__git_refs)"
}

847 848 849 850 851
_git_cherry_pick ()
{
	local cur="${COMP_WORDS[COMP_CWORD]}"
	case "$cur" in
	--*)
852
		__gitcomp "--edit --no-commit"
853 854
		;;
	*)
855
		__gitcomp "$(__git_refs)"
856 857 858 859
		;;
	esac
}

860 861 862 863 864 865 866 867 868 869 870 871 872 873
_git_clean ()
{
	__git_has_doubledash && return

	local cur="${COMP_WORDS[COMP_CWORD]}"
	case "$cur" in
	--*)
		__gitcomp "--dry-run --quiet"
		return
		;;
	esac
	COMPREPLY=()
}

874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898
_git_clone ()
{
	local cur="${COMP_WORDS[COMP_CWORD]}"
	case "$cur" in
	--*)
		__gitcomp "
			--local
			--no-hardlinks
			--shared
			--reference
			--quiet
			--no-checkout
			--bare
			--mirror
			--origin
			--upload-pack
			--template=
			--depth
			"
		return
		;;
	esac
	COMPREPLY=()
}

899 900
_git_commit ()
{
901 902
	__git_has_doubledash && return

903 904
	local cur="${COMP_WORDS[COMP_CWORD]}"
	case "$cur" in
905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921
	--cleanup=*)
		__gitcomp "default strip verbatim whitespace
			" "" "${cur##--cleanup=}"
		return
		;;
	--reuse-message=*)
		__gitcomp "$(__git_refs)" "" "${cur##--reuse-message=}"
		return
		;;
	--reedit-message=*)
		__gitcomp "$(__git_refs)" "" "${cur##--reedit-message=}"
		return
		;;
	--untracked-files=*)
		__gitcomp "all no normal" "" "${cur##--untracked-files=}"
		return
		;;
922
	--*)
923
		__gitcomp "
924
			--all --author= --signoff --verify --no-verify
925
			--edit --amend --include --only --interactive
926 927 928 929
			--dry-run --reuse-message= --reedit-message=
			--reset-author --file= --message= --template=
			--cleanup= --untracked-files --untracked-files=
			--verbose --quiet
930
			"
931 932 933 934 935
		return
	esac
	COMPREPLY=()
}

936 937
_git_describe ()
{
938 939 940 941 942 943 944 945 946
	local cur="${COMP_WORDS[COMP_CWORD]}"
	case "$cur" in
	--*)
		__gitcomp "
			--all --tags --contains --abbrev= --candidates=
			--exact-match --debug --long --match --always
			"
		return
	esac
947 948 949
	__gitcomp "$(__git_refs)"
}

950
__git_diff_common_options="--stat --numstat --shortstat --summary
951 952
			--patch-with-stat --name-only --name-status --color
			--no-color --color-words --no-renames --check
953
			--full-index --binary --abbrev --diff-filter=
954
			--find-copies-harder
955 956
			--text --ignore-space-at-eol --ignore-space-change
			--ignore-all-space --exit-code --quiet --ext-diff
957 958
			--no-ext-diff
			--no-prefix --src-prefix= --dst-prefix=
959
			--inter-hunk-context=
960
			--patience
961
			--raw
962 963
			--dirstat --dirstat= --dirstat-by-file
			--dirstat-by-file= --cumulative
964 965 966 967 968 969 970 971 972
"

_git_diff ()
{
	__git_has_doubledash && return

	local cur="${COMP_WORDS[COMP_CWORD]}"
	case "$cur" in
	--*)
973
		__gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
974 975
			--base --ours --theirs
			$__git_diff_common_options
976
			"
977 978 979
		return
		;;
	esac
980 981 982
	__git_complete_file
}

983
__git_mergetools_common="diffuse ecmerge emerge kdiff3 meld opendiff
984
			tkdiff vimdiff gvimdiff xxdiff araxis p4merge
985 986 987 988
"

_git_difftool ()
{
989 990
	__git_has_doubledash && return

991 992 993 994 995 996 997
	local cur="${COMP_WORDS[COMP_CWORD]}"
	case "$cur" in
	--tool=*)
		__gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
		return
		;;
	--*)
998 999 1000 1001 1002
		__gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
			--base --ours --theirs
			--no-renames --diff-filter= --find-copies-harder
			--relative --ignore-submodules
			--tool="
1003 1004 1005
		return
		;;
	esac
1006
	__git_complete_file
1007 1008
}

1009 1010
__git_fetch_options="
	--quiet --verbose --append --upload-pack --force --keep --depth=
1011
	--tags --no-tags --all --prune --dry-run
1012 1013
"

1014 1015
_git_fetch ()
{
1016 1017 1018 1019 1020 1021 1022
	local cur="${COMP_WORDS[COMP_CWORD]}"
	case "$cur" in
	--*)
		__gitcomp "$__git_fetch_options"
		return
		;;
	esac
1023
	__git_complete_remote_or_refspec
1024 1025
}

1026 1027 1028 1029
_git_format_patch ()
{
	local cur="${COMP_WORDS[COMP_CWORD]}"
	case "$cur" in
1030 1031 1032 1033 1034 1035
	--thread=*)
		__gitcomp "
			deep shallow
			" "" "${cur##--thread=}"
		return
		;;
1036
	--*)
1037
		__gitcomp "
1038
			--stdout --attach --no-attach --thread --thread=
1039 1040
			--output-directory
			--numbered --start-number
1041
			--numbered-files
1042 1043
			--keep-subject
			--signoff
1044
			--in-reply-to= --cc=
1045
			--full-index --binary
1046
			--not --all
1047
			--cover-letter
1048
			--no-prefix --src-prefix= --dst-prefix=
1049 1050
			--inline --suffix= --ignore-if-in-upstream
			--subject-prefix=
1051
			"
1052 1053 1054 1055 1056 1057
		return
		;;
	esac
	__git_complete_revlist
}

1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072
_git_fsck ()
{
	local cur="${COMP_WORDS[COMP_CWORD]}"
	case "$cur" in
	--*)
		__gitcomp "
			--tags --root --unreachable --cache --no-reflogs --full
			--strict --verbose --lost-found
			"
		return
		;;
	esac
	COMPREPLY=()
}

1073 1074 1075 1076 1077
_git_gc ()
{
	local cur="${COMP_WORDS[COMP_CWORD]}"
	case "$cur" in
	--*)
1078
		__gitcomp "--prune --aggressive"
1079 1080 1081 1082 1083 1084
		return
		;;
	esac
	COMPREPLY=()
}

1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098
_git_grep ()
{
	__git_has_doubledash && return

	local cur="${COMP_WORDS[COMP_CWORD]}"
	case "$cur" in
	--*)
		__gitcomp "
			--cached
			--text --ignore-case --word-regexp --invert-match
			--full-name
			--extended-regexp --basic-regexp --fixed-strings
			--files-with-matches --name-only
			--files-without-match
1099
			--max-depth
1100 1101 1102 1103 1104 1105
			--count
			--and --or --not --all-match
			"
		return
		;;
	esac
1106 1107

	__gitcomp "$(__git_refs)"
1108 1109
}

1110 1111 1112 1113 1114 1115 1116 1117 1118
_git_help ()
{
	local cur="${COMP_WORDS[COMP_CWORD]}"
	case "$cur" in
	--*)
		__gitcomp "--all --info --man --web"
		return
		;;
	esac
J
Jonathan Nieder 已提交
1119 1120
	__git_compute_all_commands
	__gitcomp "$__git_all_commands
1121 1122 1123
		attributes cli core-tutorial cvs-migration
		diffcore gitk glossary hooks ignore modules
		repository-layout tutorial tutorial-2
1124
		workflows
1125
		"
1126 1127
}

1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145
_git_init ()
{
	local cur="${COMP_WORDS[COMP_CWORD]}"
	case "$cur" in
	--shared=*)
		__gitcomp "
			false true umask group all world everybody
			" "" "${cur##--shared=}"
		return
		;;
	--*)
		__gitcomp "--quiet --bare --template= --shared --shared="
		return
		;;
	esac
	COMPREPLY=()
}

1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165
_git_ls_files ()
{
	__git_has_doubledash && return

	local cur="${COMP_WORDS[COMP_CWORD]}"
	case "$cur" in
	--*)
		__gitcomp "--cached --deleted --modified --others --ignored
			--stage --directory --no-empty-directory --unmerged
			--killed --exclude= --exclude-from=
			--exclude-per-directory= --exclude-standard
			--error-unmatch --with-tree= --full-name
			--abbrev --ignored --exclude-per-directory
			"
		return
		;;
	esac
	COMPREPLY=()
}

1166 1167
_git_ls_remote ()
{
1168
	__gitcomp "$(__git_remotes)"
1169 1170 1171 1172 1173 1174 1175
}

_git_ls_tree ()
{
	__git_complete_file
}

1176 1177 1178 1179
# Options that go well for log, shortlog and gitk
__git_log_common_options="
	--not --all
	--branches --tags --remotes
1180
	--first-parent --merges --no-merges
1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196
	--max-count=
	--max-age= --since= --after=
	--min-age= --until= --before=
"
# Options that go well for log and gitk (not shortlog)
__git_log_gitk_options="
	--dense --sparse --full-history
	--simplify-merges --simplify-by-decoration
	--left-right
"
# Options that go well for log and shortlog (not gitk)
__git_log_shortlog_options="
	--author= --committer= --grep=
	--all-match
"

1197
__git_log_pretty_formats="oneline short medium full fuller email raw format:"
1198
__git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1199

1200 1201
_git_log ()
{
1202 1203
	__git_has_doubledash && return

1204
	local cur="${COMP_WORDS[COMP_CWORD]}"
1205 1206
	local g="$(git rev-parse --git-dir 2>/dev/null)"
	local merge=""
1207
	if [ -f "$g/MERGE_HEAD" ]; then
1208 1209
		merge="--merge"
	fi
1210 1211
	case "$cur" in
	--pretty=*)
1212
		__gitcomp "$__git_log_pretty_formats
1213
			" "" "${cur##--pretty=}"
1214 1215
		return
		;;
1216 1217 1218 1219 1220
	--format=*)
		__gitcomp "$__git_log_pretty_formats
			" "" "${cur##--format=}"
		return
		;;
1221
	--date=*)
1222
		__gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1223 1224
		return
		;;
1225 1226 1227 1228
	--decorate=*)
		__gitcomp "long short" "" "${cur##--decorate=}"
		return
		;;
1229
	--*)
1230
		__gitcomp "
1231 1232 1233
			$__git_log_common_options
			$__git_log_shortlog_options
			$__git_log_gitk_options
1234
			--root --topo-order --date-order --reverse
1235
			--follow --full-diff
1236
			--abbrev-commit --abbrev=
1237
			--relative-date --date=
1238
			--pretty= --format= --oneline
1239
			--cherry-pick
1240
			--graph
1241
			--decorate --decorate=
1242
			--walk-reflogs
1243
			--parents --children
1244
			$merge
1245
			$__git_diff_common_options
1246
			--pickaxe-all --pickaxe-regex
1247
			"
1248 1249 1250
		return
		;;
	esac
1251
	__git_complete_revlist
1252 1253
}

1254 1255
__git_merge_options="
	--no-commit --no-stat --log --no-log --squash --strategy
1256
	--commit --stat --no-squash --ff --no-ff --ff-only
1257 1258
"

1259 1260
_git_merge ()
{
1261 1262
	__git_complete_strategy && return

1263 1264 1265
	local cur="${COMP_WORDS[COMP_CWORD]}"
	case "$cur" in
	--*)
1266
		__gitcomp "$__git_merge_options"
1267 1268
		return
	esac
1269
	__gitcomp "$(__git_refs)"
1270 1271
}

1272 1273 1274 1275 1276
_git_mergetool ()
{
	local cur="${COMP_WORDS[COMP_CWORD]}"
	case "$cur" in
	--tool=*)
1277
		__gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1278 1279 1280 1281 1282 1283 1284 1285 1286 1287
		return
		;;
	--*)
		__gitcomp "--tool="
		return
		;;
	esac
	COMPREPLY=()
}

1288 1289
_git_merge_base ()
{
1290
	__gitcomp "$(__git_refs)"
1291 1292
}

1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304
_git_mv ()
{
	local cur="${COMP_WORDS[COMP_CWORD]}"
	case "$cur" in
	--*)
		__gitcomp "--dry-run"
		return
		;;
	esac
	COMPREPLY=()
}

1305 1306
_git_name_rev ()
{
1307
	__gitcomp "--tags --all --stdin"
1308 1309
}

1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327
_git_notes ()
{
	local subcommands="edit show"
	if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
		__gitcomp "$subcommands"
		return
	fi

	case "${COMP_WORDS[COMP_CWORD-1]}" in
	-m|-F)
		COMPREPLY=()
		;;
	*)
		__gitcomp "$(__git_refs)"
		;;
	esac
}

1328 1329
_git_pull ()
{
1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342
	__git_complete_strategy && return

	local cur="${COMP_WORDS[COMP_CWORD]}"
	case "$cur" in
	--*)
		__gitcomp "
			--rebase --no-rebase
			$__git_merge_options
			$__git_fetch_options
		"
		return
		;;
	esac
1343
	__git_complete_remote_or_refspec
1344 1345 1346 1347
}

_git_push ()
{
1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366
	local cur="${COMP_WORDS[COMP_CWORD]}"
	case "${COMP_WORDS[COMP_CWORD-1]}" in
	--repo)
		__gitcomp "$(__git_remotes)"
		return
	esac
	case "$cur" in
	--repo=*)
		__gitcomp "$(__git_remotes)" "" "${cur##--repo=}"
		return
		;;
	--*)
		__gitcomp "
			--all --mirror --tags --dry-run --force --verbose
			--receive-pack= --repo=
		"
		return
		;;
	esac
1367
	__git_complete_remote_or_refspec
1368 1369
}

1370 1371
_git_rebase ()
{
1372
	local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
1373
	if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1374
		__gitcomp "--continue --skip --abort"
1375 1376
		return
	fi
1377
	__git_complete_strategy && return
1378
	case "$cur" in
1379 1380 1381 1382
	--whitespace=*)
		__gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
		return
		;;
1383
	--*)
1384 1385 1386 1387 1388
		__gitcomp "
			--onto --merge --strategy --interactive
			--preserve-merges --stat --no-stat
			--committer-date-is-author-date --ignore-date
			--ignore-whitespace --whitespace=
1389
			--autosquash
1390 1391
			"

1392 1393
		return
	esac
1394
	__gitcomp "$(__git_refs)"
1395 1396
}

1397
__git_send_email_confirm_options="always never auto cc compose"
1398
__git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1399

1400 1401 1402 1403
_git_send_email ()
{
	local cur="${COMP_WORDS[COMP_CWORD]}"
	case "$cur" in
1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420
	--confirm=*)
		__gitcomp "
			$__git_send_email_confirm_options
			" "" "${cur##--confirm=}"
		return
		;;
	--suppress-cc=*)
		__gitcomp "
			$__git_send_email_suppresscc_options
			" "" "${cur##--suppress-cc=}"

		return
		;;
	--smtp-encryption=*)
		__gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
		return
		;;
1421
	--*)
1422
		__gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1423 1424
			--compose --confirm= --dry-run --envelope-sender
			--from --identity
1425 1426 1427
			--in-reply-to --no-chain-reply-to --no-signed-off-by-cc
			--no-suppress-from --no-thread --quiet
			--signed-off-by-cc --smtp-pass --smtp-server
1428 1429
			--smtp-server-port --smtp-encryption= --smtp-user
			--subject --suppress-cc= --suppress-from --thread --to
1430
			--validate --no-validate"
1431 1432 1433 1434 1435 1436
		return
		;;
	esac
	COMPREPLY=()
}

1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455
__git_config_get_set_variables ()
{
	local prevword word config_file= c=$COMP_CWORD
	while [ $c -gt 1 ]; do
		word="${COMP_WORDS[c]}"
		case "$word" in
		--global|--system|--file=*)
			config_file="$word"
			break
			;;
		-f|--file)
			config_file="$word $prevword"
			break
			;;
		esac
		prevword=$word
		c=$((--c))
	done

1456 1457 1458 1459 1460 1461
	git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
	while read line
	do
		case "$line" in
		*.*=*)
			echo "${line/=*/}"
1462 1463 1464 1465 1466
			;;
		esac
	done
}

1467
_git_config ()
1468 1469 1470 1471 1472
{
	local cur="${COMP_WORDS[COMP_CWORD]}"
	local prv="${COMP_WORDS[COMP_CWORD-1]}"
	case "$prv" in
	branch.*.remote)
1473
		__gitcomp "$(__git_remotes)"
1474 1475 1476
		return
		;;
	branch.*.merge)
1477
		__gitcomp "$(__git_refs)"
1478 1479 1480 1481 1482
		return
		;;
	remote.*.fetch)
		local remote="${prv#remote.}"
		remote="${remote%.fetch}"
1483
		__gitcomp "$(__git_refs_remotes "$remote")"
1484 1485 1486 1487 1488
		return
		;;
	remote.*.push)
		local remote="${prv#remote.}"
		remote="${remote%.push}"
1489
		__gitcomp "$(git --git-dir="$(__gitdir)" \
1490
			for-each-ref --format='%(refname):%(refname)' \
1491 1492 1493 1494
			refs/heads)"
		return
		;;
	pull.twohead|pull.octopus)
J
Jonathan Nieder 已提交
1495 1496
		__git_compute_merge_strategies
		__gitcomp "$__git_merge_strategies"
1497 1498
		return
		;;
1499 1500
	color.branch|color.diff|color.interactive|\
	color.showbranch|color.status|color.ui)
1501 1502 1503
		__gitcomp "always never auto"
		return
		;;
1504 1505 1506 1507
	color.pager)
		__gitcomp "false true"
		return
		;;
1508 1509
	color.*.*)
		__gitcomp "
1510
			normal black red green yellow blue magenta cyan white
1511 1512
			bold dim ul blink reverse
			"
1513 1514
		return
		;;
1515 1516 1517 1518
	help.format)
		__gitcomp "man info web html"
		return
		;;
1519 1520 1521 1522
	log.date)
		__gitcomp "$__git_log_date_formats"
		return
		;;
1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534
	sendemail.aliasesfiletype)
		__gitcomp "mutt mailrc pine elm gnus"
		return
		;;
	sendemail.confirm)
		__gitcomp "$__git_send_email_confirm_options"
		return
		;;
	sendemail.suppresscc)
		__gitcomp "$__git_send_email_suppresscc_options"
		return
		;;
1535 1536 1537 1538
	--get|--get-all|--unset|--unset-all)
		__gitcomp "$(__git_config_get_set_variables)"
		return
		;;
1539 1540 1541 1542 1543 1544 1545
	*.*)
		COMPREPLY=()
		return
		;;
	esac
	case "$cur" in
	--*)
1546
		__gitcomp "
1547
			--global --system --file=
1548
			--list --replace-all
1549
			--get --get-all --get-regexp
1550
			--add --unset --unset-all
1551
			--remove-section --rename-section
1552
			"
1553 1554 1555 1556 1557
		return
		;;
	branch.*.*)
		local pfx="${cur%.*}."
		cur="${cur##*.}"
1558
		__gitcomp "remote merge mergeoptions rebase" "$pfx" "$cur"
1559 1560 1561 1562 1563
		return
		;;
	branch.*)
		local pfx="${cur%.*}."
		cur="${cur#*.}"
1564
		__gitcomp "$(__git_heads)" "$pfx" "$cur" "."
1565 1566
		return
		;;
1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596
	guitool.*.*)
		local pfx="${cur%.*}."
		cur="${cur##*.}"
		__gitcomp "
			argprompt cmd confirm needsfile noconsole norescan
			prompt revprompt revunmerged title
			" "$pfx" "$cur"
		return
		;;
	difftool.*.*)
		local pfx="${cur%.*}."
		cur="${cur##*.}"
		__gitcomp "cmd path" "$pfx" "$cur"
		return
		;;
	man.*.*)
		local pfx="${cur%.*}."
		cur="${cur##*.}"
		__gitcomp "cmd path" "$pfx" "$cur"
		return
		;;
	mergetool.*.*)
		local pfx="${cur%.*}."
		cur="${cur##*.}"
		__gitcomp "cmd path trustExitCode" "$pfx" "$cur"
		return
		;;
	pager.*)
		local pfx="${cur%.*}."
		cur="${cur#*.}"
J
Jonathan Nieder 已提交
1597 1598
		__git_compute_all_commands
		__gitcomp "$__git_all_commands" "$pfx" "$cur"
1599 1600
		return
		;;
1601 1602 1603
	remote.*.*)
		local pfx="${cur%.*}."
		cur="${cur##*.}"
1604
		__gitcomp "
1605
			url proxy fetch push mirror skipDefaultUpdate
1606
			receivepack uploadpack tagopt pushurl
1607
			" "$pfx" "$cur"
1608 1609 1610 1611 1612
		return
		;;
	remote.*)
		local pfx="${cur%.*}."
		cur="${cur#*.}"
1613
		__gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
1614 1615
		return
		;;
1616 1617 1618
	url.*.*)
		local pfx="${cur%.*}."
		cur="${cur##*.}"
1619
		__gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur"
1620 1621
		return
		;;
1622
	esac
1623
	__gitcomp "
1624
		add.ignore-errors
1625
		alias.
1626
		apply.ignorewhitespace
1627
		apply.whitespace
1628 1629
		branch.autosetupmerge
		branch.autosetuprebase
1630
		clean.requireForce
1631 1632 1633 1634
		color.branch
		color.branch.current
		color.branch.local
		color.branch.plain
1635
		color.branch.remote
1636
		color.diff
1637
		color.diff.commit
1638
		color.diff.frag
1639
		color.diff.meta
1640
		color.diff.new
1641 1642
		color.diff.old
		color.diff.plain
1643
		color.diff.whitespace
1644 1645 1646
		color.grep
		color.grep.external
		color.grep.match
1647 1648 1649 1650
		color.interactive
		color.interactive.header
		color.interactive.help
		color.interactive.prompt
1651
		color.pager
1652
		color.showbranch
1653
		color.status
1654 1655
		color.status.added
		color.status.changed
1656
		color.status.header
1657
		color.status.nobranch
1658
		color.status.untracked
1659 1660 1661 1662 1663
		color.status.updated
		color.ui
		commit.template
		core.autocrlf
		core.bare
1664
		core.compression
1665
		core.createObject
1666 1667 1668
		core.deltaBaseCacheLimit
		core.editor
		core.excludesfile
1669
		core.fileMode
1670
		core.fsyncobjectfiles
1671
		core.gitProxy
1672
		core.ignoreCygwinFSTricks
1673 1674 1675 1676 1677
		core.ignoreStat
		core.logAllRefUpdates
		core.loosecompression
		core.packedGitLimit
		core.packedGitWindowSize
1678
		core.pager
1679
		core.preferSymlinkRefs
1680 1681
		core.preloadindex
		core.quotepath
1682
		core.repositoryFormatVersion
1683
		core.safecrlf
1684
		core.sharedRepository
1685 1686
		core.symlinks
		core.trustctime
1687
		core.warnAmbiguousRefs
1688 1689 1690 1691 1692
		core.whitespace
		core.worktree
		diff.autorefreshindex
		diff.external
		diff.mnemonicprefix
1693
		diff.renameLimit
1694
		diff.renameLimit.
1695
		diff.renames
1696 1697 1698
		diff.suppressBlankEmpty
		diff.tool
		diff.wordRegex
1699
		difftool.
1700
		difftool.prompt
1701
		fetch.unpackLimit
1702 1703
		format.attach
		format.cc
1704
		format.headers
1705 1706
		format.numbered
		format.pretty
1707 1708
		format.signoff
		format.subjectprefix
1709
		format.suffix
1710
		format.thread
1711 1712 1713
		gc.aggressiveWindow
		gc.auto
		gc.autopacklimit
1714
		gc.packrefs
1715
		gc.pruneexpire
1716 1717 1718 1719
		gc.reflogexpire
		gc.reflogexpireunreachable
		gc.rerereresolved
		gc.rerereunresolved
1720
		gitcvs.allbinary
1721
		gitcvs.commitmsgannotation
1722
		gitcvs.dbTableNamePrefix
1723 1724 1725 1726 1727 1728
		gitcvs.dbdriver
		gitcvs.dbname
		gitcvs.dbpass
		gitcvs.dbuser
		gitcvs.enabled
		gitcvs.logfile
1729
		gitcvs.usecrlfattr
1730
		guitool.
1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744
		gui.blamehistoryctx
		gui.commitmsgwidth
		gui.copyblamethreshold
		gui.diffcontext
		gui.encoding
		gui.fastcopyblame
		gui.matchtrackingbranch
		gui.newbranchtemplate
		gui.pruneduringfetch
		gui.spellingdictionary
		gui.trustmtime
		help.autocorrect
		help.browser
		help.format
1745 1746
		http.lowSpeedLimit
		http.lowSpeedTime
1747
		http.maxRequests
1748
		http.noEPSV
1749
		http.proxy
1750 1751 1752 1753 1754
		http.sslCAInfo
		http.sslCAPath
		http.sslCert
		http.sslKey
		http.sslVerify
1755 1756
		i18n.commitEncoding
		i18n.logOutputEncoding
1757 1758 1759 1760 1761 1762 1763 1764
		imap.folder
		imap.host
		imap.pass
		imap.port
		imap.preformattedHTML
		imap.sslverify
		imap.tunnel
		imap.user
1765 1766 1767 1768 1769
		instaweb.browser
		instaweb.httpd
		instaweb.local
		instaweb.modulepath
		instaweb.port
1770
		interactive.singlekey
1771
		log.date
1772
		log.showroot
1773
		mailmap.file
1774
		man.
1775 1776 1777 1778 1779
		man.viewer
		merge.conflictstyle
		merge.log
		merge.renameLimit
		merge.stat
1780
		merge.tool
1781
		merge.verbosity
1782
		mergetool.
1783
		mergetool.keepBackup
1784
		mergetool.prompt
1785 1786
		pack.compression
		pack.deltaCacheLimit
1787 1788
		pack.deltaCacheSize
		pack.depth
1789 1790 1791
		pack.indexVersion
		pack.packSizeLimit
		pack.threads
1792 1793
		pack.window
		pack.windowMemory
1794
		pager.
1795 1796
		pull.octopus
		pull.twohead
1797 1798
		push.default
		rebase.stat
1799 1800
		receive.denyCurrentBranch
		receive.denyDeletes
1801
		receive.denyNonFastForwards
1802
		receive.fsckObjects
1803
		receive.unpackLimit
1804 1805 1806
		repack.usedeltabaseoffset
		rerere.autoupdate
		rerere.enabled
1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826
		sendemail.aliasesfile
		sendemail.aliasesfiletype
		sendemail.bcc
		sendemail.cc
		sendemail.cccmd
		sendemail.chainreplyto
		sendemail.confirm
		sendemail.envelopesender
		sendemail.multiedit
		sendemail.signedoffbycc
		sendemail.smtpencryption
		sendemail.smtppass
		sendemail.smtpserver
		sendemail.smtpserverport
		sendemail.smtpuser
		sendemail.suppresscc
		sendemail.suppressfrom
		sendemail.thread
		sendemail.to
		sendemail.validate
1827
		showbranch.default
1828 1829
		status.relativePaths
		status.showUntrackedFiles
1830 1831
		tar.umask
		transfer.unpackLimit
1832
		url.
1833
		user.email
1834
		user.name
1835
		user.signingkey
1836
		web.browser
1837
		branch. remote.
1838
	"
1839 1840
}

1841 1842
_git_remote ()
{
1843
	local subcommands="add rename rm show prune update set-head"
1844
	local subcommand="$(__git_find_on_cmdline "$subcommands")"
1845
	if [ -z "$subcommand" ]; then
1846
		__gitcomp "$subcommands"
1847 1848 1849
		return
	fi

1850
	case "$subcommand" in
1851
	rename|rm|show|prune)
1852 1853
		__gitcomp "$(__git_remotes)"
		;;
1854 1855
	update)
		local i c='' IFS=$'\n'
1856 1857 1858
		for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do
			i="${i#remotes.}"
			c="$c ${i/ */}"
1859 1860 1861
		done
		__gitcomp "$c"
		;;
1862 1863 1864 1865 1866 1867
	*)
		COMPREPLY=()
		;;
	esac
}

1868 1869 1870 1871 1872
_git_replace ()
{
	__gitcomp "$(__git_refs)"
}

1873 1874
_git_reset ()
{
1875 1876
	__git_has_doubledash && return

1877
	local cur="${COMP_WORDS[COMP_CWORD]}"
1878 1879
	case "$cur" in
	--*)
S
SZEDER Gábor 已提交
1880
		__gitcomp "--merge --mixed --hard --soft --patch"
1881 1882 1883 1884
		return
		;;
	esac
	__gitcomp "$(__git_refs)"
1885 1886
}

1887 1888 1889 1890 1891 1892 1893 1894 1895
_git_revert ()
{
	local cur="${COMP_WORDS[COMP_CWORD]}"
	case "$cur" in
	--*)
		__gitcomp "--edit --mainline --no-edit --no-commit --signoff"
		return
		;;
	esac
1896
	__gitcomp "$(__git_refs)"
1897 1898
}

1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912
_git_rm ()
{
	__git_has_doubledash && return

	local cur="${COMP_WORDS[COMP_CWORD]}"
	case "$cur" in
	--*)
		__gitcomp "--cached --dry-run --ignore-unmatch --quiet"
		return
		;;
	esac
	COMPREPLY=()
}

1913 1914
_git_shortlog ()
{
1915 1916
	__git_has_doubledash && return

1917 1918 1919 1920
	local cur="${COMP_WORDS[COMP_CWORD]}"
	case "$cur" in
	--*)
		__gitcomp "
1921 1922
			$__git_log_common_options
			$__git_log_shortlog_options
1923 1924 1925 1926 1927 1928 1929 1930
			--numbered --summary
			"
		return
		;;
	esac
	__git_complete_revlist
}

1931 1932
_git_show ()
{
1933 1934
	__git_has_doubledash && return

1935 1936 1937
	local cur="${COMP_WORDS[COMP_CWORD]}"
	case "$cur" in
	--pretty=*)
1938
		__gitcomp "$__git_log_pretty_formats
1939
			" "" "${cur##--pretty=}"
1940 1941
		return
		;;
1942 1943 1944 1945 1946
	--format=*)
		__gitcomp "$__git_log_pretty_formats
			" "" "${cur##--format=}"
		return
		;;
1947
	--*)
1948
		__gitcomp "--pretty= --format= --abbrev-commit --oneline
1949 1950
			$__git_diff_common_options
			"
1951 1952 1953 1954 1955 1956
		return
		;;
	esac
	__git_complete_file
}

1957 1958 1959 1960 1961 1962 1963 1964
_git_show_branch ()
{
	local cur="${COMP_WORDS[COMP_CWORD]}"
	case "$cur" in
	--*)
		__gitcomp "
			--all --remotes --topo-order --current --more=
			--list --independent --merge-base --no-name
1965
			--color --no-color
1966
			--sha1-name --sparse --topics --reflog
1967 1968 1969 1970 1971 1972 1973
			"
		return
		;;
	esac
	__git_complete_revlist
}

J
Junio C Hamano 已提交
1974 1975
_git_stash ()
{
1976 1977
	local cur="${COMP_WORDS[COMP_CWORD]}"
	local save_opts='--keep-index --no-keep-index --quiet --patch'
1978
	local subcommands='save list show apply clear drop pop create branch'
1979
	local subcommand="$(__git_find_on_cmdline "$subcommands")"
1980
	if [ -z "$subcommand" ]; then
1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992
		case "$cur" in
		--*)
			__gitcomp "$save_opts"
			;;
		*)
			if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
				__gitcomp "$subcommands"
			else
				COMPREPLY=()
			fi
			;;
		esac
1993 1994 1995
	else
		case "$subcommand,$cur" in
		save,--*)
1996
			__gitcomp "$save_opts"
1997
			;;
1998
		apply,--*|pop,--*)
1999
			__gitcomp "--index --quiet"
2000
			;;
2001
		show,--*|drop,--*|branch,--*)
2002 2003 2004 2005 2006 2007
			COMPREPLY=()
			;;
		show,*|apply,*|drop,*|pop,*|branch,*)
			__gitcomp "$(git --git-dir="$(__gitdir)" stash list \
					| sed -n -e 's/:.*//p')"
			;;
2008 2009 2010 2011
		*)
			COMPREPLY=()
			;;
		esac
2012
	fi
J
Junio C Hamano 已提交
2013 2014
}

2015 2016
_git_submodule ()
{
2017 2018
	__git_has_doubledash && return

2019
	local subcommands="add status init update summary foreach sync"
2020
	if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2021 2022 2023 2024 2025 2026
		local cur="${COMP_WORDS[COMP_CWORD]}"
		case "$cur" in
		--*)
			__gitcomp "--quiet --cached"
			;;
		*)
2027
			__gitcomp "$subcommands"
2028 2029 2030 2031 2032 2033
			;;
		esac
		return
	fi
}

2034 2035 2036 2037 2038
_git_svn ()
{
	local subcommands="
		init fetch clone rebase dcommit log find-rev
		set-tree commit-diff info create-ignore propget
S
SZEDER Gábor 已提交
2039
		proplist show-ignore show-externals branch tag blame
2040
		migrate mkdirs reset gc
2041
		"
2042
	local subcommand="$(__git_find_on_cmdline "$subcommands")"
2043 2044 2045 2046 2047 2048 2049 2050
	if [ -z "$subcommand" ]; then
		__gitcomp "$subcommands"
	else
		local remote_opts="--username= --config-dir= --no-auth-cache"
		local fc_opts="
			--follow-parent --authors-file= --repack=
			--no-metadata --use-svm-props --use-svnsync-props
			--log-window-size= --no-checkout --quiet
S
SZEDER Gábor 已提交
2051 2052
			--repack-flags --use-log-author --localtime
			--ignore-paths= $remote_opts
2053 2054 2055 2056 2057
			"
		local init_opts="
			--template= --shared= --trunk= --tags=
			--branches= --stdlayout --minimize-url
			--no-metadata --use-svm-props --use-svnsync-props
S
SZEDER Gábor 已提交
2058 2059
			--rewrite-root= --prefix= --use-log-author
			--add-author-from $remote_opts
2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078
			"
		local cmt_opts="
			--edit --rmdir --find-copies-harder --copy-similarity=
			"

		local cur="${COMP_WORDS[COMP_CWORD]}"
		case "$subcommand,$cur" in
		fetch,--*)
			__gitcomp "--revision= --fetch-all $fc_opts"
			;;
		clone,--*)
			__gitcomp "--revision= $fc_opts $init_opts"
			;;
		init,--*)
			__gitcomp "$init_opts"
			;;
		dcommit,--*)
			__gitcomp "
				--merge --strategy= --verbose --dry-run
S
SZEDER Gábor 已提交
2079 2080
				--fetch-all --no-rebase --commit-url
				--revision $cmt_opts $fc_opts
2081 2082 2083 2084 2085 2086
				"
			;;
		set-tree,--*)
			__gitcomp "--stdin $cmt_opts $fc_opts"
			;;
		create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2087
		show-externals,--*|mkdirs,--*)
2088 2089 2090 2091 2092 2093
			__gitcomp "--revision="
			;;
		log,--*)
			__gitcomp "
				--limit= --revision= --verbose --incremental
				--oneline --show-commit --non-recursive
S
SZEDER Gábor 已提交
2094
				--authors-file= --color
2095 2096 2097 2098 2099
				"
			;;
		rebase,--*)
			__gitcomp "
				--merge --verbose --strategy= --local
S
SZEDER Gábor 已提交
2100
				--fetch-all --dry-run $fc_opts
2101 2102 2103 2104 2105 2106 2107 2108
				"
			;;
		commit-diff,--*)
			__gitcomp "--message= --file= --revision= $cmt_opts"
			;;
		info,--*)
			__gitcomp "--url"
			;;
S
SZEDER Gábor 已提交
2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123
		branch,--*)
			__gitcomp "--dry-run --message --tag"
			;;
		tag,--*)
			__gitcomp "--dry-run --message"
			;;
		blame,--*)
			__gitcomp "--git-format"
			;;
		migrate,--*)
			__gitcomp "
				--config-dir= --ignore-paths= --minimize
				--no-auth-cache --username=
				"
			;;
2124 2125 2126
		reset,--*)
			__gitcomp "--revision= --parent"
			;;
2127 2128 2129 2130 2131 2132 2133
		*)
			COMPREPLY=()
			;;
		esac
	fi
}

2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154
_git_tag ()
{
	local i c=1 f=0
	while [ $c -lt $COMP_CWORD ]; do
		i="${COMP_WORDS[c]}"
		case "$i" in
		-d|-v)
			__gitcomp "$(__git_tags)"
			return
			;;
		-f)
			f=1
			;;
		esac
		c=$((++c))
	done

	case "${COMP_WORDS[COMP_CWORD-1]}" in
	-m|-F)
		COMPREPLY=()
		;;
2155
	-*|tag)
2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167
		if [ $f = 1 ]; then
			__gitcomp "$(__git_tags)"
		else
			COMPREPLY=()
		fi
		;;
	*)
		__gitcomp "$(__git_refs)"
		;;
	esac
}

2168 2169
_git ()
{
2170 2171 2172 2173 2174 2175 2176
	local i c=1 command __git_dir

	while [ $c -lt $COMP_CWORD ]; do
		i="${COMP_WORDS[c]}"
		case "$i" in
		--git-dir=*) __git_dir="${i#--git-dir=}" ;;
		--bare)      __git_dir="." ;;
2177 2178
		--version|-p|--paginate) ;;
		--help) command="help"; break ;;
2179 2180 2181 2182 2183
		*) command="$i"; break ;;
		esac
		c=$((++c))
	done

2184
	if [ -z "$command" ]; then
2185
		case "${COMP_WORDS[COMP_CWORD]}" in
2186
		--*)   __gitcomp "
2187
			--paginate
2188 2189 2190 2191 2192
			--no-pager
			--git-dir=
			--bare
			--version
			--exec-path
2193
			--html-path
2194 2195
			--work-tree=
			--help
2196 2197
			"
			;;
J
Jonathan Nieder 已提交
2198 2199
		*)     __git_compute_porcelain_commands
		       __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
2200 2201
		esac
		return
2202
	fi
2203

2204 2205
	local expansion=$(__git_aliased_command "$command")
	[ "$expansion" ] && command="$expansion"
2206

2207
	case "$command" in
2208
	am)          _git_am ;;
2209
	add)         _git_add ;;
2210
	apply)       _git_apply ;;
2211
	archive)     _git_archive ;;
2212
	bisect)      _git_bisect ;;
2213
	bundle)      _git_bundle ;;
2214 2215
	branch)      _git_branch ;;
	checkout)    _git_checkout ;;
2216
	cherry)      _git_cherry ;;
2217
	cherry-pick) _git_cherry_pick ;;
2218
	clean)       _git_clean ;;
2219
	clone)       _git_clone ;;
2220
	commit)      _git_commit ;;
2221
	config)      _git_config ;;
2222
	describe)    _git_describe ;;
2223
	diff)        _git_diff ;;
2224
	difftool)    _git_difftool ;;
2225
	fetch)       _git_fetch ;;
2226
	format-patch) _git_format_patch ;;
2227
	fsck)        _git_fsck ;;
2228
	gc)          _git_gc ;;
2229
	grep)        _git_grep ;;
2230
	help)        _git_help ;;
2231
	init)        _git_init ;;
2232
	log)         _git_log ;;
2233
	ls-files)    _git_ls_files ;;
2234 2235
	ls-remote)   _git_ls_remote ;;
	ls-tree)     _git_ls_tree ;;
2236
	merge)       _git_merge;;
2237
	mergetool)   _git_mergetool;;
2238
	merge-base)  _git_merge_base ;;
2239
	mv)          _git_mv ;;
2240
	name-rev)    _git_name_rev ;;
2241
	notes)       _git_notes ;;
2242 2243
	pull)        _git_pull ;;
	push)        _git_push ;;
2244
	rebase)      _git_rebase ;;
2245
	remote)      _git_remote ;;
2246
	replace)     _git_replace ;;
2247
	reset)       _git_reset ;;
2248
	revert)      _git_revert ;;
2249
	rm)          _git_rm ;;
2250
	send-email)  _git_send_email ;;
2251
	shortlog)    _git_shortlog ;;
2252
	show)        _git_show ;;
2253
	show-branch) _git_show_branch ;;
J
Junio C Hamano 已提交
2254
	stash)       _git_stash ;;
2255
	stage)       _git_add ;;
2256
	submodule)   _git_submodule ;;
2257
	svn)         _git_svn ;;
2258
	tag)         _git_tag ;;
2259 2260 2261
	whatchanged) _git_log ;;
	*)           COMPREPLY=() ;;
	esac
2262 2263 2264 2265
}

_gitk ()
{
2266 2267
	__git_has_doubledash && return

2268
	local cur="${COMP_WORDS[COMP_CWORD]}"
2269
	local g="$(__gitdir)"
2270
	local merge=""
2271
	if [ -f "$g/MERGE_HEAD" ]; then
2272 2273
		merge="--merge"
	fi
2274 2275
	case "$cur" in
	--*)
2276 2277 2278 2279 2280
		__gitcomp "
			$__git_log_common_options
			$__git_log_gitk_options
			$merge
			"
2281 2282 2283
		return
		;;
	esac
2284
	__git_complete_revlist
2285 2286
}

2287 2288 2289 2290
complete -o bashdefault -o default -o nospace -F _git git 2>/dev/null \
	|| complete -o default -o nospace -F _git git
complete -o bashdefault -o default -o nospace -F _gitk gitk 2>/dev/null \
	|| complete -o default -o nospace -F _gitk gitk
2291 2292 2293 2294 2295

# The following are necessary only for Cygwin, and only are needed
# when the user has tab-completed the executable name and consequently
# included the '.exe' suffix.
#
2296
if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
2297 2298
complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \
	|| complete -o default -o nospace -F _git git.exe
2299
fi