git-completion.bash 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586
  1. # bash/zsh completion support for core Git.
  2. #
  3. # Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
  4. # Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
  5. # Distributed under the GNU General Public License, version 2.0.
  6. #
  7. # The contained completion routines provide support for completing:
  8. #
  9. # *) local and remote branch names
  10. # *) local and remote tag names
  11. # *) .git/remotes file names
  12. # *) git 'subcommands'
  13. # *) git email aliases for git-send-email
  14. # *) tree paths within 'ref:path/to/file' expressions
  15. # *) file paths within current working directory and index
  16. # *) common --long-options
  17. #
  18. # To use these routines:
  19. #
  20. # 1) Copy this file to somewhere (e.g. ~/.git-completion.bash).
  21. # 2) Add the following line to your .bashrc/.zshrc:
  22. # source ~/.git-completion.bash
  23. # 3) Consider changing your PS1 to also show the current branch,
  24. # see git-prompt.sh for details.
  25. #
  26. # If you use complex aliases of form '!f() { ... }; f', you can use the null
  27. # command ':' as the first command in the function body to declare the desired
  28. # completion style. For example '!f() { : git commit ; ... }; f' will
  29. # tell the completion to use commit completion. This also works with aliases
  30. # of form "!sh -c '...'". For example, "!sh -c ': git commit ; ... '".
  31. #
  32. # Compatible with bash 3.2.57.
  33. #
  34. # You can set the following environment variables to influence the behavior of
  35. # the completion routines:
  36. #
  37. # GIT_COMPLETION_CHECKOUT_NO_GUESS
  38. #
  39. # When set to "1", do not include "DWIM" suggestions in git-checkout
  40. # and git-switch completion (e.g., completing "foo" when "origin/foo"
  41. # exists).
  42. #
  43. # GIT_COMPLETION_SHOW_ALL
  44. #
  45. # When set to "1" suggest all options, including options which are
  46. # typically hidden (e.g. '--allow-empty' for 'git commit').
  47. case "$COMP_WORDBREAKS" in
  48. *:*) : great ;;
  49. *) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
  50. esac
  51. # Discovers the path to the git repository taking any '--git-dir=<path>' and
  52. # '-C <path>' options into account and stores it in the $__git_repo_path
  53. # variable.
  54. __git_find_repo_path ()
  55. {
  56. if [ -n "${__git_repo_path-}" ]; then
  57. # we already know where it is
  58. return
  59. fi
  60. if [ -n "${__git_C_args-}" ]; then
  61. __git_repo_path="$(git "${__git_C_args[@]}" \
  62. ${__git_dir:+--git-dir="$__git_dir"} \
  63. rev-parse --absolute-git-dir 2>/dev/null)"
  64. elif [ -n "${__git_dir-}" ]; then
  65. test -d "$__git_dir" &&
  66. __git_repo_path="$__git_dir"
  67. elif [ -n "${GIT_DIR-}" ]; then
  68. test -d "${GIT_DIR-}" &&
  69. __git_repo_path="$GIT_DIR"
  70. elif [ -d .git ]; then
  71. __git_repo_path=.git
  72. else
  73. __git_repo_path="$(git rev-parse --git-dir 2>/dev/null)"
  74. fi
  75. }
  76. # Deprecated: use __git_find_repo_path() and $__git_repo_path instead
  77. # __gitdir accepts 0 or 1 arguments (i.e., location)
  78. # returns location of .git repo
  79. __gitdir ()
  80. {
  81. if [ -z "${1-}" ]; then
  82. __git_find_repo_path || return 1
  83. echo "$__git_repo_path"
  84. elif [ -d "$1/.git" ]; then
  85. echo "$1/.git"
  86. else
  87. echo "$1"
  88. fi
  89. }
  90. # Runs git with all the options given as argument, respecting any
  91. # '--git-dir=<path>' and '-C <path>' options present on the command line
  92. __git ()
  93. {
  94. git ${__git_C_args:+"${__git_C_args[@]}"} \
  95. ${__git_dir:+--git-dir="$__git_dir"} "$@" 2>/dev/null
  96. }
  97. # Removes backslash escaping, single quotes and double quotes from a word,
  98. # stores the result in the variable $dequoted_word.
  99. # 1: The word to dequote.
  100. __git_dequote ()
  101. {
  102. local rest="$1" len ch
  103. dequoted_word=""
  104. while test -n "$rest"; do
  105. len=${#dequoted_word}
  106. dequoted_word="$dequoted_word${rest%%[\\\'\"]*}"
  107. rest="${rest:$((${#dequoted_word}-$len))}"
  108. case "${rest:0:1}" in
  109. \\)
  110. ch="${rest:1:1}"
  111. case "$ch" in
  112. $'\n')
  113. ;;
  114. *)
  115. dequoted_word="$dequoted_word$ch"
  116. ;;
  117. esac
  118. rest="${rest:2}"
  119. ;;
  120. \')
  121. rest="${rest:1}"
  122. len=${#dequoted_word}
  123. dequoted_word="$dequoted_word${rest%%\'*}"
  124. rest="${rest:$((${#dequoted_word}-$len+1))}"
  125. ;;
  126. \")
  127. rest="${rest:1}"
  128. while test -n "$rest" ; do
  129. len=${#dequoted_word}
  130. dequoted_word="$dequoted_word${rest%%[\\\"]*}"
  131. rest="${rest:$((${#dequoted_word}-$len))}"
  132. case "${rest:0:1}" in
  133. \\)
  134. ch="${rest:1:1}"
  135. case "$ch" in
  136. \"|\\|\$|\`)
  137. dequoted_word="$dequoted_word$ch"
  138. ;;
  139. $'\n')
  140. ;;
  141. *)
  142. dequoted_word="$dequoted_word\\$ch"
  143. ;;
  144. esac
  145. rest="${rest:2}"
  146. ;;
  147. \")
  148. rest="${rest:1}"
  149. break
  150. ;;
  151. esac
  152. done
  153. ;;
  154. esac
  155. done
  156. }
  157. # The following function is based on code from:
  158. #
  159. # bash_completion - programmable completion functions for bash 3.2+
  160. #
  161. # Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
  162. # © 2009-2010, Bash Completion Maintainers
  163. # <bash-completion-devel@lists.alioth.debian.org>
  164. #
  165. # This program is free software; you can redistribute it and/or modify
  166. # it under the terms of the GNU General Public License as published by
  167. # the Free Software Foundation; either version 2, or (at your option)
  168. # any later version.
  169. #
  170. # This program is distributed in the hope that it will be useful,
  171. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  172. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  173. # GNU General Public License for more details.
  174. #
  175. # You should have received a copy of the GNU General Public License
  176. # along with this program; if not, see <http://www.gnu.org/licenses/>.
  177. #
  178. # The latest version of this software can be obtained here:
  179. #
  180. # http://bash-completion.alioth.debian.org/
  181. #
  182. # RELEASE: 2.x
  183. # This function can be used to access a tokenized list of words
  184. # on the command line:
  185. #
  186. # __git_reassemble_comp_words_by_ref '=:'
  187. # if test "${words_[cword_-1]}" = -w
  188. # then
  189. # ...
  190. # fi
  191. #
  192. # The argument should be a collection of characters from the list of
  193. # word completion separators (COMP_WORDBREAKS) to treat as ordinary
  194. # characters.
  195. #
  196. # This is roughly equivalent to going back in time and setting
  197. # COMP_WORDBREAKS to exclude those characters. The intent is to
  198. # make option types like --date=<type> and <rev>:<path> easy to
  199. # recognize by treating each shell word as a single token.
  200. #
  201. # It is best not to set COMP_WORDBREAKS directly because the value is
  202. # shared with other completion scripts. By the time the completion
  203. # function gets called, COMP_WORDS has already been populated so local
  204. # changes to COMP_WORDBREAKS have no effect.
  205. #
  206. # Output: words_, cword_, cur_.
  207. __git_reassemble_comp_words_by_ref()
  208. {
  209. local exclude i j first
  210. # Which word separators to exclude?
  211. exclude="${1//[^$COMP_WORDBREAKS]}"
  212. cword_=$COMP_CWORD
  213. if [ -z "$exclude" ]; then
  214. words_=("${COMP_WORDS[@]}")
  215. return
  216. fi
  217. # List of word completion separators has shrunk;
  218. # re-assemble words to complete.
  219. for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
  220. # Append each nonempty word consisting of just
  221. # word separator characters to the current word.
  222. first=t
  223. while
  224. [ $i -gt 0 ] &&
  225. [ -n "${COMP_WORDS[$i]}" ] &&
  226. # word consists of excluded word separators
  227. [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
  228. do
  229. # Attach to the previous token,
  230. # unless the previous token is the command name.
  231. if [ $j -ge 2 ] && [ -n "$first" ]; then
  232. ((j--))
  233. fi
  234. first=
  235. words_[$j]=${words_[j]}${COMP_WORDS[i]}
  236. if [ $i = $COMP_CWORD ]; then
  237. cword_=$j
  238. fi
  239. if (($i < ${#COMP_WORDS[@]} - 1)); then
  240. ((i++))
  241. else
  242. # Done.
  243. return
  244. fi
  245. done
  246. words_[$j]=${words_[j]}${COMP_WORDS[i]}
  247. if [ $i = $COMP_CWORD ]; then
  248. cword_=$j
  249. fi
  250. done
  251. }
  252. if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
  253. _get_comp_words_by_ref ()
  254. {
  255. local exclude cur_ words_ cword_
  256. if [ "$1" = "-n" ]; then
  257. exclude=$2
  258. shift 2
  259. fi
  260. __git_reassemble_comp_words_by_ref "$exclude"
  261. cur_=${words_[cword_]}
  262. while [ $# -gt 0 ]; do
  263. case "$1" in
  264. cur)
  265. cur=$cur_
  266. ;;
  267. prev)
  268. prev=${words_[$cword_-1]}
  269. ;;
  270. words)
  271. words=("${words_[@]}")
  272. ;;
  273. cword)
  274. cword=$cword_
  275. ;;
  276. esac
  277. shift
  278. done
  279. }
  280. fi
  281. # Fills the COMPREPLY array with prefiltered words without any additional
  282. # processing.
  283. # Callers must take care of providing only words that match the current word
  284. # to be completed and adding any prefix and/or suffix (trailing space!), if
  285. # necessary.
  286. # 1: List of newline-separated matching completion words, complete with
  287. # prefix and suffix.
  288. __gitcomp_direct ()
  289. {
  290. local IFS=$'\n'
  291. COMPREPLY=($1)
  292. }
  293. # Similar to __gitcomp_direct, but appends to COMPREPLY instead.
  294. # Callers must take care of providing only words that match the current word
  295. # to be completed and adding any prefix and/or suffix (trailing space!), if
  296. # necessary.
  297. # 1: List of newline-separated matching completion words, complete with
  298. # prefix and suffix.
  299. __gitcomp_direct_append ()
  300. {
  301. local IFS=$'\n'
  302. COMPREPLY+=($1)
  303. }
  304. __gitcompappend ()
  305. {
  306. local x i=${#COMPREPLY[@]}
  307. for x in $1; do
  308. if [[ "$x" == "$3"* ]]; then
  309. COMPREPLY[i++]="$2$x$4"
  310. fi
  311. done
  312. }
  313. __gitcompadd ()
  314. {
  315. COMPREPLY=()
  316. __gitcompappend "$@"
  317. }
  318. # Generates completion reply, appending a space to possible completion words,
  319. # if necessary.
  320. # It accepts 1 to 4 arguments:
  321. # 1: List of possible completion words.
  322. # 2: A prefix to be added to each possible completion word (optional).
  323. # 3: Generate possible completion matches for this word (optional).
  324. # 4: A suffix to be appended to each possible completion word (optional).
  325. __gitcomp ()
  326. {
  327. local cur_="${3-$cur}"
  328. case "$cur_" in
  329. --*=)
  330. ;;
  331. --no-*)
  332. local c i=0 IFS=$' \t\n'
  333. for c in $1; do
  334. if [[ $c == "--" ]]; then
  335. continue
  336. fi
  337. c="$c${4-}"
  338. if [[ $c == "$cur_"* ]]; then
  339. case $c in
  340. --*=|*.) ;;
  341. *) c="$c " ;;
  342. esac
  343. COMPREPLY[i++]="${2-}$c"
  344. fi
  345. done
  346. ;;
  347. *)
  348. local c i=0 IFS=$' \t\n'
  349. for c in $1; do
  350. if [[ $c == "--" ]]; then
  351. c="--no-...${4-}"
  352. if [[ $c == "$cur_"* ]]; then
  353. COMPREPLY[i++]="${2-}$c "
  354. fi
  355. break
  356. fi
  357. c="$c${4-}"
  358. if [[ $c == "$cur_"* ]]; then
  359. case $c in
  360. *=|*.) ;;
  361. *) c="$c " ;;
  362. esac
  363. COMPREPLY[i++]="${2-}$c"
  364. fi
  365. done
  366. ;;
  367. esac
  368. }
  369. # Clear the variables caching builtins' options when (re-)sourcing
  370. # the completion script.
  371. if [[ -n ${ZSH_VERSION-} ]]; then
  372. unset ${(M)${(k)parameters[@]}:#__gitcomp_builtin_*} 2>/dev/null
  373. else
  374. unset $(compgen -v __gitcomp_builtin_)
  375. fi
  376. # This function is equivalent to
  377. #
  378. # __gitcomp "$(git xxx --git-completion-helper) ..."
  379. #
  380. # except that the output is cached. Accept 1-3 arguments:
  381. # 1: the git command to execute, this is also the cache key
  382. # 2: extra options to be added on top (e.g. negative forms)
  383. # 3: options to be excluded
  384. __gitcomp_builtin ()
  385. {
  386. # spaces must be replaced with underscore for multi-word
  387. # commands, e.g. "git remote add" becomes remote_add.
  388. local cmd="$1"
  389. local incl="${2-}"
  390. local excl="${3-}"
  391. local var=__gitcomp_builtin_"${cmd/-/_}"
  392. local options
  393. eval "options=\${$var-}"
  394. local completion_helper
  395. if [ "$GIT_COMPLETION_SHOW_ALL" = "1" ]; then
  396. completion_helper="--git-completion-helper-all"
  397. else
  398. completion_helper="--git-completion-helper"
  399. fi
  400. if [ -z "$options" ]; then
  401. # leading and trailing spaces are significant to make
  402. # option removal work correctly.
  403. options=" $incl $(__git ${cmd/_/ } $completion_helper) " || return
  404. for i in $excl; do
  405. options="${options/ $i / }"
  406. done
  407. eval "$var=\"$options\""
  408. fi
  409. __gitcomp "$options"
  410. }
  411. # Variation of __gitcomp_nl () that appends to the existing list of
  412. # completion candidates, COMPREPLY.
  413. __gitcomp_nl_append ()
  414. {
  415. local IFS=$'\n'
  416. __gitcompappend "$1" "${2-}" "${3-$cur}" "${4- }"
  417. }
  418. # Generates completion reply from newline-separated possible completion words
  419. # by appending a space to all of them.
  420. # It accepts 1 to 4 arguments:
  421. # 1: List of possible completion words, separated by a single newline.
  422. # 2: A prefix to be added to each possible completion word (optional).
  423. # 3: Generate possible completion matches for this word (optional).
  424. # 4: A suffix to be appended to each possible completion word instead of
  425. # the default space (optional). If specified but empty, nothing is
  426. # appended.
  427. __gitcomp_nl ()
  428. {
  429. COMPREPLY=()
  430. __gitcomp_nl_append "$@"
  431. }
  432. # Fills the COMPREPLY array with prefiltered paths without any additional
  433. # processing.
  434. # Callers must take care of providing only paths that match the current path
  435. # to be completed and adding any prefix path components, if necessary.
  436. # 1: List of newline-separated matching paths, complete with all prefix
  437. # path components.
  438. __gitcomp_file_direct ()
  439. {
  440. local IFS=$'\n'
  441. COMPREPLY=($1)
  442. # use a hack to enable file mode in bash < 4
  443. compopt -o filenames +o nospace 2>/dev/null ||
  444. compgen -f /non-existing-dir/ >/dev/null ||
  445. true
  446. }
  447. # Generates completion reply with compgen from newline-separated possible
  448. # completion filenames.
  449. # It accepts 1 to 3 arguments:
  450. # 1: List of possible completion filenames, separated by a single newline.
  451. # 2: A directory prefix to be added to each possible completion filename
  452. # (optional).
  453. # 3: Generate possible completion matches for this word (optional).
  454. __gitcomp_file ()
  455. {
  456. local IFS=$'\n'
  457. # XXX does not work when the directory prefix contains a tilde,
  458. # since tilde expansion is not applied.
  459. # This means that COMPREPLY will be empty and Bash default
  460. # completion will be used.
  461. __gitcompadd "$1" "${2-}" "${3-$cur}" ""
  462. # use a hack to enable file mode in bash < 4
  463. compopt -o filenames +o nospace 2>/dev/null ||
  464. compgen -f /non-existing-dir/ >/dev/null ||
  465. true
  466. }
  467. # Execute 'git ls-files', unless the --committable option is specified, in
  468. # which case it runs 'git diff-index' to find out the files that can be
  469. # committed. It return paths relative to the directory specified in the first
  470. # argument, and using the options specified in the second argument.
  471. __git_ls_files_helper ()
  472. {
  473. if [ "$2" == "--committable" ]; then
  474. __git -C "$1" -c core.quotePath=false diff-index \
  475. --name-only --relative HEAD -- "${3//\\/\\\\}*"
  476. else
  477. # NOTE: $2 is not quoted in order to support multiple options
  478. __git -C "$1" -c core.quotePath=false ls-files \
  479. --exclude-standard $2 -- "${3//\\/\\\\}*"
  480. fi
  481. }
  482. # __git_index_files accepts 1 or 2 arguments:
  483. # 1: Options to pass to ls-files (required).
  484. # 2: A directory path (optional).
  485. # If provided, only files within the specified directory are listed.
  486. # Sub directories are never recursed. Path must have a trailing
  487. # slash.
  488. # 3: List only paths matching this path component (optional).
  489. __git_index_files ()
  490. {
  491. local root="$2" match="$3"
  492. __git_ls_files_helper "$root" "$1" "${match:-?}" |
  493. awk -F / -v pfx="${2//\\/\\\\}" '{
  494. paths[$1] = 1
  495. }
  496. END {
  497. for (p in paths) {
  498. if (substr(p, 1, 1) != "\"") {
  499. # No special characters, easy!
  500. print pfx p
  501. continue
  502. }
  503. # The path is quoted.
  504. p = dequote(p)
  505. if (p == "")
  506. continue
  507. # Even when a directory name itself does not contain
  508. # any special characters, it will still be quoted if
  509. # any of its (stripped) trailing path components do.
  510. # Because of this we may have seen the same directory
  511. # both quoted and unquoted.
  512. if (p in paths)
  513. # We have seen the same directory unquoted,
  514. # skip it.
  515. continue
  516. else
  517. print pfx p
  518. }
  519. }
  520. function dequote(p, bs_idx, out, esc, esc_idx, dec) {
  521. # Skip opening double quote.
  522. p = substr(p, 2)
  523. # Interpret backslash escape sequences.
  524. while ((bs_idx = index(p, "\\")) != 0) {
  525. out = out substr(p, 1, bs_idx - 1)
  526. esc = substr(p, bs_idx + 1, 1)
  527. p = substr(p, bs_idx + 2)
  528. if ((esc_idx = index("abtvfr\"\\", esc)) != 0) {
  529. # C-style one-character escape sequence.
  530. out = out substr("\a\b\t\v\f\r\"\\",
  531. esc_idx, 1)
  532. } else if (esc == "n") {
  533. # Uh-oh, a newline character.
  534. # We cannot reliably put a pathname
  535. # containing a newline into COMPREPLY,
  536. # and the newline would create a mess.
  537. # Skip this path.
  538. return ""
  539. } else {
  540. # Must be a \nnn octal value, then.
  541. dec = esc * 64 + \
  542. substr(p, 1, 1) * 8 + \
  543. substr(p, 2, 1)
  544. out = out sprintf("%c", dec)
  545. p = substr(p, 3)
  546. }
  547. }
  548. # Drop closing double quote, if there is one.
  549. # (There is not any if this is a directory, as it was
  550. # already stripped with the trailing path components.)
  551. if (substr(p, length(p), 1) == "\"")
  552. out = out substr(p, 1, length(p) - 1)
  553. else
  554. out = out p
  555. return out
  556. }'
  557. }
  558. # __git_complete_index_file requires 1 argument:
  559. # 1: the options to pass to ls-file
  560. #
  561. # The exception is --committable, which finds the files appropriate commit.
  562. __git_complete_index_file ()
  563. {
  564. local dequoted_word pfx="" cur_
  565. __git_dequote "$cur"
  566. case "$dequoted_word" in
  567. ?*/*)
  568. pfx="${dequoted_word%/*}/"
  569. cur_="${dequoted_word##*/}"
  570. ;;
  571. *)
  572. cur_="$dequoted_word"
  573. esac
  574. __gitcomp_file_direct "$(__git_index_files "$1" "$pfx" "$cur_")"
  575. }
  576. # Lists branches from the local repository.
  577. # 1: A prefix to be added to each listed branch (optional).
  578. # 2: List only branches matching this word (optional; list all branches if
  579. # unset or empty).
  580. # 3: A suffix to be appended to each listed branch (optional).
  581. __git_heads ()
  582. {
  583. local pfx="${1-}" cur_="${2-}" sfx="${3-}"
  584. __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
  585. "refs/heads/$cur_*" "refs/heads/$cur_*/**"
  586. }
  587. # Lists branches from remote repositories.
  588. # 1: A prefix to be added to each listed branch (optional).
  589. # 2: List only branches matching this word (optional; list all branches if
  590. # unset or empty).
  591. # 3: A suffix to be appended to each listed branch (optional).
  592. __git_remote_heads ()
  593. {
  594. local pfx="${1-}" cur_="${2-}" sfx="${3-}"
  595. __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
  596. "refs/remotes/$cur_*" "refs/remotes/$cur_*/**"
  597. }
  598. # Lists tags from the local repository.
  599. # Accepts the same positional parameters as __git_heads() above.
  600. __git_tags ()
  601. {
  602. local pfx="${1-}" cur_="${2-}" sfx="${3-}"
  603. __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
  604. "refs/tags/$cur_*" "refs/tags/$cur_*/**"
  605. }
  606. # List unique branches from refs/remotes used for 'git checkout' and 'git
  607. # switch' tracking DWIMery.
  608. # 1: A prefix to be added to each listed branch (optional)
  609. # 2: List only branches matching this word (optional; list all branches if
  610. # unset or empty).
  611. # 3: A suffix to be appended to each listed branch (optional).
  612. __git_dwim_remote_heads ()
  613. {
  614. local pfx="${1-}" cur_="${2-}" sfx="${3-}"
  615. local fer_pfx="${pfx//\%/%%}" # "escape" for-each-ref format specifiers
  616. # employ the heuristic used by git checkout and git switch
  617. # Try to find a remote branch that cur_es the completion word
  618. # but only output if the branch name is unique
  619. __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
  620. --sort="refname:strip=3" \
  621. "refs/remotes/*/$cur_*" "refs/remotes/*/$cur_*/**" | \
  622. uniq -u
  623. }
  624. # Lists refs from the local (by default) or from a remote repository.
  625. # It accepts 0, 1 or 2 arguments:
  626. # 1: The remote to list refs from (optional; ignored, if set but empty).
  627. # Can be the name of a configured remote, a path, or a URL.
  628. # 2: In addition to local refs, list unique branches from refs/remotes/ for
  629. # 'git checkout's tracking DWIMery (optional; ignored, if set but empty).
  630. # 3: A prefix to be added to each listed ref (optional).
  631. # 4: List only refs matching this word (optional; list all refs if unset or
  632. # empty).
  633. # 5: A suffix to be appended to each listed ref (optional; ignored, if set
  634. # but empty).
  635. #
  636. # Use __git_complete_refs() instead.
  637. __git_refs ()
  638. {
  639. local i hash dir track="${2-}"
  640. local list_refs_from=path remote="${1-}"
  641. local format refs
  642. local pfx="${3-}" cur_="${4-$cur}" sfx="${5-}"
  643. local match="${4-}"
  644. local fer_pfx="${pfx//\%/%%}" # "escape" for-each-ref format specifiers
  645. __git_find_repo_path
  646. dir="$__git_repo_path"
  647. if [ -z "$remote" ]; then
  648. if [ -z "$dir" ]; then
  649. return
  650. fi
  651. else
  652. if __git_is_configured_remote "$remote"; then
  653. # configured remote takes precedence over a
  654. # local directory with the same name
  655. list_refs_from=remote
  656. elif [ -d "$remote/.git" ]; then
  657. dir="$remote/.git"
  658. elif [ -d "$remote" ]; then
  659. dir="$remote"
  660. else
  661. list_refs_from=url
  662. fi
  663. fi
  664. if [ "$list_refs_from" = path ]; then
  665. if [[ "$cur_" == ^* ]]; then
  666. pfx="$pfx^"
  667. fer_pfx="$fer_pfx^"
  668. cur_=${cur_#^}
  669. match=${match#^}
  670. fi
  671. case "$cur_" in
  672. refs|refs/*)
  673. format="refname"
  674. refs=("$match*" "$match*/**")
  675. track=""
  676. ;;
  677. *)
  678. for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD REBASE_HEAD; do
  679. case "$i" in
  680. $match*)
  681. if [ -e "$dir/$i" ]; then
  682. echo "$pfx$i$sfx"
  683. fi
  684. ;;
  685. esac
  686. done
  687. format="refname:strip=2"
  688. refs=("refs/tags/$match*" "refs/tags/$match*/**"
  689. "refs/heads/$match*" "refs/heads/$match*/**"
  690. "refs/remotes/$match*" "refs/remotes/$match*/**")
  691. ;;
  692. esac
  693. __git_dir="$dir" __git for-each-ref --format="$fer_pfx%($format)$sfx" \
  694. "${refs[@]}"
  695. if [ -n "$track" ]; then
  696. __git_dwim_remote_heads "$pfx" "$match" "$sfx"
  697. fi
  698. return
  699. fi
  700. case "$cur_" in
  701. refs|refs/*)
  702. __git ls-remote "$remote" "$match*" | \
  703. while read -r hash i; do
  704. case "$i" in
  705. *^{}) ;;
  706. *) echo "$pfx$i$sfx" ;;
  707. esac
  708. done
  709. ;;
  710. *)
  711. if [ "$list_refs_from" = remote ]; then
  712. case "HEAD" in
  713. $match*) echo "${pfx}HEAD$sfx" ;;
  714. esac
  715. __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
  716. "refs/remotes/$remote/$match*" \
  717. "refs/remotes/$remote/$match*/**"
  718. else
  719. local query_symref
  720. case "HEAD" in
  721. $match*) query_symref="HEAD" ;;
  722. esac
  723. __git ls-remote "$remote" $query_symref \
  724. "refs/tags/$match*" "refs/heads/$match*" \
  725. "refs/remotes/$match*" |
  726. while read -r hash i; do
  727. case "$i" in
  728. *^{}) ;;
  729. refs/*) echo "$pfx${i#refs/*/}$sfx" ;;
  730. *) echo "$pfx$i$sfx" ;; # symbolic refs
  731. esac
  732. done
  733. fi
  734. ;;
  735. esac
  736. }
  737. # Completes refs, short and long, local and remote, symbolic and pseudo.
  738. #
  739. # Usage: __git_complete_refs [<option>]...
  740. # --remote=<remote>: The remote to list refs from, can be the name of a
  741. # configured remote, a path, or a URL.
  742. # --dwim: List unique remote branches for 'git switch's tracking DWIMery.
  743. # --pfx=<prefix>: A prefix to be added to each ref.
  744. # --cur=<word>: The current ref to be completed. Defaults to the current
  745. # word to be completed.
  746. # --sfx=<suffix>: A suffix to be appended to each ref instead of the default
  747. # space.
  748. # --mode=<mode>: What set of refs to complete, one of 'refs' (the default) to
  749. # complete all refs, 'heads' to complete only branches, or
  750. # 'remote-heads' to complete only remote branches. Note that
  751. # --remote is only compatible with --mode=refs.
  752. __git_complete_refs ()
  753. {
  754. local remote= dwim= pfx= cur_="$cur" sfx=" " mode="refs"
  755. while test $# != 0; do
  756. case "$1" in
  757. --remote=*) remote="${1##--remote=}" ;;
  758. --dwim) dwim="yes" ;;
  759. # --track is an old spelling of --dwim
  760. --track) dwim="yes" ;;
  761. --pfx=*) pfx="${1##--pfx=}" ;;
  762. --cur=*) cur_="${1##--cur=}" ;;
  763. --sfx=*) sfx="${1##--sfx=}" ;;
  764. --mode=*) mode="${1##--mode=}" ;;
  765. *) return 1 ;;
  766. esac
  767. shift
  768. done
  769. # complete references based on the specified mode
  770. case "$mode" in
  771. refs)
  772. __gitcomp_direct "$(__git_refs "$remote" "" "$pfx" "$cur_" "$sfx")" ;;
  773. heads)
  774. __gitcomp_direct "$(__git_heads "$pfx" "$cur_" "$sfx")" ;;
  775. remote-heads)
  776. __gitcomp_direct "$(__git_remote_heads "$pfx" "$cur_" "$sfx")" ;;
  777. *)
  778. return 1 ;;
  779. esac
  780. # Append DWIM remote branch names if requested
  781. if [ "$dwim" = "yes" ]; then
  782. __gitcomp_direct_append "$(__git_dwim_remote_heads "$pfx" "$cur_" "$sfx")"
  783. fi
  784. }
  785. # __git_refs2 requires 1 argument (to pass to __git_refs)
  786. # Deprecated: use __git_complete_fetch_refspecs() instead.
  787. __git_refs2 ()
  788. {
  789. local i
  790. for i in $(__git_refs "$1"); do
  791. echo "$i:$i"
  792. done
  793. }
  794. # Completes refspecs for fetching from a remote repository.
  795. # 1: The remote repository.
  796. # 2: A prefix to be added to each listed refspec (optional).
  797. # 3: The ref to be completed as a refspec instead of the current word to be
  798. # completed (optional)
  799. # 4: A suffix to be appended to each listed refspec instead of the default
  800. # space (optional).
  801. __git_complete_fetch_refspecs ()
  802. {
  803. local i remote="$1" pfx="${2-}" cur_="${3-$cur}" sfx="${4- }"
  804. __gitcomp_direct "$(
  805. for i in $(__git_refs "$remote" "" "" "$cur_") ; do
  806. echo "$pfx$i:$i$sfx"
  807. done
  808. )"
  809. }
  810. # __git_refs_remotes requires 1 argument (to pass to ls-remote)
  811. __git_refs_remotes ()
  812. {
  813. local i hash
  814. __git ls-remote "$1" 'refs/heads/*' | \
  815. while read -r hash i; do
  816. echo "$i:refs/remotes/$1/${i#refs/heads/}"
  817. done
  818. }
  819. __git_remotes ()
  820. {
  821. __git_find_repo_path
  822. test -d "$__git_repo_path/remotes" && ls -1 "$__git_repo_path/remotes"
  823. __git remote
  824. }
  825. # Returns true if $1 matches the name of a configured remote, false otherwise.
  826. __git_is_configured_remote ()
  827. {
  828. local remote
  829. for remote in $(__git_remotes); do
  830. if [ "$remote" = "$1" ]; then
  831. return 0
  832. fi
  833. done
  834. return 1
  835. }
  836. __git_list_merge_strategies ()
  837. {
  838. LANG=C LC_ALL=C git merge -s help 2>&1 |
  839. sed -n -e '/[Aa]vailable strategies are: /,/^$/{
  840. s/\.$//
  841. s/.*://
  842. s/^[ ]*//
  843. s/[ ]*$//
  844. p
  845. }'
  846. }
  847. __git_merge_strategies=
  848. # 'git merge -s help' (and thus detection of the merge strategy
  849. # list) fails, unfortunately, if run outside of any git working
  850. # tree. __git_merge_strategies is set to the empty string in
  851. # that case, and the detection will be repeated the next time it
  852. # is needed.
  853. __git_compute_merge_strategies ()
  854. {
  855. test -n "$__git_merge_strategies" ||
  856. __git_merge_strategies=$(__git_list_merge_strategies)
  857. }
  858. __git_merge_strategy_options="ours theirs subtree subtree= patience
  859. histogram diff-algorithm= ignore-space-change ignore-all-space
  860. ignore-space-at-eol renormalize no-renormalize no-renames
  861. find-renames find-renames= rename-threshold="
  862. __git_complete_revlist_file ()
  863. {
  864. local dequoted_word pfx ls ref cur_="$cur"
  865. case "$cur_" in
  866. *..?*:*)
  867. return
  868. ;;
  869. ?*:*)
  870. ref="${cur_%%:*}"
  871. cur_="${cur_#*:}"
  872. __git_dequote "$cur_"
  873. case "$dequoted_word" in
  874. ?*/*)
  875. pfx="${dequoted_word%/*}"
  876. cur_="${dequoted_word##*/}"
  877. ls="$ref:$pfx"
  878. pfx="$pfx/"
  879. ;;
  880. *)
  881. cur_="$dequoted_word"
  882. ls="$ref"
  883. ;;
  884. esac
  885. case "$COMP_WORDBREAKS" in
  886. *:*) : great ;;
  887. *) pfx="$ref:$pfx" ;;
  888. esac
  889. __gitcomp_file "$(__git ls-tree "$ls" \
  890. | sed 's/^.* //
  891. s/$//')" \
  892. "$pfx" "$cur_"
  893. ;;
  894. *...*)
  895. pfx="${cur_%...*}..."
  896. cur_="${cur_#*...}"
  897. __git_complete_refs --pfx="$pfx" --cur="$cur_"
  898. ;;
  899. *..*)
  900. pfx="${cur_%..*}.."
  901. cur_="${cur_#*..}"
  902. __git_complete_refs --pfx="$pfx" --cur="$cur_"
  903. ;;
  904. *)
  905. __git_complete_refs
  906. ;;
  907. esac
  908. }
  909. __git_complete_file ()
  910. {
  911. __git_complete_revlist_file
  912. }
  913. __git_complete_revlist ()
  914. {
  915. __git_complete_revlist_file
  916. }
  917. __git_complete_remote_or_refspec ()
  918. {
  919. local cur_="$cur" cmd="${words[1]}"
  920. local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
  921. if [ "$cmd" = "remote" ]; then
  922. ((c++))
  923. fi
  924. while [ $c -lt $cword ]; do
  925. i="${words[c]}"
  926. case "$i" in
  927. --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
  928. -d|--delete) [ "$cmd" = "push" ] && lhs=0 ;;
  929. --all)
  930. case "$cmd" in
  931. push) no_complete_refspec=1 ;;
  932. fetch)
  933. return
  934. ;;
  935. *) ;;
  936. esac
  937. ;;
  938. --multiple) no_complete_refspec=1; break ;;
  939. -*) ;;
  940. *) remote="$i"; break ;;
  941. esac
  942. ((c++))
  943. done
  944. if [ -z "$remote" ]; then
  945. __gitcomp_nl "$(__git_remotes)"
  946. return
  947. fi
  948. if [ $no_complete_refspec = 1 ]; then
  949. return
  950. fi
  951. [ "$remote" = "." ] && remote=
  952. case "$cur_" in
  953. *:*)
  954. case "$COMP_WORDBREAKS" in
  955. *:*) : great ;;
  956. *) pfx="${cur_%%:*}:" ;;
  957. esac
  958. cur_="${cur_#*:}"
  959. lhs=0
  960. ;;
  961. +*)
  962. pfx="+"
  963. cur_="${cur_#+}"
  964. ;;
  965. esac
  966. case "$cmd" in
  967. fetch)
  968. if [ $lhs = 1 ]; then
  969. __git_complete_fetch_refspecs "$remote" "$pfx" "$cur_"
  970. else
  971. __git_complete_refs --pfx="$pfx" --cur="$cur_"
  972. fi
  973. ;;
  974. pull|remote)
  975. if [ $lhs = 1 ]; then
  976. __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
  977. else
  978. __git_complete_refs --pfx="$pfx" --cur="$cur_"
  979. fi
  980. ;;
  981. push)
  982. if [ $lhs = 1 ]; then
  983. __git_complete_refs --pfx="$pfx" --cur="$cur_"
  984. else
  985. __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
  986. fi
  987. ;;
  988. esac
  989. }
  990. __git_complete_strategy ()
  991. {
  992. __git_compute_merge_strategies
  993. case "$prev" in
  994. -s|--strategy)
  995. __gitcomp "$__git_merge_strategies"
  996. return 0
  997. ;;
  998. -X)
  999. __gitcomp "$__git_merge_strategy_options"
  1000. return 0
  1001. ;;
  1002. esac
  1003. case "$cur" in
  1004. --strategy=*)
  1005. __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
  1006. return 0
  1007. ;;
  1008. --strategy-option=*)
  1009. __gitcomp "$__git_merge_strategy_options" "" "${cur##--strategy-option=}"
  1010. return 0
  1011. ;;
  1012. esac
  1013. return 1
  1014. }
  1015. __git_all_commands=
  1016. __git_compute_all_commands ()
  1017. {
  1018. test -n "$__git_all_commands" ||
  1019. __git_all_commands=$(__git --list-cmds=main,others,alias,nohelpers)
  1020. }
  1021. # Lists all set config variables starting with the given section prefix,
  1022. # with the prefix removed.
  1023. __git_get_config_variables ()
  1024. {
  1025. local section="$1" i IFS=$'\n'
  1026. for i in $(__git config --name-only --get-regexp "^$section\..*"); do
  1027. echo "${i#$section.}"
  1028. done
  1029. }
  1030. __git_pretty_aliases ()
  1031. {
  1032. __git_get_config_variables "pretty"
  1033. }
  1034. # __git_aliased_command requires 1 argument
  1035. __git_aliased_command ()
  1036. {
  1037. local word cmdline=$(__git config --get "alias.$1")
  1038. for word in $cmdline; do
  1039. case "$word" in
  1040. \!gitk|gitk)
  1041. echo "gitk"
  1042. return
  1043. ;;
  1044. \!*) : shell command alias ;;
  1045. -*) : option ;;
  1046. *=*) : setting env ;;
  1047. git) : git itself ;;
  1048. \(\)) : skip parens of shell function definition ;;
  1049. {) : skip start of shell helper function ;;
  1050. :) : skip null command ;;
  1051. \'*) : skip opening quote after sh -c ;;
  1052. *)
  1053. echo "$word"
  1054. return
  1055. esac
  1056. done
  1057. }
  1058. # Check whether one of the given words is present on the command line,
  1059. # and print the first word found.
  1060. #
  1061. # Usage: __git_find_on_cmdline [<option>]... "<wordlist>"
  1062. # --show-idx: Optionally show the index of the found word in the $words array.
  1063. __git_find_on_cmdline ()
  1064. {
  1065. local word c=1 show_idx
  1066. while test $# -gt 1; do
  1067. case "$1" in
  1068. --show-idx) show_idx=y ;;
  1069. *) return 1 ;;
  1070. esac
  1071. shift
  1072. done
  1073. local wordlist="$1"
  1074. while [ $c -lt $cword ]; do
  1075. for word in $wordlist; do
  1076. if [ "$word" = "${words[c]}" ]; then
  1077. if [ -n "${show_idx-}" ]; then
  1078. echo "$c $word"
  1079. else
  1080. echo "$word"
  1081. fi
  1082. return
  1083. fi
  1084. done
  1085. ((c++))
  1086. done
  1087. }
  1088. # Similar to __git_find_on_cmdline, except that it loops backwards and thus
  1089. # prints the *last* word found. Useful for finding which of two options that
  1090. # supersede each other came last, such as "--guess" and "--no-guess".
  1091. #
  1092. # Usage: __git_find_last_on_cmdline [<option>]... "<wordlist>"
  1093. # --show-idx: Optionally show the index of the found word in the $words array.
  1094. __git_find_last_on_cmdline ()
  1095. {
  1096. local word c=$cword show_idx
  1097. while test $# -gt 1; do
  1098. case "$1" in
  1099. --show-idx) show_idx=y ;;
  1100. *) return 1 ;;
  1101. esac
  1102. shift
  1103. done
  1104. local wordlist="$1"
  1105. while [ $c -gt 1 ]; do
  1106. ((c--))
  1107. for word in $wordlist; do
  1108. if [ "$word" = "${words[c]}" ]; then
  1109. if [ -n "$show_idx" ]; then
  1110. echo "$c $word"
  1111. else
  1112. echo "$word"
  1113. fi
  1114. return
  1115. fi
  1116. done
  1117. done
  1118. }
  1119. # Echo the value of an option set on the command line or config
  1120. #
  1121. # $1: short option name
  1122. # $2: long option name including =
  1123. # $3: list of possible values
  1124. # $4: config string (optional)
  1125. #
  1126. # example:
  1127. # result="$(__git_get_option_value "-d" "--do-something=" \
  1128. # "yes no" "core.doSomething")"
  1129. #
  1130. # result is then either empty (no option set) or "yes" or "no"
  1131. #
  1132. # __git_get_option_value requires 3 arguments
  1133. __git_get_option_value ()
  1134. {
  1135. local c short_opt long_opt val
  1136. local result= values config_key word
  1137. short_opt="$1"
  1138. long_opt="$2"
  1139. values="$3"
  1140. config_key="$4"
  1141. ((c = $cword - 1))
  1142. while [ $c -ge 0 ]; do
  1143. word="${words[c]}"
  1144. for val in $values; do
  1145. if [ "$short_opt$val" = "$word" ] ||
  1146. [ "$long_opt$val" = "$word" ]; then
  1147. result="$val"
  1148. break 2
  1149. fi
  1150. done
  1151. ((c--))
  1152. done
  1153. if [ -n "$config_key" ] && [ -z "$result" ]; then
  1154. result="$(__git config "$config_key")"
  1155. fi
  1156. echo "$result"
  1157. }
  1158. __git_has_doubledash ()
  1159. {
  1160. local c=1
  1161. while [ $c -lt $cword ]; do
  1162. if [ "--" = "${words[c]}" ]; then
  1163. return 0
  1164. fi
  1165. ((c++))
  1166. done
  1167. return 1
  1168. }
  1169. # Try to count non option arguments passed on the command line for the
  1170. # specified git command.
  1171. # When options are used, it is necessary to use the special -- option to
  1172. # tell the implementation were non option arguments begin.
  1173. # XXX this can not be improved, since options can appear everywhere, as
  1174. # an example:
  1175. # git mv x -n y
  1176. #
  1177. # __git_count_arguments requires 1 argument: the git command executed.
  1178. __git_count_arguments ()
  1179. {
  1180. local word i c=0
  1181. # Skip "git" (first argument)
  1182. for ((i=1; i < ${#words[@]}; i++)); do
  1183. word="${words[i]}"
  1184. case "$word" in
  1185. --)
  1186. # Good; we can assume that the following are only non
  1187. # option arguments.
  1188. ((c = 0))
  1189. ;;
  1190. "$1")
  1191. # Skip the specified git command and discard git
  1192. # main options
  1193. ((c = 0))
  1194. ;;
  1195. ?*)
  1196. ((c++))
  1197. ;;
  1198. esac
  1199. done
  1200. printf "%d" $c
  1201. }
  1202. __git_whitespacelist="nowarn warn error error-all fix"
  1203. __git_patchformat="mbox stgit stgit-series hg mboxrd"
  1204. __git_showcurrentpatch="diff raw"
  1205. __git_am_inprogress_options="--skip --continue --resolved --abort --quit --show-current-patch"
  1206. _git_am ()
  1207. {
  1208. __git_find_repo_path
  1209. if [ -d "$__git_repo_path"/rebase-apply ]; then
  1210. __gitcomp "$__git_am_inprogress_options"
  1211. return
  1212. fi
  1213. case "$cur" in
  1214. --whitespace=*)
  1215. __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
  1216. return
  1217. ;;
  1218. --patch-format=*)
  1219. __gitcomp "$__git_patchformat" "" "${cur##--patch-format=}"
  1220. return
  1221. ;;
  1222. --show-current-patch=*)
  1223. __gitcomp "$__git_showcurrentpatch" "" "${cur##--show-current-patch=}"
  1224. return
  1225. ;;
  1226. --*)
  1227. __gitcomp_builtin am "" \
  1228. "$__git_am_inprogress_options"
  1229. return
  1230. esac
  1231. }
  1232. _git_apply ()
  1233. {
  1234. case "$cur" in
  1235. --whitespace=*)
  1236. __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
  1237. return
  1238. ;;
  1239. --*)
  1240. __gitcomp_builtin apply
  1241. return
  1242. esac
  1243. }
  1244. _git_add ()
  1245. {
  1246. case "$cur" in
  1247. --chmod=*)
  1248. __gitcomp "+x -x" "" "${cur##--chmod=}"
  1249. return
  1250. ;;
  1251. --*)
  1252. __gitcomp_builtin add
  1253. return
  1254. esac
  1255. local complete_opt="--others --modified --directory --no-empty-directory"
  1256. if test -n "$(__git_find_on_cmdline "-u --update")"
  1257. then
  1258. complete_opt="--modified"
  1259. fi
  1260. __git_complete_index_file "$complete_opt"
  1261. }
  1262. _git_archive ()
  1263. {
  1264. case "$cur" in
  1265. --format=*)
  1266. __gitcomp "$(git archive --list)" "" "${cur##--format=}"
  1267. return
  1268. ;;
  1269. --remote=*)
  1270. __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
  1271. return
  1272. ;;
  1273. --*)
  1274. __gitcomp_builtin archive "--format= --list --verbose --prefix= --worktree-attributes"
  1275. return
  1276. ;;
  1277. esac
  1278. __git_complete_file
  1279. }
  1280. _git_bisect ()
  1281. {
  1282. __git_has_doubledash && return
  1283. local subcommands="start bad good skip reset visualize replay log run"
  1284. local subcommand="$(__git_find_on_cmdline "$subcommands")"
  1285. if [ -z "$subcommand" ]; then
  1286. __git_find_repo_path
  1287. if [ -f "$__git_repo_path"/BISECT_START ]; then
  1288. __gitcomp "$subcommands"
  1289. else
  1290. __gitcomp "replay start"
  1291. fi
  1292. return
  1293. fi
  1294. case "$subcommand" in
  1295. bad|good|reset|skip|start)
  1296. __git_complete_refs
  1297. ;;
  1298. *)
  1299. ;;
  1300. esac
  1301. }
  1302. __git_ref_fieldlist="refname objecttype objectsize objectname upstream push HEAD symref"
  1303. _git_branch ()
  1304. {
  1305. local i c=1 only_local_ref="n" has_r="n"
  1306. while [ $c -lt $cword ]; do
  1307. i="${words[c]}"
  1308. case "$i" in
  1309. -d|--delete|-m|--move) only_local_ref="y" ;;
  1310. -r|--remotes) has_r="y" ;;
  1311. esac
  1312. ((c++))
  1313. done
  1314. case "$cur" in
  1315. --set-upstream-to=*)
  1316. __git_complete_refs --cur="${cur##--set-upstream-to=}"
  1317. ;;
  1318. --*)
  1319. __gitcomp_builtin branch
  1320. ;;
  1321. *)
  1322. if [ $only_local_ref = "y" -a $has_r = "n" ]; then
  1323. __gitcomp_direct "$(__git_heads "" "$cur" " ")"
  1324. else
  1325. __git_complete_refs
  1326. fi
  1327. ;;
  1328. esac
  1329. }
  1330. _git_bundle ()
  1331. {
  1332. local cmd="${words[2]}"
  1333. case "$cword" in
  1334. 2)
  1335. __gitcomp "create list-heads verify unbundle"
  1336. ;;
  1337. 3)
  1338. # looking for a file
  1339. ;;
  1340. *)
  1341. case "$cmd" in
  1342. create)
  1343. __git_complete_revlist
  1344. ;;
  1345. esac
  1346. ;;
  1347. esac
  1348. }
  1349. # Helper function to decide whether or not we should enable DWIM logic for
  1350. # git-switch and git-checkout.
  1351. #
  1352. # To decide between the following rules in priority order
  1353. # 1) the last provided of "--guess" or "--no-guess" explicitly enable or
  1354. # disable completion of DWIM logic respectively.
  1355. # 2) If the --no-track option is provided, take this as a hint to disable the
  1356. # DWIM completion logic
  1357. # 3) If GIT_COMPLETION_CHECKOUT_NO_GUESS is set, disable the DWIM completion
  1358. # logic, as requested by the user.
  1359. # 4) Enable DWIM logic otherwise.
  1360. #
  1361. __git_checkout_default_dwim_mode ()
  1362. {
  1363. local last_option dwim_opt="--dwim"
  1364. if [ "${GIT_COMPLETION_CHECKOUT_NO_GUESS-}" = "1" ]; then
  1365. dwim_opt=""
  1366. fi
  1367. # --no-track disables DWIM, but with lower priority than
  1368. # --guess/--no-guess
  1369. if [ -n "$(__git_find_on_cmdline "--no-track")" ]; then
  1370. dwim_opt=""
  1371. fi
  1372. # Find the last provided --guess or --no-guess
  1373. last_option="$(__git_find_last_on_cmdline "--guess --no-guess")"
  1374. case "$last_option" in
  1375. --guess)
  1376. dwim_opt="--dwim"
  1377. ;;
  1378. --no-guess)
  1379. dwim_opt=""
  1380. ;;
  1381. esac
  1382. echo "$dwim_opt"
  1383. }
  1384. _git_checkout ()
  1385. {
  1386. __git_has_doubledash && return
  1387. local dwim_opt="$(__git_checkout_default_dwim_mode)"
  1388. case "$prev" in
  1389. -b|-B|--orphan)
  1390. # Complete local branches (and DWIM branch
  1391. # remote branch names) for an option argument
  1392. # specifying a new branch name. This is for
  1393. # convenience, assuming new branches are
  1394. # possibly based on pre-existing branch names.
  1395. __git_complete_refs $dwim_opt --mode="heads"
  1396. return
  1397. ;;
  1398. *)
  1399. ;;
  1400. esac
  1401. case "$cur" in
  1402. --conflict=*)
  1403. __gitcomp "diff3 merge" "" "${cur##--conflict=}"
  1404. ;;
  1405. --*)
  1406. __gitcomp_builtin checkout
  1407. ;;
  1408. *)
  1409. # At this point, we've already handled special completion for
  1410. # the arguments to -b/-B, and --orphan. There are 3 main
  1411. # things left we can possibly complete:
  1412. # 1) a start-point for -b/-B, -d/--detach, or --orphan
  1413. # 2) a remote head, for --track
  1414. # 3) an arbitrary reference, possibly including DWIM names
  1415. #
  1416. if [ -n "$(__git_find_on_cmdline "-b -B -d --detach --orphan")" ]; then
  1417. __git_complete_refs --mode="refs"
  1418. elif [ -n "$(__git_find_on_cmdline "--track")" ]; then
  1419. __git_complete_refs --mode="remote-heads"
  1420. else
  1421. __git_complete_refs $dwim_opt --mode="refs"
  1422. fi
  1423. ;;
  1424. esac
  1425. }
  1426. __git_sequencer_inprogress_options="--continue --quit --abort --skip"
  1427. __git_cherry_pick_inprogress_options=$__git_sequencer_inprogress_options
  1428. _git_cherry_pick ()
  1429. {
  1430. __git_find_repo_path
  1431. if [ -f "$__git_repo_path"/CHERRY_PICK_HEAD ]; then
  1432. __gitcomp "$__git_cherry_pick_inprogress_options"
  1433. return
  1434. fi
  1435. __git_complete_strategy && return
  1436. case "$cur" in
  1437. --*)
  1438. __gitcomp_builtin cherry-pick "" \
  1439. "$__git_cherry_pick_inprogress_options"
  1440. ;;
  1441. *)
  1442. __git_complete_refs
  1443. ;;
  1444. esac
  1445. }
  1446. _git_clean ()
  1447. {
  1448. case "$cur" in
  1449. --*)
  1450. __gitcomp_builtin clean
  1451. return
  1452. ;;
  1453. esac
  1454. # XXX should we check for -x option ?
  1455. __git_complete_index_file "--others --directory"
  1456. }
  1457. _git_clone ()
  1458. {
  1459. case "$prev" in
  1460. -c|--config)
  1461. __git_complete_config_variable_name_and_value
  1462. return
  1463. ;;
  1464. esac
  1465. case "$cur" in
  1466. --config=*)
  1467. __git_complete_config_variable_name_and_value \
  1468. --cur="${cur##--config=}"
  1469. return
  1470. ;;
  1471. --*)
  1472. __gitcomp_builtin clone
  1473. return
  1474. ;;
  1475. esac
  1476. }
  1477. __git_untracked_file_modes="all no normal"
  1478. _git_commit ()
  1479. {
  1480. case "$prev" in
  1481. -c|-C)
  1482. __git_complete_refs
  1483. return
  1484. ;;
  1485. esac
  1486. case "$cur" in
  1487. --cleanup=*)
  1488. __gitcomp "default scissors strip verbatim whitespace
  1489. " "" "${cur##--cleanup=}"
  1490. return
  1491. ;;
  1492. --reuse-message=*|--reedit-message=*|\
  1493. --fixup=*|--squash=*)
  1494. __git_complete_refs --cur="${cur#*=}"
  1495. return
  1496. ;;
  1497. --untracked-files=*)
  1498. __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
  1499. return
  1500. ;;
  1501. --*)
  1502. __gitcomp_builtin commit
  1503. return
  1504. esac
  1505. if __git rev-parse --verify --quiet HEAD >/dev/null; then
  1506. __git_complete_index_file "--committable"
  1507. else
  1508. # This is the first commit
  1509. __git_complete_index_file "--cached"
  1510. fi
  1511. }
  1512. _git_describe ()
  1513. {
  1514. case "$cur" in
  1515. --*)
  1516. __gitcomp_builtin describe
  1517. return
  1518. esac
  1519. __git_complete_refs
  1520. }
  1521. __git_diff_algorithms="myers minimal patience histogram"
  1522. __git_diff_submodule_formats="diff log short"
  1523. __git_color_moved_opts="no default plain blocks zebra dimmed-zebra"
  1524. __git_color_moved_ws_opts="no ignore-space-at-eol ignore-space-change
  1525. ignore-all-space allow-indentation-change"
  1526. __git_diff_common_options="--stat --numstat --shortstat --summary
  1527. --patch-with-stat --name-only --name-status --color
  1528. --no-color --color-words --no-renames --check
  1529. --color-moved --color-moved= --no-color-moved
  1530. --color-moved-ws= --no-color-moved-ws
  1531. --full-index --binary --abbrev --diff-filter=
  1532. --find-copies-harder --ignore-cr-at-eol
  1533. --text --ignore-space-at-eol --ignore-space-change
  1534. --ignore-all-space --ignore-blank-lines --exit-code
  1535. --quiet --ext-diff --no-ext-diff
  1536. --no-prefix --src-prefix= --dst-prefix=
  1537. --inter-hunk-context=
  1538. --patience --histogram --minimal
  1539. --raw --word-diff --word-diff-regex=
  1540. --dirstat --dirstat= --dirstat-by-file
  1541. --dirstat-by-file= --cumulative
  1542. --diff-algorithm=
  1543. --submodule --submodule= --ignore-submodules
  1544. --indent-heuristic --no-indent-heuristic
  1545. --textconv --no-textconv
  1546. "
  1547. _git_diff ()
  1548. {
  1549. __git_has_doubledash && return
  1550. case "$cur" in
  1551. --diff-algorithm=*)
  1552. __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
  1553. return
  1554. ;;
  1555. --submodule=*)
  1556. __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
  1557. return
  1558. ;;
  1559. --color-moved=*)
  1560. __gitcomp "$__git_color_moved_opts" "" "${cur##--color-moved=}"
  1561. return
  1562. ;;
  1563. --color-moved-ws=*)
  1564. __gitcomp "$__git_color_moved_ws_opts" "" "${cur##--color-moved-ws=}"
  1565. return
  1566. ;;
  1567. --*)
  1568. __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
  1569. --base --ours --theirs --no-index
  1570. $__git_diff_common_options
  1571. "
  1572. return
  1573. ;;
  1574. esac
  1575. __git_complete_revlist_file
  1576. }
  1577. __git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff
  1578. tkdiff vimdiff nvimdiff gvimdiff xxdiff araxis p4merge
  1579. bc codecompare smerge
  1580. "
  1581. _git_difftool ()
  1582. {
  1583. __git_has_doubledash && return
  1584. case "$cur" in
  1585. --tool=*)
  1586. __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
  1587. return
  1588. ;;
  1589. --*)
  1590. __gitcomp_builtin difftool "$__git_diff_common_options
  1591. --base --cached --ours --theirs
  1592. --pickaxe-all --pickaxe-regex
  1593. --relative --staged
  1594. "
  1595. return
  1596. ;;
  1597. esac
  1598. __git_complete_revlist_file
  1599. }
  1600. __git_fetch_recurse_submodules="yes on-demand no"
  1601. _git_fetch ()
  1602. {
  1603. case "$cur" in
  1604. --recurse-submodules=*)
  1605. __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
  1606. return
  1607. ;;
  1608. --filter=*)
  1609. __gitcomp "blob:none blob:limit= sparse:oid=" "" "${cur##--filter=}"
  1610. return
  1611. ;;
  1612. --*)
  1613. __gitcomp_builtin fetch
  1614. return
  1615. ;;
  1616. esac
  1617. __git_complete_remote_or_refspec
  1618. }
  1619. __git_format_patch_extra_options="
  1620. --full-index --not --all --no-prefix --src-prefix=
  1621. --dst-prefix= --notes
  1622. "
  1623. _git_format_patch ()
  1624. {
  1625. case "$cur" in
  1626. --thread=*)
  1627. __gitcomp "
  1628. deep shallow
  1629. " "" "${cur##--thread=}"
  1630. return
  1631. ;;
  1632. --base=*|--interdiff=*|--range-diff=*)
  1633. __git_complete_refs --cur="${cur#--*=}"
  1634. return
  1635. ;;
  1636. --*)
  1637. __gitcomp_builtin format-patch "$__git_format_patch_extra_options"
  1638. return
  1639. ;;
  1640. esac
  1641. __git_complete_revlist
  1642. }
  1643. _git_fsck ()
  1644. {
  1645. case "$cur" in
  1646. --*)
  1647. __gitcomp_builtin fsck
  1648. return
  1649. ;;
  1650. esac
  1651. }
  1652. _git_gitk ()
  1653. {
  1654. _gitk
  1655. }
  1656. # Lists matching symbol names from a tag (as in ctags) file.
  1657. # 1: List symbol names matching this word.
  1658. # 2: The tag file to list symbol names from.
  1659. # 3: A prefix to be added to each listed symbol name (optional).
  1660. # 4: A suffix to be appended to each listed symbol name (optional).
  1661. __git_match_ctag () {
  1662. awk -v pfx="${3-}" -v sfx="${4-}" "
  1663. /^${1//\//\\/}/ { print pfx \$1 sfx }
  1664. " "$2"
  1665. }
  1666. # Complete symbol names from a tag file.
  1667. # Usage: __git_complete_symbol [<option>]...
  1668. # --tags=<file>: The tag file to list symbol names from instead of the
  1669. # default "tags".
  1670. # --pfx=<prefix>: A prefix to be added to each symbol name.
  1671. # --cur=<word>: The current symbol name to be completed. Defaults to
  1672. # the current word to be completed.
  1673. # --sfx=<suffix>: A suffix to be appended to each symbol name instead
  1674. # of the default space.
  1675. __git_complete_symbol () {
  1676. local tags=tags pfx="" cur_="${cur-}" sfx=" "
  1677. while test $# != 0; do
  1678. case "$1" in
  1679. --tags=*) tags="${1##--tags=}" ;;
  1680. --pfx=*) pfx="${1##--pfx=}" ;;
  1681. --cur=*) cur_="${1##--cur=}" ;;
  1682. --sfx=*) sfx="${1##--sfx=}" ;;
  1683. *) return 1 ;;
  1684. esac
  1685. shift
  1686. done
  1687. if test -r "$tags"; then
  1688. __gitcomp_direct "$(__git_match_ctag "$cur_" "$tags" "$pfx" "$sfx")"
  1689. fi
  1690. }
  1691. _git_grep ()
  1692. {
  1693. __git_has_doubledash && return
  1694. case "$cur" in
  1695. --*)
  1696. __gitcomp_builtin grep
  1697. return
  1698. ;;
  1699. esac
  1700. case "$cword,$prev" in
  1701. 2,*|*,-*)
  1702. __git_complete_symbol && return
  1703. ;;
  1704. esac
  1705. __git_complete_refs
  1706. }
  1707. _git_help ()
  1708. {
  1709. case "$cur" in
  1710. --*)
  1711. __gitcomp_builtin help
  1712. return
  1713. ;;
  1714. esac
  1715. if test -n "$GIT_TESTING_ALL_COMMAND_LIST"
  1716. then
  1717. __gitcomp "$GIT_TESTING_ALL_COMMAND_LIST $(__git --list-cmds=alias,list-guide) gitk"
  1718. else
  1719. __gitcomp "$(__git --list-cmds=main,nohelpers,alias,list-guide) gitk"
  1720. fi
  1721. }
  1722. _git_init ()
  1723. {
  1724. case "$cur" in
  1725. --shared=*)
  1726. __gitcomp "
  1727. false true umask group all world everybody
  1728. " "" "${cur##--shared=}"
  1729. return
  1730. ;;
  1731. --*)
  1732. __gitcomp_builtin init
  1733. return
  1734. ;;
  1735. esac
  1736. }
  1737. _git_ls_files ()
  1738. {
  1739. case "$cur" in
  1740. --*)
  1741. __gitcomp_builtin ls-files
  1742. return
  1743. ;;
  1744. esac
  1745. # XXX ignore options like --modified and always suggest all cached
  1746. # files.
  1747. __git_complete_index_file "--cached"
  1748. }
  1749. _git_ls_remote ()
  1750. {
  1751. case "$cur" in
  1752. --*)
  1753. __gitcomp_builtin ls-remote
  1754. return
  1755. ;;
  1756. esac
  1757. __gitcomp_nl "$(__git_remotes)"
  1758. }
  1759. _git_ls_tree ()
  1760. {
  1761. case "$cur" in
  1762. --*)
  1763. __gitcomp_builtin ls-tree
  1764. return
  1765. ;;
  1766. esac
  1767. __git_complete_file
  1768. }
  1769. # Options that go well for log, shortlog and gitk
  1770. __git_log_common_options="
  1771. --not --all
  1772. --branches --tags --remotes
  1773. --first-parent --merges --no-merges
  1774. --max-count=
  1775. --max-age= --since= --after=
  1776. --min-age= --until= --before=
  1777. --min-parents= --max-parents=
  1778. --no-min-parents --no-max-parents
  1779. "
  1780. # Options that go well for log and gitk (not shortlog)
  1781. __git_log_gitk_options="
  1782. --dense --sparse --full-history
  1783. --simplify-merges --simplify-by-decoration
  1784. --left-right --notes --no-notes
  1785. "
  1786. # Options that go well for log and shortlog (not gitk)
  1787. __git_log_shortlog_options="
  1788. --author= --committer= --grep=
  1789. --all-match --invert-grep
  1790. "
  1791. __git_log_pretty_formats="oneline short medium full fuller reference email raw format: tformat: mboxrd"
  1792. __git_log_date_formats="relative iso8601 iso8601-strict rfc2822 short local default raw unix format:"
  1793. _git_log ()
  1794. {
  1795. __git_has_doubledash && return
  1796. __git_find_repo_path
  1797. local merge=""
  1798. if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
  1799. merge="--merge"
  1800. fi
  1801. case "$prev,$cur" in
  1802. -L,:*:*)
  1803. return # fall back to Bash filename completion
  1804. ;;
  1805. -L,:*)
  1806. __git_complete_symbol --cur="${cur#:}" --sfx=":"
  1807. return
  1808. ;;
  1809. -G,*|-S,*)
  1810. __git_complete_symbol
  1811. return
  1812. ;;
  1813. esac
  1814. case "$cur" in
  1815. --pretty=*|--format=*)
  1816. __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
  1817. " "" "${cur#*=}"
  1818. return
  1819. ;;
  1820. --date=*)
  1821. __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
  1822. return
  1823. ;;
  1824. --decorate=*)
  1825. __gitcomp "full short no" "" "${cur##--decorate=}"
  1826. return
  1827. ;;
  1828. --diff-algorithm=*)
  1829. __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
  1830. return
  1831. ;;
  1832. --submodule=*)
  1833. __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
  1834. return
  1835. ;;
  1836. --no-walk=*)
  1837. __gitcomp "sorted unsorted" "" "${cur##--no-walk=}"
  1838. return
  1839. ;;
  1840. --*)
  1841. __gitcomp "
  1842. $__git_log_common_options
  1843. $__git_log_shortlog_options
  1844. $__git_log_gitk_options
  1845. --root --topo-order --date-order --reverse
  1846. --follow --full-diff
  1847. --abbrev-commit --no-abbrev-commit --abbrev=
  1848. --relative-date --date=
  1849. --pretty= --format= --oneline
  1850. --show-signature
  1851. --cherry-mark
  1852. --cherry-pick
  1853. --graph
  1854. --decorate --decorate= --no-decorate
  1855. --walk-reflogs
  1856. --no-walk --no-walk= --do-walk
  1857. --parents --children
  1858. --expand-tabs --expand-tabs= --no-expand-tabs
  1859. --patch
  1860. $merge
  1861. $__git_diff_common_options
  1862. --pickaxe-all --pickaxe-regex
  1863. --patch --no-patch
  1864. "
  1865. return
  1866. ;;
  1867. -L:*:*)
  1868. return # fall back to Bash filename completion
  1869. ;;
  1870. -L:*)
  1871. __git_complete_symbol --cur="${cur#-L:}" --sfx=":"
  1872. return
  1873. ;;
  1874. -G*)
  1875. __git_complete_symbol --pfx="-G" --cur="${cur#-G}"
  1876. return
  1877. ;;
  1878. -S*)
  1879. __git_complete_symbol --pfx="-S" --cur="${cur#-S}"
  1880. return
  1881. ;;
  1882. esac
  1883. __git_complete_revlist
  1884. }
  1885. _git_merge ()
  1886. {
  1887. __git_complete_strategy && return
  1888. case "$cur" in
  1889. --*)
  1890. __gitcomp_builtin merge
  1891. return
  1892. esac
  1893. __git_complete_refs
  1894. }
  1895. _git_mergetool ()
  1896. {
  1897. case "$cur" in
  1898. --tool=*)
  1899. __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
  1900. return
  1901. ;;
  1902. --*)
  1903. __gitcomp "--tool= --prompt --no-prompt --gui --no-gui"
  1904. return
  1905. ;;
  1906. esac
  1907. }
  1908. _git_merge_base ()
  1909. {
  1910. case "$cur" in
  1911. --*)
  1912. __gitcomp_builtin merge-base
  1913. return
  1914. ;;
  1915. esac
  1916. __git_complete_refs
  1917. }
  1918. _git_mv ()
  1919. {
  1920. case "$cur" in
  1921. --*)
  1922. __gitcomp_builtin mv
  1923. return
  1924. ;;
  1925. esac
  1926. if [ $(__git_count_arguments "mv") -gt 0 ]; then
  1927. # We need to show both cached and untracked files (including
  1928. # empty directories) since this may not be the last argument.
  1929. __git_complete_index_file "--cached --others --directory"
  1930. else
  1931. __git_complete_index_file "--cached"
  1932. fi
  1933. }
  1934. _git_notes ()
  1935. {
  1936. local subcommands='add append copy edit get-ref list merge prune remove show'
  1937. local subcommand="$(__git_find_on_cmdline "$subcommands")"
  1938. case "$subcommand,$cur" in
  1939. ,--*)
  1940. __gitcomp_builtin notes
  1941. ;;
  1942. ,*)
  1943. case "$prev" in
  1944. --ref)
  1945. __git_complete_refs
  1946. ;;
  1947. *)
  1948. __gitcomp "$subcommands --ref"
  1949. ;;
  1950. esac
  1951. ;;
  1952. *,--reuse-message=*|*,--reedit-message=*)
  1953. __git_complete_refs --cur="${cur#*=}"
  1954. ;;
  1955. *,--*)
  1956. __gitcomp_builtin notes_$subcommand
  1957. ;;
  1958. prune,*|get-ref,*)
  1959. # this command does not take a ref, do not complete it
  1960. ;;
  1961. *)
  1962. case "$prev" in
  1963. -m|-F)
  1964. ;;
  1965. *)
  1966. __git_complete_refs
  1967. ;;
  1968. esac
  1969. ;;
  1970. esac
  1971. }
  1972. _git_pull ()
  1973. {
  1974. __git_complete_strategy && return
  1975. case "$cur" in
  1976. --recurse-submodules=*)
  1977. __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
  1978. return
  1979. ;;
  1980. --*)
  1981. __gitcomp_builtin pull
  1982. return
  1983. ;;
  1984. esac
  1985. __git_complete_remote_or_refspec
  1986. }
  1987. __git_push_recurse_submodules="check on-demand only"
  1988. __git_complete_force_with_lease ()
  1989. {
  1990. local cur_=$1
  1991. case "$cur_" in
  1992. --*=)
  1993. ;;
  1994. *:*)
  1995. __git_complete_refs --cur="${cur_#*:}"
  1996. ;;
  1997. *)
  1998. __git_complete_refs --cur="$cur_"
  1999. ;;
  2000. esac
  2001. }
  2002. _git_push ()
  2003. {
  2004. case "$prev" in
  2005. --repo)
  2006. __gitcomp_nl "$(__git_remotes)"
  2007. return
  2008. ;;
  2009. --recurse-submodules)
  2010. __gitcomp "$__git_push_recurse_submodules"
  2011. return
  2012. ;;
  2013. esac
  2014. case "$cur" in
  2015. --repo=*)
  2016. __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
  2017. return
  2018. ;;
  2019. --recurse-submodules=*)
  2020. __gitcomp "$__git_push_recurse_submodules" "" "${cur##--recurse-submodules=}"
  2021. return
  2022. ;;
  2023. --force-with-lease=*)
  2024. __git_complete_force_with_lease "${cur##--force-with-lease=}"
  2025. return
  2026. ;;
  2027. --*)
  2028. __gitcomp_builtin push
  2029. return
  2030. ;;
  2031. esac
  2032. __git_complete_remote_or_refspec
  2033. }
  2034. _git_range_diff ()
  2035. {
  2036. case "$cur" in
  2037. --*)
  2038. __gitcomp "
  2039. --creation-factor= --no-dual-color
  2040. $__git_diff_common_options
  2041. "
  2042. return
  2043. ;;
  2044. esac
  2045. __git_complete_revlist
  2046. }
  2047. __git_rebase_inprogress_options="--continue --skip --abort --quit --show-current-patch"
  2048. __git_rebase_interactive_inprogress_options="$__git_rebase_inprogress_options --edit-todo"
  2049. _git_rebase ()
  2050. {
  2051. __git_find_repo_path
  2052. if [ -f "$__git_repo_path"/rebase-merge/interactive ]; then
  2053. __gitcomp "$__git_rebase_interactive_inprogress_options"
  2054. return
  2055. elif [ -d "$__git_repo_path"/rebase-apply ] || \
  2056. [ -d "$__git_repo_path"/rebase-merge ]; then
  2057. __gitcomp "$__git_rebase_inprogress_options"
  2058. return
  2059. fi
  2060. __git_complete_strategy && return
  2061. case "$cur" in
  2062. --whitespace=*)
  2063. __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
  2064. return
  2065. ;;
  2066. --onto=*)
  2067. __git_complete_refs --cur="${cur##--onto=}"
  2068. return
  2069. ;;
  2070. --*)
  2071. __gitcomp_builtin rebase "" \
  2072. "$__git_rebase_interactive_inprogress_options"
  2073. return
  2074. esac
  2075. __git_complete_refs
  2076. }
  2077. _git_reflog ()
  2078. {
  2079. local subcommands="show delete expire"
  2080. local subcommand="$(__git_find_on_cmdline "$subcommands")"
  2081. if [ -z "$subcommand" ]; then
  2082. __gitcomp "$subcommands"
  2083. else
  2084. __git_complete_refs
  2085. fi
  2086. }
  2087. __git_send_email_confirm_options="always never auto cc compose"
  2088. __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
  2089. _git_send_email ()
  2090. {
  2091. case "$prev" in
  2092. --to|--cc|--bcc|--from)
  2093. __gitcomp "$(__git send-email --dump-aliases)"
  2094. return
  2095. ;;
  2096. esac
  2097. case "$cur" in
  2098. --confirm=*)
  2099. __gitcomp "
  2100. $__git_send_email_confirm_options
  2101. " "" "${cur##--confirm=}"
  2102. return
  2103. ;;
  2104. --suppress-cc=*)
  2105. __gitcomp "
  2106. $__git_send_email_suppresscc_options
  2107. " "" "${cur##--suppress-cc=}"
  2108. return
  2109. ;;
  2110. --smtp-encryption=*)
  2111. __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
  2112. return
  2113. ;;
  2114. --thread=*)
  2115. __gitcomp "
  2116. deep shallow
  2117. " "" "${cur##--thread=}"
  2118. return
  2119. ;;
  2120. --to=*|--cc=*|--bcc=*|--from=*)
  2121. __gitcomp "$(__git send-email --dump-aliases)" "" "${cur#--*=}"
  2122. return
  2123. ;;
  2124. --*)
  2125. __gitcomp_builtin send-email "--annotate --bcc --cc --cc-cmd --chain-reply-to
  2126. --compose --confirm= --dry-run --envelope-sender
  2127. --from --identity
  2128. --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
  2129. --no-suppress-from --no-thread --quiet --reply-to
  2130. --signed-off-by-cc --smtp-pass --smtp-server
  2131. --smtp-server-port --smtp-encryption= --smtp-user
  2132. --subject --suppress-cc= --suppress-from --thread --to
  2133. --validate --no-validate
  2134. $__git_format_patch_extra_options"
  2135. return
  2136. ;;
  2137. esac
  2138. __git_complete_revlist
  2139. }
  2140. _git_stage ()
  2141. {
  2142. _git_add
  2143. }
  2144. _git_status ()
  2145. {
  2146. local complete_opt
  2147. local untracked_state
  2148. case "$cur" in
  2149. --ignore-submodules=*)
  2150. __gitcomp "none untracked dirty all" "" "${cur##--ignore-submodules=}"
  2151. return
  2152. ;;
  2153. --untracked-files=*)
  2154. __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
  2155. return
  2156. ;;
  2157. --column=*)
  2158. __gitcomp "
  2159. always never auto column row plain dense nodense
  2160. " "" "${cur##--column=}"
  2161. return
  2162. ;;
  2163. --*)
  2164. __gitcomp_builtin status
  2165. return
  2166. ;;
  2167. esac
  2168. untracked_state="$(__git_get_option_value "-u" "--untracked-files=" \
  2169. "$__git_untracked_file_modes" "status.showUntrackedFiles")"
  2170. case "$untracked_state" in
  2171. no)
  2172. # --ignored option does not matter
  2173. complete_opt=
  2174. ;;
  2175. all|normal|*)
  2176. complete_opt="--cached --directory --no-empty-directory --others"
  2177. if [ -n "$(__git_find_on_cmdline "--ignored")" ]; then
  2178. complete_opt="$complete_opt --ignored --exclude=*"
  2179. fi
  2180. ;;
  2181. esac
  2182. __git_complete_index_file "$complete_opt"
  2183. }
  2184. _git_switch ()
  2185. {
  2186. local dwim_opt="$(__git_checkout_default_dwim_mode)"
  2187. case "$prev" in
  2188. -c|-C|--orphan)
  2189. # Complete local branches (and DWIM branch
  2190. # remote branch names) for an option argument
  2191. # specifying a new branch name. This is for
  2192. # convenience, assuming new branches are
  2193. # possibly based on pre-existing branch names.
  2194. __git_complete_refs $dwim_opt --mode="heads"
  2195. return
  2196. ;;
  2197. *)
  2198. ;;
  2199. esac
  2200. case "$cur" in
  2201. --conflict=*)
  2202. __gitcomp "diff3 merge" "" "${cur##--conflict=}"
  2203. ;;
  2204. --*)
  2205. __gitcomp_builtin switch
  2206. ;;
  2207. *)
  2208. # Unlike in git checkout, git switch --orphan does not take
  2209. # a start point. Thus we really have nothing to complete after
  2210. # the branch name.
  2211. if [ -n "$(__git_find_on_cmdline "--orphan")" ]; then
  2212. return
  2213. fi
  2214. # At this point, we've already handled special completion for
  2215. # -c/-C, and --orphan. There are 3 main things left to
  2216. # complete:
  2217. # 1) a start-point for -c/-C or -d/--detach
  2218. # 2) a remote head, for --track
  2219. # 3) a branch name, possibly including DWIM remote branches
  2220. if [ -n "$(__git_find_on_cmdline "-c -C -d --detach")" ]; then
  2221. __git_complete_refs --mode="refs"
  2222. elif [ -n "$(__git_find_on_cmdline "--track")" ]; then
  2223. __git_complete_refs --mode="remote-heads"
  2224. else
  2225. __git_complete_refs $dwim_opt --mode="heads"
  2226. fi
  2227. ;;
  2228. esac
  2229. }
  2230. __git_config_get_set_variables ()
  2231. {
  2232. local prevword word config_file= c=$cword
  2233. while [ $c -gt 1 ]; do
  2234. word="${words[c]}"
  2235. case "$word" in
  2236. --system|--global|--local|--file=*)
  2237. config_file="$word"
  2238. break
  2239. ;;
  2240. -f|--file)
  2241. config_file="$word $prevword"
  2242. break
  2243. ;;
  2244. esac
  2245. prevword=$word
  2246. c=$((--c))
  2247. done
  2248. __git config $config_file --name-only --list
  2249. }
  2250. __git_config_vars=
  2251. __git_compute_config_vars ()
  2252. {
  2253. test -n "$__git_config_vars" ||
  2254. __git_config_vars="$(git help --config-for-completion | sort -u)"
  2255. }
  2256. # Completes possible values of various configuration variables.
  2257. #
  2258. # Usage: __git_complete_config_variable_value [<option>]...
  2259. # --varname=<word>: The name of the configuration variable whose value is
  2260. # to be completed. Defaults to the previous word on the
  2261. # command line.
  2262. # --cur=<word>: The current value to be completed. Defaults to the current
  2263. # word to be completed.
  2264. __git_complete_config_variable_value ()
  2265. {
  2266. local varname="$prev" cur_="$cur"
  2267. while test $# != 0; do
  2268. case "$1" in
  2269. --varname=*) varname="${1##--varname=}" ;;
  2270. --cur=*) cur_="${1##--cur=}" ;;
  2271. *) return 1 ;;
  2272. esac
  2273. shift
  2274. done
  2275. if [ "${BASH_VERSINFO[0]:-0}" -ge 4 ]; then
  2276. varname="${varname,,}"
  2277. else
  2278. varname="$(echo "$varname" |tr A-Z a-z)"
  2279. fi
  2280. case "$varname" in
  2281. branch.*.remote|branch.*.pushremote)
  2282. __gitcomp_nl "$(__git_remotes)" "" "$cur_"
  2283. return
  2284. ;;
  2285. branch.*.merge)
  2286. __git_complete_refs --cur="$cur_"
  2287. return
  2288. ;;
  2289. branch.*.rebase)
  2290. __gitcomp "false true merges preserve interactive" "" "$cur_"
  2291. return
  2292. ;;
  2293. remote.pushdefault)
  2294. __gitcomp_nl "$(__git_remotes)" "" "$cur_"
  2295. return
  2296. ;;
  2297. remote.*.fetch)
  2298. local remote="${varname#remote.}"
  2299. remote="${remote%.fetch}"
  2300. if [ -z "$cur_" ]; then
  2301. __gitcomp_nl "refs/heads/" "" "" ""
  2302. return
  2303. fi
  2304. __gitcomp_nl "$(__git_refs_remotes "$remote")" "" "$cur_"
  2305. return
  2306. ;;
  2307. remote.*.push)
  2308. local remote="${varname#remote.}"
  2309. remote="${remote%.push}"
  2310. __gitcomp_nl "$(__git for-each-ref \
  2311. --format='%(refname):%(refname)' refs/heads)" "" "$cur_"
  2312. return
  2313. ;;
  2314. pull.twohead|pull.octopus)
  2315. __git_compute_merge_strategies
  2316. __gitcomp "$__git_merge_strategies" "" "$cur_"
  2317. return
  2318. ;;
  2319. color.pager)
  2320. __gitcomp "false true" "" "$cur_"
  2321. return
  2322. ;;
  2323. color.*.*)
  2324. __gitcomp "
  2325. normal black red green yellow blue magenta cyan white
  2326. bold dim ul blink reverse
  2327. " "" "$cur_"
  2328. return
  2329. ;;
  2330. color.*)
  2331. __gitcomp "false true always never auto" "" "$cur_"
  2332. return
  2333. ;;
  2334. diff.submodule)
  2335. __gitcomp "$__git_diff_submodule_formats" "" "$cur_"
  2336. return
  2337. ;;
  2338. help.format)
  2339. __gitcomp "man info web html" "" "$cur_"
  2340. return
  2341. ;;
  2342. log.date)
  2343. __gitcomp "$__git_log_date_formats" "" "$cur_"
  2344. return
  2345. ;;
  2346. sendemail.aliasfiletype)
  2347. __gitcomp "mutt mailrc pine elm gnus" "" "$cur_"
  2348. return
  2349. ;;
  2350. sendemail.confirm)
  2351. __gitcomp "$__git_send_email_confirm_options" "" "$cur_"
  2352. return
  2353. ;;
  2354. sendemail.suppresscc)
  2355. __gitcomp "$__git_send_email_suppresscc_options" "" "$cur_"
  2356. return
  2357. ;;
  2358. sendemail.transferencoding)
  2359. __gitcomp "7bit 8bit quoted-printable base64" "" "$cur_"
  2360. return
  2361. ;;
  2362. *.*)
  2363. return
  2364. ;;
  2365. esac
  2366. }
  2367. # Completes configuration sections, subsections, variable names.
  2368. #
  2369. # Usage: __git_complete_config_variable_name [<option>]...
  2370. # --cur=<word>: The current configuration section/variable name to be
  2371. # completed. Defaults to the current word to be completed.
  2372. # --sfx=<suffix>: A suffix to be appended to each fully completed
  2373. # configuration variable name (but not to sections or
  2374. # subsections) instead of the default space.
  2375. __git_complete_config_variable_name ()
  2376. {
  2377. local cur_="$cur" sfx
  2378. while test $# != 0; do
  2379. case "$1" in
  2380. --cur=*) cur_="${1##--cur=}" ;;
  2381. --sfx=*) sfx="${1##--sfx=}" ;;
  2382. *) return 1 ;;
  2383. esac
  2384. shift
  2385. done
  2386. case "$cur_" in
  2387. branch.*.*)
  2388. local pfx="${cur_%.*}."
  2389. cur_="${cur_##*.}"
  2390. __gitcomp "remote pushRemote merge mergeOptions rebase" "$pfx" "$cur_" "$sfx"
  2391. return
  2392. ;;
  2393. branch.*)
  2394. local pfx="${cur%.*}."
  2395. cur_="${cur#*.}"
  2396. __gitcomp_direct "$(__git_heads "$pfx" "$cur_" ".")"
  2397. __gitcomp_nl_append $'autoSetupMerge\nautoSetupRebase\n' "$pfx" "$cur_" "$sfx"
  2398. return
  2399. ;;
  2400. guitool.*.*)
  2401. local pfx="${cur_%.*}."
  2402. cur_="${cur_##*.}"
  2403. __gitcomp "
  2404. argPrompt cmd confirm needsFile noConsole noRescan
  2405. prompt revPrompt revUnmerged title
  2406. " "$pfx" "$cur_" "$sfx"
  2407. return
  2408. ;;
  2409. difftool.*.*)
  2410. local pfx="${cur_%.*}."
  2411. cur_="${cur_##*.}"
  2412. __gitcomp "cmd path" "$pfx" "$cur_" "$sfx"
  2413. return
  2414. ;;
  2415. man.*.*)
  2416. local pfx="${cur_%.*}."
  2417. cur_="${cur_##*.}"
  2418. __gitcomp "cmd path" "$pfx" "$cur_" "$sfx"
  2419. return
  2420. ;;
  2421. mergetool.*.*)
  2422. local pfx="${cur_%.*}."
  2423. cur_="${cur_##*.}"
  2424. __gitcomp "cmd path trustExitCode" "$pfx" "$cur_" "$sfx"
  2425. return
  2426. ;;
  2427. pager.*)
  2428. local pfx="${cur_%.*}."
  2429. cur_="${cur_#*.}"
  2430. __git_compute_all_commands
  2431. __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_" "$sfx"
  2432. return
  2433. ;;
  2434. remote.*.*)
  2435. local pfx="${cur_%.*}."
  2436. cur_="${cur_##*.}"
  2437. __gitcomp "
  2438. url proxy fetch push mirror skipDefaultUpdate
  2439. receivepack uploadpack tagOpt pushurl
  2440. " "$pfx" "$cur_" "$sfx"
  2441. return
  2442. ;;
  2443. remote.*)
  2444. local pfx="${cur_%.*}."
  2445. cur_="${cur_#*.}"
  2446. __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
  2447. __gitcomp_nl_append "pushDefault" "$pfx" "$cur_" "$sfx"
  2448. return
  2449. ;;
  2450. url.*.*)
  2451. local pfx="${cur_%.*}."
  2452. cur_="${cur_##*.}"
  2453. __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_" "$sfx"
  2454. return
  2455. ;;
  2456. *.*)
  2457. __git_compute_config_vars
  2458. __gitcomp "$__git_config_vars" "" "$cur_" "$sfx"
  2459. ;;
  2460. *)
  2461. __git_compute_config_vars
  2462. __gitcomp "$(echo "$__git_config_vars" |
  2463. awk -F . '{
  2464. sections[$1] = 1
  2465. }
  2466. END {
  2467. for (s in sections)
  2468. print s "."
  2469. }
  2470. ')" "" "$cur_"
  2471. ;;
  2472. esac
  2473. }
  2474. # Completes '='-separated configuration sections/variable names and values
  2475. # for 'git -c section.name=value'.
  2476. #
  2477. # Usage: __git_complete_config_variable_name_and_value [<option>]...
  2478. # --cur=<word>: The current configuration section/variable name/value to be
  2479. # completed. Defaults to the current word to be completed.
  2480. __git_complete_config_variable_name_and_value ()
  2481. {
  2482. local cur_="$cur"
  2483. while test $# != 0; do
  2484. case "$1" in
  2485. --cur=*) cur_="${1##--cur=}" ;;
  2486. *) return 1 ;;
  2487. esac
  2488. shift
  2489. done
  2490. case "$cur_" in
  2491. *=*)
  2492. __git_complete_config_variable_value \
  2493. --varname="${cur_%%=*}" --cur="${cur_#*=}"
  2494. ;;
  2495. *)
  2496. __git_complete_config_variable_name --cur="$cur_" --sfx='='
  2497. ;;
  2498. esac
  2499. }
  2500. _git_config ()
  2501. {
  2502. case "$prev" in
  2503. --get|--get-all|--unset|--unset-all)
  2504. __gitcomp_nl "$(__git_config_get_set_variables)"
  2505. return
  2506. ;;
  2507. *.*)
  2508. __git_complete_config_variable_value
  2509. return
  2510. ;;
  2511. esac
  2512. case "$cur" in
  2513. --*)
  2514. __gitcomp_builtin config
  2515. ;;
  2516. *)
  2517. __git_complete_config_variable_name
  2518. ;;
  2519. esac
  2520. }
  2521. _git_remote ()
  2522. {
  2523. local subcommands="
  2524. add rename remove set-head set-branches
  2525. get-url set-url show prune update
  2526. "
  2527. local subcommand="$(__git_find_on_cmdline "$subcommands")"
  2528. if [ -z "$subcommand" ]; then
  2529. case "$cur" in
  2530. --*)
  2531. __gitcomp_builtin remote
  2532. ;;
  2533. *)
  2534. __gitcomp "$subcommands"
  2535. ;;
  2536. esac
  2537. return
  2538. fi
  2539. case "$subcommand,$cur" in
  2540. add,--*)
  2541. __gitcomp_builtin remote_add
  2542. ;;
  2543. add,*)
  2544. ;;
  2545. set-head,--*)
  2546. __gitcomp_builtin remote_set-head
  2547. ;;
  2548. set-branches,--*)
  2549. __gitcomp_builtin remote_set-branches
  2550. ;;
  2551. set-head,*|set-branches,*)
  2552. __git_complete_remote_or_refspec
  2553. ;;
  2554. update,--*)
  2555. __gitcomp_builtin remote_update
  2556. ;;
  2557. update,*)
  2558. __gitcomp "$(__git_remotes) $(__git_get_config_variables "remotes")"
  2559. ;;
  2560. set-url,--*)
  2561. __gitcomp_builtin remote_set-url
  2562. ;;
  2563. get-url,--*)
  2564. __gitcomp_builtin remote_get-url
  2565. ;;
  2566. prune,--*)
  2567. __gitcomp_builtin remote_prune
  2568. ;;
  2569. *)
  2570. __gitcomp_nl "$(__git_remotes)"
  2571. ;;
  2572. esac
  2573. }
  2574. _git_replace ()
  2575. {
  2576. case "$cur" in
  2577. --format=*)
  2578. __gitcomp "short medium long" "" "${cur##--format=}"
  2579. return
  2580. ;;
  2581. --*)
  2582. __gitcomp_builtin replace
  2583. return
  2584. ;;
  2585. esac
  2586. __git_complete_refs
  2587. }
  2588. _git_rerere ()
  2589. {
  2590. local subcommands="clear forget diff remaining status gc"
  2591. local subcommand="$(__git_find_on_cmdline "$subcommands")"
  2592. if test -z "$subcommand"
  2593. then
  2594. __gitcomp "$subcommands"
  2595. return
  2596. fi
  2597. }
  2598. _git_reset ()
  2599. {
  2600. __git_has_doubledash && return
  2601. case "$cur" in
  2602. --*)
  2603. __gitcomp_builtin reset
  2604. return
  2605. ;;
  2606. esac
  2607. __git_complete_refs
  2608. }
  2609. _git_restore ()
  2610. {
  2611. case "$prev" in
  2612. -s)
  2613. __git_complete_refs
  2614. return
  2615. ;;
  2616. esac
  2617. case "$cur" in
  2618. --conflict=*)
  2619. __gitcomp "diff3 merge" "" "${cur##--conflict=}"
  2620. ;;
  2621. --source=*)
  2622. __git_complete_refs --cur="${cur##--source=}"
  2623. ;;
  2624. --*)
  2625. __gitcomp_builtin restore
  2626. ;;
  2627. esac
  2628. }
  2629. __git_revert_inprogress_options=$__git_sequencer_inprogress_options
  2630. _git_revert ()
  2631. {
  2632. __git_find_repo_path
  2633. if [ -f "$__git_repo_path"/REVERT_HEAD ]; then
  2634. __gitcomp "$__git_revert_inprogress_options"
  2635. return
  2636. fi
  2637. __git_complete_strategy && return
  2638. case "$cur" in
  2639. --*)
  2640. __gitcomp_builtin revert "" \
  2641. "$__git_revert_inprogress_options"
  2642. return
  2643. ;;
  2644. esac
  2645. __git_complete_refs
  2646. }
  2647. _git_rm ()
  2648. {
  2649. case "$cur" in
  2650. --*)
  2651. __gitcomp_builtin rm
  2652. return
  2653. ;;
  2654. esac
  2655. __git_complete_index_file "--cached"
  2656. }
  2657. _git_shortlog ()
  2658. {
  2659. __git_has_doubledash && return
  2660. case "$cur" in
  2661. --*)
  2662. __gitcomp "
  2663. $__git_log_common_options
  2664. $__git_log_shortlog_options
  2665. --numbered --summary --email
  2666. "
  2667. return
  2668. ;;
  2669. esac
  2670. __git_complete_revlist
  2671. }
  2672. _git_show ()
  2673. {
  2674. __git_has_doubledash && return
  2675. case "$cur" in
  2676. --pretty=*|--format=*)
  2677. __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
  2678. " "" "${cur#*=}"
  2679. return
  2680. ;;
  2681. --diff-algorithm=*)
  2682. __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
  2683. return
  2684. ;;
  2685. --submodule=*)
  2686. __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
  2687. return
  2688. ;;
  2689. --color-moved=*)
  2690. __gitcomp "$__git_color_moved_opts" "" "${cur##--color-moved=}"
  2691. return
  2692. ;;
  2693. --color-moved-ws=*)
  2694. __gitcomp "$__git_color_moved_ws_opts" "" "${cur##--color-moved-ws=}"
  2695. return
  2696. ;;
  2697. --*)
  2698. __gitcomp "--pretty= --format= --abbrev-commit --no-abbrev-commit
  2699. --oneline --show-signature --patch
  2700. --expand-tabs --expand-tabs= --no-expand-tabs
  2701. $__git_diff_common_options
  2702. "
  2703. return
  2704. ;;
  2705. esac
  2706. __git_complete_revlist_file
  2707. }
  2708. _git_show_branch ()
  2709. {
  2710. case "$cur" in
  2711. --*)
  2712. __gitcomp_builtin show-branch
  2713. return
  2714. ;;
  2715. esac
  2716. __git_complete_revlist
  2717. }
  2718. _git_sparse_checkout ()
  2719. {
  2720. local subcommands="list init set disable"
  2721. local subcommand="$(__git_find_on_cmdline "$subcommands")"
  2722. if [ -z "$subcommand" ]; then
  2723. __gitcomp "$subcommands"
  2724. return
  2725. fi
  2726. case "$subcommand,$cur" in
  2727. init,--*)
  2728. __gitcomp "--cone"
  2729. ;;
  2730. set,--*)
  2731. __gitcomp "--stdin"
  2732. ;;
  2733. *)
  2734. ;;
  2735. esac
  2736. }
  2737. _git_stash ()
  2738. {
  2739. local save_opts='--all --keep-index --no-keep-index --quiet --patch --include-untracked'
  2740. local subcommands='push list show apply clear drop pop create branch'
  2741. local subcommand="$(__git_find_on_cmdline "$subcommands save")"
  2742. if [ -z "$subcommand" -a -n "$(__git_find_on_cmdline "-p")" ]; then
  2743. subcommand="push"
  2744. fi
  2745. if [ -z "$subcommand" ]; then
  2746. case "$cur" in
  2747. --*)
  2748. __gitcomp "$save_opts"
  2749. ;;
  2750. sa*)
  2751. if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
  2752. __gitcomp "save"
  2753. fi
  2754. ;;
  2755. *)
  2756. if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
  2757. __gitcomp "$subcommands"
  2758. fi
  2759. ;;
  2760. esac
  2761. else
  2762. case "$subcommand,$cur" in
  2763. push,--*)
  2764. __gitcomp "$save_opts --message"
  2765. ;;
  2766. save,--*)
  2767. __gitcomp "$save_opts"
  2768. ;;
  2769. apply,--*|pop,--*)
  2770. __gitcomp "--index --quiet"
  2771. ;;
  2772. drop,--*)
  2773. __gitcomp "--quiet"
  2774. ;;
  2775. list,--*)
  2776. __gitcomp "--name-status --oneline --patch-with-stat"
  2777. ;;
  2778. show,--*|branch,--*)
  2779. ;;
  2780. branch,*)
  2781. if [ $cword -eq 3 ]; then
  2782. __git_complete_refs
  2783. else
  2784. __gitcomp_nl "$(__git stash list \
  2785. | sed -n -e 's/:.*//p')"
  2786. fi
  2787. ;;
  2788. show,*|apply,*|drop,*|pop,*)
  2789. __gitcomp_nl "$(__git stash list \
  2790. | sed -n -e 's/:.*//p')"
  2791. ;;
  2792. *)
  2793. ;;
  2794. esac
  2795. fi
  2796. }
  2797. _git_submodule ()
  2798. {
  2799. __git_has_doubledash && return
  2800. local subcommands="add status init deinit update set-branch set-url summary foreach sync absorbgitdirs"
  2801. local subcommand="$(__git_find_on_cmdline "$subcommands")"
  2802. if [ -z "$subcommand" ]; then
  2803. case "$cur" in
  2804. --*)
  2805. __gitcomp "--quiet"
  2806. ;;
  2807. *)
  2808. __gitcomp "$subcommands"
  2809. ;;
  2810. esac
  2811. return
  2812. fi
  2813. case "$subcommand,$cur" in
  2814. add,--*)
  2815. __gitcomp "--branch --force --name --reference --depth"
  2816. ;;
  2817. status,--*)
  2818. __gitcomp "--cached --recursive"
  2819. ;;
  2820. deinit,--*)
  2821. __gitcomp "--force --all"
  2822. ;;
  2823. update,--*)
  2824. __gitcomp "
  2825. --init --remote --no-fetch
  2826. --recommend-shallow --no-recommend-shallow
  2827. --force --rebase --merge --reference --depth --recursive --jobs
  2828. "
  2829. ;;
  2830. set-branch,--*)
  2831. __gitcomp "--default --branch"
  2832. ;;
  2833. summary,--*)
  2834. __gitcomp "--cached --files --summary-limit"
  2835. ;;
  2836. foreach,--*|sync,--*)
  2837. __gitcomp "--recursive"
  2838. ;;
  2839. *)
  2840. ;;
  2841. esac
  2842. }
  2843. _git_svn ()
  2844. {
  2845. local subcommands="
  2846. init fetch clone rebase dcommit log find-rev
  2847. set-tree commit-diff info create-ignore propget
  2848. proplist show-ignore show-externals branch tag blame
  2849. migrate mkdirs reset gc
  2850. "
  2851. local subcommand="$(__git_find_on_cmdline "$subcommands")"
  2852. if [ -z "$subcommand" ]; then
  2853. __gitcomp "$subcommands"
  2854. else
  2855. local remote_opts="--username= --config-dir= --no-auth-cache"
  2856. local fc_opts="
  2857. --follow-parent --authors-file= --repack=
  2858. --no-metadata --use-svm-props --use-svnsync-props
  2859. --log-window-size= --no-checkout --quiet
  2860. --repack-flags --use-log-author --localtime
  2861. --add-author-from
  2862. --recursive
  2863. --ignore-paths= --include-paths= $remote_opts
  2864. "
  2865. local init_opts="
  2866. --template= --shared= --trunk= --tags=
  2867. --branches= --stdlayout --minimize-url
  2868. --no-metadata --use-svm-props --use-svnsync-props
  2869. --rewrite-root= --prefix= $remote_opts
  2870. "
  2871. local cmt_opts="
  2872. --edit --rmdir --find-copies-harder --copy-similarity=
  2873. "
  2874. case "$subcommand,$cur" in
  2875. fetch,--*)
  2876. __gitcomp "--revision= --fetch-all $fc_opts"
  2877. ;;
  2878. clone,--*)
  2879. __gitcomp "--revision= $fc_opts $init_opts"
  2880. ;;
  2881. init,--*)
  2882. __gitcomp "$init_opts"
  2883. ;;
  2884. dcommit,--*)
  2885. __gitcomp "
  2886. --merge --strategy= --verbose --dry-run
  2887. --fetch-all --no-rebase --commit-url
  2888. --revision --interactive $cmt_opts $fc_opts
  2889. "
  2890. ;;
  2891. set-tree,--*)
  2892. __gitcomp "--stdin $cmt_opts $fc_opts"
  2893. ;;
  2894. create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
  2895. show-externals,--*|mkdirs,--*)
  2896. __gitcomp "--revision="
  2897. ;;
  2898. log,--*)
  2899. __gitcomp "
  2900. --limit= --revision= --verbose --incremental
  2901. --oneline --show-commit --non-recursive
  2902. --authors-file= --color
  2903. "
  2904. ;;
  2905. rebase,--*)
  2906. __gitcomp "
  2907. --merge --verbose --strategy= --local
  2908. --fetch-all --dry-run $fc_opts
  2909. "
  2910. ;;
  2911. commit-diff,--*)
  2912. __gitcomp "--message= --file= --revision= $cmt_opts"
  2913. ;;
  2914. info,--*)
  2915. __gitcomp "--url"
  2916. ;;
  2917. branch,--*)
  2918. __gitcomp "--dry-run --message --tag"
  2919. ;;
  2920. tag,--*)
  2921. __gitcomp "--dry-run --message"
  2922. ;;
  2923. blame,--*)
  2924. __gitcomp "--git-format"
  2925. ;;
  2926. migrate,--*)
  2927. __gitcomp "
  2928. --config-dir= --ignore-paths= --minimize
  2929. --no-auth-cache --username=
  2930. "
  2931. ;;
  2932. reset,--*)
  2933. __gitcomp "--revision= --parent"
  2934. ;;
  2935. *)
  2936. ;;
  2937. esac
  2938. fi
  2939. }
  2940. _git_tag ()
  2941. {
  2942. local i c=1 f=0
  2943. while [ $c -lt $cword ]; do
  2944. i="${words[c]}"
  2945. case "$i" in
  2946. -d|--delete|-v|--verify)
  2947. __gitcomp_direct "$(__git_tags "" "$cur" " ")"
  2948. return
  2949. ;;
  2950. -f)
  2951. f=1
  2952. ;;
  2953. esac
  2954. ((c++))
  2955. done
  2956. case "$prev" in
  2957. -m|-F)
  2958. ;;
  2959. -*|tag)
  2960. if [ $f = 1 ]; then
  2961. __gitcomp_direct "$(__git_tags "" "$cur" " ")"
  2962. fi
  2963. ;;
  2964. *)
  2965. __git_complete_refs
  2966. ;;
  2967. esac
  2968. case "$cur" in
  2969. --*)
  2970. __gitcomp_builtin tag
  2971. ;;
  2972. esac
  2973. }
  2974. _git_whatchanged ()
  2975. {
  2976. _git_log
  2977. }
  2978. __git_complete_worktree_paths ()
  2979. {
  2980. local IFS=$'\n'
  2981. __gitcomp_nl "$(git worktree list --porcelain |
  2982. # Skip the first entry: it's the path of the main worktree,
  2983. # which can't be moved, removed, locked, etc.
  2984. sed -n -e '2,$ s/^worktree //p')"
  2985. }
  2986. _git_worktree ()
  2987. {
  2988. local subcommands="add list lock move prune remove unlock"
  2989. local subcommand subcommand_idx
  2990. subcommand="$(__git_find_on_cmdline --show-idx "$subcommands")"
  2991. subcommand_idx="${subcommand% *}"
  2992. subcommand="${subcommand#* }"
  2993. case "$subcommand,$cur" in
  2994. ,*)
  2995. __gitcomp "$subcommands"
  2996. ;;
  2997. *,--*)
  2998. __gitcomp_builtin worktree_$subcommand
  2999. ;;
  3000. add,*) # usage: git worktree add [<options>] <path> [<commit-ish>]
  3001. # Here we are not completing an --option, it's either the
  3002. # path or a ref.
  3003. case "$prev" in
  3004. -b|-B) # Complete refs for branch to be created/reseted.
  3005. __git_complete_refs
  3006. ;;
  3007. -*) # The previous word is an -o|--option without an
  3008. # unstuck argument: have to complete the path for
  3009. # the new worktree, so don't list anything, but let
  3010. # Bash fall back to filename completion.
  3011. ;;
  3012. *) # The previous word is not an --option, so it must
  3013. # be either the 'add' subcommand, the unstuck
  3014. # argument of an option (e.g. branch for -b|-B), or
  3015. # the path for the new worktree.
  3016. if [ $cword -eq $((subcommand_idx+1)) ]; then
  3017. # Right after the 'add' subcommand: have to
  3018. # complete the path, so fall back to Bash
  3019. # filename completion.
  3020. :
  3021. else
  3022. case "${words[cword-2]}" in
  3023. -b|-B) # After '-b <branch>': have to
  3024. # complete the path, so fall back
  3025. # to Bash filename completion.
  3026. ;;
  3027. *) # After the path: have to complete
  3028. # the ref to be checked out.
  3029. __git_complete_refs
  3030. ;;
  3031. esac
  3032. fi
  3033. ;;
  3034. esac
  3035. ;;
  3036. lock,*|remove,*|unlock,*)
  3037. __git_complete_worktree_paths
  3038. ;;
  3039. move,*)
  3040. if [ $cword -eq $((subcommand_idx+1)) ]; then
  3041. # The first parameter must be an existing working
  3042. # tree to be moved.
  3043. __git_complete_worktree_paths
  3044. else
  3045. # The second parameter is the destination: it could
  3046. # be any path, so don't list anything, but let Bash
  3047. # fall back to filename completion.
  3048. :
  3049. fi
  3050. ;;
  3051. esac
  3052. }
  3053. __git_complete_common () {
  3054. local command="$1"
  3055. case "$cur" in
  3056. --*)
  3057. __gitcomp_builtin "$command"
  3058. ;;
  3059. esac
  3060. }
  3061. __git_cmds_with_parseopt_helper=
  3062. __git_support_parseopt_helper () {
  3063. test -n "$__git_cmds_with_parseopt_helper" ||
  3064. __git_cmds_with_parseopt_helper="$(__git --list-cmds=parseopt)"
  3065. case " $__git_cmds_with_parseopt_helper " in
  3066. *" $1 "*)
  3067. return 0
  3068. ;;
  3069. *)
  3070. return 1
  3071. ;;
  3072. esac
  3073. }
  3074. __git_complete_command () {
  3075. local command="$1"
  3076. local completion_func="_git_${command//-/_}"
  3077. if ! declare -f $completion_func >/dev/null 2>/dev/null &&
  3078. declare -f _completion_loader >/dev/null 2>/dev/null
  3079. then
  3080. _completion_loader "git-$command"
  3081. fi
  3082. if declare -f $completion_func >/dev/null 2>/dev/null
  3083. then
  3084. $completion_func
  3085. return 0
  3086. elif __git_support_parseopt_helper "$command"
  3087. then
  3088. __git_complete_common "$command"
  3089. return 0
  3090. else
  3091. return 1
  3092. fi
  3093. }
  3094. __git_main ()
  3095. {
  3096. local i c=1 command __git_dir __git_repo_path
  3097. local __git_C_args C_args_count=0
  3098. while [ $c -lt $cword ]; do
  3099. i="${words[c]}"
  3100. case "$i" in
  3101. --git-dir=*) __git_dir="${i#--git-dir=}" ;;
  3102. --git-dir) ((c++)) ; __git_dir="${words[c]}" ;;
  3103. --bare) __git_dir="." ;;
  3104. --help) command="help"; break ;;
  3105. -c|--work-tree|--namespace) ((c++)) ;;
  3106. -C) __git_C_args[C_args_count++]=-C
  3107. ((c++))
  3108. __git_C_args[C_args_count++]="${words[c]}"
  3109. ;;
  3110. -*) ;;
  3111. *) command="$i"; break ;;
  3112. esac
  3113. ((c++))
  3114. done
  3115. if [ -z "${command-}" ]; then
  3116. case "$prev" in
  3117. --git-dir|-C|--work-tree)
  3118. # these need a path argument, let's fall back to
  3119. # Bash filename completion
  3120. return
  3121. ;;
  3122. -c)
  3123. __git_complete_config_variable_name_and_value
  3124. return
  3125. ;;
  3126. --namespace)
  3127. # we don't support completing these options' arguments
  3128. return
  3129. ;;
  3130. esac
  3131. case "$cur" in
  3132. --*) __gitcomp "
  3133. --paginate
  3134. --no-pager
  3135. --git-dir=
  3136. --bare
  3137. --version
  3138. --exec-path
  3139. --exec-path=
  3140. --html-path
  3141. --man-path
  3142. --info-path
  3143. --work-tree=
  3144. --namespace=
  3145. --no-replace-objects
  3146. --help
  3147. "
  3148. ;;
  3149. *)
  3150. if test -n "${GIT_TESTING_PORCELAIN_COMMAND_LIST-}"
  3151. then
  3152. __gitcomp "$GIT_TESTING_PORCELAIN_COMMAND_LIST"
  3153. else
  3154. __gitcomp "$(__git --list-cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config)"
  3155. fi
  3156. ;;
  3157. esac
  3158. return
  3159. fi
  3160. __git_complete_command "$command" && return
  3161. local expansion=$(__git_aliased_command "$command")
  3162. if [ -n "$expansion" ]; then
  3163. words[1]=$expansion
  3164. __git_complete_command "$expansion"
  3165. fi
  3166. }
  3167. __gitk_main ()
  3168. {
  3169. __git_has_doubledash && return
  3170. local __git_repo_path
  3171. __git_find_repo_path
  3172. local merge=""
  3173. if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
  3174. merge="--merge"
  3175. fi
  3176. case "$cur" in
  3177. --*)
  3178. __gitcomp "
  3179. $__git_log_common_options
  3180. $__git_log_gitk_options
  3181. $merge
  3182. "
  3183. return
  3184. ;;
  3185. esac
  3186. __git_complete_revlist
  3187. }
  3188. if [[ -n ${ZSH_VERSION-} ]] &&
  3189. # Don't define these functions when sourced from 'git-completion.zsh',
  3190. # it has its own implementations.
  3191. [[ -z ${GIT_SOURCING_ZSH_COMPLETION-} ]]; then
  3192. echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
  3193. autoload -U +X compinit && compinit
  3194. __gitcomp ()
  3195. {
  3196. emulate -L zsh
  3197. local cur_="${3-$cur}"
  3198. case "$cur_" in
  3199. --*=)
  3200. ;;
  3201. *)
  3202. local c IFS=$' \t\n'
  3203. local -a array
  3204. for c in ${=1}; do
  3205. c="$c${4-}"
  3206. case $c in
  3207. --*=*|*.) ;;
  3208. *) c="$c " ;;
  3209. esac
  3210. array[${#array[@]}+1]="$c"
  3211. done
  3212. compset -P '*[=:]'
  3213. compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
  3214. ;;
  3215. esac
  3216. }
  3217. __gitcomp_direct ()
  3218. {
  3219. emulate -L zsh
  3220. local IFS=$'\n'
  3221. compset -P '*[=:]'
  3222. compadd -Q -- ${=1} && _ret=0
  3223. }
  3224. __gitcomp_nl ()
  3225. {
  3226. emulate -L zsh
  3227. local IFS=$'\n'
  3228. compset -P '*[=:]'
  3229. compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
  3230. }
  3231. __gitcomp_file_direct ()
  3232. {
  3233. emulate -L zsh
  3234. local IFS=$'\n'
  3235. compset -P '*[=:]'
  3236. compadd -f -- ${=1} && _ret=0
  3237. }
  3238. __gitcomp_file ()
  3239. {
  3240. emulate -L zsh
  3241. local IFS=$'\n'
  3242. compset -P '*[=:]'
  3243. compadd -p "${2-}" -f -- ${=1} && _ret=0
  3244. }
  3245. _git ()
  3246. {
  3247. local _ret=1 cur cword prev
  3248. cur=${words[CURRENT]}
  3249. prev=${words[CURRENT-1]}
  3250. let cword=CURRENT-1
  3251. emulate ksh -c __${service}_main
  3252. let _ret && _default && _ret=0
  3253. return _ret
  3254. }
  3255. compdef _git git gitk
  3256. return
  3257. fi
  3258. __git_func_wrap ()
  3259. {
  3260. local cur words cword prev
  3261. _get_comp_words_by_ref -n =: cur words cword prev
  3262. $1
  3263. }
  3264. # Setup completion for certain functions defined above by setting common
  3265. # variables and workarounds.
  3266. # This is NOT a public function; use at your own risk.
  3267. __git_complete ()
  3268. {
  3269. local wrapper="__git_wrap${2}"
  3270. eval "$wrapper () { __git_func_wrap $2 ; }"
  3271. complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
  3272. || complete -o default -o nospace -F $wrapper $1
  3273. }
  3274. # wrapper for backwards compatibility
  3275. _git ()
  3276. {
  3277. __git_wrap__git_main
  3278. }
  3279. # wrapper for backwards compatibility
  3280. _gitk ()
  3281. {
  3282. __git_wrap__gitk_main
  3283. }
  3284. __git_complete git __git_main
  3285. __git_complete gitk __gitk_main
  3286. # The following are necessary only for Cygwin, and only are needed
  3287. # when the user has tab-completed the executable name and consequently
  3288. # included the '.exe' suffix.
  3289. #
  3290. if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
  3291. __git_complete git.exe __git_main
  3292. fi