git-completion.bash 53 KB

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