git-completion.bash 55 KB

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