git-completion.bash 55 KB

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