git-completion.bash 48 KB

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