git-completion.bash 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776
  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. column) : internal helper;;
  626. commit-tree) : plumbing;;
  627. count-objects) : infrequent;;
  628. credential) : credentials;;
  629. credential-*) : credentials helper;;
  630. cvsexportcommit) : export;;
  631. cvsimport) : import;;
  632. cvsserver) : daemon;;
  633. daemon) : daemon;;
  634. diff-files) : plumbing;;
  635. diff-index) : plumbing;;
  636. diff-tree) : plumbing;;
  637. fast-import) : import;;
  638. fast-export) : export;;
  639. fsck-objects) : plumbing;;
  640. fetch-pack) : plumbing;;
  641. fmt-merge-msg) : plumbing;;
  642. for-each-ref) : plumbing;;
  643. hash-object) : plumbing;;
  644. http-*) : transport;;
  645. index-pack) : plumbing;;
  646. init-db) : deprecated;;
  647. local-fetch) : plumbing;;
  648. ls-files) : plumbing;;
  649. ls-remote) : plumbing;;
  650. ls-tree) : plumbing;;
  651. mailinfo) : plumbing;;
  652. mailsplit) : plumbing;;
  653. merge-*) : plumbing;;
  654. mktree) : plumbing;;
  655. mktag) : plumbing;;
  656. pack-objects) : plumbing;;
  657. pack-redundant) : plumbing;;
  658. pack-refs) : plumbing;;
  659. parse-remote) : plumbing;;
  660. patch-id) : plumbing;;
  661. prune) : plumbing;;
  662. prune-packed) : plumbing;;
  663. quiltimport) : import;;
  664. read-tree) : plumbing;;
  665. receive-pack) : plumbing;;
  666. remote-*) : transport;;
  667. rerere) : plumbing;;
  668. rev-list) : plumbing;;
  669. rev-parse) : plumbing;;
  670. runstatus) : plumbing;;
  671. sh-setup) : internal;;
  672. shell) : daemon;;
  673. show-ref) : plumbing;;
  674. send-pack) : plumbing;;
  675. show-index) : plumbing;;
  676. ssh-*) : transport;;
  677. stripspace) : plumbing;;
  678. symbolic-ref) : plumbing;;
  679. unpack-file) : plumbing;;
  680. unpack-objects) : plumbing;;
  681. update-index) : plumbing;;
  682. update-ref) : plumbing;;
  683. update-server-info) : daemon;;
  684. upload-archive) : plumbing;;
  685. upload-pack) : plumbing;;
  686. write-tree) : plumbing;;
  687. var) : infrequent;;
  688. verify-pack) : infrequent;;
  689. verify-tag) : plumbing;;
  690. *) echo $i;;
  691. esac
  692. done
  693. }
  694. __git_porcelain_commands=
  695. __git_compute_porcelain_commands ()
  696. {
  697. test -n "$__git_porcelain_commands" ||
  698. __git_porcelain_commands=$(__git_list_porcelain_commands)
  699. }
  700. # Lists all set config variables starting with the given section prefix,
  701. # with the prefix removed.
  702. __git_get_config_variables ()
  703. {
  704. local section="$1" i IFS=$'\n'
  705. for i in $(git --git-dir="$(__gitdir)" config --name-only --get-regexp "^$section\..*" 2>/dev/null); do
  706. echo "${i#$section.}"
  707. done
  708. }
  709. __git_pretty_aliases ()
  710. {
  711. __git_get_config_variables "pretty"
  712. }
  713. __git_aliases ()
  714. {
  715. __git_get_config_variables "alias"
  716. }
  717. # __git_aliased_command requires 1 argument
  718. __git_aliased_command ()
  719. {
  720. local word cmdline=$(git --git-dir="$(__gitdir)" \
  721. config --get "alias.$1")
  722. for word in $cmdline; do
  723. case "$word" in
  724. \!gitk|gitk)
  725. echo "gitk"
  726. return
  727. ;;
  728. \!*) : shell command alias ;;
  729. -*) : option ;;
  730. *=*) : setting env ;;
  731. git) : git itself ;;
  732. \(\)) : skip parens of shell function definition ;;
  733. {) : skip start of shell helper function ;;
  734. :) : skip null command ;;
  735. \'*) : skip opening quote after sh -c ;;
  736. *)
  737. echo "$word"
  738. return
  739. esac
  740. done
  741. }
  742. # __git_find_on_cmdline requires 1 argument
  743. __git_find_on_cmdline ()
  744. {
  745. local word subcommand c=1
  746. while [ $c -lt $cword ]; do
  747. word="${words[c]}"
  748. for subcommand in $1; do
  749. if [ "$subcommand" = "$word" ]; then
  750. echo "$subcommand"
  751. return
  752. fi
  753. done
  754. ((c++))
  755. done
  756. }
  757. __git_has_doubledash ()
  758. {
  759. local c=1
  760. while [ $c -lt $cword ]; do
  761. if [ "--" = "${words[c]}" ]; then
  762. return 0
  763. fi
  764. ((c++))
  765. done
  766. return 1
  767. }
  768. # Try to count non option arguments passed on the command line for the
  769. # specified git command.
  770. # When options are used, it is necessary to use the special -- option to
  771. # tell the implementation were non option arguments begin.
  772. # XXX this can not be improved, since options can appear everywhere, as
  773. # an example:
  774. # git mv x -n y
  775. #
  776. # __git_count_arguments requires 1 argument: the git command executed.
  777. __git_count_arguments ()
  778. {
  779. local word i c=0
  780. # Skip "git" (first argument)
  781. for ((i=1; i < ${#words[@]}; i++)); do
  782. word="${words[i]}"
  783. case "$word" in
  784. --)
  785. # Good; we can assume that the following are only non
  786. # option arguments.
  787. ((c = 0))
  788. ;;
  789. "$1")
  790. # Skip the specified git command and discard git
  791. # main options
  792. ((c = 0))
  793. ;;
  794. ?*)
  795. ((c++))
  796. ;;
  797. esac
  798. done
  799. printf "%d" $c
  800. }
  801. __git_whitespacelist="nowarn warn error error-all fix"
  802. _git_am ()
  803. {
  804. local dir="$(__gitdir)"
  805. if [ -d "$dir"/rebase-apply ]; then
  806. __gitcomp "--skip --continue --resolved --abort"
  807. return
  808. fi
  809. case "$cur" in
  810. --whitespace=*)
  811. __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
  812. return
  813. ;;
  814. --*)
  815. __gitcomp "
  816. --3way --committer-date-is-author-date --ignore-date
  817. --ignore-whitespace --ignore-space-change
  818. --interactive --keep --no-utf8 --signoff --utf8
  819. --whitespace= --scissors
  820. "
  821. return
  822. esac
  823. }
  824. _git_apply ()
  825. {
  826. case "$cur" in
  827. --whitespace=*)
  828. __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
  829. return
  830. ;;
  831. --*)
  832. __gitcomp "
  833. --stat --numstat --summary --check --index
  834. --cached --index-info --reverse --reject --unidiff-zero
  835. --apply --no-add --exclude=
  836. --ignore-whitespace --ignore-space-change
  837. --whitespace= --inaccurate-eof --verbose
  838. "
  839. return
  840. esac
  841. }
  842. _git_add ()
  843. {
  844. case "$cur" in
  845. --*)
  846. __gitcomp "
  847. --interactive --refresh --patch --update --dry-run
  848. --ignore-errors --intent-to-add
  849. "
  850. return
  851. esac
  852. # XXX should we check for --update and --all options ?
  853. __git_complete_index_file "--others --modified --directory --no-empty-directory"
  854. }
  855. _git_archive ()
  856. {
  857. case "$cur" in
  858. --format=*)
  859. __gitcomp "$(git archive --list)" "" "${cur##--format=}"
  860. return
  861. ;;
  862. --remote=*)
  863. __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
  864. return
  865. ;;
  866. --*)
  867. __gitcomp "
  868. --format= --list --verbose
  869. --prefix= --remote= --exec=
  870. "
  871. return
  872. ;;
  873. esac
  874. __git_complete_file
  875. }
  876. _git_bisect ()
  877. {
  878. __git_has_doubledash && return
  879. local subcommands="start bad good skip reset visualize replay log run"
  880. local subcommand="$(__git_find_on_cmdline "$subcommands")"
  881. if [ -z "$subcommand" ]; then
  882. if [ -f "$(__gitdir)"/BISECT_START ]; then
  883. __gitcomp "$subcommands"
  884. else
  885. __gitcomp "replay start"
  886. fi
  887. return
  888. fi
  889. case "$subcommand" in
  890. bad|good|reset|skip|start)
  891. __gitcomp_nl "$(__git_refs)"
  892. ;;
  893. *)
  894. ;;
  895. esac
  896. }
  897. _git_branch ()
  898. {
  899. local i c=1 only_local_ref="n" has_r="n"
  900. while [ $c -lt $cword ]; do
  901. i="${words[c]}"
  902. case "$i" in
  903. -d|-m) only_local_ref="y" ;;
  904. -r) has_r="y" ;;
  905. esac
  906. ((c++))
  907. done
  908. case "$cur" in
  909. --set-upstream-to=*)
  910. __gitcomp_nl "$(__git_refs)" "" "${cur##--set-upstream-to=}"
  911. ;;
  912. --*)
  913. __gitcomp "
  914. --color --no-color --verbose --abbrev= --no-abbrev
  915. --track --no-track --contains --merged --no-merged
  916. --set-upstream-to= --edit-description --list
  917. --unset-upstream
  918. "
  919. ;;
  920. *)
  921. if [ $only_local_ref = "y" -a $has_r = "n" ]; then
  922. __gitcomp_nl "$(__git_heads)"
  923. else
  924. __gitcomp_nl "$(__git_refs)"
  925. fi
  926. ;;
  927. esac
  928. }
  929. _git_bundle ()
  930. {
  931. local cmd="${words[2]}"
  932. case "$cword" in
  933. 2)
  934. __gitcomp "create list-heads verify unbundle"
  935. ;;
  936. 3)
  937. # looking for a file
  938. ;;
  939. *)
  940. case "$cmd" in
  941. create)
  942. __git_complete_revlist
  943. ;;
  944. esac
  945. ;;
  946. esac
  947. }
  948. _git_checkout ()
  949. {
  950. __git_has_doubledash && return
  951. case "$cur" in
  952. --conflict=*)
  953. __gitcomp "diff3 merge" "" "${cur##--conflict=}"
  954. ;;
  955. --*)
  956. __gitcomp "
  957. --quiet --ours --theirs --track --no-track --merge
  958. --conflict= --orphan --patch
  959. "
  960. ;;
  961. *)
  962. # check if --track, --no-track, or --no-guess was specified
  963. # if so, disable DWIM mode
  964. local flags="--track --no-track --no-guess" track=1
  965. if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
  966. track=''
  967. fi
  968. __gitcomp_nl "$(__git_refs '' $track)"
  969. ;;
  970. esac
  971. }
  972. _git_cherry ()
  973. {
  974. __gitcomp_nl "$(__git_refs)"
  975. }
  976. _git_cherry_pick ()
  977. {
  978. local dir="$(__gitdir)"
  979. if [ -f "$dir"/CHERRY_PICK_HEAD ]; then
  980. __gitcomp "--continue --quit --abort"
  981. return
  982. fi
  983. case "$cur" in
  984. --*)
  985. __gitcomp "--edit --no-commit --signoff --strategy= --mainline"
  986. ;;
  987. *)
  988. __gitcomp_nl "$(__git_refs)"
  989. ;;
  990. esac
  991. }
  992. _git_clean ()
  993. {
  994. case "$cur" in
  995. --*)
  996. __gitcomp "--dry-run --quiet"
  997. return
  998. ;;
  999. esac
  1000. # XXX should we check for -x option ?
  1001. __git_complete_index_file "--others --directory"
  1002. }
  1003. _git_clone ()
  1004. {
  1005. case "$cur" in
  1006. --*)
  1007. __gitcomp "
  1008. --local
  1009. --no-hardlinks
  1010. --shared
  1011. --reference
  1012. --quiet
  1013. --no-checkout
  1014. --bare
  1015. --mirror
  1016. --origin
  1017. --upload-pack
  1018. --template=
  1019. --depth
  1020. --single-branch
  1021. --branch
  1022. "
  1023. return
  1024. ;;
  1025. esac
  1026. }
  1027. _git_commit ()
  1028. {
  1029. case "$prev" in
  1030. -c|-C)
  1031. __gitcomp_nl "$(__git_refs)" "" "${cur}"
  1032. return
  1033. ;;
  1034. esac
  1035. case "$cur" in
  1036. --cleanup=*)
  1037. __gitcomp "default scissors strip verbatim whitespace
  1038. " "" "${cur##--cleanup=}"
  1039. return
  1040. ;;
  1041. --reuse-message=*|--reedit-message=*|\
  1042. --fixup=*|--squash=*)
  1043. __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
  1044. return
  1045. ;;
  1046. --untracked-files=*)
  1047. __gitcomp "all no normal" "" "${cur##--untracked-files=}"
  1048. return
  1049. ;;
  1050. --*)
  1051. __gitcomp "
  1052. --all --author= --signoff --verify --no-verify
  1053. --edit --no-edit
  1054. --amend --include --only --interactive
  1055. --dry-run --reuse-message= --reedit-message=
  1056. --reset-author --file= --message= --template=
  1057. --cleanup= --untracked-files --untracked-files=
  1058. --verbose --quiet --fixup= --squash=
  1059. "
  1060. return
  1061. esac
  1062. if git rev-parse --verify --quiet HEAD >/dev/null; then
  1063. __git_complete_index_file "--committable"
  1064. else
  1065. # This is the first commit
  1066. __git_complete_index_file "--cached"
  1067. fi
  1068. }
  1069. _git_describe ()
  1070. {
  1071. case "$cur" in
  1072. --*)
  1073. __gitcomp "
  1074. --all --tags --contains --abbrev= --candidates=
  1075. --exact-match --debug --long --match --always
  1076. "
  1077. return
  1078. esac
  1079. __gitcomp_nl "$(__git_refs)"
  1080. }
  1081. __git_diff_algorithms="myers minimal patience histogram"
  1082. __git_diff_common_options="--stat --numstat --shortstat --summary
  1083. --patch-with-stat --name-only --name-status --color
  1084. --no-color --color-words --no-renames --check
  1085. --full-index --binary --abbrev --diff-filter=
  1086. --find-copies-harder
  1087. --text --ignore-space-at-eol --ignore-space-change
  1088. --ignore-all-space --ignore-blank-lines --exit-code
  1089. --quiet --ext-diff --no-ext-diff
  1090. --no-prefix --src-prefix= --dst-prefix=
  1091. --inter-hunk-context=
  1092. --patience --histogram --minimal
  1093. --raw --word-diff --word-diff-regex=
  1094. --dirstat --dirstat= --dirstat-by-file
  1095. --dirstat-by-file= --cumulative
  1096. --diff-algorithm=
  1097. "
  1098. _git_diff ()
  1099. {
  1100. __git_has_doubledash && return
  1101. case "$cur" in
  1102. --diff-algorithm=*)
  1103. __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
  1104. return
  1105. ;;
  1106. --*)
  1107. __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
  1108. --base --ours --theirs --no-index
  1109. $__git_diff_common_options
  1110. "
  1111. return
  1112. ;;
  1113. esac
  1114. __git_complete_revlist_file
  1115. }
  1116. __git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff
  1117. tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc codecompare
  1118. "
  1119. _git_difftool ()
  1120. {
  1121. __git_has_doubledash && return
  1122. case "$cur" in
  1123. --tool=*)
  1124. __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
  1125. return
  1126. ;;
  1127. --*)
  1128. __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
  1129. --base --ours --theirs
  1130. --no-renames --diff-filter= --find-copies-harder
  1131. --relative --ignore-submodules
  1132. --tool="
  1133. return
  1134. ;;
  1135. esac
  1136. __git_complete_revlist_file
  1137. }
  1138. __git_fetch_recurse_submodules="yes on-demand no"
  1139. __git_fetch_options="
  1140. --quiet --verbose --append --upload-pack --force --keep --depth=
  1141. --tags --no-tags --all --prune --dry-run --recurse-submodules=
  1142. "
  1143. _git_fetch ()
  1144. {
  1145. case "$cur" in
  1146. --recurse-submodules=*)
  1147. __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
  1148. return
  1149. ;;
  1150. --*)
  1151. __gitcomp "$__git_fetch_options"
  1152. return
  1153. ;;
  1154. esac
  1155. __git_complete_remote_or_refspec
  1156. }
  1157. __git_format_patch_options="
  1158. --stdout --attach --no-attach --thread --thread= --no-thread
  1159. --numbered --start-number --numbered-files --keep-subject --signoff
  1160. --signature --no-signature --in-reply-to= --cc= --full-index --binary
  1161. --not --all --cover-letter --no-prefix --src-prefix= --dst-prefix=
  1162. --inline --suffix= --ignore-if-in-upstream --subject-prefix=
  1163. --output-directory --reroll-count --to= --quiet --notes
  1164. "
  1165. _git_format_patch ()
  1166. {
  1167. case "$cur" in
  1168. --thread=*)
  1169. __gitcomp "
  1170. deep shallow
  1171. " "" "${cur##--thread=}"
  1172. return
  1173. ;;
  1174. --*)
  1175. __gitcomp "$__git_format_patch_options"
  1176. return
  1177. ;;
  1178. esac
  1179. __git_complete_revlist
  1180. }
  1181. _git_fsck ()
  1182. {
  1183. case "$cur" in
  1184. --*)
  1185. __gitcomp "
  1186. --tags --root --unreachable --cache --no-reflogs --full
  1187. --strict --verbose --lost-found
  1188. "
  1189. return
  1190. ;;
  1191. esac
  1192. }
  1193. _git_gc ()
  1194. {
  1195. case "$cur" in
  1196. --*)
  1197. __gitcomp "--prune --aggressive"
  1198. return
  1199. ;;
  1200. esac
  1201. }
  1202. _git_gitk ()
  1203. {
  1204. _gitk
  1205. }
  1206. __git_match_ctag() {
  1207. awk "/^${1//\//\\/}/ { print \$1 }" "$2"
  1208. }
  1209. _git_grep ()
  1210. {
  1211. __git_has_doubledash && return
  1212. case "$cur" in
  1213. --*)
  1214. __gitcomp "
  1215. --cached
  1216. --text --ignore-case --word-regexp --invert-match
  1217. --full-name --line-number
  1218. --extended-regexp --basic-regexp --fixed-strings
  1219. --perl-regexp
  1220. --threads
  1221. --files-with-matches --name-only
  1222. --files-without-match
  1223. --max-depth
  1224. --count
  1225. --and --or --not --all-match
  1226. "
  1227. return
  1228. ;;
  1229. esac
  1230. case "$cword,$prev" in
  1231. 2,*|*,-*)
  1232. if test -r tags; then
  1233. __gitcomp_nl "$(__git_match_ctag "$cur" tags)"
  1234. return
  1235. fi
  1236. ;;
  1237. esac
  1238. __gitcomp_nl "$(__git_refs)"
  1239. }
  1240. _git_help ()
  1241. {
  1242. case "$cur" in
  1243. --*)
  1244. __gitcomp "--all --info --man --web"
  1245. return
  1246. ;;
  1247. esac
  1248. __git_compute_all_commands
  1249. __gitcomp "$__git_all_commands $(__git_aliases)
  1250. attributes cli core-tutorial cvs-migration
  1251. diffcore gitk glossary hooks ignore modules
  1252. namespaces repository-layout tutorial tutorial-2
  1253. workflows
  1254. "
  1255. }
  1256. _git_init ()
  1257. {
  1258. case "$cur" in
  1259. --shared=*)
  1260. __gitcomp "
  1261. false true umask group all world everybody
  1262. " "" "${cur##--shared=}"
  1263. return
  1264. ;;
  1265. --*)
  1266. __gitcomp "--quiet --bare --template= --shared --shared="
  1267. return
  1268. ;;
  1269. esac
  1270. }
  1271. _git_ls_files ()
  1272. {
  1273. case "$cur" in
  1274. --*)
  1275. __gitcomp "--cached --deleted --modified --others --ignored
  1276. --stage --directory --no-empty-directory --unmerged
  1277. --killed --exclude= --exclude-from=
  1278. --exclude-per-directory= --exclude-standard
  1279. --error-unmatch --with-tree= --full-name
  1280. --abbrev --ignored --exclude-per-directory
  1281. "
  1282. return
  1283. ;;
  1284. esac
  1285. # XXX ignore options like --modified and always suggest all cached
  1286. # files.
  1287. __git_complete_index_file "--cached"
  1288. }
  1289. _git_ls_remote ()
  1290. {
  1291. __gitcomp_nl "$(__git_remotes)"
  1292. }
  1293. _git_ls_tree ()
  1294. {
  1295. __git_complete_file
  1296. }
  1297. # Options that go well for log, shortlog and gitk
  1298. __git_log_common_options="
  1299. --not --all
  1300. --branches --tags --remotes
  1301. --first-parent --merges --no-merges
  1302. --max-count=
  1303. --max-age= --since= --after=
  1304. --min-age= --until= --before=
  1305. --min-parents= --max-parents=
  1306. --no-min-parents --no-max-parents
  1307. "
  1308. # Options that go well for log and gitk (not shortlog)
  1309. __git_log_gitk_options="
  1310. --dense --sparse --full-history
  1311. --simplify-merges --simplify-by-decoration
  1312. --left-right --notes --no-notes
  1313. "
  1314. # Options that go well for log and shortlog (not gitk)
  1315. __git_log_shortlog_options="
  1316. --author= --committer= --grep=
  1317. --all-match --invert-grep
  1318. "
  1319. __git_log_pretty_formats="oneline short medium full fuller email raw format:"
  1320. __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
  1321. _git_log ()
  1322. {
  1323. __git_has_doubledash && return
  1324. local g="$(git rev-parse --git-dir 2>/dev/null)"
  1325. local merge=""
  1326. if [ -f "$g/MERGE_HEAD" ]; then
  1327. merge="--merge"
  1328. fi
  1329. case "$cur" in
  1330. --pretty=*|--format=*)
  1331. __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
  1332. " "" "${cur#*=}"
  1333. return
  1334. ;;
  1335. --date=*)
  1336. __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
  1337. return
  1338. ;;
  1339. --decorate=*)
  1340. __gitcomp "full short no" "" "${cur##--decorate=}"
  1341. return
  1342. ;;
  1343. --*)
  1344. __gitcomp "
  1345. $__git_log_common_options
  1346. $__git_log_shortlog_options
  1347. $__git_log_gitk_options
  1348. --root --topo-order --date-order --reverse
  1349. --follow --full-diff
  1350. --abbrev-commit --abbrev=
  1351. --relative-date --date=
  1352. --pretty= --format= --oneline
  1353. --show-signature
  1354. --cherry-pick
  1355. --graph
  1356. --decorate --decorate=
  1357. --walk-reflogs
  1358. --parents --children
  1359. $merge
  1360. $__git_diff_common_options
  1361. --pickaxe-all --pickaxe-regex
  1362. "
  1363. return
  1364. ;;
  1365. esac
  1366. __git_complete_revlist
  1367. }
  1368. # Common merge options shared by git-merge(1) and git-pull(1).
  1369. __git_merge_options="
  1370. --no-commit --no-stat --log --no-log --squash --strategy
  1371. --commit --stat --no-squash --ff --no-ff --ff-only --edit --no-edit
  1372. --verify-signatures --no-verify-signatures --gpg-sign
  1373. --quiet --verbose --progress --no-progress
  1374. "
  1375. _git_merge ()
  1376. {
  1377. __git_complete_strategy && return
  1378. case "$cur" in
  1379. --*)
  1380. __gitcomp "$__git_merge_options
  1381. --rerere-autoupdate --no-rerere-autoupdate --abort"
  1382. return
  1383. esac
  1384. __gitcomp_nl "$(__git_refs)"
  1385. }
  1386. _git_mergetool ()
  1387. {
  1388. case "$cur" in
  1389. --tool=*)
  1390. __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
  1391. return
  1392. ;;
  1393. --*)
  1394. __gitcomp "--tool="
  1395. return
  1396. ;;
  1397. esac
  1398. }
  1399. _git_merge_base ()
  1400. {
  1401. case "$cur" in
  1402. --*)
  1403. __gitcomp "--octopus --independent --is-ancestor --fork-point"
  1404. return
  1405. ;;
  1406. esac
  1407. __gitcomp_nl "$(__git_refs)"
  1408. }
  1409. _git_mv ()
  1410. {
  1411. case "$cur" in
  1412. --*)
  1413. __gitcomp "--dry-run"
  1414. return
  1415. ;;
  1416. esac
  1417. if [ $(__git_count_arguments "mv") -gt 0 ]; then
  1418. # We need to show both cached and untracked files (including
  1419. # empty directories) since this may not be the last argument.
  1420. __git_complete_index_file "--cached --others --directory"
  1421. else
  1422. __git_complete_index_file "--cached"
  1423. fi
  1424. }
  1425. _git_name_rev ()
  1426. {
  1427. __gitcomp "--tags --all --stdin"
  1428. }
  1429. _git_notes ()
  1430. {
  1431. local subcommands='add append copy edit list prune remove show'
  1432. local subcommand="$(__git_find_on_cmdline "$subcommands")"
  1433. case "$subcommand,$cur" in
  1434. ,--*)
  1435. __gitcomp '--ref'
  1436. ;;
  1437. ,*)
  1438. case "$prev" in
  1439. --ref)
  1440. __gitcomp_nl "$(__git_refs)"
  1441. ;;
  1442. *)
  1443. __gitcomp "$subcommands --ref"
  1444. ;;
  1445. esac
  1446. ;;
  1447. add,--reuse-message=*|append,--reuse-message=*|\
  1448. add,--reedit-message=*|append,--reedit-message=*)
  1449. __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
  1450. ;;
  1451. add,--*|append,--*)
  1452. __gitcomp '--file= --message= --reedit-message=
  1453. --reuse-message='
  1454. ;;
  1455. copy,--*)
  1456. __gitcomp '--stdin'
  1457. ;;
  1458. prune,--*)
  1459. __gitcomp '--dry-run --verbose'
  1460. ;;
  1461. prune,*)
  1462. ;;
  1463. *)
  1464. case "$prev" in
  1465. -m|-F)
  1466. ;;
  1467. *)
  1468. __gitcomp_nl "$(__git_refs)"
  1469. ;;
  1470. esac
  1471. ;;
  1472. esac
  1473. }
  1474. _git_pull ()
  1475. {
  1476. __git_complete_strategy && return
  1477. case "$cur" in
  1478. --recurse-submodules=*)
  1479. __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
  1480. return
  1481. ;;
  1482. --*)
  1483. __gitcomp "
  1484. --rebase --no-rebase
  1485. $__git_merge_options
  1486. $__git_fetch_options
  1487. "
  1488. return
  1489. ;;
  1490. esac
  1491. __git_complete_remote_or_refspec
  1492. }
  1493. __git_push_recurse_submodules="check on-demand"
  1494. __git_complete_force_with_lease ()
  1495. {
  1496. local cur_=$1
  1497. case "$cur_" in
  1498. --*=)
  1499. ;;
  1500. *:*)
  1501. __gitcomp_nl "$(__git_refs)" "" "${cur_#*:}"
  1502. ;;
  1503. *)
  1504. __gitcomp_nl "$(__git_refs)" "" "$cur_"
  1505. ;;
  1506. esac
  1507. }
  1508. _git_push ()
  1509. {
  1510. case "$prev" in
  1511. --repo)
  1512. __gitcomp_nl "$(__git_remotes)"
  1513. return
  1514. ;;
  1515. --recurse-submodules)
  1516. __gitcomp "$__git_push_recurse_submodules"
  1517. return
  1518. ;;
  1519. esac
  1520. case "$cur" in
  1521. --repo=*)
  1522. __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
  1523. return
  1524. ;;
  1525. --recurse-submodules=*)
  1526. __gitcomp "$__git_push_recurse_submodules" "" "${cur##--recurse-submodules=}"
  1527. return
  1528. ;;
  1529. --force-with-lease=*)
  1530. __git_complete_force_with_lease "${cur##--force-with-lease=}"
  1531. return
  1532. ;;
  1533. --*)
  1534. __gitcomp "
  1535. --all --mirror --tags --dry-run --force --verbose
  1536. --quiet --prune --delete --follow-tags
  1537. --receive-pack= --repo= --set-upstream
  1538. --force-with-lease --force-with-lease= --recurse-submodules=
  1539. "
  1540. return
  1541. ;;
  1542. esac
  1543. __git_complete_remote_or_refspec
  1544. }
  1545. _git_rebase ()
  1546. {
  1547. local dir="$(__gitdir)"
  1548. if [ -f "$dir"/rebase-merge/interactive ]; then
  1549. __gitcomp "--continue --skip --abort --edit-todo"
  1550. return
  1551. elif [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
  1552. __gitcomp "--continue --skip --abort"
  1553. return
  1554. fi
  1555. __git_complete_strategy && return
  1556. case "$cur" in
  1557. --whitespace=*)
  1558. __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
  1559. return
  1560. ;;
  1561. --*)
  1562. __gitcomp "
  1563. --onto --merge --strategy --interactive
  1564. --preserve-merges --stat --no-stat
  1565. --committer-date-is-author-date --ignore-date
  1566. --ignore-whitespace --whitespace=
  1567. --autosquash --no-autosquash
  1568. --fork-point --no-fork-point
  1569. --autostash --no-autostash
  1570. --verify --no-verify
  1571. --keep-empty --root --force-rebase --no-ff
  1572. --exec
  1573. "
  1574. return
  1575. esac
  1576. __gitcomp_nl "$(__git_refs)"
  1577. }
  1578. _git_reflog ()
  1579. {
  1580. local subcommands="show delete expire"
  1581. local subcommand="$(__git_find_on_cmdline "$subcommands")"
  1582. if [ -z "$subcommand" ]; then
  1583. __gitcomp "$subcommands"
  1584. else
  1585. __gitcomp_nl "$(__git_refs)"
  1586. fi
  1587. }
  1588. __git_send_email_confirm_options="always never auto cc compose"
  1589. __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
  1590. _git_send_email ()
  1591. {
  1592. case "$prev" in
  1593. --to|--cc|--bcc|--from)
  1594. __gitcomp "
  1595. $(git --git-dir="$(__gitdir)" send-email --dump-aliases 2>/dev/null)
  1596. "
  1597. return
  1598. ;;
  1599. esac
  1600. case "$cur" in
  1601. --confirm=*)
  1602. __gitcomp "
  1603. $__git_send_email_confirm_options
  1604. " "" "${cur##--confirm=}"
  1605. return
  1606. ;;
  1607. --suppress-cc=*)
  1608. __gitcomp "
  1609. $__git_send_email_suppresscc_options
  1610. " "" "${cur##--suppress-cc=}"
  1611. return
  1612. ;;
  1613. --smtp-encryption=*)
  1614. __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
  1615. return
  1616. ;;
  1617. --thread=*)
  1618. __gitcomp "
  1619. deep shallow
  1620. " "" "${cur##--thread=}"
  1621. return
  1622. ;;
  1623. --to=*|--cc=*|--bcc=*|--from=*)
  1624. __gitcomp "
  1625. $(git --git-dir="$(__gitdir)" send-email --dump-aliases 2>/dev/null)
  1626. " "" "${cur#--*=}"
  1627. return
  1628. ;;
  1629. --*)
  1630. __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
  1631. --compose --confirm= --dry-run --envelope-sender
  1632. --from --identity
  1633. --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
  1634. --no-suppress-from --no-thread --quiet
  1635. --signed-off-by-cc --smtp-pass --smtp-server
  1636. --smtp-server-port --smtp-encryption= --smtp-user
  1637. --subject --suppress-cc= --suppress-from --thread --to
  1638. --validate --no-validate
  1639. $__git_format_patch_options"
  1640. return
  1641. ;;
  1642. esac
  1643. __git_complete_revlist
  1644. }
  1645. _git_stage ()
  1646. {
  1647. _git_add
  1648. }
  1649. __git_config_get_set_variables ()
  1650. {
  1651. local prevword word config_file= c=$cword
  1652. while [ $c -gt 1 ]; do
  1653. word="${words[c]}"
  1654. case "$word" in
  1655. --system|--global|--local|--file=*)
  1656. config_file="$word"
  1657. break
  1658. ;;
  1659. -f|--file)
  1660. config_file="$word $prevword"
  1661. break
  1662. ;;
  1663. esac
  1664. prevword=$word
  1665. c=$((--c))
  1666. done
  1667. git --git-dir="$(__gitdir)" config $config_file --name-only --list 2>/dev/null
  1668. }
  1669. _git_config ()
  1670. {
  1671. case "$prev" in
  1672. branch.*.remote|branch.*.pushremote)
  1673. __gitcomp_nl "$(__git_remotes)"
  1674. return
  1675. ;;
  1676. branch.*.merge)
  1677. __gitcomp_nl "$(__git_refs)"
  1678. return
  1679. ;;
  1680. branch.*.rebase)
  1681. __gitcomp "false true preserve interactive"
  1682. return
  1683. ;;
  1684. remote.pushdefault)
  1685. __gitcomp_nl "$(__git_remotes)"
  1686. return
  1687. ;;
  1688. remote.*.fetch)
  1689. local remote="${prev#remote.}"
  1690. remote="${remote%.fetch}"
  1691. if [ -z "$cur" ]; then
  1692. __gitcomp_nl "refs/heads/" "" "" ""
  1693. return
  1694. fi
  1695. __gitcomp_nl "$(__git_refs_remotes "$remote")"
  1696. return
  1697. ;;
  1698. remote.*.push)
  1699. local remote="${prev#remote.}"
  1700. remote="${remote%.push}"
  1701. __gitcomp_nl "$(git --git-dir="$(__gitdir)" \
  1702. for-each-ref --format='%(refname):%(refname)' \
  1703. refs/heads)"
  1704. return
  1705. ;;
  1706. pull.twohead|pull.octopus)
  1707. __git_compute_merge_strategies
  1708. __gitcomp "$__git_merge_strategies"
  1709. return
  1710. ;;
  1711. color.branch|color.diff|color.interactive|\
  1712. color.showbranch|color.status|color.ui)
  1713. __gitcomp "always never auto"
  1714. return
  1715. ;;
  1716. color.pager)
  1717. __gitcomp "false true"
  1718. return
  1719. ;;
  1720. color.*.*)
  1721. __gitcomp "
  1722. normal black red green yellow blue magenta cyan white
  1723. bold dim ul blink reverse
  1724. "
  1725. return
  1726. ;;
  1727. diff.submodule)
  1728. __gitcomp "log short"
  1729. return
  1730. ;;
  1731. help.format)
  1732. __gitcomp "man info web html"
  1733. return
  1734. ;;
  1735. log.date)
  1736. __gitcomp "$__git_log_date_formats"
  1737. return
  1738. ;;
  1739. sendemail.aliasesfiletype)
  1740. __gitcomp "mutt mailrc pine elm gnus"
  1741. return
  1742. ;;
  1743. sendemail.confirm)
  1744. __gitcomp "$__git_send_email_confirm_options"
  1745. return
  1746. ;;
  1747. sendemail.suppresscc)
  1748. __gitcomp "$__git_send_email_suppresscc_options"
  1749. return
  1750. ;;
  1751. sendemail.transferencoding)
  1752. __gitcomp "7bit 8bit quoted-printable base64"
  1753. return
  1754. ;;
  1755. --get|--get-all|--unset|--unset-all)
  1756. __gitcomp_nl "$(__git_config_get_set_variables)"
  1757. return
  1758. ;;
  1759. *.*)
  1760. return
  1761. ;;
  1762. esac
  1763. case "$cur" in
  1764. --*)
  1765. __gitcomp "
  1766. --system --global --local --file=
  1767. --list --replace-all
  1768. --get --get-all --get-regexp
  1769. --add --unset --unset-all
  1770. --remove-section --rename-section
  1771. --name-only
  1772. "
  1773. return
  1774. ;;
  1775. branch.*.*)
  1776. local pfx="${cur%.*}." cur_="${cur##*.}"
  1777. __gitcomp "remote pushremote merge mergeoptions rebase" "$pfx" "$cur_"
  1778. return
  1779. ;;
  1780. branch.*)
  1781. local pfx="${cur%.*}." cur_="${cur#*.}"
  1782. __gitcomp_nl "$(__git_heads)" "$pfx" "$cur_" "."
  1783. __gitcomp_nl_append $'autosetupmerge\nautosetuprebase\n' "$pfx" "$cur_"
  1784. return
  1785. ;;
  1786. guitool.*.*)
  1787. local pfx="${cur%.*}." cur_="${cur##*.}"
  1788. __gitcomp "
  1789. argprompt cmd confirm needsfile noconsole norescan
  1790. prompt revprompt revunmerged title
  1791. " "$pfx" "$cur_"
  1792. return
  1793. ;;
  1794. difftool.*.*)
  1795. local pfx="${cur%.*}." cur_="${cur##*.}"
  1796. __gitcomp "cmd path" "$pfx" "$cur_"
  1797. return
  1798. ;;
  1799. man.*.*)
  1800. local pfx="${cur%.*}." cur_="${cur##*.}"
  1801. __gitcomp "cmd path" "$pfx" "$cur_"
  1802. return
  1803. ;;
  1804. mergetool.*.*)
  1805. local pfx="${cur%.*}." cur_="${cur##*.}"
  1806. __gitcomp "cmd path trustExitCode" "$pfx" "$cur_"
  1807. return
  1808. ;;
  1809. pager.*)
  1810. local pfx="${cur%.*}." cur_="${cur#*.}"
  1811. __git_compute_all_commands
  1812. __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_"
  1813. return
  1814. ;;
  1815. remote.*.*)
  1816. local pfx="${cur%.*}." cur_="${cur##*.}"
  1817. __gitcomp "
  1818. url proxy fetch push mirror skipDefaultUpdate
  1819. receivepack uploadpack tagopt pushurl
  1820. " "$pfx" "$cur_"
  1821. return
  1822. ;;
  1823. remote.*)
  1824. local pfx="${cur%.*}." cur_="${cur#*.}"
  1825. __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
  1826. __gitcomp_nl_append "pushdefault" "$pfx" "$cur_"
  1827. return
  1828. ;;
  1829. url.*.*)
  1830. local pfx="${cur%.*}." cur_="${cur##*.}"
  1831. __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_"
  1832. return
  1833. ;;
  1834. esac
  1835. __gitcomp "
  1836. add.ignoreErrors
  1837. advice.commitBeforeMerge
  1838. advice.detachedHead
  1839. advice.implicitIdentity
  1840. advice.pushNonFastForward
  1841. advice.resolveConflict
  1842. advice.statusHints
  1843. alias.
  1844. am.keepcr
  1845. apply.ignorewhitespace
  1846. apply.whitespace
  1847. branch.autosetupmerge
  1848. branch.autosetuprebase
  1849. browser.
  1850. clean.requireForce
  1851. color.branch
  1852. color.branch.current
  1853. color.branch.local
  1854. color.branch.plain
  1855. color.branch.remote
  1856. color.decorate.HEAD
  1857. color.decorate.branch
  1858. color.decorate.remoteBranch
  1859. color.decorate.stash
  1860. color.decorate.tag
  1861. color.diff
  1862. color.diff.commit
  1863. color.diff.frag
  1864. color.diff.func
  1865. color.diff.meta
  1866. color.diff.new
  1867. color.diff.old
  1868. color.diff.plain
  1869. color.diff.whitespace
  1870. color.grep
  1871. color.grep.context
  1872. color.grep.filename
  1873. color.grep.function
  1874. color.grep.linenumber
  1875. color.grep.match
  1876. color.grep.selected
  1877. color.grep.separator
  1878. color.interactive
  1879. color.interactive.error
  1880. color.interactive.header
  1881. color.interactive.help
  1882. color.interactive.prompt
  1883. color.pager
  1884. color.showbranch
  1885. color.status
  1886. color.status.added
  1887. color.status.changed
  1888. color.status.header
  1889. color.status.nobranch
  1890. color.status.unmerged
  1891. color.status.untracked
  1892. color.status.updated
  1893. color.ui
  1894. commit.status
  1895. commit.template
  1896. core.abbrev
  1897. core.askpass
  1898. core.attributesfile
  1899. core.autocrlf
  1900. core.bare
  1901. core.bigFileThreshold
  1902. core.compression
  1903. core.createObject
  1904. core.deltaBaseCacheLimit
  1905. core.editor
  1906. core.eol
  1907. core.excludesfile
  1908. core.fileMode
  1909. core.fsyncobjectfiles
  1910. core.gitProxy
  1911. core.ignoreStat
  1912. core.ignorecase
  1913. core.logAllRefUpdates
  1914. core.loosecompression
  1915. core.notesRef
  1916. core.packedGitLimit
  1917. core.packedGitWindowSize
  1918. core.pager
  1919. core.preferSymlinkRefs
  1920. core.preloadindex
  1921. core.quotepath
  1922. core.repositoryFormatVersion
  1923. core.safecrlf
  1924. core.sharedRepository
  1925. core.sparseCheckout
  1926. core.symlinks
  1927. core.trustctime
  1928. core.untrackedCache
  1929. core.warnAmbiguousRefs
  1930. core.whitespace
  1931. core.worktree
  1932. diff.autorefreshindex
  1933. diff.external
  1934. diff.ignoreSubmodules
  1935. diff.mnemonicprefix
  1936. diff.noprefix
  1937. diff.renameLimit
  1938. diff.renames
  1939. diff.statGraphWidth
  1940. diff.submodule
  1941. diff.suppressBlankEmpty
  1942. diff.tool
  1943. diff.wordRegex
  1944. diff.algorithm
  1945. difftool.
  1946. difftool.prompt
  1947. fetch.recurseSubmodules
  1948. fetch.unpackLimit
  1949. format.attach
  1950. format.cc
  1951. format.coverLetter
  1952. format.headers
  1953. format.numbered
  1954. format.pretty
  1955. format.signature
  1956. format.signoff
  1957. format.subjectprefix
  1958. format.suffix
  1959. format.thread
  1960. format.to
  1961. gc.
  1962. gc.aggressiveWindow
  1963. gc.auto
  1964. gc.autopacklimit
  1965. gc.packrefs
  1966. gc.pruneexpire
  1967. gc.reflogexpire
  1968. gc.reflogexpireunreachable
  1969. gc.rerereresolved
  1970. gc.rerereunresolved
  1971. gitcvs.allbinary
  1972. gitcvs.commitmsgannotation
  1973. gitcvs.dbTableNamePrefix
  1974. gitcvs.dbdriver
  1975. gitcvs.dbname
  1976. gitcvs.dbpass
  1977. gitcvs.dbuser
  1978. gitcvs.enabled
  1979. gitcvs.logfile
  1980. gitcvs.usecrlfattr
  1981. guitool.
  1982. gui.blamehistoryctx
  1983. gui.commitmsgwidth
  1984. gui.copyblamethreshold
  1985. gui.diffcontext
  1986. gui.encoding
  1987. gui.fastcopyblame
  1988. gui.matchtrackingbranch
  1989. gui.newbranchtemplate
  1990. gui.pruneduringfetch
  1991. gui.spellingdictionary
  1992. gui.trustmtime
  1993. help.autocorrect
  1994. help.browser
  1995. help.format
  1996. http.lowSpeedLimit
  1997. http.lowSpeedTime
  1998. http.maxRequests
  1999. http.minSessions
  2000. http.noEPSV
  2001. http.postBuffer
  2002. http.proxy
  2003. http.sslCipherList
  2004. http.sslVersion
  2005. http.sslCAInfo
  2006. http.sslCAPath
  2007. http.sslCert
  2008. http.sslCertPasswordProtected
  2009. http.sslKey
  2010. http.sslVerify
  2011. http.useragent
  2012. i18n.commitEncoding
  2013. i18n.logOutputEncoding
  2014. imap.authMethod
  2015. imap.folder
  2016. imap.host
  2017. imap.pass
  2018. imap.port
  2019. imap.preformattedHTML
  2020. imap.sslverify
  2021. imap.tunnel
  2022. imap.user
  2023. init.templatedir
  2024. instaweb.browser
  2025. instaweb.httpd
  2026. instaweb.local
  2027. instaweb.modulepath
  2028. instaweb.port
  2029. interactive.singlekey
  2030. log.date
  2031. log.decorate
  2032. log.showroot
  2033. mailmap.file
  2034. man.
  2035. man.viewer
  2036. merge.
  2037. merge.conflictstyle
  2038. merge.log
  2039. merge.renameLimit
  2040. merge.renormalize
  2041. merge.stat
  2042. merge.tool
  2043. merge.verbosity
  2044. mergetool.
  2045. mergetool.keepBackup
  2046. mergetool.keepTemporaries
  2047. mergetool.prompt
  2048. notes.displayRef
  2049. notes.rewrite.
  2050. notes.rewrite.amend
  2051. notes.rewrite.rebase
  2052. notes.rewriteMode
  2053. notes.rewriteRef
  2054. pack.compression
  2055. pack.deltaCacheLimit
  2056. pack.deltaCacheSize
  2057. pack.depth
  2058. pack.indexVersion
  2059. pack.packSizeLimit
  2060. pack.threads
  2061. pack.window
  2062. pack.windowMemory
  2063. pager.
  2064. pretty.
  2065. pull.octopus
  2066. pull.twohead
  2067. push.default
  2068. push.followTags
  2069. rebase.autosquash
  2070. rebase.stat
  2071. receive.autogc
  2072. receive.denyCurrentBranch
  2073. receive.denyDeleteCurrent
  2074. receive.denyDeletes
  2075. receive.denyNonFastForwards
  2076. receive.fsckObjects
  2077. receive.unpackLimit
  2078. receive.updateserverinfo
  2079. remote.pushdefault
  2080. remotes.
  2081. repack.usedeltabaseoffset
  2082. rerere.autoupdate
  2083. rerere.enabled
  2084. sendemail.
  2085. sendemail.aliasesfile
  2086. sendemail.aliasfiletype
  2087. sendemail.bcc
  2088. sendemail.cc
  2089. sendemail.cccmd
  2090. sendemail.chainreplyto
  2091. sendemail.confirm
  2092. sendemail.envelopesender
  2093. sendemail.from
  2094. sendemail.identity
  2095. sendemail.multiedit
  2096. sendemail.signedoffbycc
  2097. sendemail.smtpdomain
  2098. sendemail.smtpencryption
  2099. sendemail.smtppass
  2100. sendemail.smtpserver
  2101. sendemail.smtpserveroption
  2102. sendemail.smtpserverport
  2103. sendemail.smtpuser
  2104. sendemail.suppresscc
  2105. sendemail.suppressfrom
  2106. sendemail.thread
  2107. sendemail.to
  2108. sendemail.validate
  2109. showbranch.default
  2110. status.relativePaths
  2111. status.showUntrackedFiles
  2112. status.submodulesummary
  2113. submodule.
  2114. tar.umask
  2115. transfer.unpackLimit
  2116. url.
  2117. user.email
  2118. user.name
  2119. user.signingkey
  2120. web.browser
  2121. branch. remote.
  2122. "
  2123. }
  2124. _git_remote ()
  2125. {
  2126. local subcommands="add rename remove set-head set-branches set-url show prune update"
  2127. local subcommand="$(__git_find_on_cmdline "$subcommands")"
  2128. if [ -z "$subcommand" ]; then
  2129. __gitcomp "$subcommands"
  2130. return
  2131. fi
  2132. case "$subcommand" in
  2133. rename|remove|set-url|show|prune)
  2134. __gitcomp_nl "$(__git_remotes)"
  2135. ;;
  2136. set-head|set-branches)
  2137. __git_complete_remote_or_refspec
  2138. ;;
  2139. update)
  2140. __gitcomp "$(__git_get_config_variables "remotes")"
  2141. ;;
  2142. *)
  2143. ;;
  2144. esac
  2145. }
  2146. _git_replace ()
  2147. {
  2148. __gitcomp_nl "$(__git_refs)"
  2149. }
  2150. _git_reset ()
  2151. {
  2152. __git_has_doubledash && return
  2153. case "$cur" in
  2154. --*)
  2155. __gitcomp "--merge --mixed --hard --soft --patch"
  2156. return
  2157. ;;
  2158. esac
  2159. __gitcomp_nl "$(__git_refs)"
  2160. }
  2161. _git_revert ()
  2162. {
  2163. local dir="$(__gitdir)"
  2164. if [ -f "$dir"/REVERT_HEAD ]; then
  2165. __gitcomp "--continue --quit --abort"
  2166. return
  2167. fi
  2168. case "$cur" in
  2169. --*)
  2170. __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
  2171. return
  2172. ;;
  2173. esac
  2174. __gitcomp_nl "$(__git_refs)"
  2175. }
  2176. _git_rm ()
  2177. {
  2178. case "$cur" in
  2179. --*)
  2180. __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
  2181. return
  2182. ;;
  2183. esac
  2184. __git_complete_index_file "--cached"
  2185. }
  2186. _git_shortlog ()
  2187. {
  2188. __git_has_doubledash && return
  2189. case "$cur" in
  2190. --*)
  2191. __gitcomp "
  2192. $__git_log_common_options
  2193. $__git_log_shortlog_options
  2194. --numbered --summary
  2195. "
  2196. return
  2197. ;;
  2198. esac
  2199. __git_complete_revlist
  2200. }
  2201. _git_show ()
  2202. {
  2203. __git_has_doubledash && return
  2204. case "$cur" in
  2205. --pretty=*|--format=*)
  2206. __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
  2207. " "" "${cur#*=}"
  2208. return
  2209. ;;
  2210. --diff-algorithm=*)
  2211. __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
  2212. return
  2213. ;;
  2214. --*)
  2215. __gitcomp "--pretty= --format= --abbrev-commit --oneline
  2216. --show-signature
  2217. $__git_diff_common_options
  2218. "
  2219. return
  2220. ;;
  2221. esac
  2222. __git_complete_revlist_file
  2223. }
  2224. _git_show_branch ()
  2225. {
  2226. case "$cur" in
  2227. --*)
  2228. __gitcomp "
  2229. --all --remotes --topo-order --date-order --current --more=
  2230. --list --independent --merge-base --no-name
  2231. --color --no-color
  2232. --sha1-name --sparse --topics --reflog
  2233. "
  2234. return
  2235. ;;
  2236. esac
  2237. __git_complete_revlist
  2238. }
  2239. _git_stash ()
  2240. {
  2241. local save_opts='--all --keep-index --no-keep-index --quiet --patch --include-untracked'
  2242. local subcommands='save list show apply clear drop pop create branch'
  2243. local subcommand="$(__git_find_on_cmdline "$subcommands")"
  2244. if [ -z "$subcommand" ]; then
  2245. case "$cur" in
  2246. --*)
  2247. __gitcomp "$save_opts"
  2248. ;;
  2249. *)
  2250. if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
  2251. __gitcomp "$subcommands"
  2252. fi
  2253. ;;
  2254. esac
  2255. else
  2256. case "$subcommand,$cur" in
  2257. save,--*)
  2258. __gitcomp "$save_opts"
  2259. ;;
  2260. apply,--*|pop,--*)
  2261. __gitcomp "--index --quiet"
  2262. ;;
  2263. drop,--*)
  2264. __gitcomp "--quiet"
  2265. ;;
  2266. show,--*|branch,--*)
  2267. ;;
  2268. branch,*)
  2269. if [ $cword -eq 3 ]; then
  2270. __gitcomp_nl "$(__git_refs)";
  2271. else
  2272. __gitcomp_nl "$(git --git-dir="$(__gitdir)" stash list \
  2273. | sed -n -e 's/:.*//p')"
  2274. fi
  2275. ;;
  2276. show,*|apply,*|drop,*|pop,*)
  2277. __gitcomp_nl "$(git --git-dir="$(__gitdir)" stash list \
  2278. | sed -n -e 's/:.*//p')"
  2279. ;;
  2280. *)
  2281. ;;
  2282. esac
  2283. fi
  2284. }
  2285. _git_submodule ()
  2286. {
  2287. __git_has_doubledash && return
  2288. local subcommands="add status init deinit update summary foreach sync"
  2289. if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
  2290. case "$cur" in
  2291. --*)
  2292. __gitcomp "--quiet --cached"
  2293. ;;
  2294. *)
  2295. __gitcomp "$subcommands"
  2296. ;;
  2297. esac
  2298. return
  2299. fi
  2300. }
  2301. _git_svn ()
  2302. {
  2303. local subcommands="
  2304. init fetch clone rebase dcommit log find-rev
  2305. set-tree commit-diff info create-ignore propget
  2306. proplist show-ignore show-externals branch tag blame
  2307. migrate mkdirs reset gc
  2308. "
  2309. local subcommand="$(__git_find_on_cmdline "$subcommands")"
  2310. if [ -z "$subcommand" ]; then
  2311. __gitcomp "$subcommands"
  2312. else
  2313. local remote_opts="--username= --config-dir= --no-auth-cache"
  2314. local fc_opts="
  2315. --follow-parent --authors-file= --repack=
  2316. --no-metadata --use-svm-props --use-svnsync-props
  2317. --log-window-size= --no-checkout --quiet
  2318. --repack-flags --use-log-author --localtime
  2319. --ignore-paths= --include-paths= $remote_opts
  2320. "
  2321. local init_opts="
  2322. --template= --shared= --trunk= --tags=
  2323. --branches= --stdlayout --minimize-url
  2324. --no-metadata --use-svm-props --use-svnsync-props
  2325. --rewrite-root= --prefix= --use-log-author
  2326. --add-author-from $remote_opts
  2327. "
  2328. local cmt_opts="
  2329. --edit --rmdir --find-copies-harder --copy-similarity=
  2330. "
  2331. case "$subcommand,$cur" in
  2332. fetch,--*)
  2333. __gitcomp "--revision= --fetch-all $fc_opts"
  2334. ;;
  2335. clone,--*)
  2336. __gitcomp "--revision= $fc_opts $init_opts"
  2337. ;;
  2338. init,--*)
  2339. __gitcomp "$init_opts"
  2340. ;;
  2341. dcommit,--*)
  2342. __gitcomp "
  2343. --merge --strategy= --verbose --dry-run
  2344. --fetch-all --no-rebase --commit-url
  2345. --revision --interactive $cmt_opts $fc_opts
  2346. "
  2347. ;;
  2348. set-tree,--*)
  2349. __gitcomp "--stdin $cmt_opts $fc_opts"
  2350. ;;
  2351. create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
  2352. show-externals,--*|mkdirs,--*)
  2353. __gitcomp "--revision="
  2354. ;;
  2355. log,--*)
  2356. __gitcomp "
  2357. --limit= --revision= --verbose --incremental
  2358. --oneline --show-commit --non-recursive
  2359. --authors-file= --color
  2360. "
  2361. ;;
  2362. rebase,--*)
  2363. __gitcomp "
  2364. --merge --verbose --strategy= --local
  2365. --fetch-all --dry-run $fc_opts
  2366. "
  2367. ;;
  2368. commit-diff,--*)
  2369. __gitcomp "--message= --file= --revision= $cmt_opts"
  2370. ;;
  2371. info,--*)
  2372. __gitcomp "--url"
  2373. ;;
  2374. branch,--*)
  2375. __gitcomp "--dry-run --message --tag"
  2376. ;;
  2377. tag,--*)
  2378. __gitcomp "--dry-run --message"
  2379. ;;
  2380. blame,--*)
  2381. __gitcomp "--git-format"
  2382. ;;
  2383. migrate,--*)
  2384. __gitcomp "
  2385. --config-dir= --ignore-paths= --minimize
  2386. --no-auth-cache --username=
  2387. "
  2388. ;;
  2389. reset,--*)
  2390. __gitcomp "--revision= --parent"
  2391. ;;
  2392. *)
  2393. ;;
  2394. esac
  2395. fi
  2396. }
  2397. _git_tag ()
  2398. {
  2399. local i c=1 f=0
  2400. while [ $c -lt $cword ]; do
  2401. i="${words[c]}"
  2402. case "$i" in
  2403. -d|-v)
  2404. __gitcomp_nl "$(__git_tags)"
  2405. return
  2406. ;;
  2407. -f)
  2408. f=1
  2409. ;;
  2410. esac
  2411. ((c++))
  2412. done
  2413. case "$prev" in
  2414. -m|-F)
  2415. ;;
  2416. -*|tag)
  2417. if [ $f = 1 ]; then
  2418. __gitcomp_nl "$(__git_tags)"
  2419. fi
  2420. ;;
  2421. *)
  2422. __gitcomp_nl "$(__git_refs)"
  2423. ;;
  2424. esac
  2425. case "$cur" in
  2426. --*)
  2427. __gitcomp "
  2428. --list --delete --verify --annotate --message --file
  2429. --sign --cleanup --local-user --force --column --sort
  2430. --contains --points-at
  2431. "
  2432. ;;
  2433. esac
  2434. }
  2435. _git_whatchanged ()
  2436. {
  2437. _git_log
  2438. }
  2439. __git_main ()
  2440. {
  2441. local i c=1 command __git_dir
  2442. while [ $c -lt $cword ]; do
  2443. i="${words[c]}"
  2444. case "$i" in
  2445. --git-dir=*) __git_dir="${i#--git-dir=}" ;;
  2446. --git-dir) ((c++)) ; __git_dir="${words[c]}" ;;
  2447. --bare) __git_dir="." ;;
  2448. --help) command="help"; break ;;
  2449. -c|--work-tree|--namespace) ((c++)) ;;
  2450. -*) ;;
  2451. *) command="$i"; break ;;
  2452. esac
  2453. ((c++))
  2454. done
  2455. if [ -z "$command" ]; then
  2456. case "$cur" in
  2457. --*) __gitcomp "
  2458. --paginate
  2459. --no-pager
  2460. --git-dir=
  2461. --bare
  2462. --version
  2463. --exec-path
  2464. --exec-path=
  2465. --html-path
  2466. --man-path
  2467. --info-path
  2468. --work-tree=
  2469. --namespace=
  2470. --no-replace-objects
  2471. --help
  2472. "
  2473. ;;
  2474. *) __git_compute_porcelain_commands
  2475. __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
  2476. esac
  2477. return
  2478. fi
  2479. local completion_func="_git_${command//-/_}"
  2480. declare -f $completion_func >/dev/null && $completion_func && return
  2481. local expansion=$(__git_aliased_command "$command")
  2482. if [ -n "$expansion" ]; then
  2483. words[1]=$expansion
  2484. completion_func="_git_${expansion//-/_}"
  2485. declare -f $completion_func >/dev/null && $completion_func
  2486. fi
  2487. }
  2488. __gitk_main ()
  2489. {
  2490. __git_has_doubledash && return
  2491. local g="$(__gitdir)"
  2492. local merge=""
  2493. if [ -f "$g/MERGE_HEAD" ]; then
  2494. merge="--merge"
  2495. fi
  2496. case "$cur" in
  2497. --*)
  2498. __gitcomp "
  2499. $__git_log_common_options
  2500. $__git_log_gitk_options
  2501. $merge
  2502. "
  2503. return
  2504. ;;
  2505. esac
  2506. __git_complete_revlist
  2507. }
  2508. if [[ -n ${ZSH_VERSION-} ]]; then
  2509. echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
  2510. autoload -U +X compinit && compinit
  2511. __gitcomp ()
  2512. {
  2513. emulate -L zsh
  2514. local cur_="${3-$cur}"
  2515. case "$cur_" in
  2516. --*=)
  2517. ;;
  2518. *)
  2519. local c IFS=$' \t\n'
  2520. local -a array
  2521. for c in ${=1}; do
  2522. c="$c${4-}"
  2523. case $c in
  2524. --*=*|*.) ;;
  2525. *) c="$c " ;;
  2526. esac
  2527. array[${#array[@]}+1]="$c"
  2528. done
  2529. compset -P '*[=:]'
  2530. compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
  2531. ;;
  2532. esac
  2533. }
  2534. __gitcomp_nl ()
  2535. {
  2536. emulate -L zsh
  2537. local IFS=$'\n'
  2538. compset -P '*[=:]'
  2539. compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
  2540. }
  2541. __gitcomp_file ()
  2542. {
  2543. emulate -L zsh
  2544. local IFS=$'\n'
  2545. compset -P '*[=:]'
  2546. compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
  2547. }
  2548. _git ()
  2549. {
  2550. local _ret=1 cur cword prev
  2551. cur=${words[CURRENT]}
  2552. prev=${words[CURRENT-1]}
  2553. let cword=CURRENT-1
  2554. emulate ksh -c __${service}_main
  2555. let _ret && _default && _ret=0
  2556. return _ret
  2557. }
  2558. compdef _git git gitk
  2559. return
  2560. fi
  2561. __git_func_wrap ()
  2562. {
  2563. local cur words cword prev
  2564. _get_comp_words_by_ref -n =: cur words cword prev
  2565. $1
  2566. }
  2567. # Setup completion for certain functions defined above by setting common
  2568. # variables and workarounds.
  2569. # This is NOT a public function; use at your own risk.
  2570. __git_complete ()
  2571. {
  2572. local wrapper="__git_wrap${2}"
  2573. eval "$wrapper () { __git_func_wrap $2 ; }"
  2574. complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
  2575. || complete -o default -o nospace -F $wrapper $1
  2576. }
  2577. # wrapper for backwards compatibility
  2578. _git ()
  2579. {
  2580. __git_wrap__git_main
  2581. }
  2582. # wrapper for backwards compatibility
  2583. _gitk ()
  2584. {
  2585. __git_wrap__gitk_main
  2586. }
  2587. __git_complete git __git_main
  2588. __git_complete gitk __gitk_main
  2589. # The following are necessary only for Cygwin, and only are needed
  2590. # when the user has tab-completed the executable name and consequently
  2591. # included the '.exe' suffix.
  2592. #
  2593. if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
  2594. __git_complete git.exe __git_main
  2595. fi