git-completion.bash 57 KB

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