git-completion.bash 22.0 KB
Newer Older
1 2 3
#
# bash completion support for core Git.
#
4
# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
5
# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
6
# Distributed under the GNU General Public License, version 2.0.
7 8 9 10 11 12 13 14
#
# 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
15
#    *) common --long-options
16 17 18 19 20 21 22
#
# 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
#
23 24 25 26 27 28 29
#    3) You may want to make sure the git executable is available
#       in your PATH before this script is sourced, as some caching
#       is performed while the script loads.  If git isn't found
#       at source time then all lookups will be done on demand,
#       which may be slightly slower.
#
#    4) Consider changing your PS1 to also show the current branch:
30 31 32 33 34 35
#        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.
#
36 37 38 39 40 41 42 43 44 45 46
# 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
#
47

48 49
__gitdir ()
{
50 51 52 53 54 55 56 57 58 59 60 61 62
	if [ -z "$1" ]; then
		if [ -n "$__git_dir" ]; then
			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
63 64
}

65 66 67 68 69 70 71 72 73 74 75 76
__git_ps1 ()
{
	local b="$(git symbolic-ref HEAD 2>/dev/null)"
	if [ -n "$b" ]; then
		if [ -n "$1" ]; then
			printf "$1" "${b##refs/heads/}"
		else
			printf " (%s)" "${b##refs/heads/}"
		fi
	fi
}

77 78 79
__gitcomp ()
{
	local all c s=$'\n' IFS=' '$'\t'$'\n'
80
	local cur="${COMP_WORDS[COMP_CWORD]}"
81
	if [ $# -gt 2 ]; then
82 83
		cur="$3"
	fi
84
	for c in $1; do
85 86 87 88
		case "$c$4" in
		--*=*) all="$all$c$4$s" ;;
		*.)    all="$all$c$4$s" ;;
		*)     all="$all$c$4 $s" ;;
89 90 91
		esac
	done
	IFS=$s
92
	COMPREPLY=($(compgen -P "$2" -W "$all" -- "$cur"))
93 94 95
	return
}

96 97
__git_heads ()
{
98
	local cmd i is_hash=y dir="$(__gitdir "$1")"
99 100 101 102 103 104 105 106
	if [ -d "$dir" ]; then
		for i in $(git --git-dir="$dir" \
			for-each-ref --format='%(refname)' \
			refs/heads ); do
			echo "${i#refs/heads/}"
		done
		return
	fi
107
	for i in $(git-ls-remote "$1" 2>/dev/null); do
108 109 110 111 112 113 114 115 116
		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
}

117 118
__git_refs ()
{
119
	local cmd i is_hash=y dir="$(__gitdir "$1")"
120
	if [ -d "$dir" ]; then
121 122 123 124 125 126 127 128 129 130 131 132
		if [ -e "$dir/HEAD" ]; then echo HEAD; fi
		for i in $(git --git-dir="$dir" \
			for-each-ref --format='%(refname)' \
			refs/tags refs/heads refs/remotes); do
			case "$i" in
				refs/tags/*)    echo "${i#refs/tags/}" ;;
				refs/heads/*)   echo "${i#refs/heads/}" ;;
				refs/remotes/*) echo "${i#refs/remotes/}" ;;
				*)              echo "$i" ;;
			esac
		done
		return
133
	fi
134
	for i in $(git-ls-remote "$dir" 2>/dev/null); do
135 136 137 138 139
		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/}" ;;
140
		n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
141 142 143 144 145 146 147
		n,*) is_hash=y; echo "$i" ;;
		esac
	done
}

__git_refs2 ()
{
148 149 150
	local i
	for i in $(__git_refs "$1"); do
		echo "$i:$i"
151 152 153
	done
}

154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
__git_refs_remotes ()
{
	local cmd i is_hash=y
	for i in $(git-ls-remote "$1" 2>/dev/null); do
		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
}

171 172
__git_remotes ()
{
173
	local i ngoff IFS=$'\n' d="$(__gitdir)"
174
	shopt -q nullglob || ngoff=1
175
	shopt -s nullglob
176 177
	for i in "$d/remotes"/*; do
		echo ${i#$d/remotes/}
178
	done
179
	[ "$ngoff" ] && shopt -u nullglob
180
	for i in $(git --git-dir="$d" config --list); do
181 182 183 184 185 186 187
		case "$i" in
		remote.*.url=*)
			i="${i#remote.}"
			echo "${i/.url=*/}"
			;;
		esac
	done
188 189
}

190 191
__git_merge_strategies ()
{
192 193 194 195
	if [ -n "$__git_merge_strategylist" ]; then
		echo "$__git_merge_strategylist"
		return
	fi
196 197 198 199 200 201 202
	sed -n "/^all_strategies='/{
		s/^all_strategies='//
		s/'//
		p
		q
		}" "$(git --exec-path)/git-merge"
}
203 204
__git_merge_strategylist=
__git_merge_strategylist="$(__git_merge_strategies 2>/dev/null)"
205

206 207
__git_complete_file ()
{
208
	local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
209 210
	case "$cur" in
	?*:*)
211 212
		ref="${cur%%:*}"
		cur="${cur#*:}"
213 214
		case "$cur" in
		?*/*)
215 216
			pfx="${cur%/*}"
			cur="${cur##*/}"
217 218 219 220 221 222 223 224
			ls="$ref:$pfx"
			pfx="$pfx/"
			;;
		*)
			ls="$ref"
			;;
	    esac
		COMPREPLY=($(compgen -P "$pfx" \
225
			-W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
226 227 228 229 230 231 232 233 234
				| sed '/^100... blob /s,^.*	,,
				       /^040000 tree /{
				           s,^.*	,,
				           s,$,/,
				       }
				       s/^.*	//')" \
			-- "$cur"))
		;;
	*)
235
		__gitcomp "$(__git_refs)"
236 237 238 239
		;;
	esac
}

240 241 242 243 244 245 246
__git_complete_revlist ()
{
	local pfx cur="${COMP_WORDS[COMP_CWORD]}"
	case "$cur" in
	*...*)
		pfx="${cur%...*}..."
		cur="${cur#*...}"
247
		__gitcomp "$(__git_refs)" "$pfx" "$cur"
248 249 250 251
		;;
	*..*)
		pfx="${cur%..*}.."
		cur="${cur#*..}"
252 253 254 255
		__gitcomp "$(__git_refs)" "$pfx" "$cur"
		;;
	*.)
		__gitcomp "$cur."
256 257
		;;
	*)
258
		__gitcomp "$(__git_refs)"
259 260 261 262
		;;
	esac
}

263 264
__git_commands ()
{
265 266 267 268
	if [ -n "$__git_commandlist" ]; then
		echo "$__git_commandlist"
		return
	fi
269 270 271 272
	local i IFS=" "$'\n'
	for i in $(git help -a|egrep '^ ')
	do
		case $i in
273
		add--interactive) : plumbing;;
274 275 276
		applymbox)        : ask gittus;;
		applypatch)       : ask gittus;;
		archimport)       : import;;
277
		cat-file)         : plumbing;;
278
		check-attr)       : plumbing;;
279 280 281
		check-ref-format) : plumbing;;
		commit-tree)      : plumbing;;
		convert-objects)  : plumbing;;
282 283
		cvsexportcommit)  : export;;
		cvsimport)        : import;;
284 285
		cvsserver)        : daemon;;
		daemon)           : daemon;;
286 287 288
		diff-files)       : plumbing;;
		diff-index)       : plumbing;;
		diff-tree)        : plumbing;;
S
Shawn O. Pearce 已提交
289
		fast-import)      : import;;
290
		fsck-objects)     : plumbing;;
291
		fetch--tool)      : plumbing;;
292
		fetch-pack)       : plumbing;;
293
		fmt-merge-msg)    : plumbing;;
294
		for-each-ref)     : plumbing;;
295 296 297
		hash-object)      : plumbing;;
		http-*)           : transport;;
		index-pack)       : plumbing;;
298
		init-db)          : deprecated;;
299 300 301 302 303 304 305 306 307 308 309 310
		local-fetch)      : plumbing;;
		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;;
311 312 313
		prune)            : plumbing;;
		prune-packed)     : plumbing;;
		quiltimport)      : import;;
314 315
		read-tree)        : plumbing;;
		receive-pack)     : plumbing;;
316
		reflog)           : plumbing;;
317
		repo-config)      : plumbing;;
318 319 320 321 322 323 324 325 326 327
		rerere)           : plumbing;;
		rev-list)         : plumbing;;
		rev-parse)        : plumbing;;
		runstatus)        : plumbing;;
		sh-setup)         : internal;;
		shell)            : daemon;;
		send-pack)        : plumbing;;
		show-index)       : plumbing;;
		ssh-*)            : transport;;
		stripspace)       : plumbing;;
328 329
		svn)              : import export;;
		svnimport)        : import;;
330
		symbolic-ref)     : plumbing;;
331
		tar-tree)         : deprecated;;
332 333
		unpack-file)      : plumbing;;
		unpack-objects)   : plumbing;;
334
		update-index)     : plumbing;;
335 336 337 338 339
		update-ref)       : plumbing;;
		update-server-info) : daemon;;
		upload-archive)   : plumbing;;
		upload-pack)      : plumbing;;
		write-tree)       : plumbing;;
340
		verify-tag)       : plumbing;;
341 342 343 344
		*) echo $i;;
		esac
	done
}
345 346
__git_commandlist=
__git_commandlist="$(__git_commands 2>/dev/null)"
347

348 349
__git_aliases ()
{
350
	local i IFS=$'\n'
351
	for i in $(git --git-dir="$(__gitdir)" config --list); do
352 353 354 355 356 357 358
		case "$i" in
		alias.*)
			i="${i#alias.}"
			echo "${i/=*/}"
			;;
		esac
	done
359 360 361 362
}

__git_aliased_command ()
{
363
	local word cmdline=$(git --git-dir="$(__gitdir)" \
364
		config --get "alias.$1")
365 366 367 368 369 370 371 372
	for word in $cmdline; do
		if [ "${word##-*}" ]; then
			echo $word
			return
		fi
	done
}

373 374 375 376 377 378
__git_whitespacelist="nowarn warn error error-all strip"

_git_am ()
{
	local cur="${COMP_WORDS[COMP_CWORD]}"
	if [ -d .dotest ]; then
379
		__gitcomp "--skip --resolved"
380 381 382 383
		return
	fi
	case "$cur" in
	--whitespace=*)
384
		__gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
385 386 387
		return
		;;
	--*)
388
		__gitcomp "
389 390
			--signoff --utf8 --binary --3way --interactive
			--whitespace=
391
			"
392 393 394 395 396 397 398 399 400 401
		return
	esac
	COMPREPLY=()
}

_git_apply ()
{
	local cur="${COMP_WORDS[COMP_CWORD]}"
	case "$cur" in
	--whitespace=*)
402
		__gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
403 404 405
		return
		;;
	--*)
406
		__gitcomp "
407 408 409 410
			--stat --numstat --summary --check --index
			--cached --index-info --reverse --reject --unidiff-zero
			--apply --no-add --exclude=
			--whitespace= --inaccurate-eof --verbose
411
			"
412 413 414 415 416
		return
	esac
	COMPREPLY=()
}

417 418 419 420 421
_git_add ()
{
	local cur="${COMP_WORDS[COMP_CWORD]}"
	case "$cur" in
	--*)
422
		__gitcomp "--interactive"
423 424 425 426 427
		return
	esac
	COMPREPLY=()
}

428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456
_git_bisect ()
{
	local i c=1 command
	while [ $c -lt $COMP_CWORD ]; do
		i="${COMP_WORDS[c]}"
		case "$i" in
		start|bad|good|reset|visualize|replay|log)
			command="$i"
			break
			;;
		esac
		c=$((++c))
	done

	if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
		__gitcomp "start bad good reset visualize replay log"
		return
	fi

	case "$command" in
	bad|good|reset)
		__gitcomp "$(__git_refs)"
		;;
	*)
		COMPREPLY=()
		;;
	esac
}

457 458
_git_branch ()
{
459
	__gitcomp "$(__git_refs)"
460 461 462 463
}

_git_checkout ()
{
464
	__gitcomp "$(__git_refs)"
465 466
}

467 468 469 470 471
_git_cherry ()
{
	__gitcomp "$(__git_refs)"
}

472 473 474 475 476
_git_cherry_pick ()
{
	local cur="${COMP_WORDS[COMP_CWORD]}"
	case "$cur" in
	--*)
477
		__gitcomp "--edit --no-commit"
478 479
		;;
	*)
480
		__gitcomp "$(__git_refs)"
481 482 483 484
		;;
	esac
}

485 486 487 488 489
_git_commit ()
{
	local cur="${COMP_WORDS[COMP_CWORD]}"
	case "$cur" in
	--*)
490
		__gitcomp "
491 492
			--all --author= --signoff --verify --no-verify
			--edit --amend --include --only
493
			"
494 495 496 497 498
		return
	esac
	COMPREPLY=()
}

499 500 501 502 503 504 505
_git_diff ()
{
	__git_complete_file
}

_git_diff_tree ()
{
506
	__gitcomp "$(__git_refs)"
507 508 509 510 511 512 513 514
}

_git_fetch ()
{
	local cur="${COMP_WORDS[COMP_CWORD]}"

	case "${COMP_WORDS[0]},$COMP_CWORD" in
	git-fetch*,1)
515
		__gitcomp "$(__git_remotes)"
516 517
		;;
	git,2)
518
		__gitcomp "$(__git_remotes)"
519 520 521 522
		;;
	*)
		case "$cur" in
		*:*)
523
			__gitcomp "$(__git_refs)" "" "${cur#*:}"
524 525 526 527 528 529 530
			;;
		*)
			local remote
			case "${COMP_WORDS[0]}" in
			git-fetch) remote="${COMP_WORDS[1]}" ;;
			git)       remote="${COMP_WORDS[2]}" ;;
			esac
531
			__gitcomp "$(__git_refs2 "$remote")"
532 533 534 535 536 537
			;;
		esac
		;;
	esac
}

538 539 540 541 542
_git_format_patch ()
{
	local cur="${COMP_WORDS[COMP_CWORD]}"
	case "$cur" in
	--*)
543
		__gitcomp "
544 545 546 547 548 549 550
			--stdout --attach --thread
			--output-directory
			--numbered --start-number
			--keep-subject
			--signoff
			--in-reply-to=
			--full-index --binary
551
			--not --all
552
			"
553 554 555 556 557 558
		return
		;;
	esac
	__git_complete_revlist
}

559 560 561 562 563 564 565 566 567 568 569 570
_git_gc ()
{
	local cur="${COMP_WORDS[COMP_CWORD]}"
	case "$cur" in
	--*)
		__gitcomp "--prune"
		return
		;;
	esac
	COMPREPLY=()
}

571 572
_git_ls_remote ()
{
573
	__gitcomp "$(__git_remotes)"
574 575 576 577 578 579 580 581 582
}

_git_ls_tree ()
{
	__git_complete_file
}

_git_log ()
{
583 584 585
	local cur="${COMP_WORDS[COMP_CWORD]}"
	case "$cur" in
	--pretty=*)
586
		__gitcomp "
587
			oneline short medium full fuller email raw
588
			" "" "${cur##--pretty=}"
589 590 591
		return
		;;
	--*)
592
		__gitcomp "
593 594
			--max-count= --max-age= --since= --after=
			--min-age= --before= --until=
595
			--root --topo-order --date-order
596 597 598 599 600 601
			--no-merges
			--abbrev-commit --abbrev=
			--relative-date
			--author= --committer= --grep=
			--all-match
			--pretty= --name-status --name-only
602
			--not --all
603
			"
604 605 606
		return
		;;
	esac
607
	__git_complete_revlist
608 609
}

610 611 612
_git_merge ()
{
	local cur="${COMP_WORDS[COMP_CWORD]}"
613 614
	case "${COMP_WORDS[COMP_CWORD-1]}" in
	-s|--strategy)
615
		__gitcomp "$(__git_merge_strategies)"
616 617
		return
	esac
618
	case "$cur" in
619
	--strategy=*)
620
		__gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
621 622
		return
		;;
623
	--*)
624
		__gitcomp "
625
			--no-commit --no-summary --squash --strategy
626
			"
627 628
		return
	esac
629
	__gitcomp "$(__git_refs)"
630 631
}

632 633
_git_merge_base ()
{
634
	__gitcomp "$(__git_refs)"
635 636
}

637 638
_git_name_rev ()
{
639
	__gitcomp "--tags --all --stdin"
640 641
}

642 643 644 645 646 647
_git_pull ()
{
	local cur="${COMP_WORDS[COMP_CWORD]}"

	case "${COMP_WORDS[0]},$COMP_CWORD" in
	git-pull*,1)
648
		__gitcomp "$(__git_remotes)"
649 650
		;;
	git,2)
651
		__gitcomp "$(__git_remotes)"
652 653 654 655 656 657 658
		;;
	*)
		local remote
		case "${COMP_WORDS[0]}" in
		git-pull)  remote="${COMP_WORDS[1]}" ;;
		git)       remote="${COMP_WORDS[2]}" ;;
		esac
659
		__gitcomp "$(__git_refs "$remote")"
660 661 662 663 664 665 666 667 668 669
		;;
	esac
}

_git_push ()
{
	local cur="${COMP_WORDS[COMP_CWORD]}"

	case "${COMP_WORDS[0]},$COMP_CWORD" in
	git-push*,1)
670
		__gitcomp "$(__git_remotes)"
671 672
		;;
	git,2)
673
		__gitcomp "$(__git_remotes)"
674 675 676 677 678 679 680 681 682
		;;
	*)
		case "$cur" in
		*:*)
			local remote
			case "${COMP_WORDS[0]}" in
			git-push)  remote="${COMP_WORDS[1]}" ;;
			git)       remote="${COMP_WORDS[2]}" ;;
			esac
683
			__gitcomp "$(__git_refs "$remote")" "" "${cur#*:}"
684 685
			;;
		*)
686
			__gitcomp "$(__git_refs2)"
687 688 689 690 691 692
			;;
		esac
		;;
	esac
}

693 694 695
_git_rebase ()
{
	local cur="${COMP_WORDS[COMP_CWORD]}"
696
	if [ -d .dotest ] || [ -d .git/.dotest-merge ]; then
697
		__gitcomp "--continue --skip --abort"
698 699
		return
	fi
700 701
	case "${COMP_WORDS[COMP_CWORD-1]}" in
	-s|--strategy)
702
		__gitcomp "$(__git_merge_strategies)"
703 704
		return
	esac
705
	case "$cur" in
706
	--strategy=*)
707
		__gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
708 709
		return
		;;
710
	--*)
711
		__gitcomp "--onto --merge --strategy"
712 713
		return
	esac
714
	__gitcomp "$(__git_refs)"
715 716
}

717
_git_config ()
718 719 720 721 722
{
	local cur="${COMP_WORDS[COMP_CWORD]}"
	local prv="${COMP_WORDS[COMP_CWORD-1]}"
	case "$prv" in
	branch.*.remote)
723
		__gitcomp "$(__git_remotes)"
724 725 726
		return
		;;
	branch.*.merge)
727
		__gitcomp "$(__git_refs)"
728 729 730 731 732
		return
		;;
	remote.*.fetch)
		local remote="${prv#remote.}"
		remote="${remote%.fetch}"
733
		__gitcomp "$(__git_refs_remotes "$remote")"
734 735 736 737 738
		return
		;;
	remote.*.push)
		local remote="${prv#remote.}"
		remote="${remote%.push}"
739
		__gitcomp "$(git --git-dir="$(__gitdir)" \
740
			for-each-ref --format='%(refname):%(refname)' \
741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756
			refs/heads)"
		return
		;;
	pull.twohead|pull.octopus)
		__gitcomp "$(__git_merge_strategies)"
		return
		;;
	color.branch|color.diff|color.status)
		__gitcomp "always never auto"
		return
		;;
	color.*.*)
		__gitcomp "
			black red green yellow blue magenta cyan white
			bold dim ul blink reverse
			"
757 758 759 760 761 762 763 764 765
		return
		;;
	*.*)
		COMPREPLY=()
		return
		;;
	esac
	case "$cur" in
	--*)
766
		__gitcomp "
767 768
			--global --list --replace-all
			--get --get-all --get-regexp
769
			--add --unset --unset-all
770
			"
771 772 773 774 775
		return
		;;
	branch.*.*)
		local pfx="${cur%.*}."
		cur="${cur##*.}"
776
		__gitcomp "remote merge" "$pfx" "$cur"
777 778 779 780 781
		return
		;;
	branch.*)
		local pfx="${cur%.*}."
		cur="${cur#*.}"
782
		__gitcomp "$(__git_heads)" "$pfx" "$cur" "."
783 784 785 786 787
		return
		;;
	remote.*.*)
		local pfx="${cur%.*}."
		cur="${cur##*.}"
788
		__gitcomp "url fetch push" "$pfx" "$cur"
789 790 791 792 793
		return
		;;
	remote.*)
		local pfx="${cur%.*}."
		cur="${cur#*.}"
794
		__gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
795 796 797
		return
		;;
	esac
798
	__gitcomp "
799 800 801 802 803 804 805 806 807 808 809
		apply.whitespace
		core.fileMode
		core.gitProxy
		core.ignoreStat
		core.preferSymlinkRefs
		core.logAllRefUpdates
		core.repositoryFormatVersion
		core.sharedRepository
		core.warnAmbiguousRefs
		core.compression
		core.legacyHeaders
810 811
		core.packedGitWindowSize
		core.packedGitLimit
812
		clean.requireForce
813 814 815 816 817
		color.branch
		color.branch.current
		color.branch.local
		color.branch.remote
		color.branch.plain
818
		color.diff
819 820 821 822 823 824 825
		color.diff.plain
		color.diff.meta
		color.diff.frag
		color.diff.old
		color.diff.new
		color.diff.commit
		color.diff.whitespace
826 827
		color.pager
		color.status
828 829 830 831 832 833 834 835 836 837 838 839 840 841
		color.status.header
		color.status.added
		color.status.changed
		color.status.untracked
		diff.renameLimit
		diff.renames
		fetch.unpackLimit
		format.headers
		gitcvs.enabled
		gitcvs.logfile
		gc.reflogexpire
		gc.reflogexpireunreachable
		gc.rerereresolved
		gc.rerereunresolved
842 843 844 845 846 847
		http.sslVerify
		http.sslCert
		http.sslKey
		http.sslCAInfo
		http.sslCAPath
		http.maxRequests
848 849
		http.lowSpeedLimit
		http.lowSpeedTime
850
		http.noEPSV
851 852 853 854 855
		i18n.commitEncoding
		i18n.logOutputEncoding
		log.showroot
		merge.summary
		merge.verbosity
856
		pack.window
857 858
		pull.octopus
		pull.twohead
859
		repack.useDeltaBaseOffset
860 861 862 863
		show.difftree
		showbranch.default
		tar.umask
		transfer.unpackLimit
864 865
		receive.unpackLimit
		receive.denyNonFastForwards
866 867 868 869
		user.name
		user.email
		user.signingkey
		whatchanged.difftree
870
		branch. remote.
871
	"
872 873
}

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 899
_git_remote ()
{
	local i c=1 command
	while [ $c -lt $COMP_CWORD ]; do
		i="${COMP_WORDS[c]}"
		case "$i" in
		add|show|prune) command="$i"; break ;;
		esac
		c=$((++c))
	done

	if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
		__gitcomp "add show prune"
		return
	fi

	case "$command" in
	show|prune)
		__gitcomp "$(__git_remotes)"
		;;
	*)
		COMPREPLY=()
		;;
	esac
}

900 901 902
_git_reset ()
{
	local cur="${COMP_WORDS[COMP_CWORD]}"
903 904 905 906 907 908 909
	case "$cur" in
	--*)
		__gitcomp "--mixed --hard --soft"
		return
		;;
	esac
	__gitcomp "$(__git_refs)"
910 911
}

912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931
_git_shortlog ()
{
	local cur="${COMP_WORDS[COMP_CWORD]}"
	case "$cur" in
	--*)
		__gitcomp "
			--max-count= --max-age= --since= --after=
			--min-age= --before= --until=
			--no-merges
			--author= --committer= --grep=
			--all-match
			--not --all
			--numbered --summary
			"
		return
		;;
	esac
	__git_complete_revlist
}

932 933 934 935 936
_git_show ()
{
	local cur="${COMP_WORDS[COMP_CWORD]}"
	case "$cur" in
	--pretty=*)
937
		__gitcomp "
938
			oneline short medium full fuller email raw
939
			" "" "${cur##--pretty=}"
940 941 942
		return
		;;
	--*)
943
		__gitcomp "--pretty="
944 945 946 947 948 949
		return
		;;
	esac
	__git_complete_file
}

950 951
_git ()
{
952 953 954 955 956 957 958 959 960 961 962 963 964 965
	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="." ;;
		--version|--help|-p|--paginate) ;;
		*) command="$i"; break ;;
		esac
		c=$((++c))
	done

	if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
966 967 968 969 970 971
		case "${COMP_WORDS[COMP_CWORD]}" in
		--*=*) COMPREPLY=() ;;
		--*)   __gitcomp "--git-dir= --bare --version --exec-path" ;;
		*)     __gitcomp "$(__git_commands) $(__git_aliases)" ;;
		esac
		return
972
	fi
973

974 975
	local expansion=$(__git_aliased_command "$command")
	[ "$expansion" ] && command="$expansion"
976

977
	case "$command" in
978
	am)          _git_am ;;
979
	add)         _git_add ;;
980
	apply)       _git_apply ;;
981
	bisect)      _git_bisect ;;
982 983
	branch)      _git_branch ;;
	checkout)    _git_checkout ;;
984
	cherry)      _git_cherry ;;
985
	cherry-pick) _git_cherry_pick ;;
986
	commit)      _git_commit ;;
987
	config)      _git_config ;;
988 989
	diff)        _git_diff ;;
	fetch)       _git_fetch ;;
990
	format-patch) _git_format_patch ;;
991
	gc)          _git_gc ;;
992 993 994
	log)         _git_log ;;
	ls-remote)   _git_ls_remote ;;
	ls-tree)     _git_ls_tree ;;
995
	merge)       _git_merge;;
996
	merge-base)  _git_merge_base ;;
997
	name-rev)    _git_name_rev ;;
998 999
	pull)        _git_pull ;;
	push)        _git_push ;;
1000
	rebase)      _git_rebase ;;
1001
	remote)      _git_remote ;;
1002
	reset)       _git_reset ;;
1003
	shortlog)    _git_shortlog ;;
1004
	show)        _git_show ;;
1005 1006 1007 1008
	show-branch) _git_log ;;
	whatchanged) _git_log ;;
	*)           COMPREPLY=() ;;
	esac
1009 1010 1011 1012 1013
}

_gitk ()
{
	local cur="${COMP_WORDS[COMP_CWORD]}"
1014 1015 1016 1017 1018 1019
	case "$cur" in
	--*)
		__gitcomp "--not --all"
		return
		;;
	esac
1020
	__git_complete_revlist
1021 1022 1023
}

complete -o default -o nospace -F _git git
1024 1025 1026
complete -o default -o nospace -F _gitk gitk
complete -o default -o nospace -F _git_am git-am
complete -o default -o nospace -F _git_apply git-apply
1027
complete -o default -o nospace -F _git_bisect git-bisect
1028 1029
complete -o default -o nospace -F _git_branch git-branch
complete -o default -o nospace -F _git_checkout git-checkout
1030
complete -o default -o nospace -F _git_cherry git-cherry
1031 1032
complete -o default -o nospace -F _git_cherry_pick git-cherry-pick
complete -o default -o nospace -F _git_commit git-commit
1033 1034
complete -o default -o nospace -F _git_diff git-diff
complete -o default -o nospace -F _git_fetch git-fetch
1035
complete -o default -o nospace -F _git_format_patch git-format-patch
1036
complete -o default -o nospace -F _git_gc git-gc
1037
complete -o default -o nospace -F _git_log git-log
1038
complete -o default -o nospace -F _git_ls_remote git-ls-remote
1039
complete -o default -o nospace -F _git_ls_tree git-ls-tree
1040 1041 1042
complete -o default -o nospace -F _git_merge git-merge
complete -o default -o nospace -F _git_merge_base git-merge-base
complete -o default -o nospace -F _git_name_rev git-name-rev
1043 1044
complete -o default -o nospace -F _git_pull git-pull
complete -o default -o nospace -F _git_push git-push
1045 1046
complete -o default -o nospace -F _git_rebase git-rebase
complete -o default -o nospace -F _git_config git-config
1047
complete -o default -o nospace -F _git_remote git-remote
1048
complete -o default -o nospace -F _git_reset git-reset
1049
complete -o default -o nospace -F _git_shortlog git-shortlog
1050
complete -o default -o nospace -F _git_show git-show
1051
complete -o default -o nospace -F _git_log git-show-branch
1052 1053 1054 1055 1056 1057
complete -o default -o nospace -F _git_log git-whatchanged

# 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.
#
1058
if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
1059 1060
complete -o default -o nospace -F _git_add git-add.exe
complete -o default -o nospace -F _git_apply git-apply.exe
1061
complete -o default -o nospace -F _git git.exe
1062
complete -o default -o nospace -F _git_branch git-branch.exe
1063
complete -o default -o nospace -F _git_cherry git-cherry.exe
1064
complete -o default -o nospace -F _git_diff git-diff.exe
1065
complete -o default -o nospace -F _git_format_patch git-format-patch.exe
1066 1067
complete -o default -o nospace -F _git_log git-log.exe
complete -o default -o nospace -F _git_ls_tree git-ls-tree.exe
1068 1069
complete -o default -o nospace -F _git_merge_base git-merge-base.exe
complete -o default -o nospace -F _git_name_rev git-name-rev.exe
1070
complete -o default -o nospace -F _git_push git-push.exe
1071
complete -o default -o nospace -F _git_config git-config
1072
complete -o default -o nospace -F _git_shortlog git-shortlog.exe
1073
complete -o default -o nospace -F _git_show git-show.exe
1074
complete -o default -o nospace -F _git_log git-show-branch.exe
1075
complete -o default -o nospace -F _git_log git-whatchanged.exe
1076
fi