Subversion Repositories configs

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4 - 1
# bash completion support for core Git.
2
#
3
# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
4
# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
5
# Distributed under the GNU General Public License, version 2.0.
6
#
7
# The contained completion routines provide support for completing:
8
#
9
#    *) local and remote branch names
10
#    *) local and remote tag names
11
#    *) .git/remotes file names
12
#    *) git 'subcommands'
13
#    *) tree paths within 'ref:path/to/file' expressions
14
#    *) common --long-options
15
#
16
# To use these routines:
17
#
18
#    1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
19
#    2) Added the following line to your .bashrc:
20
#        source ~/.git-completion.sh
21
#
22
#    3) Consider changing your PS1 to also show the current branch:
23
#        PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
24
#
25
#       The argument to __git_ps1 will be displayed only if you
26
#       are currently in a git repository.  The %s token will be
27
#       the name of the current branch.
28
#
29
#       In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty
30
#       value, unstaged (*) and staged (+) changes will be shown next
31
#       to the branch name.  You can configure this per-repository
32
#       with the bash.showDirtyState variable, which defaults to true
33
#       once GIT_PS1_SHOWDIRTYSTATE is enabled.
34
#
35
#       You can also see if currently something is stashed, by setting
36
#       GIT_PS1_SHOWSTASHSTATE to a nonempty value. If something is stashed,
37
#       then a '$' will be shown next to the branch name.
38
#
39
#       If you would like to see if there're untracked files, then you can
40
#       set GIT_PS1_SHOWUNTRACKEDFILES to a nonempty value. If there're
41
#       untracked files, then a '%' will be shown next to the branch name.
42
#
43
# To submit patches:
44
#
45
#    *) Read Documentation/SubmittingPatches
46
#    *) Send all patches to the current maintainer:
47
#
48
#       "Shawn O. Pearce" <spearce@spearce.org>
49
#
50
#    *) Always CC the Git mailing list:
51
#
52
#       git@vger.kernel.org
53
#
54
 
55
case "$COMP_WORDBREAKS" in
56
*:*) : great ;;
57
*)   COMP_WORDBREAKS="$COMP_WORDBREAKS:"
58
esac
59
 
60
# __gitdir accepts 0 or 1 arguments (i.e., location)
61
# returns location of .git repo
62
__gitdir ()
63
{
64
	if [ -z "${1-}" ]; then
65
		if [ -n "${__git_dir-}" ]; then
66
			echo "$__git_dir"
67
		elif [ -d .git ]; then
68
			echo .git
69
		else
70
			git rev-parse --git-dir 2>/dev/null
71
		fi
72
	elif [ -d "$1/.git" ]; then
73
		echo "$1/.git"
74
	else
75
		echo "$1"
76
	fi
77
}
78
 
79
# __git_ps1 accepts 0 or 1 arguments (i.e., format string)
80
# returns text to add to bash PS1 prompt (includes branch name)
81
__git_ps1 ()
82
{
83
	local g="$(__gitdir)"
84
	if [ -n "$g" ]; then
85
		local r
86
		local b
87
		if [ -f "$g/rebase-merge/interactive" ]; then
88
			r="|REBASE-i"
89
			b="$(cat "$g/rebase-merge/head-name")"
90
		elif [ -d "$g/rebase-merge" ]; then
91
			r="|REBASE-m"
92
			b="$(cat "$g/rebase-merge/head-name")"
93
		else
94
			if [ -d "$g/rebase-apply" ]; then
95
				if [ -f "$g/rebase-apply/rebasing" ]; then
96
					r="|REBASE"
97
				elif [ -f "$g/rebase-apply/applying" ]; then
98
					r="|AM"
99
				else
100
					r="|AM/REBASE"
101
				fi
102
			elif [ -f "$g/MERGE_HEAD" ]; then
103
				r="|MERGING"
104
			elif [ -f "$g/BISECT_LOG" ]; then
105
				r="|BISECTING"
106
			fi
107
 
108
			b="$(git symbolic-ref HEAD 2>/dev/null)" || {
109
 
110
				b="$(
111
				case "${GIT_PS1_DESCRIBE_STYLE-}" in
112
				(contains)
113
					git describe --contains HEAD ;;
114
				(branch)
115
					git describe --contains --all HEAD ;;
116
				(describe)
117
					git describe HEAD ;;
118
				(* | default)
119
					git describe --exact-match HEAD ;;
120
				esac 2>/dev/null)" ||
121
 
122
				b="$(cut -c1-7 "$g/HEAD" 2>/dev/null)..." ||
123
				b="unknown"
124
				b="($b)"
125
			}
126
		fi
127
 
128
		local w
129
		local i
130
		local s
131
		local u
132
		local c
133
 
134
		if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then
135
			if [ "true" = "$(git rev-parse --is-bare-repository 2>/dev/null)" ]; then
136
				c="BARE:"
137
			else
138
				b="GIT_DIR!"
139
			fi
140
		elif [ "true" = "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then
141
			if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ]; then
142
				if [ "$(git config --bool bash.showDirtyState)" != "false" ]; then
143
					git diff --no-ext-diff --quiet --exit-code || w="*"
144
					if git rev-parse --quiet --verify HEAD >/dev/null; then
145
						git diff-index --cached --quiet HEAD -- || i="+"
146
					else
147
						i="#"
148
					fi
149
				fi
150
			fi
151
			if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ]; then
152
			        git rev-parse --verify refs/stash >/dev/null 2>&1 && s="$"
153
			fi
154
 
155
			if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ]; then
156
			   if [ -n "$(git ls-files --others --exclude-standard)" ]; then
157
			      u="%"
158
			   fi
159
			fi
160
		fi
161
 
162
		local f="$w$i$s$u"
163
		printf "${1:- (%s)}" "$c${b##refs/heads/}${f:+ $f}$r"
164
	fi
165
}
166
 
167
# __gitcomp_1 requires 2 arguments
168
__gitcomp_1 ()
169
{
170
	local c IFS=' '$'\t'$'\n'
171
	for c in $1; do
172
		case "$c$2" in
173
		--*=*) printf %s$'\n' "$c$2" ;;
174
		*.)    printf %s$'\n' "$c$2" ;;
175
		*)     printf %s$'\n' "$c$2 " ;;
176
		esac
177
	done
178
}
179
 
180
# __gitcomp accepts 1, 2, 3, or 4 arguments
181
# generates completion reply with compgen
182
__gitcomp ()
183
{
184
	local cur="${COMP_WORDS[COMP_CWORD]}"
185
	if [ $# -gt 2 ]; then
186
		cur="$3"
187
	fi
188
	case "$cur" in
189
	--*=)
190
		COMPREPLY=()
191
		;;
192
	*)
193
		local IFS=$'\n'
194
		COMPREPLY=($(compgen -P "${2-}" \
195
			-W "$(__gitcomp_1 "${1-}" "${4-}")" \
196
			-- "$cur"))
197
		;;
198
	esac
199
}
200
 
201
# __git_heads accepts 0 or 1 arguments (to pass to __gitdir)
202
__git_heads ()
203
{
204
	local cmd i is_hash=y dir="$(__gitdir "${1-}")"
205
	if [ -d "$dir" ]; then
206
		git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
207
			refs/heads
208
		return
209
	fi
210
	for i in $(git ls-remote "${1-}" 2>/dev/null); do
211
		case "$is_hash,$i" in
212
		y,*) is_hash=n ;;
213
		n,*^{}) is_hash=y ;;
214
		n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
215
		n,*) is_hash=y; echo "$i" ;;
216
		esac
217
	done
218
}
219
 
220
# __git_tags accepts 0 or 1 arguments (to pass to __gitdir)
221
__git_tags ()
222
{
223
	local cmd i is_hash=y dir="$(__gitdir "${1-}")"
224
	if [ -d "$dir" ]; then
225
		git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
226
			refs/tags
227
		return
228
	fi
229
	for i in $(git ls-remote "${1-}" 2>/dev/null); do
230
		case "$is_hash,$i" in
231
		y,*) is_hash=n ;;
232
		n,*^{}) is_hash=y ;;
233
		n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
234
		n,*) is_hash=y; echo "$i" ;;
235
		esac
236
	done
237
}
238
 
239
# __git_refs accepts 0 or 1 arguments (to pass to __gitdir)
240
__git_refs ()
241
{
242
	local i is_hash=y dir="$(__gitdir "${1-}")"
243
	local cur="${COMP_WORDS[COMP_CWORD]}" format refs
244
	if [ -d "$dir" ]; then
245
		case "$cur" in
246
		refs|refs/*)
247
			format="refname"
248
			refs="${cur%/*}"
249
			;;
250
		*)
251
			for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
252
				if [ -e "$dir/$i" ]; then echo $i; fi
253
			done
254
			format="refname:short"
255
			refs="refs/tags refs/heads refs/remotes"
256
			;;
257
		esac
258
		git --git-dir="$dir" for-each-ref --format="%($format)" \
259
			$refs
260
		return
261
	fi
262
	for i in $(git ls-remote "$dir" 2>/dev/null); do
263
		case "$is_hash,$i" in
264
		y,*) is_hash=n ;;
265
		n,*^{}) is_hash=y ;;
266
		n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
267
		n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
268
		n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
269
		n,*) is_hash=y; echo "$i" ;;
270
		esac
271
	done
272
}
273
 
274
# __git_refs2 requires 1 argument (to pass to __git_refs)
275
__git_refs2 ()
276
{
277
	local i
278
	for i in $(__git_refs "$1"); do
279
		echo "$i:$i"
280
	done
281
}
282
 
283
# __git_refs_remotes requires 1 argument (to pass to ls-remote)
284
__git_refs_remotes ()
285
{
286
	local cmd i is_hash=y
287
	for i in $(git ls-remote "$1" 2>/dev/null); do
288
		case "$is_hash,$i" in
289
		n,refs/heads/*)
290
			is_hash=y
291
			echo "$i:refs/remotes/$1/${i#refs/heads/}"
292
			;;
293
		y,*) is_hash=n ;;
294
		n,*^{}) is_hash=y ;;
295
		n,refs/tags/*) is_hash=y;;
296
		n,*) is_hash=y; ;;
297
		esac
298
	done
299
}
300
 
301
__git_remotes ()
302
{
303
	local i ngoff IFS=$'\n' d="$(__gitdir)"
304
	shopt -q nullglob || ngoff=1
305
	shopt -s nullglob
306
	for i in "$d/remotes"/*; do
307
		echo ${i#$d/remotes/}
308
	done
309
	[ "$ngoff" ] && shopt -u nullglob
310
	for i in $(git --git-dir="$d" config --get-regexp 'remote\..*\.url' 2>/dev/null); do
311
		i="${i#remote.}"
312
		echo "${i/.url*/}"
313
	done
314
}
315
 
316
__git_list_merge_strategies ()
317
{
318
	git merge -s help 2>&1 |
319
	sed -n -e '/[Aa]vailable strategies are: /,/^$/{
320
		s/\.$//
321
		s/.*://
322
		s/^[ 	]*//
323
		s/[ 	]*$//
324
		p
325
	}'
326
}
327
 
328
__git_merge_strategies=
329
# 'git merge -s help' (and thus detection of the merge strategy
330
# list) fails, unfortunately, if run outside of any git working
331
# tree.  __git_merge_strategies is set to the empty string in
332
# that case, and the detection will be repeated the next time it
333
# is needed.
334
__git_compute_merge_strategies ()
335
{
336
	: ${__git_merge_strategies:=$(__git_list_merge_strategies)}
337
}
338
 
339
__git_complete_file ()
340
{
341
	local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
342
	case "$cur" in
343
	?*:*)
344
		ref="${cur%%:*}"
345
		cur="${cur#*:}"
346
		case "$cur" in
347
		?*/*)
348
			pfx="${cur%/*}"
349
			cur="${cur##*/}"
350
			ls="$ref:$pfx"
351
			pfx="$pfx/"
352
			;;
353
		*)
354
			ls="$ref"
355
			;;
356
	    esac
357
 
358
		case "$COMP_WORDBREAKS" in
359
		*:*) : great ;;
360
		*)   pfx="$ref:$pfx" ;;
361
		esac
362
 
363
		local IFS=$'\n'
364
		COMPREPLY=($(compgen -P "$pfx" \
365
			-W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
366
				| sed '/^100... blob /{
367
				           s,^.*	,,
368
				           s,$, ,
369
				       }
370
				       /^120000 blob /{
371
				           s,^.*	,,
372
				           s,$, ,
373
				       }
374
				       /^040000 tree /{
375
				           s,^.*	,,
376
				           s,$,/,
377
				       }
378
				       s/^.*	//')" \
379
			-- "$cur"))
380
		;;
381
	*)
382
		__gitcomp "$(__git_refs)"
383
		;;
384
	esac
385
}
386
 
387
__git_complete_revlist ()
388
{
389
	local pfx cur="${COMP_WORDS[COMP_CWORD]}"
390
	case "$cur" in
391
	*...*)
392
		pfx="${cur%...*}..."
393
		cur="${cur#*...}"
394
		__gitcomp "$(__git_refs)" "$pfx" "$cur"
395
		;;
396
	*..*)
397
		pfx="${cur%..*}.."
398
		cur="${cur#*..}"
399
		__gitcomp "$(__git_refs)" "$pfx" "$cur"
400
		;;
401
	*)
402
		__gitcomp "$(__git_refs)"
403
		;;
404
	esac
405
}
406
 
407
__git_complete_remote_or_refspec ()
408
{
409
	local cmd="${COMP_WORDS[1]}"
410
	local cur="${COMP_WORDS[COMP_CWORD]}"
411
	local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
412
	while [ $c -lt $COMP_CWORD ]; do
413
		i="${COMP_WORDS[c]}"
414
		case "$i" in
415
		--mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
416
		--all)
417
			case "$cmd" in
418
			push) no_complete_refspec=1 ;;
419
			fetch)
420
				COMPREPLY=()
421
				return
422
				;;
423
			*) ;;
424
			esac
425
			;;
426
		-*) ;;
427
		*) remote="$i"; break ;;
428
		esac
429
		c=$((++c))
430
	done
431
	if [ -z "$remote" ]; then
432
		__gitcomp "$(__git_remotes)"
433
		return
434
	fi
435
	if [ $no_complete_refspec = 1 ]; then
436
		COMPREPLY=()
437
		return
438
	fi
439
	[ "$remote" = "." ] && remote=
440
	case "$cur" in
441
	*:*)
442
		case "$COMP_WORDBREAKS" in
443
		*:*) : great ;;
444
		*)   pfx="${cur%%:*}:" ;;
445
		esac
446
		cur="${cur#*:}"
447
		lhs=0
448
		;;
449
	+*)
450
		pfx="+"
451
		cur="${cur#+}"
452
		;;
453
	esac
454
	case "$cmd" in
455
	fetch)
456
		if [ $lhs = 1 ]; then
457
			__gitcomp "$(__git_refs2 "$remote")" "$pfx" "$cur"
458
		else
459
			__gitcomp "$(__git_refs)" "$pfx" "$cur"
460
		fi
461
		;;
462
	pull)
463
		if [ $lhs = 1 ]; then
464
			__gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
465
		else
466
			__gitcomp "$(__git_refs)" "$pfx" "$cur"
467
		fi
468
		;;
469
	push)
470
		if [ $lhs = 1 ]; then
471
			__gitcomp "$(__git_refs)" "$pfx" "$cur"
472
		else
473
			__gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
474
		fi
475
		;;
476
	esac
477
}
478
 
479
__git_complete_strategy ()
480
{
481
	__git_compute_merge_strategies
482
	case "${COMP_WORDS[COMP_CWORD-1]}" in
483
	-s|--strategy)
484
		__gitcomp "$__git_merge_strategies"
485
		return 0
486
	esac
487
	local cur="${COMP_WORDS[COMP_CWORD]}"
488
	case "$cur" in
489
	--strategy=*)
490
		__gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
491
		return 0
492
		;;
493
	esac
494
	return 1
495
}
496
 
497
__git_list_all_commands ()
498
{
499
	local i IFS=" "$'\n'
500
	for i in $(git help -a|egrep '^  [a-zA-Z0-9]')
501
	do
502
		case $i in
503
		*--*)             : helper pattern;;
504
		*) echo $i;;
505
		esac
506
	done
507
}
508
 
509
__git_all_commands=
510
__git_compute_all_commands ()
511
{
512
	: ${__git_all_commands:=$(__git_list_all_commands)}
513
}
514
 
515
__git_list_porcelain_commands ()
516
{
517
	local i IFS=" "$'\n'
518
	__git_compute_all_commands
519
	for i in "help" $__git_all_commands
520
	do
521
		case $i in
522
		*--*)             : helper pattern;;
523
		applymbox)        : ask gittus;;
524
		applypatch)       : ask gittus;;
525
		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
		cvsexportcommit)  : export;;
533
		cvsimport)        : import;;
534
		cvsserver)        : daemon;;
535
		daemon)           : daemon;;
536
		diff-files)       : plumbing;;
537
		diff-index)       : plumbing;;
538
		diff-tree)        : plumbing;;
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
		hash-object)      : plumbing;;
546
		http-*)           : transport;;
547
		index-pack)       : plumbing;;
548
		init-db)          : deprecated;;
549
		local-fetch)      : plumbing;;
550
		lost-found)       : infrequent;;
551
		ls-files)         : plumbing;;
552
		ls-remote)        : plumbing;;
553
		ls-tree)          : plumbing;;
554
		mailinfo)         : plumbing;;
555
		mailsplit)        : plumbing;;
556
		merge-*)          : plumbing;;
557
		mktree)           : plumbing;;
558
		mktag)            : plumbing;;
559
		pack-objects)     : plumbing;;
560
		pack-redundant)   : plumbing;;
561
		pack-refs)        : plumbing;;
562
		parse-remote)     : plumbing;;
563
		patch-id)         : plumbing;;
564
		peek-remote)      : plumbing;;
565
		prune)            : plumbing;;
566
		prune-packed)     : plumbing;;
567
		quiltimport)      : import;;
568
		read-tree)        : plumbing;;
569
		receive-pack)     : plumbing;;
570
		reflog)           : plumbing;;
571
		remote-*)         : transport;;
572
		repo-config)      : deprecated;;
573
		rerere)           : plumbing;;
574
		rev-list)         : plumbing;;
575
		rev-parse)        : plumbing;;
576
		runstatus)        : plumbing;;
577
		sh-setup)         : internal;;
578
		shell)            : daemon;;
579
		show-ref)         : plumbing;;
580
		send-pack)        : plumbing;;
581
		show-index)       : plumbing;;
582
		ssh-*)            : transport;;
583
		stripspace)       : plumbing;;
584
		symbolic-ref)     : plumbing;;
585
		tar-tree)         : deprecated;;
586
		unpack-file)      : plumbing;;
587
		unpack-objects)   : plumbing;;
588
		update-index)     : plumbing;;
589
		update-ref)       : plumbing;;
590
		update-server-info) : daemon;;
591
		upload-archive)   : plumbing;;
592
		upload-pack)      : plumbing;;
593
		write-tree)       : plumbing;;
594
		var)              : infrequent;;
595
		verify-pack)      : infrequent;;
596
		verify-tag)       : plumbing;;
597
		*) echo $i;;
598
		esac
599
	done
600
}
601
 
602
__git_porcelain_commands=
603
__git_compute_porcelain_commands ()
604
{
605
	__git_compute_all_commands
606
	: ${__git_porcelain_commands:=$(__git_list_porcelain_commands)}
607
}
608
 
609
__git_aliases ()
610
{
611
	local i IFS=$'\n'
612
	for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do
613
		case "$i" in
614
		alias.*)
615
			i="${i#alias.}"
616
			echo "${i/ */}"
617
			;;
618
		esac
619
	done
620
}
621
 
622
# __git_aliased_command requires 1 argument
623
__git_aliased_command ()
624
{
625
	local word cmdline=$(git --git-dir="$(__gitdir)" \
626
		config --get "alias.$1")
627
	for word in $cmdline; do
628
		case "$word" in
629
		\!gitk|gitk)
630
			echo "gitk"
631
			return
632
			;;
633
		\!*)	: shell command alias ;;
634
		-*)	: option ;;
635
		*=*)	: setting env ;;
636
		git)	: git itself ;;
637
		*)
638
			echo "$word"
639
			return
640
		esac
641
	done
642
}
643
 
644
# __git_find_on_cmdline requires 1 argument
645
__git_find_on_cmdline ()
646
{
647
	local word subcommand c=1
648
 
649
	while [ $c -lt $COMP_CWORD ]; do
650
		word="${COMP_WORDS[c]}"
651
		for subcommand in $1; do
652
			if [ "$subcommand" = "$word" ]; then
653
				echo "$subcommand"
654
				return
655
			fi
656
		done
657
		c=$((++c))
658
	done
659
}
660
 
661
__git_has_doubledash ()
662
{
663
	local c=1
664
	while [ $c -lt $COMP_CWORD ]; do
665
		if [ "--" = "${COMP_WORDS[c]}" ]; then
666
			return 0
667
		fi
668
		c=$((++c))
669
	done
670
	return 1
671
}
672
 
673
__git_whitespacelist="nowarn warn error error-all fix"
674
 
675
_git_am ()
676
{
677
	local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
678
	if [ -d "$dir"/rebase-apply ]; then
679
		__gitcomp "--skip --continue --resolved --abort"
680
		return
681
	fi
682
	case "$cur" in
683
	--whitespace=*)
684
		__gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
685
		return
686
		;;
687
	--*)
688
		__gitcomp "
689
			--3way --committer-date-is-author-date --ignore-date
690
			--ignore-whitespace --ignore-space-change
691
			--interactive --keep --no-utf8 --signoff --utf8
692
			--whitespace= --scissors
693
			"
694
		return
695
	esac
696
	COMPREPLY=()
697
}
698
 
699
_git_apply ()
700
{
701
	local cur="${COMP_WORDS[COMP_CWORD]}"
702
	case "$cur" in
703
	--whitespace=*)
704
		__gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
705
		return
706
		;;
707
	--*)
708
		__gitcomp "
709
			--stat --numstat --summary --check --index
710
			--cached --index-info --reverse --reject --unidiff-zero
711
			--apply --no-add --exclude=
712
			--ignore-whitespace --ignore-space-change
713
			--whitespace= --inaccurate-eof --verbose
714
			"
715
		return
716
	esac
717
	COMPREPLY=()
718
}
719
 
720
_git_add ()
721
{
722
	__git_has_doubledash && return
723
 
724
	local cur="${COMP_WORDS[COMP_CWORD]}"
725
	case "$cur" in
726
	--*)
727
		__gitcomp "
728
			--interactive --refresh --patch --update --dry-run
729
			--ignore-errors --intent-to-add
730
			"
731
		return
732
	esac
733
	COMPREPLY=()
734
}
735
 
736
_git_archive ()
737
{
738
	local cur="${COMP_WORDS[COMP_CWORD]}"
739
	case "$cur" in
740
	--format=*)
741
		__gitcomp "$(git archive --list)" "" "${cur##--format=}"
742
		return
743
		;;
744
	--remote=*)
745
		__gitcomp "$(__git_remotes)" "" "${cur##--remote=}"
746
		return
747
		;;
748
	--*)
749
		__gitcomp "
750
			--format= --list --verbose
751
			--prefix= --remote= --exec=
752
			"
753
		return
754
		;;
755
	esac
756
	__git_complete_file
757
}
758
 
759
_git_bisect ()
760
{
761
	__git_has_doubledash && return
762
 
763
	local subcommands="start bad good skip reset visualize replay log run"
764
	local subcommand="$(__git_find_on_cmdline "$subcommands")"
765
	if [ -z "$subcommand" ]; then
766
		__gitcomp "$subcommands"
767
		return
768
	fi
769
 
770
	case "$subcommand" in
771
	bad|good|reset|skip)
772
		__gitcomp "$(__git_refs)"
773
		;;
774
	*)
775
		COMPREPLY=()
776
		;;
777
	esac
778
}
779
 
780
_git_branch ()
781
{
782
	local i c=1 only_local_ref="n" has_r="n"
783
 
784
	while [ $c -lt $COMP_CWORD ]; do
785
		i="${COMP_WORDS[c]}"
786
		case "$i" in
787
		-d|-m)	only_local_ref="y" ;;
788
		-r)	has_r="y" ;;
789
		esac
790
		c=$((++c))
791
	done
792
 
793
	case "${COMP_WORDS[COMP_CWORD]}" in
794
	--*)
795
		__gitcomp "
796
			--color --no-color --verbose --abbrev= --no-abbrev
797
			--track --no-track --contains --merged --no-merged
798
			"
799
		;;
800
	*)
801
		if [ $only_local_ref = "y" -a $has_r = "n" ]; then
802
			__gitcomp "$(__git_heads)"
803
		else
804
			__gitcomp "$(__git_refs)"
805
		fi
806
		;;
807
	esac
808
}
809
 
810
_git_bundle ()
811
{
812
	local cmd="${COMP_WORDS[2]}"
813
	case "$COMP_CWORD" in
814
	2)
815
		__gitcomp "create list-heads verify unbundle"
816
		;;
817
	3)
818
		# looking for a file
819
		;;
820
	*)
821
		case "$cmd" in
822
			create)
823
				__git_complete_revlist
824
			;;
825
		esac
826
		;;
827
	esac
828
}
829
 
830
_git_checkout ()
831
{
832
	__git_has_doubledash && return
833
 
834
	local cur="${COMP_WORDS[COMP_CWORD]}"
835
	case "$cur" in
836
	--conflict=*)
837
		__gitcomp "diff3 merge" "" "${cur##--conflict=}"
838
		;;
839
	--*)
840
		__gitcomp "
841
			--quiet --ours --theirs --track --no-track --merge
842
			--conflict= --patch
843
			"
844
		;;
845
	*)
846
		__gitcomp "$(__git_refs)"
847
		;;
848
	esac
849
}
850
 
851
_git_cherry ()
852
{
853
	__gitcomp "$(__git_refs)"
854
}
855
 
856
_git_cherry_pick ()
857
{
858
	local cur="${COMP_WORDS[COMP_CWORD]}"
859
	case "$cur" in
860
	--*)
861
		__gitcomp "--edit --no-commit"
862
		;;
863
	*)
864
		__gitcomp "$(__git_refs)"
865
		;;
866
	esac
867
}
868
 
869
_git_clean ()
870
{
871
	__git_has_doubledash && return
872
 
873
	local cur="${COMP_WORDS[COMP_CWORD]}"
874
	case "$cur" in
875
	--*)
876
		__gitcomp "--dry-run --quiet"
877
		return
878
		;;
879
	esac
880
	COMPREPLY=()
881
}
882
 
883
_git_clone ()
884
{
885
	local cur="${COMP_WORDS[COMP_CWORD]}"
886
	case "$cur" in
887
	--*)
888
		__gitcomp "
889
			--local
890
			--no-hardlinks
891
			--shared
892
			--reference
893
			--quiet
894
			--no-checkout
895
			--bare
896
			--mirror
897
			--origin
898
			--upload-pack
899
			--template=
900
			--depth
901
			"
902
		return
903
		;;
904
	esac
905
	COMPREPLY=()
906
}
907
 
908
_git_commit ()
909
{
910
	__git_has_doubledash && return
911
 
912
	local cur="${COMP_WORDS[COMP_CWORD]}"
913
	case "$cur" in
914
	--cleanup=*)
915
		__gitcomp "default strip verbatim whitespace
916
			" "" "${cur##--cleanup=}"
917
		return
918
		;;
919
	--reuse-message=*)
920
		__gitcomp "$(__git_refs)" "" "${cur##--reuse-message=}"
921
		return
922
		;;
923
	--reedit-message=*)
924
		__gitcomp "$(__git_refs)" "" "${cur##--reedit-message=}"
925
		return
926
		;;
927
	--untracked-files=*)
928
		__gitcomp "all no normal" "" "${cur##--untracked-files=}"
929
		return
930
		;;
931
	--*)
932
		__gitcomp "
933
			--all --author= --signoff --verify --no-verify
934
			--edit --amend --include --only --interactive
935
			--dry-run --reuse-message= --reedit-message=
936
			--reset-author --file= --message= --template=
937
			--cleanup= --untracked-files --untracked-files=
938
			--verbose --quiet
939
			"
940
		return
941
	esac
942
	COMPREPLY=()
943
}
944
 
945
_git_describe ()
946
{
947
	local cur="${COMP_WORDS[COMP_CWORD]}"
948
	case "$cur" in
949
	--*)
950
		__gitcomp "
951
			--all --tags --contains --abbrev= --candidates=
952
			--exact-match --debug --long --match --always
953
			"
954
		return
955
	esac
956
	__gitcomp "$(__git_refs)"
957
}
958
 
959
__git_diff_common_options="--stat --numstat --shortstat --summary
960
			--patch-with-stat --name-only --name-status --color
961
			--no-color --color-words --no-renames --check
962
			--full-index --binary --abbrev --diff-filter=
963
			--find-copies-harder
964
			--text --ignore-space-at-eol --ignore-space-change
965
			--ignore-all-space --exit-code --quiet --ext-diff
966
			--no-ext-diff
967
			--no-prefix --src-prefix= --dst-prefix=
968
			--inter-hunk-context=
969
			--patience
970
			--raw
971
			--dirstat --dirstat= --dirstat-by-file
972
			--dirstat-by-file= --cumulative
973
"
974
 
975
_git_diff ()
976
{
977
	__git_has_doubledash && return
978
 
979
	local cur="${COMP_WORDS[COMP_CWORD]}"
980
	case "$cur" in
981
	--*)
982
		__gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
983
			--base --ours --theirs
984
			$__git_diff_common_options
985
			"
986
		return
987
		;;
988
	esac
989
	__git_complete_file
990
}
991
 
992
__git_mergetools_common="diffuse ecmerge emerge kdiff3 meld opendiff
993
			tkdiff vimdiff gvimdiff xxdiff araxis p4merge
994
"
995
 
996
_git_difftool ()
997
{
998
	__git_has_doubledash && return
999
 
1000
	local cur="${COMP_WORDS[COMP_CWORD]}"
1001
	case "$cur" in
1002
	--tool=*)
1003
		__gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1004
		return
1005
		;;
1006
	--*)
1007
		__gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1008
			--base --ours --theirs
1009
			--no-renames --diff-filter= --find-copies-harder
1010
			--relative --ignore-submodules
1011
			--tool="
1012
		return
1013
		;;
1014
	esac
1015
	__git_complete_file
1016
}
1017
 
1018
__git_fetch_options="
1019
	--quiet --verbose --append --upload-pack --force --keep --depth=
1020
	--tags --no-tags --all --prune --dry-run
1021
"
1022
 
1023
_git_fetch ()
1024
{
1025
	local cur="${COMP_WORDS[COMP_CWORD]}"
1026
	case "$cur" in
1027
	--*)
1028
		__gitcomp "$__git_fetch_options"
1029
		return
1030
		;;
1031
	esac
1032
	__git_complete_remote_or_refspec
1033
}
1034
 
1035
_git_format_patch ()
1036
{
1037
	local cur="${COMP_WORDS[COMP_CWORD]}"
1038
	case "$cur" in
1039
	--thread=*)
1040
		__gitcomp "
1041
			deep shallow
1042
			" "" "${cur##--thread=}"
1043
		return
1044
		;;
1045
	--*)
1046
		__gitcomp "
1047
			--stdout --attach --no-attach --thread --thread=
1048
			--output-directory
1049
			--numbered --start-number
1050
			--numbered-files
1051
			--keep-subject
1052
			--signoff
1053
			--in-reply-to= --cc=
1054
			--full-index --binary
1055
			--not --all
1056
			--cover-letter
1057
			--no-prefix --src-prefix= --dst-prefix=
1058
			--inline --suffix= --ignore-if-in-upstream
1059
			--subject-prefix=
1060
			"
1061
		return
1062
		;;
1063
	esac
1064
	__git_complete_revlist
1065
}
1066
 
1067
_git_fsck ()
1068
{
1069
	local cur="${COMP_WORDS[COMP_CWORD]}"
1070
	case "$cur" in
1071
	--*)
1072
		__gitcomp "
1073
			--tags --root --unreachable --cache --no-reflogs --full
1074
			--strict --verbose --lost-found
1075
			"
1076
		return
1077
		;;
1078
	esac
1079
	COMPREPLY=()
1080
}
1081
 
1082
_git_gc ()
1083
{
1084
	local cur="${COMP_WORDS[COMP_CWORD]}"
1085
	case "$cur" in
1086
	--*)
1087
		__gitcomp "--prune --aggressive"
1088
		return
1089
		;;
1090
	esac
1091
	COMPREPLY=()
1092
}
1093
 
1094
_git_gitk ()
1095
{
1096
	_gitk
1097
}
1098
 
1099
_git_grep ()
1100
{
1101
	__git_has_doubledash && return
1102
 
1103
	local cur="${COMP_WORDS[COMP_CWORD]}"
1104
	case "$cur" in
1105
	--*)
1106
		__gitcomp "
1107
			--cached
1108
			--text --ignore-case --word-regexp --invert-match
1109
			--full-name
1110
			--extended-regexp --basic-regexp --fixed-strings
1111
			--files-with-matches --name-only
1112
			--files-without-match
1113
			--max-depth
1114
			--count
1115
			--and --or --not --all-match
1116
			"
1117
		return
1118
		;;
1119
	esac
1120
 
1121
	__gitcomp "$(__git_refs)"
1122
}
1123
 
1124
_git_help ()
1125
{
1126
	local cur="${COMP_WORDS[COMP_CWORD]}"
1127
	case "$cur" in
1128
	--*)
1129
		__gitcomp "--all --info --man --web"
1130
		return
1131
		;;
1132
	esac
1133
	__git_compute_all_commands
1134
	__gitcomp "$__git_all_commands
1135
		attributes cli core-tutorial cvs-migration
1136
		diffcore gitk glossary hooks ignore modules
1137
		repository-layout tutorial tutorial-2
1138
		workflows
1139
		"
1140
}
1141
 
1142
_git_init ()
1143
{
1144
	local cur="${COMP_WORDS[COMP_CWORD]}"
1145
	case "$cur" in
1146
	--shared=*)
1147
		__gitcomp "
1148
			false true umask group all world everybody
1149
			" "" "${cur##--shared=}"
1150
		return
1151
		;;
1152
	--*)
1153
		__gitcomp "--quiet --bare --template= --shared --shared="
1154
		return
1155
		;;
1156
	esac
1157
	COMPREPLY=()
1158
}
1159
 
1160
_git_ls_files ()
1161
{
1162
	__git_has_doubledash && return
1163
 
1164
	local cur="${COMP_WORDS[COMP_CWORD]}"
1165
	case "$cur" in
1166
	--*)
1167
		__gitcomp "--cached --deleted --modified --others --ignored
1168
			--stage --directory --no-empty-directory --unmerged
1169
			--killed --exclude= --exclude-from=
1170
			--exclude-per-directory= --exclude-standard
1171
			--error-unmatch --with-tree= --full-name
1172
			--abbrev --ignored --exclude-per-directory
1173
			"
1174
		return
1175
		;;
1176
	esac
1177
	COMPREPLY=()
1178
}
1179
 
1180
_git_ls_remote ()
1181
{
1182
	__gitcomp "$(__git_remotes)"
1183
}
1184
 
1185
_git_ls_tree ()
1186
{
1187
	__git_complete_file
1188
}
1189
 
1190
# Options that go well for log, shortlog and gitk
1191
__git_log_common_options="
1192
	--not --all
1193
	--branches --tags --remotes
1194
	--first-parent --merges --no-merges
1195
	--max-count=
1196
	--max-age= --since= --after=
1197
	--min-age= --until= --before=
1198
"
1199
# Options that go well for log and gitk (not shortlog)
1200
__git_log_gitk_options="
1201
	--dense --sparse --full-history
1202
	--simplify-merges --simplify-by-decoration
1203
	--left-right
1204
"
1205
# Options that go well for log and shortlog (not gitk)
1206
__git_log_shortlog_options="
1207
	--author= --committer= --grep=
1208
	--all-match
1209
"
1210
 
1211
__git_log_pretty_formats="oneline short medium full fuller email raw format:"
1212
__git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1213
 
1214
_git_log ()
1215
{
1216
	__git_has_doubledash && return
1217
 
1218
	local cur="${COMP_WORDS[COMP_CWORD]}"
1219
	local g="$(git rev-parse --git-dir 2>/dev/null)"
1220
	local merge=""
1221
	if [ -f "$g/MERGE_HEAD" ]; then
1222
		merge="--merge"
1223
	fi
1224
	case "$cur" in
1225
	--pretty=*)
1226
		__gitcomp "$__git_log_pretty_formats
1227
			" "" "${cur##--pretty=}"
1228
		return
1229
		;;
1230
	--format=*)
1231
		__gitcomp "$__git_log_pretty_formats
1232
			" "" "${cur##--format=}"
1233
		return
1234
		;;
1235
	--date=*)
1236
		__gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1237
		return
1238
		;;
1239
	--decorate=*)
1240
		__gitcomp "long short" "" "${cur##--decorate=}"
1241
		return
1242
		;;
1243
	--*)
1244
		__gitcomp "
1245
			$__git_log_common_options
1246
			$__git_log_shortlog_options
1247
			$__git_log_gitk_options
1248
			--root --topo-order --date-order --reverse
1249
			--follow --full-diff
1250
			--abbrev-commit --abbrev=
1251
			--relative-date --date=
1252
			--pretty= --format= --oneline
1253
			--cherry-pick
1254
			--graph
1255
			--decorate --decorate=
1256
			--walk-reflogs
1257
			--parents --children
1258
			$merge
1259
			$__git_diff_common_options
1260
			--pickaxe-all --pickaxe-regex
1261
			"
1262
		return
1263
		;;
1264
	esac
1265
	__git_complete_revlist
1266
}
1267
 
1268
__git_merge_options="
1269
	--no-commit --no-stat --log --no-log --squash --strategy
1270
	--commit --stat --no-squash --ff --no-ff --ff-only
1271
"
1272
 
1273
_git_merge ()
1274
{
1275
	__git_complete_strategy && return
1276
 
1277
	local cur="${COMP_WORDS[COMP_CWORD]}"
1278
	case "$cur" in
1279
	--*)
1280
		__gitcomp "$__git_merge_options"
1281
		return
1282
	esac
1283
	__gitcomp "$(__git_refs)"
1284
}
1285
 
1286
_git_mergetool ()
1287
{
1288
	local cur="${COMP_WORDS[COMP_CWORD]}"
1289
	case "$cur" in
1290
	--tool=*)
1291
		__gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1292
		return
1293
		;;
1294
	--*)
1295
		__gitcomp "--tool="
1296
		return
1297
		;;
1298
	esac
1299
	COMPREPLY=()
1300
}
1301
 
1302
_git_merge_base ()
1303
{
1304
	__gitcomp "$(__git_refs)"
1305
}
1306
 
1307
_git_mv ()
1308
{
1309
	local cur="${COMP_WORDS[COMP_CWORD]}"
1310
	case "$cur" in
1311
	--*)
1312
		__gitcomp "--dry-run"
1313
		return
1314
		;;
1315
	esac
1316
	COMPREPLY=()
1317
}
1318
 
1319
_git_name_rev ()
1320
{
1321
	__gitcomp "--tags --all --stdin"
1322
}
1323
 
1324
_git_notes ()
1325
{
1326
	local subcommands="edit show"
1327
	if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
1328
		__gitcomp "$subcommands"
1329
		return
1330
	fi
1331
 
1332
	case "${COMP_WORDS[COMP_CWORD-1]}" in
1333
	-m|-F)
1334
		COMPREPLY=()
1335
		;;
1336
	*)
1337
		__gitcomp "$(__git_refs)"
1338
		;;
1339
	esac
1340
}
1341
 
1342
_git_pull ()
1343
{
1344
	__git_complete_strategy && return
1345
 
1346
	local cur="${COMP_WORDS[COMP_CWORD]}"
1347
	case "$cur" in
1348
	--*)
1349
		__gitcomp "
1350
			--rebase --no-rebase
1351
			$__git_merge_options
1352
			$__git_fetch_options
1353
		"
1354
		return
1355
		;;
1356
	esac
1357
	__git_complete_remote_or_refspec
1358
}
1359
 
1360
_git_push ()
1361
{
1362
	local cur="${COMP_WORDS[COMP_CWORD]}"
1363
	case "${COMP_WORDS[COMP_CWORD-1]}" in
1364
	--repo)
1365
		__gitcomp "$(__git_remotes)"
1366
		return
1367
	esac
1368
	case "$cur" in
1369
	--repo=*)
1370
		__gitcomp "$(__git_remotes)" "" "${cur##--repo=}"
1371
		return
1372
		;;
1373
	--*)
1374
		__gitcomp "
1375
			--all --mirror --tags --dry-run --force --verbose
1376
			--receive-pack= --repo=
1377
		"
1378
		return
1379
		;;
1380
	esac
1381
	__git_complete_remote_or_refspec
1382
}
1383
 
1384
_git_rebase ()
1385
{
1386
	local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
1387
	if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1388
		__gitcomp "--continue --skip --abort"
1389
		return
1390
	fi
1391
	__git_complete_strategy && return
1392
	case "$cur" in
1393
	--whitespace=*)
1394
		__gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1395
		return
1396
		;;
1397
	--*)
1398
		__gitcomp "
1399
			--onto --merge --strategy --interactive
1400
			--preserve-merges --stat --no-stat
1401
			--committer-date-is-author-date --ignore-date
1402
			--ignore-whitespace --whitespace=
1403
			--autosquash
1404
			"
1405
 
1406
		return
1407
	esac
1408
	__gitcomp "$(__git_refs)"
1409
}
1410
 
1411
__git_send_email_confirm_options="always never auto cc compose"
1412
__git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1413
 
1414
_git_send_email ()
1415
{
1416
	local cur="${COMP_WORDS[COMP_CWORD]}"
1417
	case "$cur" in
1418
	--confirm=*)
1419
		__gitcomp "
1420
			$__git_send_email_confirm_options
1421
			" "" "${cur##--confirm=}"
1422
		return
1423
		;;
1424
	--suppress-cc=*)
1425
		__gitcomp "
1426
			$__git_send_email_suppresscc_options
1427
			" "" "${cur##--suppress-cc=}"
1428
 
1429
		return
1430
		;;
1431
	--smtp-encryption=*)
1432
		__gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1433
		return
1434
		;;
1435
	--*)
1436
		__gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1437
			--compose --confirm= --dry-run --envelope-sender
1438
			--from --identity
1439
			--in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1440
			--no-suppress-from --no-thread --quiet
1441
			--signed-off-by-cc --smtp-pass --smtp-server
1442
			--smtp-server-port --smtp-encryption= --smtp-user
1443
			--subject --suppress-cc= --suppress-from --thread --to
1444
			--validate --no-validate"
1445
		return
1446
		;;
1447
	esac
1448
	COMPREPLY=()
1449
}
1450
 
1451
_git_stage ()
1452
{
1453
	_git_add
1454
}
1455
 
1456
__git_config_get_set_variables ()
1457
{
1458
	local prevword word config_file= c=$COMP_CWORD
1459
	while [ $c -gt 1 ]; do
1460
		word="${COMP_WORDS[c]}"
1461
		case "$word" in
1462
		--global|--system|--file=*)
1463
			config_file="$word"
1464
			break
1465
			;;
1466
		-f|--file)
1467
			config_file="$word $prevword"
1468
			break
1469
			;;
1470
		esac
1471
		prevword=$word
1472
		c=$((--c))
1473
	done
1474
 
1475
	git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
1476
	while read line
1477
	do
1478
		case "$line" in
1479
		*.*=*)
1480
			echo "${line/=*/}"
1481
			;;
1482
		esac
1483
	done
1484
}
1485
 
1486
_git_config ()
1487
{
1488
	local cur="${COMP_WORDS[COMP_CWORD]}"
1489
	local prv="${COMP_WORDS[COMP_CWORD-1]}"
1490
	case "$prv" in
1491
	branch.*.remote)
1492
		__gitcomp "$(__git_remotes)"
1493
		return
1494
		;;
1495
	branch.*.merge)
1496
		__gitcomp "$(__git_refs)"
1497
		return
1498
		;;
1499
	remote.*.fetch)
1500
		local remote="${prv#remote.}"
1501
		remote="${remote%.fetch}"
1502
		__gitcomp "$(__git_refs_remotes "$remote")"
1503
		return
1504
		;;
1505
	remote.*.push)
1506
		local remote="${prv#remote.}"
1507
		remote="${remote%.push}"
1508
		__gitcomp "$(git --git-dir="$(__gitdir)" \
1509
			for-each-ref --format='%(refname):%(refname)' \
1510
			refs/heads)"
1511
		return
1512
		;;
1513
	pull.twohead|pull.octopus)
1514
		__git_compute_merge_strategies
1515
		__gitcomp "$__git_merge_strategies"
1516
		return
1517
		;;
1518
	color.branch|color.diff|color.interactive|\
1519
	color.showbranch|color.status|color.ui)
1520
		__gitcomp "always never auto"
1521
		return
1522
		;;
1523
	color.pager)
1524
		__gitcomp "false true"
1525
		return
1526
		;;
1527
	color.*.*)
1528
		__gitcomp "
1529
			normal black red green yellow blue magenta cyan white
1530
			bold dim ul blink reverse
1531
			"
1532
		return
1533
		;;
1534
	help.format)
1535
		__gitcomp "man info web html"
1536
		return
1537
		;;
1538
	log.date)
1539
		__gitcomp "$__git_log_date_formats"
1540
		return
1541
		;;
1542
	sendemail.aliasesfiletype)
1543
		__gitcomp "mutt mailrc pine elm gnus"
1544
		return
1545
		;;
1546
	sendemail.confirm)
1547
		__gitcomp "$__git_send_email_confirm_options"
1548
		return
1549
		;;
1550
	sendemail.suppresscc)
1551
		__gitcomp "$__git_send_email_suppresscc_options"
1552
		return
1553
		;;
1554
	--get|--get-all|--unset|--unset-all)
1555
		__gitcomp "$(__git_config_get_set_variables)"
1556
		return
1557
		;;
1558
	*.*)
1559
		COMPREPLY=()
1560
		return
1561
		;;
1562
	esac
1563
	case "$cur" in
1564
	--*)
1565
		__gitcomp "
1566
			--global --system --file=
1567
			--list --replace-all
1568
			--get --get-all --get-regexp
1569
			--add --unset --unset-all
1570
			--remove-section --rename-section
1571
			"
1572
		return
1573
		;;
1574
	branch.*.*)
1575
		local pfx="${cur%.*}."
1576
		cur="${cur##*.}"
1577
		__gitcomp "remote merge mergeoptions rebase" "$pfx" "$cur"
1578
		return
1579
		;;
1580
	branch.*)
1581
		local pfx="${cur%.*}."
1582
		cur="${cur#*.}"
1583
		__gitcomp "$(__git_heads)" "$pfx" "$cur" "."
1584
		return
1585
		;;
1586
	guitool.*.*)
1587
		local pfx="${cur%.*}."
1588
		cur="${cur##*.}"
1589
		__gitcomp "
1590
			argprompt cmd confirm needsfile noconsole norescan
1591
			prompt revprompt revunmerged title
1592
			" "$pfx" "$cur"
1593
		return
1594
		;;
1595
	difftool.*.*)
1596
		local pfx="${cur%.*}."
1597
		cur="${cur##*.}"
1598
		__gitcomp "cmd path" "$pfx" "$cur"
1599
		return
1600
		;;
1601
	man.*.*)
1602
		local pfx="${cur%.*}."
1603
		cur="${cur##*.}"
1604
		__gitcomp "cmd path" "$pfx" "$cur"
1605
		return
1606
		;;
1607
	mergetool.*.*)
1608
		local pfx="${cur%.*}."
1609
		cur="${cur##*.}"
1610
		__gitcomp "cmd path trustExitCode" "$pfx" "$cur"
1611
		return
1612
		;;
1613
	pager.*)
1614
		local pfx="${cur%.*}."
1615
		cur="${cur#*.}"
1616
		__git_compute_all_commands
1617
		__gitcomp "$__git_all_commands" "$pfx" "$cur"
1618
		return
1619
		;;
1620
	remote.*.*)
1621
		local pfx="${cur%.*}."
1622
		cur="${cur##*.}"
1623
		__gitcomp "
1624
			url proxy fetch push mirror skipDefaultUpdate
1625
			receivepack uploadpack tagopt pushurl
1626
			" "$pfx" "$cur"
1627
		return
1628
		;;
1629
	remote.*)
1630
		local pfx="${cur%.*}."
1631
		cur="${cur#*.}"
1632
		__gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
1633
		return
1634
		;;
1635
	url.*.*)
1636
		local pfx="${cur%.*}."
1637
		cur="${cur##*.}"
1638
		__gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur"
1639
		return
1640
		;;
1641
	esac
1642
	__gitcomp "
1643
		add.ignore-errors
1644
		alias.
1645
		apply.ignorewhitespace
1646
		apply.whitespace
1647
		branch.autosetupmerge
1648
		branch.autosetuprebase
1649
		clean.requireForce
1650
		color.branch
1651
		color.branch.current
1652
		color.branch.local
1653
		color.branch.plain
1654
		color.branch.remote
1655
		color.diff
1656
		color.diff.commit
1657
		color.diff.frag
1658
		color.diff.meta
1659
		color.diff.new
1660
		color.diff.old
1661
		color.diff.plain
1662
		color.diff.whitespace
1663
		color.grep
1664
		color.grep.external
1665
		color.grep.match
1666
		color.interactive
1667
		color.interactive.header
1668
		color.interactive.help
1669
		color.interactive.prompt
1670
		color.pager
1671
		color.showbranch
1672
		color.status
1673
		color.status.added
1674
		color.status.changed
1675
		color.status.header
1676
		color.status.nobranch
1677
		color.status.untracked
1678
		color.status.updated
1679
		color.ui
1680
		commit.template
1681
		core.autocrlf
1682
		core.bare
1683
		core.compression
1684
		core.createObject
1685
		core.deltaBaseCacheLimit
1686
		core.editor
1687
		core.excludesfile
1688
		core.fileMode
1689
		core.fsyncobjectfiles
1690
		core.gitProxy
1691
		core.ignoreCygwinFSTricks
1692
		core.ignoreStat
1693
		core.logAllRefUpdates
1694
		core.loosecompression
1695
		core.packedGitLimit
1696
		core.packedGitWindowSize
1697
		core.pager
1698
		core.preferSymlinkRefs
1699
		core.preloadindex
1700
		core.quotepath
1701
		core.repositoryFormatVersion
1702
		core.safecrlf
1703
		core.sharedRepository
1704
		core.symlinks
1705
		core.trustctime
1706
		core.warnAmbiguousRefs
1707
		core.whitespace
1708
		core.worktree
1709
		diff.autorefreshindex
1710
		diff.external
1711
		diff.mnemonicprefix
1712
		diff.renameLimit
1713
		diff.renameLimit.
1714
		diff.renames
1715
		diff.suppressBlankEmpty
1716
		diff.tool
1717
		diff.wordRegex
1718
		difftool.
1719
		difftool.prompt
1720
		fetch.unpackLimit
1721
		format.attach
1722
		format.cc
1723
		format.headers
1724
		format.numbered
1725
		format.pretty
1726
		format.signoff
1727
		format.subjectprefix
1728
		format.suffix
1729
		format.thread
1730
		gc.aggressiveWindow
1731
		gc.auto
1732
		gc.autopacklimit
1733
		gc.packrefs
1734
		gc.pruneexpire
1735
		gc.reflogexpire
1736
		gc.reflogexpireunreachable
1737
		gc.rerereresolved
1738
		gc.rerereunresolved
1739
		gitcvs.allbinary
1740
		gitcvs.commitmsgannotation
1741
		gitcvs.dbTableNamePrefix
1742
		gitcvs.dbdriver
1743
		gitcvs.dbname
1744
		gitcvs.dbpass
1745
		gitcvs.dbuser
1746
		gitcvs.enabled
1747
		gitcvs.logfile
1748
		gitcvs.usecrlfattr
1749
		guitool.
1750
		gui.blamehistoryctx
1751
		gui.commitmsgwidth
1752
		gui.copyblamethreshold
1753
		gui.diffcontext
1754
		gui.encoding
1755
		gui.fastcopyblame
1756
		gui.matchtrackingbranch
1757
		gui.newbranchtemplate
1758
		gui.pruneduringfetch
1759
		gui.spellingdictionary
1760
		gui.trustmtime
1761
		help.autocorrect
1762
		help.browser
1763
		help.format
1764
		http.lowSpeedLimit
1765
		http.lowSpeedTime
1766
		http.maxRequests
1767
		http.noEPSV
1768
		http.proxy
1769
		http.sslCAInfo
1770
		http.sslCAPath
1771
		http.sslCert
1772
		http.sslKey
1773
		http.sslVerify
1774
		i18n.commitEncoding
1775
		i18n.logOutputEncoding
1776
		imap.folder
1777
		imap.host
1778
		imap.pass
1779
		imap.port
1780
		imap.preformattedHTML
1781
		imap.sslverify
1782
		imap.tunnel
1783
		imap.user
1784
		instaweb.browser
1785
		instaweb.httpd
1786
		instaweb.local
1787
		instaweb.modulepath
1788
		instaweb.port
1789
		interactive.singlekey
1790
		log.date
1791
		log.showroot
1792
		mailmap.file
1793
		man.
1794
		man.viewer
1795
		merge.conflictstyle
1796
		merge.log
1797
		merge.renameLimit
1798
		merge.stat
1799
		merge.tool
1800
		merge.verbosity
1801
		mergetool.
1802
		mergetool.keepBackup
1803
		mergetool.prompt
1804
		pack.compression
1805
		pack.deltaCacheLimit
1806
		pack.deltaCacheSize
1807
		pack.depth
1808
		pack.indexVersion
1809
		pack.packSizeLimit
1810
		pack.threads
1811
		pack.window
1812
		pack.windowMemory
1813
		pager.
1814
		pull.octopus
1815
		pull.twohead
1816
		push.default
1817
		rebase.stat
1818
		receive.denyCurrentBranch
1819
		receive.denyDeletes
1820
		receive.denyNonFastForwards
1821
		receive.fsckObjects
1822
		receive.unpackLimit
1823
		repack.usedeltabaseoffset
1824
		rerere.autoupdate
1825
		rerere.enabled
1826
		sendemail.aliasesfile
1827
		sendemail.aliasesfiletype
1828
		sendemail.bcc
1829
		sendemail.cc
1830
		sendemail.cccmd
1831
		sendemail.chainreplyto
1832
		sendemail.confirm
1833
		sendemail.envelopesender
1834
		sendemail.multiedit
1835
		sendemail.signedoffbycc
1836
		sendemail.smtpencryption
1837
		sendemail.smtppass
1838
		sendemail.smtpserver
1839
		sendemail.smtpserverport
1840
		sendemail.smtpuser
1841
		sendemail.suppresscc
1842
		sendemail.suppressfrom
1843
		sendemail.thread
1844
		sendemail.to
1845
		sendemail.validate
1846
		showbranch.default
1847
		status.relativePaths
1848
		status.showUntrackedFiles
1849
		tar.umask
1850
		transfer.unpackLimit
1851
		url.
1852
		user.email
1853
		user.name
1854
		user.signingkey
1855
		web.browser
1856
		branch. remote.
1857
	"
1858
}
1859
 
1860
_git_remote ()
1861
{
1862
	local subcommands="add rename rm show prune update set-head"
1863
	local subcommand="$(__git_find_on_cmdline "$subcommands")"
1864
	if [ -z "$subcommand" ]; then
1865
		__gitcomp "$subcommands"
1866
		return
1867
	fi
1868
 
1869
	case "$subcommand" in
1870
	rename|rm|show|prune)
1871
		__gitcomp "$(__git_remotes)"
1872
		;;
1873
	update)
1874
		local i c='' IFS=$'\n'
1875
		for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do
1876
			i="${i#remotes.}"
1877
			c="$c ${i/ */}"
1878
		done
1879
		__gitcomp "$c"
1880
		;;
1881
	*)
1882
		COMPREPLY=()
1883
		;;
1884
	esac
1885
}
1886
 
1887
_git_replace ()
1888
{
1889
	__gitcomp "$(__git_refs)"
1890
}
1891
 
1892
_git_reset ()
1893
{
1894
	__git_has_doubledash && return
1895
 
1896
	local cur="${COMP_WORDS[COMP_CWORD]}"
1897
	case "$cur" in
1898
	--*)
1899
		__gitcomp "--merge --mixed --hard --soft --patch"
1900
		return
1901
		;;
1902
	esac
1903
	__gitcomp "$(__git_refs)"
1904
}
1905
 
1906
_git_revert ()
1907
{
1908
	local cur="${COMP_WORDS[COMP_CWORD]}"
1909
	case "$cur" in
1910
	--*)
1911
		__gitcomp "--edit --mainline --no-edit --no-commit --signoff"
1912
		return
1913
		;;
1914
	esac
1915
	__gitcomp "$(__git_refs)"
1916
}
1917
 
1918
_git_rm ()
1919
{
1920
	__git_has_doubledash && return
1921
 
1922
	local cur="${COMP_WORDS[COMP_CWORD]}"
1923
	case "$cur" in
1924
	--*)
1925
		__gitcomp "--cached --dry-run --ignore-unmatch --quiet"
1926
		return
1927
		;;
1928
	esac
1929
	COMPREPLY=()
1930
}
1931
 
1932
_git_shortlog ()
1933
{
1934
	__git_has_doubledash && return
1935
 
1936
	local cur="${COMP_WORDS[COMP_CWORD]}"
1937
	case "$cur" in
1938
	--*)
1939
		__gitcomp "
1940
			$__git_log_common_options
1941
			$__git_log_shortlog_options
1942
			--numbered --summary
1943
			"
1944
		return
1945
		;;
1946
	esac
1947
	__git_complete_revlist
1948
}
1949
 
1950
_git_show ()
1951
{
1952
	__git_has_doubledash && return
1953
 
1954
	local cur="${COMP_WORDS[COMP_CWORD]}"
1955
	case "$cur" in
1956
	--pretty=*)
1957
		__gitcomp "$__git_log_pretty_formats
1958
			" "" "${cur##--pretty=}"
1959
		return
1960
		;;
1961
	--format=*)
1962
		__gitcomp "$__git_log_pretty_formats
1963
			" "" "${cur##--format=}"
1964
		return
1965
		;;
1966
	--*)
1967
		__gitcomp "--pretty= --format= --abbrev-commit --oneline
1968
			$__git_diff_common_options
1969
			"
1970
		return
1971
		;;
1972
	esac
1973
	__git_complete_file
1974
}
1975
 
1976
_git_show_branch ()
1977
{
1978
	local cur="${COMP_WORDS[COMP_CWORD]}"
1979
	case "$cur" in
1980
	--*)
1981
		__gitcomp "
1982
			--all --remotes --topo-order --current --more=
1983
			--list --independent --merge-base --no-name
1984
			--color --no-color
1985
			--sha1-name --sparse --topics --reflog
1986
			"
1987
		return
1988
		;;
1989
	esac
1990
	__git_complete_revlist
1991
}
1992
 
1993
_git_stash ()
1994
{
1995
	local cur="${COMP_WORDS[COMP_CWORD]}"
1996
	local save_opts='--keep-index --no-keep-index --quiet --patch'
1997
	local subcommands='save list show apply clear drop pop create branch'
1998
	local subcommand="$(__git_find_on_cmdline "$subcommands")"
1999
	if [ -z "$subcommand" ]; then
2000
		case "$cur" in
2001
		--*)
2002
			__gitcomp "$save_opts"
2003
			;;
2004
		*)
2005
			if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2006
				__gitcomp "$subcommands"
2007
			else
2008
				COMPREPLY=()
2009
			fi
2010
			;;
2011
		esac
2012
	else
2013
		case "$subcommand,$cur" in
2014
		save,--*)
2015
			__gitcomp "$save_opts"
2016
			;;
2017
		apply,--*|pop,--*)
2018
			__gitcomp "--index --quiet"
2019
			;;
2020
		show,--*|drop,--*|branch,--*)
2021
			COMPREPLY=()
2022
			;;
2023
		show,*|apply,*|drop,*|pop,*|branch,*)
2024
			__gitcomp "$(git --git-dir="$(__gitdir)" stash list \
2025
					| sed -n -e 's/:.*//p')"
2026
			;;
2027
		*)
2028
			COMPREPLY=()
2029
			;;
2030
		esac
2031
	fi
2032
}
2033
 
2034
_git_submodule ()
2035
{
2036
	__git_has_doubledash && return
2037
 
2038
	local subcommands="add status init update summary foreach sync"
2039
	if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2040
		local cur="${COMP_WORDS[COMP_CWORD]}"
2041
		case "$cur" in
2042
		--*)
2043
			__gitcomp "--quiet --cached"
2044
			;;
2045
		*)
2046
			__gitcomp "$subcommands"
2047
			;;
2048
		esac
2049
		return
2050
	fi
2051
}
2052
 
2053
_git_svn ()
2054
{
2055
	local subcommands="
2056
		init fetch clone rebase dcommit log find-rev
2057
		set-tree commit-diff info create-ignore propget
2058
		proplist show-ignore show-externals branch tag blame
2059
		migrate mkdirs reset gc
2060
		"
2061
	local subcommand="$(__git_find_on_cmdline "$subcommands")"
2062
	if [ -z "$subcommand" ]; then
2063
		__gitcomp "$subcommands"
2064
	else
2065
		local remote_opts="--username= --config-dir= --no-auth-cache"
2066
		local fc_opts="
2067
			--follow-parent --authors-file= --repack=
2068
			--no-metadata --use-svm-props --use-svnsync-props
2069
			--log-window-size= --no-checkout --quiet
2070
			--repack-flags --use-log-author --localtime
2071
			--ignore-paths= $remote_opts
2072
			"
2073
		local init_opts="
2074
			--template= --shared= --trunk= --tags=
2075
			--branches= --stdlayout --minimize-url
2076
			--no-metadata --use-svm-props --use-svnsync-props
2077
			--rewrite-root= --prefix= --use-log-author
2078
			--add-author-from $remote_opts
2079
			"
2080
		local cmt_opts="
2081
			--edit --rmdir --find-copies-harder --copy-similarity=
2082
			"
2083
 
2084
		local cur="${COMP_WORDS[COMP_CWORD]}"
2085
		case "$subcommand,$cur" in
2086
		fetch,--*)
2087
			__gitcomp "--revision= --fetch-all $fc_opts"
2088
			;;
2089
		clone,--*)
2090
			__gitcomp "--revision= $fc_opts $init_opts"
2091
			;;
2092
		init,--*)
2093
			__gitcomp "$init_opts"
2094
			;;
2095
		dcommit,--*)
2096
			__gitcomp "
2097
				--merge --strategy= --verbose --dry-run
2098
				--fetch-all --no-rebase --commit-url
2099
				--revision $cmt_opts $fc_opts
2100
				"
2101
			;;
2102
		set-tree,--*)
2103
			__gitcomp "--stdin $cmt_opts $fc_opts"
2104
			;;
2105
		create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2106
		show-externals,--*|mkdirs,--*)
2107
			__gitcomp "--revision="
2108
			;;
2109
		log,--*)
2110
			__gitcomp "
2111
				--limit= --revision= --verbose --incremental
2112
				--oneline --show-commit --non-recursive
2113
				--authors-file= --color
2114
				"
2115
			;;
2116
		rebase,--*)
2117
			__gitcomp "
2118
				--merge --verbose --strategy= --local
2119
				--fetch-all --dry-run $fc_opts
2120
				"
2121
			;;
2122
		commit-diff,--*)
2123
			__gitcomp "--message= --file= --revision= $cmt_opts"
2124
			;;
2125
		info,--*)
2126
			__gitcomp "--url"
2127
			;;
2128
		branch,--*)
2129
			__gitcomp "--dry-run --message --tag"
2130
			;;
2131
		tag,--*)
2132
			__gitcomp "--dry-run --message"
2133
			;;
2134
		blame,--*)
2135
			__gitcomp "--git-format"
2136
			;;
2137
		migrate,--*)
2138
			__gitcomp "
2139
				--config-dir= --ignore-paths= --minimize
2140
				--no-auth-cache --username=
2141
				"
2142
			;;
2143
		reset,--*)
2144
			__gitcomp "--revision= --parent"
2145
			;;
2146
		*)
2147
			COMPREPLY=()
2148
			;;
2149
		esac
2150
	fi
2151
}
2152
 
2153
_git_tag ()
2154
{
2155
	local i c=1 f=0
2156
	while [ $c -lt $COMP_CWORD ]; do
2157
		i="${COMP_WORDS[c]}"
2158
		case "$i" in
2159
		-d|-v)
2160
			__gitcomp "$(__git_tags)"
2161
			return
2162
			;;
2163
		-f)
2164
			f=1
2165
			;;
2166
		esac
2167
		c=$((++c))
2168
	done
2169
 
2170
	case "${COMP_WORDS[COMP_CWORD-1]}" in
2171
	-m|-F)
2172
		COMPREPLY=()
2173
		;;
2174
	-*|tag)
2175
		if [ $f = 1 ]; then
2176
			__gitcomp "$(__git_tags)"
2177
		else
2178
			COMPREPLY=()
2179
		fi
2180
		;;
2181
	*)
2182
		__gitcomp "$(__git_refs)"
2183
		;;
2184
	esac
2185
}
2186
 
2187
_git_whatchanged ()
2188
{
2189
	_git_log
2190
}
2191
 
2192
_git ()
2193
{
2194
	local i c=1 command __git_dir
2195
 
2196
	while [ $c -lt $COMP_CWORD ]; do
2197
		i="${COMP_WORDS[c]}"
2198
		case "$i" in
2199
		--git-dir=*) __git_dir="${i#--git-dir=}" ;;
2200
		--bare)      __git_dir="." ;;
2201
		--version|-p|--paginate) ;;
2202
		--help) command="help"; break ;;
2203
		*) command="$i"; break ;;
2204
		esac
2205
		c=$((++c))
2206
	done
2207
 
2208
	if [ -z "$command" ]; then
2209
		case "${COMP_WORDS[COMP_CWORD]}" in
2210
		--*)   __gitcomp "
2211
			--paginate
2212
			--no-pager
2213
			--git-dir=
2214
			--bare
2215
			--version
2216
			--exec-path
2217
			--html-path
2218
			--work-tree=
2219
			--help
2220
			"
2221
			;;
2222
		*)     __git_compute_porcelain_commands
2223
		       __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
2224
		esac
2225
		return
2226
	fi
2227
 
2228
	local completion_func="_git_${command//-/_}"
2229
	declare -F $completion_func >/dev/null && $completion_func && return
2230
 
2231
	local expansion=$(__git_aliased_command "$command")
2232
	if [ -n "$expansion" ]; then
2233
		completion_func="_git_${expansion//-/_}"
2234
		declare -F $completion_func >/dev/null && $completion_func
2235
	fi
2236
}
2237
 
2238
_gitk ()
2239
{
2240
	__git_has_doubledash && return
2241
 
2242
	local cur="${COMP_WORDS[COMP_CWORD]}"
2243
	local g="$(__gitdir)"
2244
	local merge=""
2245
	if [ -f "$g/MERGE_HEAD" ]; then
2246
		merge="--merge"
2247
	fi
2248
	case "$cur" in
2249
	--*)
2250
		__gitcomp "
2251
			$__git_log_common_options
2252
			$__git_log_gitk_options
2253
			$merge
2254
			"
2255
		return
2256
		;;
2257
	esac
2258
	__git_complete_revlist
2259
}
2260
 
2261
complete -o bashdefault -o default -o nospace -F _git git 2>/dev/null \
2262
	|| complete -o default -o nospace -F _git git
2263
complete -o bashdefault -o default -o nospace -F _gitk gitk 2>/dev/null \
2264
	|| complete -o default -o nospace -F _gitk gitk
2265
 
2266
# The following are necessary only for Cygwin, and only are needed
2267
# when the user has tab-completed the executable name and consequently
2268
# included the '.exe' suffix.
2269
#
2270
if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
2271
complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \
2272
	|| complete -o default -o nospace -F _git git.exe
2273
fi