git-completion.bash 80 KB

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