2
0

git-completion.bash 56 KB

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