git-completion.bash 69 KB

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