git-completion.bash 65 KB

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