git-completion.bash 114 KB

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