git-completion.bash 53 KB

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