git-completion.bash 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320
  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, see <http://www.gnu.org/licenses/>.
  109. #
  110. # The latest version of this software can be obtained here:
  111. #
  112. # http://bash-completion.alioth.debian.org/
  113. #
  114. # RELEASE: 2.x
  115. # This function can be used to access a tokenized list of words
  116. # on the command line:
  117. #
  118. # __git_reassemble_comp_words_by_ref '=:'
  119. # if test "${words_[cword_-1]}" = -w
  120. # then
  121. # ...
  122. # fi
  123. #
  124. # The argument should be a collection of characters from the list of
  125. # word completion separators (COMP_WORDBREAKS) to treat as ordinary
  126. # characters.
  127. #
  128. # This is roughly equivalent to going back in time and setting
  129. # COMP_WORDBREAKS to exclude those characters. The intent is to
  130. # make option types like --date=<type> and <rev>:<path> easy to
  131. # recognize by treating each shell word as a single token.
  132. #
  133. # It is best not to set COMP_WORDBREAKS directly because the value is
  134. # shared with other completion scripts. By the time the completion
  135. # function gets called, COMP_WORDS has already been populated so local
  136. # changes to COMP_WORDBREAKS have no effect.
  137. #
  138. # Output: words_, cword_, cur_.
  139. __git_reassemble_comp_words_by_ref()
  140. {
  141. local exclude i j first
  142. # Which word separators to exclude?
  143. exclude="${1//[^$COMP_WORDBREAKS]}"
  144. cword_=$COMP_CWORD
  145. if [ -z "$exclude" ]; then
  146. words_=("${COMP_WORDS[@]}")
  147. return
  148. fi
  149. # List of word completion separators has shrunk;
  150. # re-assemble words to complete.
  151. for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
  152. # Append each nonempty word consisting of just
  153. # word separator characters to the current word.
  154. first=t
  155. while
  156. [ $i -gt 0 ] &&
  157. [ -n "${COMP_WORDS[$i]}" ] &&
  158. # word consists of excluded word separators
  159. [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
  160. do
  161. # Attach to the previous token,
  162. # unless the previous token is the command name.
  163. if [ $j -ge 2 ] && [ -n "$first" ]; then
  164. ((j--))
  165. fi
  166. first=
  167. words_[$j]=${words_[j]}${COMP_WORDS[i]}
  168. if [ $i = $COMP_CWORD ]; then
  169. cword_=$j
  170. fi
  171. if (($i < ${#COMP_WORDS[@]} - 1)); then
  172. ((i++))
  173. else
  174. # Done.
  175. return
  176. fi
  177. done
  178. words_[$j]=${words_[j]}${COMP_WORDS[i]}
  179. if [ $i = $COMP_CWORD ]; then
  180. cword_=$j
  181. fi
  182. done
  183. }
  184. if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
  185. _get_comp_words_by_ref ()
  186. {
  187. local exclude cur_ words_ cword_
  188. if [ "$1" = "-n" ]; then
  189. exclude=$2
  190. shift 2
  191. fi
  192. __git_reassemble_comp_words_by_ref "$exclude"
  193. cur_=${words_[cword_]}
  194. while [ $# -gt 0 ]; do
  195. case "$1" in
  196. cur)
  197. cur=$cur_
  198. ;;
  199. prev)
  200. prev=${words_[$cword_-1]}
  201. ;;
  202. words)
  203. words=("${words_[@]}")
  204. ;;
  205. cword)
  206. cword=$cword_
  207. ;;
  208. esac
  209. shift
  210. done
  211. }
  212. fi
  213. # Fills the COMPREPLY array with prefiltered words without any additional
  214. # processing.
  215. # Callers must take care of providing only words that match the current word
  216. # to be completed and adding any prefix and/or suffix (trailing space!), if
  217. # necessary.
  218. # 1: List of newline-separated matching completion words, complete with
  219. # prefix and suffix.
  220. __gitcomp_direct ()
  221. {
  222. local IFS=$'\n'
  223. COMPREPLY=($1)
  224. }
  225. __gitcompappend ()
  226. {
  227. local x i=${#COMPREPLY[@]}
  228. for x in $1; do
  229. if [[ "$x" == "$3"* ]]; then
  230. COMPREPLY[i++]="$2$x$4"
  231. fi
  232. done
  233. }
  234. __gitcompadd ()
  235. {
  236. COMPREPLY=()
  237. __gitcompappend "$@"
  238. }
  239. # Generates completion reply, appending a space to possible completion words,
  240. # if necessary.
  241. # It accepts 1 to 4 arguments:
  242. # 1: List of possible completion words.
  243. # 2: A prefix to be added to each possible completion word (optional).
  244. # 3: Generate possible completion matches for this word (optional).
  245. # 4: A suffix to be appended to each possible completion word (optional).
  246. __gitcomp ()
  247. {
  248. local cur_="${3-$cur}"
  249. case "$cur_" in
  250. --*=)
  251. ;;
  252. *)
  253. local c i=0 IFS=$' \t\n'
  254. for c in $1; do
  255. c="$c${4-}"
  256. if [[ $c == "$cur_"* ]]; then
  257. case $c in
  258. --*=*|*.) ;;
  259. *) c="$c " ;;
  260. esac
  261. COMPREPLY[i++]="${2-}$c"
  262. fi
  263. done
  264. ;;
  265. esac
  266. }
  267. # Variation of __gitcomp_nl () that appends to the existing list of
  268. # completion candidates, COMPREPLY.
  269. __gitcomp_nl_append ()
  270. {
  271. local IFS=$'\n'
  272. __gitcompappend "$1" "${2-}" "${3-$cur}" "${4- }"
  273. }
  274. # Generates completion reply from newline-separated possible completion words
  275. # by appending a space to all of them.
  276. # It accepts 1 to 4 arguments:
  277. # 1: List of possible completion words, separated by a single newline.
  278. # 2: A prefix to be added to each possible completion word (optional).
  279. # 3: Generate possible completion matches for this word (optional).
  280. # 4: A suffix to be appended to each possible completion word instead of
  281. # the default space (optional). If specified but empty, nothing is
  282. # appended.
  283. __gitcomp_nl ()
  284. {
  285. COMPREPLY=()
  286. __gitcomp_nl_append "$@"
  287. }
  288. # Generates completion reply with compgen from newline-separated possible
  289. # completion filenames.
  290. # It accepts 1 to 3 arguments:
  291. # 1: List of possible completion filenames, separated by a single newline.
  292. # 2: A directory prefix to be added to each possible completion filename
  293. # (optional).
  294. # 3: Generate possible completion matches for this word (optional).
  295. __gitcomp_file ()
  296. {
  297. local IFS=$'\n'
  298. # XXX does not work when the directory prefix contains a tilde,
  299. # since tilde expansion is not applied.
  300. # This means that COMPREPLY will be empty and Bash default
  301. # completion will be used.
  302. __gitcompadd "$1" "${2-}" "${3-$cur}" ""
  303. # use a hack to enable file mode in bash < 4
  304. compopt -o filenames +o nospace 2>/dev/null ||
  305. compgen -f /non-existing-dir/ > /dev/null
  306. }
  307. # Execute 'git ls-files', unless the --committable option is specified, in
  308. # which case it runs 'git diff-index' to find out the files that can be
  309. # committed. It return paths relative to the directory specified in the first
  310. # argument, and using the options specified in the second argument.
  311. __git_ls_files_helper ()
  312. {
  313. if [ "$2" == "--committable" ]; then
  314. __git -C "$1" diff-index --name-only --relative HEAD
  315. else
  316. # NOTE: $2 is not quoted in order to support multiple options
  317. __git -C "$1" ls-files --exclude-standard $2
  318. fi
  319. }
  320. # __git_index_files accepts 1 or 2 arguments:
  321. # 1: Options to pass to ls-files (required).
  322. # 2: A directory path (optional).
  323. # If provided, only files within the specified directory are listed.
  324. # Sub directories are never recursed. Path must have a trailing
  325. # slash.
  326. __git_index_files ()
  327. {
  328. local root="${2-.}" file
  329. __git_ls_files_helper "$root" "$1" |
  330. while read -r file; do
  331. case "$file" in
  332. ?*/*) echo "${file%%/*}" ;;
  333. *) echo "$file" ;;
  334. esac
  335. done | sort | uniq
  336. }
  337. # Lists branches from the local repository.
  338. # 1: A prefix to be added to each listed branch (optional).
  339. # 2: List only branches matching this word (optional; list all branches if
  340. # unset or empty).
  341. # 3: A suffix to be appended to each listed branch (optional).
  342. __git_heads ()
  343. {
  344. local pfx="${1-}" cur_="${2-}" sfx="${3-}"
  345. __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
  346. "refs/heads/$cur_*" "refs/heads/$cur_*/**"
  347. }
  348. # Lists tags from the local repository.
  349. # Accepts the same positional parameters as __git_heads() above.
  350. __git_tags ()
  351. {
  352. local pfx="${1-}" cur_="${2-}" sfx="${3-}"
  353. __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
  354. "refs/tags/$cur_*" "refs/tags/$cur_*/**"
  355. }
  356. # Lists refs from the local (by default) or from a remote repository.
  357. # It accepts 0, 1 or 2 arguments:
  358. # 1: The remote to list refs from (optional; ignored, if set but empty).
  359. # Can be the name of a configured remote, a path, or a URL.
  360. # 2: In addition to local refs, list unique branches from refs/remotes/ for
  361. # 'git checkout's tracking DWIMery (optional; ignored, if set but empty).
  362. # 3: A prefix to be added to each listed ref (optional).
  363. # 4: List only refs matching this word (optional; list all refs if unset or
  364. # empty).
  365. # 5: A suffix to be appended to each listed ref (optional; ignored, if set
  366. # but empty).
  367. #
  368. # Use __git_complete_refs() instead.
  369. __git_refs ()
  370. {
  371. local i hash dir track="${2-}"
  372. local list_refs_from=path remote="${1-}"
  373. local format refs
  374. local pfx="${3-}" cur_="${4-$cur}" sfx="${5-}"
  375. local match="${4-}"
  376. local fer_pfx="${pfx//\%/%%}" # "escape" for-each-ref format specifiers
  377. __git_find_repo_path
  378. dir="$__git_repo_path"
  379. if [ -z "$remote" ]; then
  380. if [ -z "$dir" ]; then
  381. return
  382. fi
  383. else
  384. if __git_is_configured_remote "$remote"; then
  385. # configured remote takes precedence over a
  386. # local directory with the same name
  387. list_refs_from=remote
  388. elif [ -d "$remote/.git" ]; then
  389. dir="$remote/.git"
  390. elif [ -d "$remote" ]; then
  391. dir="$remote"
  392. else
  393. list_refs_from=url
  394. fi
  395. fi
  396. if [ "$list_refs_from" = path ]; then
  397. if [[ "$cur_" == ^* ]]; then
  398. pfx="$pfx^"
  399. fer_pfx="$fer_pfx^"
  400. cur_=${cur_#^}
  401. match=${match#^}
  402. fi
  403. case "$cur_" in
  404. refs|refs/*)
  405. format="refname"
  406. refs=("$match*" "$match*/**")
  407. track=""
  408. ;;
  409. *)
  410. for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
  411. case "$i" in
  412. $match*)
  413. if [ -e "$dir/$i" ]; then
  414. echo "$pfx$i$sfx"
  415. fi
  416. ;;
  417. esac
  418. done
  419. format="refname:strip=2"
  420. refs=("refs/tags/$match*" "refs/tags/$match*/**"
  421. "refs/heads/$match*" "refs/heads/$match*/**"
  422. "refs/remotes/$match*" "refs/remotes/$match*/**")
  423. ;;
  424. esac
  425. __git_dir="$dir" __git for-each-ref --format="$fer_pfx%($format)$sfx" \
  426. "${refs[@]}"
  427. if [ -n "$track" ]; then
  428. # employ the heuristic used by git checkout
  429. # Try to find a remote branch that matches the completion word
  430. # but only output if the branch name is unique
  431. __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
  432. --sort="refname:strip=3" \
  433. "refs/remotes/*/$match*" "refs/remotes/*/$match*/**" | \
  434. uniq -u
  435. fi
  436. return
  437. fi
  438. case "$cur_" in
  439. refs|refs/*)
  440. __git ls-remote "$remote" "$match*" | \
  441. while read -r hash i; do
  442. case "$i" in
  443. *^{}) ;;
  444. *) echo "$pfx$i$sfx" ;;
  445. esac
  446. done
  447. ;;
  448. *)
  449. if [ "$list_refs_from" = remote ]; then
  450. case "HEAD" in
  451. $match*) echo "${pfx}HEAD$sfx" ;;
  452. esac
  453. __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
  454. "refs/remotes/$remote/$match*" \
  455. "refs/remotes/$remote/$match*/**"
  456. else
  457. local query_symref
  458. case "HEAD" in
  459. $match*) query_symref="HEAD" ;;
  460. esac
  461. __git ls-remote "$remote" $query_symref \
  462. "refs/tags/$match*" "refs/heads/$match*" \
  463. "refs/remotes/$match*" |
  464. while read -r hash i; do
  465. case "$i" in
  466. *^{}) ;;
  467. refs/*) echo "$pfx${i#refs/*/}$sfx" ;;
  468. *) echo "$pfx$i$sfx" ;; # symbolic refs
  469. esac
  470. done
  471. fi
  472. ;;
  473. esac
  474. }
  475. # Completes refs, short and long, local and remote, symbolic and pseudo.
  476. #
  477. # Usage: __git_complete_refs [<option>]...
  478. # --remote=<remote>: The remote to list refs from, can be the name of a
  479. # configured remote, a path, or a URL.
  480. # --track: List unique remote branches for 'git checkout's tracking DWIMery.
  481. # --pfx=<prefix>: A prefix to be added to each ref.
  482. # --cur=<word>: The current ref to be completed. Defaults to the current
  483. # word to be completed.
  484. # --sfx=<suffix>: A suffix to be appended to each ref instead of the default
  485. # space.
  486. __git_complete_refs ()
  487. {
  488. local remote track pfx cur_="$cur" sfx=" "
  489. while test $# != 0; do
  490. case "$1" in
  491. --remote=*) remote="${1##--remote=}" ;;
  492. --track) track="yes" ;;
  493. --pfx=*) pfx="${1##--pfx=}" ;;
  494. --cur=*) cur_="${1##--cur=}" ;;
  495. --sfx=*) sfx="${1##--sfx=}" ;;
  496. *) return 1 ;;
  497. esac
  498. shift
  499. done
  500. __gitcomp_direct "$(__git_refs "$remote" "$track" "$pfx" "$cur_" "$sfx")"
  501. }
  502. # __git_refs2 requires 1 argument (to pass to __git_refs)
  503. # Deprecated: use __git_complete_fetch_refspecs() instead.
  504. __git_refs2 ()
  505. {
  506. local i
  507. for i in $(__git_refs "$1"); do
  508. echo "$i:$i"
  509. done
  510. }
  511. # Completes refspecs for fetching from a remote repository.
  512. # 1: The remote repository.
  513. # 2: A prefix to be added to each listed refspec (optional).
  514. # 3: The ref to be completed as a refspec instead of the current word to be
  515. # completed (optional)
  516. # 4: A suffix to be appended to each listed refspec instead of the default
  517. # space (optional).
  518. __git_complete_fetch_refspecs ()
  519. {
  520. local i remote="$1" pfx="${2-}" cur_="${3-$cur}" sfx="${4- }"
  521. __gitcomp_direct "$(
  522. for i in $(__git_refs "$remote" "" "" "$cur_") ; do
  523. echo "$pfx$i:$i$sfx"
  524. done
  525. )"
  526. }
  527. # __git_refs_remotes requires 1 argument (to pass to ls-remote)
  528. __git_refs_remotes ()
  529. {
  530. local i hash
  531. __git ls-remote "$1" 'refs/heads/*' | \
  532. while read -r hash i; do
  533. echo "$i:refs/remotes/$1/${i#refs/heads/}"
  534. done
  535. }
  536. __git_remotes ()
  537. {
  538. __git_find_repo_path
  539. test -d "$__git_repo_path/remotes" && ls -1 "$__git_repo_path/remotes"
  540. __git remote
  541. }
  542. # Returns true if $1 matches the name of a configured remote, false otherwise.
  543. __git_is_configured_remote ()
  544. {
  545. local remote
  546. for remote in $(__git_remotes); do
  547. if [ "$remote" = "$1" ]; then
  548. return 0
  549. fi
  550. done
  551. return 1
  552. }
  553. __git_list_merge_strategies ()
  554. {
  555. git merge -s help 2>&1 |
  556. sed -n -e '/[Aa]vailable strategies are: /,/^$/{
  557. s/\.$//
  558. s/.*://
  559. s/^[ ]*//
  560. s/[ ]*$//
  561. p
  562. }'
  563. }
  564. __git_merge_strategies=
  565. # 'git merge -s help' (and thus detection of the merge strategy
  566. # list) fails, unfortunately, if run outside of any git working
  567. # tree. __git_merge_strategies is set to the empty string in
  568. # that case, and the detection will be repeated the next time it
  569. # is needed.
  570. __git_compute_merge_strategies ()
  571. {
  572. test -n "$__git_merge_strategies" ||
  573. __git_merge_strategies=$(__git_list_merge_strategies)
  574. }
  575. __git_complete_revlist_file ()
  576. {
  577. local pfx ls ref cur_="$cur"
  578. case "$cur_" in
  579. *..?*:*)
  580. return
  581. ;;
  582. ?*:*)
  583. ref="${cur_%%:*}"
  584. cur_="${cur_#*:}"
  585. case "$cur_" in
  586. ?*/*)
  587. pfx="${cur_%/*}"
  588. cur_="${cur_##*/}"
  589. ls="$ref:$pfx"
  590. pfx="$pfx/"
  591. ;;
  592. *)
  593. ls="$ref"
  594. ;;
  595. esac
  596. case "$COMP_WORDBREAKS" in
  597. *:*) : great ;;
  598. *) pfx="$ref:$pfx" ;;
  599. esac
  600. __gitcomp_nl "$(__git ls-tree "$ls" \
  601. | sed '/^100... blob /{
  602. s,^.* ,,
  603. s,$, ,
  604. }
  605. /^120000 blob /{
  606. s,^.* ,,
  607. s,$, ,
  608. }
  609. /^040000 tree /{
  610. s,^.* ,,
  611. s,$,/,
  612. }
  613. s/^.* //')" \
  614. "$pfx" "$cur_" ""
  615. ;;
  616. *...*)
  617. pfx="${cur_%...*}..."
  618. cur_="${cur_#*...}"
  619. __git_complete_refs --pfx="$pfx" --cur="$cur_"
  620. ;;
  621. *..*)
  622. pfx="${cur_%..*}.."
  623. cur_="${cur_#*..}"
  624. __git_complete_refs --pfx="$pfx" --cur="$cur_"
  625. ;;
  626. *)
  627. __git_complete_refs
  628. ;;
  629. esac
  630. }
  631. # __git_complete_index_file requires 1 argument:
  632. # 1: the options to pass to ls-file
  633. #
  634. # The exception is --committable, which finds the files appropriate commit.
  635. __git_complete_index_file ()
  636. {
  637. local pfx="" cur_="$cur"
  638. case "$cur_" in
  639. ?*/*)
  640. pfx="${cur_%/*}"
  641. cur_="${cur_##*/}"
  642. pfx="${pfx}/"
  643. ;;
  644. esac
  645. __gitcomp_file "$(__git_index_files "$1" ${pfx:+"$pfx"})" "$pfx" "$cur_"
  646. }
  647. __git_complete_file ()
  648. {
  649. __git_complete_revlist_file
  650. }
  651. __git_complete_revlist ()
  652. {
  653. __git_complete_revlist_file
  654. }
  655. __git_complete_remote_or_refspec ()
  656. {
  657. local cur_="$cur" cmd="${words[1]}"
  658. local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
  659. if [ "$cmd" = "remote" ]; then
  660. ((c++))
  661. fi
  662. while [ $c -lt $cword ]; do
  663. i="${words[c]}"
  664. case "$i" in
  665. --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
  666. -d|--delete) [ "$cmd" = "push" ] && lhs=0 ;;
  667. --all)
  668. case "$cmd" in
  669. push) no_complete_refspec=1 ;;
  670. fetch)
  671. return
  672. ;;
  673. *) ;;
  674. esac
  675. ;;
  676. -*) ;;
  677. *) remote="$i"; break ;;
  678. esac
  679. ((c++))
  680. done
  681. if [ -z "$remote" ]; then
  682. __gitcomp_nl "$(__git_remotes)"
  683. return
  684. fi
  685. if [ $no_complete_refspec = 1 ]; then
  686. return
  687. fi
  688. [ "$remote" = "." ] && remote=
  689. case "$cur_" in
  690. *:*)
  691. case "$COMP_WORDBREAKS" in
  692. *:*) : great ;;
  693. *) pfx="${cur_%%:*}:" ;;
  694. esac
  695. cur_="${cur_#*:}"
  696. lhs=0
  697. ;;
  698. +*)
  699. pfx="+"
  700. cur_="${cur_#+}"
  701. ;;
  702. esac
  703. case "$cmd" in
  704. fetch)
  705. if [ $lhs = 1 ]; then
  706. __git_complete_fetch_refspecs "$remote" "$pfx" "$cur_"
  707. else
  708. __git_complete_refs --pfx="$pfx" --cur="$cur_"
  709. fi
  710. ;;
  711. pull|remote)
  712. if [ $lhs = 1 ]; then
  713. __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
  714. else
  715. __git_complete_refs --pfx="$pfx" --cur="$cur_"
  716. fi
  717. ;;
  718. push)
  719. if [ $lhs = 1 ]; then
  720. __git_complete_refs --pfx="$pfx" --cur="$cur_"
  721. else
  722. __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
  723. fi
  724. ;;
  725. esac
  726. }
  727. __git_complete_strategy ()
  728. {
  729. __git_compute_merge_strategies
  730. case "$prev" in
  731. -s|--strategy)
  732. __gitcomp "$__git_merge_strategies"
  733. return 0
  734. esac
  735. case "$cur" in
  736. --strategy=*)
  737. __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
  738. return 0
  739. ;;
  740. esac
  741. return 1
  742. }
  743. __git_commands () {
  744. if test -n "${GIT_TESTING_COMMAND_COMPLETION:-}"
  745. then
  746. printf "%s" "${GIT_TESTING_COMMAND_COMPLETION}"
  747. else
  748. git help -a|egrep '^ [a-zA-Z0-9]'
  749. fi
  750. }
  751. __git_list_all_commands ()
  752. {
  753. local i IFS=" "$'\n'
  754. for i in $(__git_commands)
  755. do
  756. case $i in
  757. *--*) : helper pattern;;
  758. *) echo $i;;
  759. esac
  760. done
  761. }
  762. __git_all_commands=
  763. __git_compute_all_commands ()
  764. {
  765. test -n "$__git_all_commands" ||
  766. __git_all_commands=$(__git_list_all_commands)
  767. }
  768. __git_list_porcelain_commands ()
  769. {
  770. local i IFS=" "$'\n'
  771. __git_compute_all_commands
  772. for i in $__git_all_commands
  773. do
  774. case $i in
  775. *--*) : helper pattern;;
  776. applymbox) : ask gittus;;
  777. applypatch) : ask gittus;;
  778. archimport) : import;;
  779. cat-file) : plumbing;;
  780. check-attr) : plumbing;;
  781. check-ignore) : plumbing;;
  782. check-mailmap) : plumbing;;
  783. check-ref-format) : plumbing;;
  784. checkout-index) : plumbing;;
  785. column) : internal helper;;
  786. commit-tree) : plumbing;;
  787. count-objects) : infrequent;;
  788. credential) : credentials;;
  789. credential-*) : credentials helper;;
  790. cvsexportcommit) : export;;
  791. cvsimport) : import;;
  792. cvsserver) : daemon;;
  793. daemon) : daemon;;
  794. diff-files) : plumbing;;
  795. diff-index) : plumbing;;
  796. diff-tree) : plumbing;;
  797. fast-import) : import;;
  798. fast-export) : export;;
  799. fsck-objects) : plumbing;;
  800. fetch-pack) : plumbing;;
  801. fmt-merge-msg) : plumbing;;
  802. for-each-ref) : plumbing;;
  803. hash-object) : plumbing;;
  804. http-*) : transport;;
  805. index-pack) : plumbing;;
  806. init-db) : deprecated;;
  807. local-fetch) : plumbing;;
  808. ls-files) : plumbing;;
  809. ls-remote) : plumbing;;
  810. ls-tree) : plumbing;;
  811. mailinfo) : plumbing;;
  812. mailsplit) : plumbing;;
  813. merge-*) : plumbing;;
  814. mktree) : plumbing;;
  815. mktag) : plumbing;;
  816. pack-objects) : plumbing;;
  817. pack-redundant) : plumbing;;
  818. pack-refs) : plumbing;;
  819. parse-remote) : plumbing;;
  820. patch-id) : plumbing;;
  821. prune) : plumbing;;
  822. prune-packed) : plumbing;;
  823. quiltimport) : import;;
  824. read-tree) : plumbing;;
  825. receive-pack) : plumbing;;
  826. remote-*) : transport;;
  827. rerere) : plumbing;;
  828. rev-list) : plumbing;;
  829. rev-parse) : plumbing;;
  830. runstatus) : plumbing;;
  831. sh-setup) : internal;;
  832. shell) : daemon;;
  833. show-ref) : plumbing;;
  834. send-pack) : plumbing;;
  835. show-index) : plumbing;;
  836. ssh-*) : transport;;
  837. stripspace) : plumbing;;
  838. symbolic-ref) : plumbing;;
  839. unpack-file) : plumbing;;
  840. unpack-objects) : plumbing;;
  841. update-index) : plumbing;;
  842. update-ref) : plumbing;;
  843. update-server-info) : daemon;;
  844. upload-archive) : plumbing;;
  845. upload-pack) : plumbing;;
  846. write-tree) : plumbing;;
  847. var) : infrequent;;
  848. verify-pack) : infrequent;;
  849. verify-tag) : plumbing;;
  850. *) echo $i;;
  851. esac
  852. done
  853. }
  854. __git_porcelain_commands=
  855. __git_compute_porcelain_commands ()
  856. {
  857. test -n "$__git_porcelain_commands" ||
  858. __git_porcelain_commands=$(__git_list_porcelain_commands)
  859. }
  860. # Lists all set config variables starting with the given section prefix,
  861. # with the prefix removed.
  862. __git_get_config_variables ()
  863. {
  864. local section="$1" i IFS=$'\n'
  865. for i in $(__git config --name-only --get-regexp "^$section\..*"); do
  866. echo "${i#$section.}"
  867. done
  868. }
  869. __git_pretty_aliases ()
  870. {
  871. __git_get_config_variables "pretty"
  872. }
  873. __git_aliases ()
  874. {
  875. __git_get_config_variables "alias"
  876. }
  877. # __git_aliased_command requires 1 argument
  878. __git_aliased_command ()
  879. {
  880. local word cmdline=$(__git config --get "alias.$1")
  881. for word in $cmdline; do
  882. case "$word" in
  883. \!gitk|gitk)
  884. echo "gitk"
  885. return
  886. ;;
  887. \!*) : shell command alias ;;
  888. -*) : option ;;
  889. *=*) : setting env ;;
  890. git) : git itself ;;
  891. \(\)) : skip parens of shell function definition ;;
  892. {) : skip start of shell helper function ;;
  893. :) : skip null command ;;
  894. \'*) : skip opening quote after sh -c ;;
  895. *)
  896. echo "$word"
  897. return
  898. esac
  899. done
  900. }
  901. # __git_find_on_cmdline requires 1 argument
  902. __git_find_on_cmdline ()
  903. {
  904. local word subcommand c=1
  905. while [ $c -lt $cword ]; do
  906. word="${words[c]}"
  907. for subcommand in $1; do
  908. if [ "$subcommand" = "$word" ]; then
  909. echo "$subcommand"
  910. return
  911. fi
  912. done
  913. ((c++))
  914. done
  915. }
  916. # Echo the value of an option set on the command line or config
  917. #
  918. # $1: short option name
  919. # $2: long option name including =
  920. # $3: list of possible values
  921. # $4: config string (optional)
  922. #
  923. # example:
  924. # result="$(__git_get_option_value "-d" "--do-something=" \
  925. # "yes no" "core.doSomething")"
  926. #
  927. # result is then either empty (no option set) or "yes" or "no"
  928. #
  929. # __git_get_option_value requires 3 arguments
  930. __git_get_option_value ()
  931. {
  932. local c short_opt long_opt val
  933. local result= values config_key word
  934. short_opt="$1"
  935. long_opt="$2"
  936. values="$3"
  937. config_key="$4"
  938. ((c = $cword - 1))
  939. while [ $c -ge 0 ]; do
  940. word="${words[c]}"
  941. for val in $values; do
  942. if [ "$short_opt$val" = "$word" ] ||
  943. [ "$long_opt$val" = "$word" ]; then
  944. result="$val"
  945. break 2
  946. fi
  947. done
  948. ((c--))
  949. done
  950. if [ -n "$config_key" ] && [ -z "$result" ]; then
  951. result="$(__git config "$config_key")"
  952. fi
  953. echo "$result"
  954. }
  955. __git_has_doubledash ()
  956. {
  957. local c=1
  958. while [ $c -lt $cword ]; do
  959. if [ "--" = "${words[c]}" ]; then
  960. return 0
  961. fi
  962. ((c++))
  963. done
  964. return 1
  965. }
  966. # Try to count non option arguments passed on the command line for the
  967. # specified git command.
  968. # When options are used, it is necessary to use the special -- option to
  969. # tell the implementation were non option arguments begin.
  970. # XXX this can not be improved, since options can appear everywhere, as
  971. # an example:
  972. # git mv x -n y
  973. #
  974. # __git_count_arguments requires 1 argument: the git command executed.
  975. __git_count_arguments ()
  976. {
  977. local word i c=0
  978. # Skip "git" (first argument)
  979. for ((i=1; i < ${#words[@]}; i++)); do
  980. word="${words[i]}"
  981. case "$word" in
  982. --)
  983. # Good; we can assume that the following are only non
  984. # option arguments.
  985. ((c = 0))
  986. ;;
  987. "$1")
  988. # Skip the specified git command and discard git
  989. # main options
  990. ((c = 0))
  991. ;;
  992. ?*)
  993. ((c++))
  994. ;;
  995. esac
  996. done
  997. printf "%d" $c
  998. }
  999. __git_whitespacelist="nowarn warn error error-all fix"
  1000. _git_am ()
  1001. {
  1002. __git_find_repo_path
  1003. if [ -d "$__git_repo_path"/rebase-apply ]; then
  1004. __gitcomp "--skip --continue --resolved --abort"
  1005. return
  1006. fi
  1007. case "$cur" in
  1008. --whitespace=*)
  1009. __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
  1010. return
  1011. ;;
  1012. --*)
  1013. __gitcomp "
  1014. --3way --committer-date-is-author-date --ignore-date
  1015. --ignore-whitespace --ignore-space-change
  1016. --interactive --keep --no-utf8 --signoff --utf8
  1017. --whitespace= --scissors
  1018. "
  1019. return
  1020. esac
  1021. }
  1022. _git_apply ()
  1023. {
  1024. case "$cur" in
  1025. --whitespace=*)
  1026. __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
  1027. return
  1028. ;;
  1029. --*)
  1030. __gitcomp "
  1031. --stat --numstat --summary --check --index
  1032. --cached --index-info --reverse --reject --unidiff-zero
  1033. --apply --no-add --exclude=
  1034. --ignore-whitespace --ignore-space-change
  1035. --whitespace= --inaccurate-eof --verbose
  1036. --recount --directory=
  1037. "
  1038. return
  1039. esac
  1040. }
  1041. _git_add ()
  1042. {
  1043. case "$cur" in
  1044. --*)
  1045. __gitcomp "
  1046. --interactive --refresh --patch --update --dry-run
  1047. --ignore-errors --intent-to-add --force --edit --chmod=
  1048. "
  1049. return
  1050. esac
  1051. local complete_opt="--others --modified --directory --no-empty-directory"
  1052. if test -n "$(__git_find_on_cmdline "-u --update")"
  1053. then
  1054. complete_opt="--modified"
  1055. fi
  1056. __git_complete_index_file "$complete_opt"
  1057. }
  1058. _git_archive ()
  1059. {
  1060. case "$cur" in
  1061. --format=*)
  1062. __gitcomp "$(git archive --list)" "" "${cur##--format=}"
  1063. return
  1064. ;;
  1065. --remote=*)
  1066. __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
  1067. return
  1068. ;;
  1069. --*)
  1070. __gitcomp "
  1071. --format= --list --verbose
  1072. --prefix= --remote= --exec= --output
  1073. "
  1074. return
  1075. ;;
  1076. esac
  1077. __git_complete_file
  1078. }
  1079. _git_bisect ()
  1080. {
  1081. __git_has_doubledash && return
  1082. local subcommands="start bad good skip reset visualize replay log run"
  1083. local subcommand="$(__git_find_on_cmdline "$subcommands")"
  1084. if [ -z "$subcommand" ]; then
  1085. __git_find_repo_path
  1086. if [ -f "$__git_repo_path"/BISECT_START ]; then
  1087. __gitcomp "$subcommands"
  1088. else
  1089. __gitcomp "replay start"
  1090. fi
  1091. return
  1092. fi
  1093. case "$subcommand" in
  1094. bad|good|reset|skip|start)
  1095. __git_complete_refs
  1096. ;;
  1097. *)
  1098. ;;
  1099. esac
  1100. }
  1101. _git_branch ()
  1102. {
  1103. local i c=1 only_local_ref="n" has_r="n"
  1104. while [ $c -lt $cword ]; do
  1105. i="${words[c]}"
  1106. case "$i" in
  1107. -d|--delete|-m|--move) only_local_ref="y" ;;
  1108. -r|--remotes) has_r="y" ;;
  1109. esac
  1110. ((c++))
  1111. done
  1112. case "$cur" in
  1113. --set-upstream-to=*)
  1114. __git_complete_refs --cur="${cur##--set-upstream-to=}"
  1115. ;;
  1116. --*)
  1117. __gitcomp "
  1118. --color --no-color --verbose --abbrev= --no-abbrev
  1119. --track --no-track --contains --no-contains --merged --no-merged
  1120. --set-upstream-to= --edit-description --list
  1121. --unset-upstream --delete --move --copy --remotes
  1122. --column --no-column --sort= --points-at
  1123. "
  1124. ;;
  1125. *)
  1126. if [ $only_local_ref = "y" -a $has_r = "n" ]; then
  1127. __gitcomp_direct "$(__git_heads "" "$cur" " ")"
  1128. else
  1129. __git_complete_refs
  1130. fi
  1131. ;;
  1132. esac
  1133. }
  1134. _git_bundle ()
  1135. {
  1136. local cmd="${words[2]}"
  1137. case "$cword" in
  1138. 2)
  1139. __gitcomp "create list-heads verify unbundle"
  1140. ;;
  1141. 3)
  1142. # looking for a file
  1143. ;;
  1144. *)
  1145. case "$cmd" in
  1146. create)
  1147. __git_complete_revlist
  1148. ;;
  1149. esac
  1150. ;;
  1151. esac
  1152. }
  1153. _git_checkout ()
  1154. {
  1155. __git_has_doubledash && return
  1156. case "$cur" in
  1157. --conflict=*)
  1158. __gitcomp "diff3 merge" "" "${cur##--conflict=}"
  1159. ;;
  1160. --*)
  1161. __gitcomp "
  1162. --quiet --ours --theirs --track --no-track --merge
  1163. --conflict= --orphan --patch --detach --ignore-skip-worktree-bits
  1164. --recurse-submodules --no-recurse-submodules
  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 --dirty --broken
  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 --ignore-cr-at-eol
  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. --autostash --no-autostash
  1781. $__git_merge_options
  1782. $__git_fetch_options
  1783. "
  1784. return
  1785. ;;
  1786. esac
  1787. __git_complete_remote_or_refspec
  1788. }
  1789. __git_push_recurse_submodules="check on-demand only"
  1790. __git_complete_force_with_lease ()
  1791. {
  1792. local cur_=$1
  1793. case "$cur_" in
  1794. --*=)
  1795. ;;
  1796. *:*)
  1797. __git_complete_refs --cur="${cur_#*:}"
  1798. ;;
  1799. *)
  1800. __git_complete_refs --cur="$cur_"
  1801. ;;
  1802. esac
  1803. }
  1804. _git_push ()
  1805. {
  1806. case "$prev" in
  1807. --repo)
  1808. __gitcomp_nl "$(__git_remotes)"
  1809. return
  1810. ;;
  1811. --recurse-submodules)
  1812. __gitcomp "$__git_push_recurse_submodules"
  1813. return
  1814. ;;
  1815. esac
  1816. case "$cur" in
  1817. --repo=*)
  1818. __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
  1819. return
  1820. ;;
  1821. --recurse-submodules=*)
  1822. __gitcomp "$__git_push_recurse_submodules" "" "${cur##--recurse-submodules=}"
  1823. return
  1824. ;;
  1825. --force-with-lease=*)
  1826. __git_complete_force_with_lease "${cur##--force-with-lease=}"
  1827. return
  1828. ;;
  1829. --*)
  1830. __gitcomp "
  1831. --all --mirror --tags --dry-run --force --verbose
  1832. --quiet --prune --delete --follow-tags
  1833. --receive-pack= --repo= --set-upstream
  1834. --force-with-lease --force-with-lease= --recurse-submodules=
  1835. "
  1836. return
  1837. ;;
  1838. esac
  1839. __git_complete_remote_or_refspec
  1840. }
  1841. _git_rebase ()
  1842. {
  1843. __git_find_repo_path
  1844. if [ -f "$__git_repo_path"/rebase-merge/interactive ]; then
  1845. __gitcomp "--continue --skip --abort --quit --edit-todo"
  1846. return
  1847. elif [ -d "$__git_repo_path"/rebase-apply ] || \
  1848. [ -d "$__git_repo_path"/rebase-merge ]; then
  1849. __gitcomp "--continue --skip --abort --quit"
  1850. return
  1851. fi
  1852. __git_complete_strategy && return
  1853. case "$cur" in
  1854. --whitespace=*)
  1855. __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
  1856. return
  1857. ;;
  1858. --*)
  1859. __gitcomp "
  1860. --onto --merge --strategy --interactive
  1861. --preserve-merges --stat --no-stat
  1862. --committer-date-is-author-date --ignore-date
  1863. --ignore-whitespace --whitespace=
  1864. --autosquash --no-autosquash
  1865. --fork-point --no-fork-point
  1866. --autostash --no-autostash
  1867. --verify --no-verify
  1868. --keep-empty --root --force-rebase --no-ff
  1869. --exec
  1870. "
  1871. return
  1872. esac
  1873. __git_complete_refs
  1874. }
  1875. _git_reflog ()
  1876. {
  1877. local subcommands="show delete expire"
  1878. local subcommand="$(__git_find_on_cmdline "$subcommands")"
  1879. if [ -z "$subcommand" ]; then
  1880. __gitcomp "$subcommands"
  1881. else
  1882. __git_complete_refs
  1883. fi
  1884. }
  1885. __git_send_email_confirm_options="always never auto cc compose"
  1886. __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
  1887. _git_send_email ()
  1888. {
  1889. case "$prev" in
  1890. --to|--cc|--bcc|--from)
  1891. __gitcomp "$(__git send-email --dump-aliases)"
  1892. return
  1893. ;;
  1894. esac
  1895. case "$cur" in
  1896. --confirm=*)
  1897. __gitcomp "
  1898. $__git_send_email_confirm_options
  1899. " "" "${cur##--confirm=}"
  1900. return
  1901. ;;
  1902. --suppress-cc=*)
  1903. __gitcomp "
  1904. $__git_send_email_suppresscc_options
  1905. " "" "${cur##--suppress-cc=}"
  1906. return
  1907. ;;
  1908. --smtp-encryption=*)
  1909. __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
  1910. return
  1911. ;;
  1912. --thread=*)
  1913. __gitcomp "
  1914. deep shallow
  1915. " "" "${cur##--thread=}"
  1916. return
  1917. ;;
  1918. --to=*|--cc=*|--bcc=*|--from=*)
  1919. __gitcomp "$(__git send-email --dump-aliases)" "" "${cur#--*=}"
  1920. return
  1921. ;;
  1922. --*)
  1923. __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
  1924. --compose --confirm= --dry-run --envelope-sender
  1925. --from --identity
  1926. --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
  1927. --no-suppress-from --no-thread --quiet
  1928. --signed-off-by-cc --smtp-pass --smtp-server
  1929. --smtp-server-port --smtp-encryption= --smtp-user
  1930. --subject --suppress-cc= --suppress-from --thread --to
  1931. --validate --no-validate
  1932. $__git_format_patch_options"
  1933. return
  1934. ;;
  1935. esac
  1936. __git_complete_revlist
  1937. }
  1938. _git_stage ()
  1939. {
  1940. _git_add
  1941. }
  1942. _git_status ()
  1943. {
  1944. local complete_opt
  1945. local untracked_state
  1946. case "$cur" in
  1947. --ignore-submodules=*)
  1948. __gitcomp "none untracked dirty all" "" "${cur##--ignore-submodules=}"
  1949. return
  1950. ;;
  1951. --untracked-files=*)
  1952. __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
  1953. return
  1954. ;;
  1955. --column=*)
  1956. __gitcomp "
  1957. always never auto column row plain dense nodense
  1958. " "" "${cur##--column=}"
  1959. return
  1960. ;;
  1961. --*)
  1962. __gitcomp "
  1963. --short --branch --porcelain --long --verbose
  1964. --untracked-files= --ignore-submodules= --ignored
  1965. --column= --no-column
  1966. "
  1967. return
  1968. ;;
  1969. esac
  1970. untracked_state="$(__git_get_option_value "-u" "--untracked-files=" \
  1971. "$__git_untracked_file_modes" "status.showUntrackedFiles")"
  1972. case "$untracked_state" in
  1973. no)
  1974. # --ignored option does not matter
  1975. complete_opt=
  1976. ;;
  1977. all|normal|*)
  1978. complete_opt="--cached --directory --no-empty-directory --others"
  1979. if [ -n "$(__git_find_on_cmdline "--ignored")" ]; then
  1980. complete_opt="$complete_opt --ignored --exclude=*"
  1981. fi
  1982. ;;
  1983. esac
  1984. __git_complete_index_file "$complete_opt"
  1985. }
  1986. __git_config_get_set_variables ()
  1987. {
  1988. local prevword word config_file= c=$cword
  1989. while [ $c -gt 1 ]; do
  1990. word="${words[c]}"
  1991. case "$word" in
  1992. --system|--global|--local|--file=*)
  1993. config_file="$word"
  1994. break
  1995. ;;
  1996. -f|--file)
  1997. config_file="$word $prevword"
  1998. break
  1999. ;;
  2000. esac
  2001. prevword=$word
  2002. c=$((--c))
  2003. done
  2004. __git config $config_file --name-only --list
  2005. }
  2006. _git_config ()
  2007. {
  2008. case "$prev" in
  2009. branch.*.remote|branch.*.pushremote)
  2010. __gitcomp_nl "$(__git_remotes)"
  2011. return
  2012. ;;
  2013. branch.*.merge)
  2014. __git_complete_refs
  2015. return
  2016. ;;
  2017. branch.*.rebase)
  2018. __gitcomp "false true preserve interactive"
  2019. return
  2020. ;;
  2021. remote.pushdefault)
  2022. __gitcomp_nl "$(__git_remotes)"
  2023. return
  2024. ;;
  2025. remote.*.fetch)
  2026. local remote="${prev#remote.}"
  2027. remote="${remote%.fetch}"
  2028. if [ -z "$cur" ]; then
  2029. __gitcomp_nl "refs/heads/" "" "" ""
  2030. return
  2031. fi
  2032. __gitcomp_nl "$(__git_refs_remotes "$remote")"
  2033. return
  2034. ;;
  2035. remote.*.push)
  2036. local remote="${prev#remote.}"
  2037. remote="${remote%.push}"
  2038. __gitcomp_nl "$(__git for-each-ref \
  2039. --format='%(refname):%(refname)' refs/heads)"
  2040. return
  2041. ;;
  2042. pull.twohead|pull.octopus)
  2043. __git_compute_merge_strategies
  2044. __gitcomp "$__git_merge_strategies"
  2045. return
  2046. ;;
  2047. color.branch|color.diff|color.interactive|\
  2048. color.showbranch|color.status|color.ui)
  2049. __gitcomp "always never auto"
  2050. return
  2051. ;;
  2052. color.pager)
  2053. __gitcomp "false true"
  2054. return
  2055. ;;
  2056. color.*.*)
  2057. __gitcomp "
  2058. normal black red green yellow blue magenta cyan white
  2059. bold dim ul blink reverse
  2060. "
  2061. return
  2062. ;;
  2063. diff.submodule)
  2064. __gitcomp "log short"
  2065. return
  2066. ;;
  2067. help.format)
  2068. __gitcomp "man info web html"
  2069. return
  2070. ;;
  2071. log.date)
  2072. __gitcomp "$__git_log_date_formats"
  2073. return
  2074. ;;
  2075. sendemail.aliasesfiletype)
  2076. __gitcomp "mutt mailrc pine elm gnus"
  2077. return
  2078. ;;
  2079. sendemail.confirm)
  2080. __gitcomp "$__git_send_email_confirm_options"
  2081. return
  2082. ;;
  2083. sendemail.suppresscc)
  2084. __gitcomp "$__git_send_email_suppresscc_options"
  2085. return
  2086. ;;
  2087. sendemail.transferencoding)
  2088. __gitcomp "7bit 8bit quoted-printable base64"
  2089. return
  2090. ;;
  2091. --get|--get-all|--unset|--unset-all)
  2092. __gitcomp_nl "$(__git_config_get_set_variables)"
  2093. return
  2094. ;;
  2095. *.*)
  2096. return
  2097. ;;
  2098. esac
  2099. case "$cur" in
  2100. --*)
  2101. __gitcomp "
  2102. --system --global --local --file=
  2103. --list --replace-all
  2104. --get --get-all --get-regexp
  2105. --add --unset --unset-all
  2106. --remove-section --rename-section
  2107. --name-only
  2108. "
  2109. return
  2110. ;;
  2111. branch.*.*)
  2112. local pfx="${cur%.*}." cur_="${cur##*.}"
  2113. __gitcomp "remote pushremote merge mergeoptions rebase" "$pfx" "$cur_"
  2114. return
  2115. ;;
  2116. branch.*)
  2117. local pfx="${cur%.*}." cur_="${cur#*.}"
  2118. __gitcomp_direct "$(__git_heads "$pfx" "$cur_" ".")"
  2119. __gitcomp_nl_append $'autosetupmerge\nautosetuprebase\n' "$pfx" "$cur_"
  2120. return
  2121. ;;
  2122. guitool.*.*)
  2123. local pfx="${cur%.*}." cur_="${cur##*.}"
  2124. __gitcomp "
  2125. argprompt cmd confirm needsfile noconsole norescan
  2126. prompt revprompt revunmerged title
  2127. " "$pfx" "$cur_"
  2128. return
  2129. ;;
  2130. difftool.*.*)
  2131. local pfx="${cur%.*}." cur_="${cur##*.}"
  2132. __gitcomp "cmd path" "$pfx" "$cur_"
  2133. return
  2134. ;;
  2135. man.*.*)
  2136. local pfx="${cur%.*}." cur_="${cur##*.}"
  2137. __gitcomp "cmd path" "$pfx" "$cur_"
  2138. return
  2139. ;;
  2140. mergetool.*.*)
  2141. local pfx="${cur%.*}." cur_="${cur##*.}"
  2142. __gitcomp "cmd path trustExitCode" "$pfx" "$cur_"
  2143. return
  2144. ;;
  2145. pager.*)
  2146. local pfx="${cur%.*}." cur_="${cur#*.}"
  2147. __git_compute_all_commands
  2148. __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_"
  2149. return
  2150. ;;
  2151. remote.*.*)
  2152. local pfx="${cur%.*}." cur_="${cur##*.}"
  2153. __gitcomp "
  2154. url proxy fetch push mirror skipDefaultUpdate
  2155. receivepack uploadpack tagopt pushurl
  2156. " "$pfx" "$cur_"
  2157. return
  2158. ;;
  2159. remote.*)
  2160. local pfx="${cur%.*}." cur_="${cur#*.}"
  2161. __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
  2162. __gitcomp_nl_append "pushdefault" "$pfx" "$cur_"
  2163. return
  2164. ;;
  2165. url.*.*)
  2166. local pfx="${cur%.*}." cur_="${cur##*.}"
  2167. __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_"
  2168. return
  2169. ;;
  2170. esac
  2171. __gitcomp "
  2172. add.ignoreErrors
  2173. advice.amWorkDir
  2174. advice.commitBeforeMerge
  2175. advice.detachedHead
  2176. advice.implicitIdentity
  2177. advice.pushAlreadyExists
  2178. advice.pushFetchFirst
  2179. advice.pushNeedsForce
  2180. advice.pushNonFFCurrent
  2181. advice.pushNonFFMatching
  2182. advice.pushUpdateRejected
  2183. advice.resolveConflict
  2184. advice.rmHints
  2185. advice.statusHints
  2186. advice.statusUoption
  2187. advice.ignoredHook
  2188. alias.
  2189. am.keepcr
  2190. am.threeWay
  2191. apply.ignorewhitespace
  2192. apply.whitespace
  2193. branch.autosetupmerge
  2194. branch.autosetuprebase
  2195. browser.
  2196. clean.requireForce
  2197. color.branch
  2198. color.branch.current
  2199. color.branch.local
  2200. color.branch.plain
  2201. color.branch.remote
  2202. color.decorate.HEAD
  2203. color.decorate.branch
  2204. color.decorate.remoteBranch
  2205. color.decorate.stash
  2206. color.decorate.tag
  2207. color.diff
  2208. color.diff.commit
  2209. color.diff.frag
  2210. color.diff.func
  2211. color.diff.meta
  2212. color.diff.new
  2213. color.diff.old
  2214. color.diff.plain
  2215. color.diff.whitespace
  2216. color.grep
  2217. color.grep.context
  2218. color.grep.filename
  2219. color.grep.function
  2220. color.grep.linenumber
  2221. color.grep.match
  2222. color.grep.selected
  2223. color.grep.separator
  2224. color.interactive
  2225. color.interactive.error
  2226. color.interactive.header
  2227. color.interactive.help
  2228. color.interactive.prompt
  2229. color.pager
  2230. color.showbranch
  2231. color.status
  2232. color.status.added
  2233. color.status.changed
  2234. color.status.header
  2235. color.status.localBranch
  2236. color.status.nobranch
  2237. color.status.remoteBranch
  2238. color.status.unmerged
  2239. color.status.untracked
  2240. color.status.updated
  2241. color.ui
  2242. commit.cleanup
  2243. commit.gpgSign
  2244. commit.status
  2245. commit.template
  2246. commit.verbose
  2247. core.abbrev
  2248. core.askpass
  2249. core.attributesfile
  2250. core.autocrlf
  2251. core.bare
  2252. core.bigFileThreshold
  2253. core.checkStat
  2254. core.commentChar
  2255. core.compression
  2256. core.createObject
  2257. core.deltaBaseCacheLimit
  2258. core.editor
  2259. core.eol
  2260. core.excludesfile
  2261. core.fileMode
  2262. core.fsyncobjectfiles
  2263. core.gitProxy
  2264. core.hideDotFiles
  2265. core.hooksPath
  2266. core.ignoreStat
  2267. core.ignorecase
  2268. core.logAllRefUpdates
  2269. core.loosecompression
  2270. core.notesRef
  2271. core.packedGitLimit
  2272. core.packedGitWindowSize
  2273. core.packedRefsTimeout
  2274. core.pager
  2275. core.precomposeUnicode
  2276. core.preferSymlinkRefs
  2277. core.preloadindex
  2278. core.protectHFS
  2279. core.protectNTFS
  2280. core.quotepath
  2281. core.repositoryFormatVersion
  2282. core.safecrlf
  2283. core.sharedRepository
  2284. core.sparseCheckout
  2285. core.splitIndex
  2286. core.sshCommand
  2287. core.symlinks
  2288. core.trustctime
  2289. core.untrackedCache
  2290. core.warnAmbiguousRefs
  2291. core.whitespace
  2292. core.worktree
  2293. credential.helper
  2294. credential.useHttpPath
  2295. credential.username
  2296. credentialCache.ignoreSIGHUP
  2297. diff.autorefreshindex
  2298. diff.external
  2299. diff.ignoreSubmodules
  2300. diff.mnemonicprefix
  2301. diff.noprefix
  2302. diff.renameLimit
  2303. diff.renames
  2304. diff.statGraphWidth
  2305. diff.submodule
  2306. diff.suppressBlankEmpty
  2307. diff.tool
  2308. diff.wordRegex
  2309. diff.algorithm
  2310. difftool.
  2311. difftool.prompt
  2312. fetch.recurseSubmodules
  2313. fetch.unpackLimit
  2314. format.attach
  2315. format.cc
  2316. format.coverLetter
  2317. format.from
  2318. format.headers
  2319. format.numbered
  2320. format.pretty
  2321. format.signature
  2322. format.signoff
  2323. format.subjectprefix
  2324. format.suffix
  2325. format.thread
  2326. format.to
  2327. gc.
  2328. gc.aggressiveDepth
  2329. gc.aggressiveWindow
  2330. gc.auto
  2331. gc.autoDetach
  2332. gc.autopacklimit
  2333. gc.logExpiry
  2334. gc.packrefs
  2335. gc.pruneexpire
  2336. gc.reflogexpire
  2337. gc.reflogexpireunreachable
  2338. gc.rerereresolved
  2339. gc.rerereunresolved
  2340. gc.worktreePruneExpire
  2341. gitcvs.allbinary
  2342. gitcvs.commitmsgannotation
  2343. gitcvs.dbTableNamePrefix
  2344. gitcvs.dbdriver
  2345. gitcvs.dbname
  2346. gitcvs.dbpass
  2347. gitcvs.dbuser
  2348. gitcvs.enabled
  2349. gitcvs.logfile
  2350. gitcvs.usecrlfattr
  2351. guitool.
  2352. gui.blamehistoryctx
  2353. gui.commitmsgwidth
  2354. gui.copyblamethreshold
  2355. gui.diffcontext
  2356. gui.encoding
  2357. gui.fastcopyblame
  2358. gui.matchtrackingbranch
  2359. gui.newbranchtemplate
  2360. gui.pruneduringfetch
  2361. gui.spellingdictionary
  2362. gui.trustmtime
  2363. help.autocorrect
  2364. help.browser
  2365. help.format
  2366. http.lowSpeedLimit
  2367. http.lowSpeedTime
  2368. http.maxRequests
  2369. http.minSessions
  2370. http.noEPSV
  2371. http.postBuffer
  2372. http.proxy
  2373. http.sslCipherList
  2374. http.sslVersion
  2375. http.sslCAInfo
  2376. http.sslCAPath
  2377. http.sslCert
  2378. http.sslCertPasswordProtected
  2379. http.sslKey
  2380. http.sslVerify
  2381. http.useragent
  2382. i18n.commitEncoding
  2383. i18n.logOutputEncoding
  2384. imap.authMethod
  2385. imap.folder
  2386. imap.host
  2387. imap.pass
  2388. imap.port
  2389. imap.preformattedHTML
  2390. imap.sslverify
  2391. imap.tunnel
  2392. imap.user
  2393. init.templatedir
  2394. instaweb.browser
  2395. instaweb.httpd
  2396. instaweb.local
  2397. instaweb.modulepath
  2398. instaweb.port
  2399. interactive.singlekey
  2400. log.date
  2401. log.decorate
  2402. log.showroot
  2403. mailmap.file
  2404. man.
  2405. man.viewer
  2406. merge.
  2407. merge.conflictstyle
  2408. merge.log
  2409. merge.renameLimit
  2410. merge.renormalize
  2411. merge.stat
  2412. merge.tool
  2413. merge.verbosity
  2414. mergetool.
  2415. mergetool.keepBackup
  2416. mergetool.keepTemporaries
  2417. mergetool.prompt
  2418. notes.displayRef
  2419. notes.rewrite.
  2420. notes.rewrite.amend
  2421. notes.rewrite.rebase
  2422. notes.rewriteMode
  2423. notes.rewriteRef
  2424. pack.compression
  2425. pack.deltaCacheLimit
  2426. pack.deltaCacheSize
  2427. pack.depth
  2428. pack.indexVersion
  2429. pack.packSizeLimit
  2430. pack.threads
  2431. pack.window
  2432. pack.windowMemory
  2433. pager.
  2434. pretty.
  2435. pull.octopus
  2436. pull.twohead
  2437. push.default
  2438. push.followTags
  2439. rebase.autosquash
  2440. rebase.stat
  2441. receive.autogc
  2442. receive.denyCurrentBranch
  2443. receive.denyDeleteCurrent
  2444. receive.denyDeletes
  2445. receive.denyNonFastForwards
  2446. receive.fsckObjects
  2447. receive.unpackLimit
  2448. receive.updateserverinfo
  2449. remote.pushdefault
  2450. remotes.
  2451. repack.usedeltabaseoffset
  2452. rerere.autoupdate
  2453. rerere.enabled
  2454. sendemail.
  2455. sendemail.aliasesfile
  2456. sendemail.aliasfiletype
  2457. sendemail.bcc
  2458. sendemail.cc
  2459. sendemail.cccmd
  2460. sendemail.chainreplyto
  2461. sendemail.confirm
  2462. sendemail.envelopesender
  2463. sendemail.from
  2464. sendemail.identity
  2465. sendemail.multiedit
  2466. sendemail.signedoffbycc
  2467. sendemail.smtpdomain
  2468. sendemail.smtpencryption
  2469. sendemail.smtppass
  2470. sendemail.smtpserver
  2471. sendemail.smtpserveroption
  2472. sendemail.smtpserverport
  2473. sendemail.smtpuser
  2474. sendemail.suppresscc
  2475. sendemail.suppressfrom
  2476. sendemail.thread
  2477. sendemail.to
  2478. sendemail.tocmd
  2479. sendemail.validate
  2480. sendemail.smtpbatchsize
  2481. sendemail.smtprelogindelay
  2482. showbranch.default
  2483. status.relativePaths
  2484. status.showUntrackedFiles
  2485. status.submodulesummary
  2486. submodule.
  2487. tar.umask
  2488. transfer.unpackLimit
  2489. url.
  2490. user.email
  2491. user.name
  2492. user.signingkey
  2493. web.browser
  2494. branch. remote.
  2495. "
  2496. }
  2497. _git_remote ()
  2498. {
  2499. local subcommands="
  2500. add rename remove set-head set-branches
  2501. get-url set-url show prune update
  2502. "
  2503. local subcommand="$(__git_find_on_cmdline "$subcommands")"
  2504. if [ -z "$subcommand" ]; then
  2505. case "$cur" in
  2506. --*)
  2507. __gitcomp "--verbose"
  2508. ;;
  2509. *)
  2510. __gitcomp "$subcommands"
  2511. ;;
  2512. esac
  2513. return
  2514. fi
  2515. case "$subcommand,$cur" in
  2516. add,--*)
  2517. __gitcomp "--track --master --fetch --tags --no-tags --mirror="
  2518. ;;
  2519. add,*)
  2520. ;;
  2521. set-head,--*)
  2522. __gitcomp "--auto --delete"
  2523. ;;
  2524. set-branches,--*)
  2525. __gitcomp "--add"
  2526. ;;
  2527. set-head,*|set-branches,*)
  2528. __git_complete_remote_or_refspec
  2529. ;;
  2530. update,--*)
  2531. __gitcomp "--prune"
  2532. ;;
  2533. update,*)
  2534. __gitcomp "$(__git_get_config_variables "remotes")"
  2535. ;;
  2536. set-url,--*)
  2537. __gitcomp "--push --add --delete"
  2538. ;;
  2539. get-url,--*)
  2540. __gitcomp "--push --all"
  2541. ;;
  2542. prune,--*)
  2543. __gitcomp "--dry-run"
  2544. ;;
  2545. *)
  2546. __gitcomp_nl "$(__git_remotes)"
  2547. ;;
  2548. esac
  2549. }
  2550. _git_replace ()
  2551. {
  2552. case "$cur" in
  2553. --*)
  2554. __gitcomp "--edit --graft --format= --list --delete"
  2555. return
  2556. ;;
  2557. esac
  2558. __git_complete_refs
  2559. }
  2560. _git_rerere ()
  2561. {
  2562. local subcommands="clear forget diff remaining status gc"
  2563. local subcommand="$(__git_find_on_cmdline "$subcommands")"
  2564. if test -z "$subcommand"
  2565. then
  2566. __gitcomp "$subcommands"
  2567. return
  2568. fi
  2569. }
  2570. _git_reset ()
  2571. {
  2572. __git_has_doubledash && return
  2573. case "$cur" in
  2574. --*)
  2575. __gitcomp "--merge --mixed --hard --soft --patch --keep"
  2576. return
  2577. ;;
  2578. esac
  2579. __git_complete_refs
  2580. }
  2581. _git_revert ()
  2582. {
  2583. __git_find_repo_path
  2584. if [ -f "$__git_repo_path"/REVERT_HEAD ]; then
  2585. __gitcomp "--continue --quit --abort"
  2586. return
  2587. fi
  2588. case "$cur" in
  2589. --*)
  2590. __gitcomp "
  2591. --edit --mainline --no-edit --no-commit --signoff
  2592. --strategy= --strategy-option=
  2593. "
  2594. return
  2595. ;;
  2596. esac
  2597. __git_complete_refs
  2598. }
  2599. _git_rm ()
  2600. {
  2601. case "$cur" in
  2602. --*)
  2603. __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
  2604. return
  2605. ;;
  2606. esac
  2607. __git_complete_index_file "--cached"
  2608. }
  2609. _git_shortlog ()
  2610. {
  2611. __git_has_doubledash && return
  2612. case "$cur" in
  2613. --*)
  2614. __gitcomp "
  2615. $__git_log_common_options
  2616. $__git_log_shortlog_options
  2617. --numbered --summary --email
  2618. "
  2619. return
  2620. ;;
  2621. esac
  2622. __git_complete_revlist
  2623. }
  2624. _git_show ()
  2625. {
  2626. __git_has_doubledash && return
  2627. case "$cur" in
  2628. --pretty=*|--format=*)
  2629. __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
  2630. " "" "${cur#*=}"
  2631. return
  2632. ;;
  2633. --diff-algorithm=*)
  2634. __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
  2635. return
  2636. ;;
  2637. --submodule=*)
  2638. __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
  2639. return
  2640. ;;
  2641. --*)
  2642. __gitcomp "--pretty= --format= --abbrev-commit --oneline
  2643. --show-signature
  2644. $__git_diff_common_options
  2645. "
  2646. return
  2647. ;;
  2648. esac
  2649. __git_complete_revlist_file
  2650. }
  2651. _git_show_branch ()
  2652. {
  2653. case "$cur" in
  2654. --*)
  2655. __gitcomp "
  2656. --all --remotes --topo-order --date-order --current --more=
  2657. --list --independent --merge-base --no-name
  2658. --color --no-color
  2659. --sha1-name --sparse --topics --reflog
  2660. "
  2661. return
  2662. ;;
  2663. esac
  2664. __git_complete_revlist
  2665. }
  2666. _git_stash ()
  2667. {
  2668. local save_opts='--all --keep-index --no-keep-index --quiet --patch --include-untracked'
  2669. local subcommands='push save list show apply clear drop pop create branch'
  2670. local subcommand="$(__git_find_on_cmdline "$subcommands")"
  2671. if [ -z "$subcommand" ]; then
  2672. case "$cur" in
  2673. --*)
  2674. __gitcomp "$save_opts"
  2675. ;;
  2676. *)
  2677. if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
  2678. __gitcomp "$subcommands"
  2679. fi
  2680. ;;
  2681. esac
  2682. else
  2683. case "$subcommand,$cur" in
  2684. push,--*)
  2685. __gitcomp "$save_opts --message"
  2686. ;;
  2687. save,--*)
  2688. __gitcomp "$save_opts"
  2689. ;;
  2690. apply,--*|pop,--*)
  2691. __gitcomp "--index --quiet"
  2692. ;;
  2693. drop,--*)
  2694. __gitcomp "--quiet"
  2695. ;;
  2696. show,--*|branch,--*)
  2697. ;;
  2698. branch,*)
  2699. if [ $cword -eq 3 ]; then
  2700. __git_complete_refs
  2701. else
  2702. __gitcomp_nl "$(__git stash list \
  2703. | sed -n -e 's/:.*//p')"
  2704. fi
  2705. ;;
  2706. show,*|apply,*|drop,*|pop,*)
  2707. __gitcomp_nl "$(__git stash list \
  2708. | sed -n -e 's/:.*//p')"
  2709. ;;
  2710. *)
  2711. ;;
  2712. esac
  2713. fi
  2714. }
  2715. _git_submodule ()
  2716. {
  2717. __git_has_doubledash && return
  2718. local subcommands="add status init deinit update summary foreach sync"
  2719. local subcommand="$(__git_find_on_cmdline "$subcommands")"
  2720. if [ -z "$subcommand" ]; then
  2721. case "$cur" in
  2722. --*)
  2723. __gitcomp "--quiet"
  2724. ;;
  2725. *)
  2726. __gitcomp "$subcommands"
  2727. ;;
  2728. esac
  2729. return
  2730. fi
  2731. case "$subcommand,$cur" in
  2732. add,--*)
  2733. __gitcomp "--branch --force --name --reference --depth"
  2734. ;;
  2735. status,--*)
  2736. __gitcomp "--cached --recursive"
  2737. ;;
  2738. deinit,--*)
  2739. __gitcomp "--force --all"
  2740. ;;
  2741. update,--*)
  2742. __gitcomp "
  2743. --init --remote --no-fetch
  2744. --recommend-shallow --no-recommend-shallow
  2745. --force --rebase --merge --reference --depth --recursive --jobs
  2746. "
  2747. ;;
  2748. summary,--*)
  2749. __gitcomp "--cached --files --summary-limit"
  2750. ;;
  2751. foreach,--*|sync,--*)
  2752. __gitcomp "--recursive"
  2753. ;;
  2754. *)
  2755. ;;
  2756. esac
  2757. }
  2758. _git_svn ()
  2759. {
  2760. local subcommands="
  2761. init fetch clone rebase dcommit log find-rev
  2762. set-tree commit-diff info create-ignore propget
  2763. proplist show-ignore show-externals branch tag blame
  2764. migrate mkdirs reset gc
  2765. "
  2766. local subcommand="$(__git_find_on_cmdline "$subcommands")"
  2767. if [ -z "$subcommand" ]; then
  2768. __gitcomp "$subcommands"
  2769. else
  2770. local remote_opts="--username= --config-dir= --no-auth-cache"
  2771. local fc_opts="
  2772. --follow-parent --authors-file= --repack=
  2773. --no-metadata --use-svm-props --use-svnsync-props
  2774. --log-window-size= --no-checkout --quiet
  2775. --repack-flags --use-log-author --localtime
  2776. --add-author-from
  2777. --ignore-paths= --include-paths= $remote_opts
  2778. "
  2779. local init_opts="
  2780. --template= --shared= --trunk= --tags=
  2781. --branches= --stdlayout --minimize-url
  2782. --no-metadata --use-svm-props --use-svnsync-props
  2783. --rewrite-root= --prefix= $remote_opts
  2784. "
  2785. local cmt_opts="
  2786. --edit --rmdir --find-copies-harder --copy-similarity=
  2787. "
  2788. case "$subcommand,$cur" in
  2789. fetch,--*)
  2790. __gitcomp "--revision= --fetch-all $fc_opts"
  2791. ;;
  2792. clone,--*)
  2793. __gitcomp "--revision= $fc_opts $init_opts"
  2794. ;;
  2795. init,--*)
  2796. __gitcomp "$init_opts"
  2797. ;;
  2798. dcommit,--*)
  2799. __gitcomp "
  2800. --merge --strategy= --verbose --dry-run
  2801. --fetch-all --no-rebase --commit-url
  2802. --revision --interactive $cmt_opts $fc_opts
  2803. "
  2804. ;;
  2805. set-tree,--*)
  2806. __gitcomp "--stdin $cmt_opts $fc_opts"
  2807. ;;
  2808. create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
  2809. show-externals,--*|mkdirs,--*)
  2810. __gitcomp "--revision="
  2811. ;;
  2812. log,--*)
  2813. __gitcomp "
  2814. --limit= --revision= --verbose --incremental
  2815. --oneline --show-commit --non-recursive
  2816. --authors-file= --color
  2817. "
  2818. ;;
  2819. rebase,--*)
  2820. __gitcomp "
  2821. --merge --verbose --strategy= --local
  2822. --fetch-all --dry-run $fc_opts
  2823. "
  2824. ;;
  2825. commit-diff,--*)
  2826. __gitcomp "--message= --file= --revision= $cmt_opts"
  2827. ;;
  2828. info,--*)
  2829. __gitcomp "--url"
  2830. ;;
  2831. branch,--*)
  2832. __gitcomp "--dry-run --message --tag"
  2833. ;;
  2834. tag,--*)
  2835. __gitcomp "--dry-run --message"
  2836. ;;
  2837. blame,--*)
  2838. __gitcomp "--git-format"
  2839. ;;
  2840. migrate,--*)
  2841. __gitcomp "
  2842. --config-dir= --ignore-paths= --minimize
  2843. --no-auth-cache --username=
  2844. "
  2845. ;;
  2846. reset,--*)
  2847. __gitcomp "--revision= --parent"
  2848. ;;
  2849. *)
  2850. ;;
  2851. esac
  2852. fi
  2853. }
  2854. _git_tag ()
  2855. {
  2856. local i c=1 f=0
  2857. while [ $c -lt $cword ]; do
  2858. i="${words[c]}"
  2859. case "$i" in
  2860. -d|-v)
  2861. __gitcomp_direct "$(__git_tags "" "$cur" " ")"
  2862. return
  2863. ;;
  2864. -f)
  2865. f=1
  2866. ;;
  2867. esac
  2868. ((c++))
  2869. done
  2870. case "$prev" in
  2871. -m|-F)
  2872. ;;
  2873. -*|tag)
  2874. if [ $f = 1 ]; then
  2875. __gitcomp_direct "$(__git_tags "" "$cur" " ")"
  2876. fi
  2877. ;;
  2878. *)
  2879. __git_complete_refs
  2880. ;;
  2881. esac
  2882. case "$cur" in
  2883. --*)
  2884. __gitcomp "
  2885. --list --delete --verify --annotate --message --file
  2886. --sign --cleanup --local-user --force --column --sort=
  2887. --contains --no-contains --points-at --merged --no-merged --create-reflog
  2888. "
  2889. ;;
  2890. esac
  2891. }
  2892. _git_whatchanged ()
  2893. {
  2894. _git_log
  2895. }
  2896. _git_worktree ()
  2897. {
  2898. local subcommands="add list lock prune unlock"
  2899. local subcommand="$(__git_find_on_cmdline "$subcommands")"
  2900. if [ -z "$subcommand" ]; then
  2901. __gitcomp "$subcommands"
  2902. else
  2903. case "$subcommand,$cur" in
  2904. add,--*)
  2905. __gitcomp "--detach"
  2906. ;;
  2907. list,--*)
  2908. __gitcomp "--porcelain"
  2909. ;;
  2910. lock,--*)
  2911. __gitcomp "--reason"
  2912. ;;
  2913. prune,--*)
  2914. __gitcomp "--dry-run --expire --verbose"
  2915. ;;
  2916. *)
  2917. ;;
  2918. esac
  2919. fi
  2920. }
  2921. __git_main ()
  2922. {
  2923. local i c=1 command __git_dir __git_repo_path
  2924. local __git_C_args C_args_count=0
  2925. while [ $c -lt $cword ]; do
  2926. i="${words[c]}"
  2927. case "$i" in
  2928. --git-dir=*) __git_dir="${i#--git-dir=}" ;;
  2929. --git-dir) ((c++)) ; __git_dir="${words[c]}" ;;
  2930. --bare) __git_dir="." ;;
  2931. --help) command="help"; break ;;
  2932. -c|--work-tree|--namespace) ((c++)) ;;
  2933. -C) __git_C_args[C_args_count++]=-C
  2934. ((c++))
  2935. __git_C_args[C_args_count++]="${words[c]}"
  2936. ;;
  2937. -*) ;;
  2938. *) command="$i"; break ;;
  2939. esac
  2940. ((c++))
  2941. done
  2942. if [ -z "$command" ]; then
  2943. case "$prev" in
  2944. --git-dir|-C|--work-tree)
  2945. # these need a path argument, let's fall back to
  2946. # Bash filename completion
  2947. return
  2948. ;;
  2949. -c|--namespace)
  2950. # we don't support completing these options' arguments
  2951. return
  2952. ;;
  2953. esac
  2954. case "$cur" in
  2955. --*) __gitcomp "
  2956. --paginate
  2957. --no-pager
  2958. --git-dir=
  2959. --bare
  2960. --version
  2961. --exec-path
  2962. --exec-path=
  2963. --html-path
  2964. --man-path
  2965. --info-path
  2966. --work-tree=
  2967. --namespace=
  2968. --no-replace-objects
  2969. --help
  2970. "
  2971. ;;
  2972. *) __git_compute_porcelain_commands
  2973. __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
  2974. esac
  2975. return
  2976. fi
  2977. local completion_func="_git_${command//-/_}"
  2978. declare -f $completion_func >/dev/null 2>/dev/null && $completion_func && return
  2979. local expansion=$(__git_aliased_command "$command")
  2980. if [ -n "$expansion" ]; then
  2981. words[1]=$expansion
  2982. completion_func="_git_${expansion//-/_}"
  2983. declare -f $completion_func >/dev/null 2>/dev/null && $completion_func
  2984. fi
  2985. }
  2986. __gitk_main ()
  2987. {
  2988. __git_has_doubledash && return
  2989. local __git_repo_path
  2990. __git_find_repo_path
  2991. local merge=""
  2992. if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
  2993. merge="--merge"
  2994. fi
  2995. case "$cur" in
  2996. --*)
  2997. __gitcomp "
  2998. $__git_log_common_options
  2999. $__git_log_gitk_options
  3000. $merge
  3001. "
  3002. return
  3003. ;;
  3004. esac
  3005. __git_complete_revlist
  3006. }
  3007. if [[ -n ${ZSH_VERSION-} ]]; then
  3008. echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
  3009. autoload -U +X compinit && compinit
  3010. __gitcomp ()
  3011. {
  3012. emulate -L zsh
  3013. local cur_="${3-$cur}"
  3014. case "$cur_" in
  3015. --*=)
  3016. ;;
  3017. *)
  3018. local c IFS=$' \t\n'
  3019. local -a array
  3020. for c in ${=1}; do
  3021. c="$c${4-}"
  3022. case $c in
  3023. --*=*|*.) ;;
  3024. *) c="$c " ;;
  3025. esac
  3026. array[${#array[@]}+1]="$c"
  3027. done
  3028. compset -P '*[=:]'
  3029. compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
  3030. ;;
  3031. esac
  3032. }
  3033. __gitcomp_direct ()
  3034. {
  3035. emulate -L zsh
  3036. local IFS=$'\n'
  3037. compset -P '*[=:]'
  3038. compadd -Q -- ${=1} && _ret=0
  3039. }
  3040. __gitcomp_nl ()
  3041. {
  3042. emulate -L zsh
  3043. local IFS=$'\n'
  3044. compset -P '*[=:]'
  3045. compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
  3046. }
  3047. __gitcomp_file ()
  3048. {
  3049. emulate -L zsh
  3050. local IFS=$'\n'
  3051. compset -P '*[=:]'
  3052. compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
  3053. }
  3054. _git ()
  3055. {
  3056. local _ret=1 cur cword prev
  3057. cur=${words[CURRENT]}
  3058. prev=${words[CURRENT-1]}
  3059. let cword=CURRENT-1
  3060. emulate ksh -c __${service}_main
  3061. let _ret && _default && _ret=0
  3062. return _ret
  3063. }
  3064. compdef _git git gitk
  3065. return
  3066. fi
  3067. __git_func_wrap ()
  3068. {
  3069. local cur words cword prev
  3070. _get_comp_words_by_ref -n =: cur words cword prev
  3071. $1
  3072. }
  3073. # Setup completion for certain functions defined above by setting common
  3074. # variables and workarounds.
  3075. # This is NOT a public function; use at your own risk.
  3076. __git_complete ()
  3077. {
  3078. local wrapper="__git_wrap${2}"
  3079. eval "$wrapper () { __git_func_wrap $2 ; }"
  3080. complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
  3081. || complete -o default -o nospace -F $wrapper $1
  3082. }
  3083. # wrapper for backwards compatibility
  3084. _git ()
  3085. {
  3086. __git_wrap__git_main
  3087. }
  3088. # wrapper for backwards compatibility
  3089. _gitk ()
  3090. {
  3091. __git_wrap__gitk_main
  3092. }
  3093. __git_complete git __git_main
  3094. __git_complete gitk __gitk_main
  3095. # The following are necessary only for Cygwin, and only are needed
  3096. # when the user has tab-completed the executable name and consequently
  3097. # included the '.exe' suffix.
  3098. #
  3099. if [[ "$OSTYPE" = cygwin* ]]; then
  3100. __git_complete git.exe __git_main
  3101. fi