[关闭]
@Zjmainstay 2015-10-21T14:17:54.000000Z 字数 43965 阅读 1062

.git-completion.bash

git gitconfig


  1. # bash/zsh completion support for core Git.
  2. #
  3. # Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
  4. # Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
  5. # Distributed under the GNU General Public License, version 2.0.
  6. #
  7. # The contained completion routines provide support for completing:
  8. #
  9. # *) local and remote branch names
  10. # *) local and remote tag names
  11. # *) .git/remotes file names
  12. # *) git 'subcommands'
  13. # *) tree paths within 'ref:path/to/file' expressions
  14. # *) file paths within current working directory and index
  15. # *) common --long-options
  16. #
  17. # To use these routines:
  18. #
  19. # 1) Copy this file to somewhere (e.g. ~/.git-completion.bash).
  20. # 2) Add the following line to your .bashrc/.zshrc:
  21. # source ~/.git-completion.bash
  22. # 3) Consider changing your PS1 to also show the current branch,
  23. # see git-prompt.sh for details.
  24. 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_recurse_submodules="yes on-demand no"
  1141. __git_fetch_options="
  1142. --quiet --verbose --append --upload-pack --force --keep --depth=
  1143. --tags --no-tags --all --prune --dry-run --recurse-submodules=
  1144. "
  1145. _git_fetch ()
  1146. {
  1147. case "$cur" in
  1148. --recurse-submodules=*)
  1149. __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
  1150. return
  1151. ;;
  1152. --*)
  1153. __gitcomp "$__git_fetch_options"
  1154. return
  1155. ;;
  1156. esac
  1157. __git_complete_remote_or_refspec
  1158. }
  1159. __git_format_patch_options="
  1160. --stdout --attach --no-attach --thread --thread= --no-thread
  1161. --numbered --start-number --numbered-files --keep-subject --signoff
  1162. --signature --no-signature --in-reply-to= --cc= --full-index --binary
  1163. --not --all --cover-letter --no-prefix --src-prefix= --dst-prefix=
  1164. --inline --suffix= --ignore-if-in-upstream --subject-prefix=
  1165. --output-directory --reroll-count --to= --quiet --notes
  1166. "
  1167. _git_format_patch ()
  1168. {
  1169. case "$cur" in
  1170. --thread=*)
  1171. __gitcomp "
  1172. deep shallow
  1173. " "" "${cur##--thread=}"
  1174. return
  1175. ;;
  1176. --*)
  1177. __gitcomp "$__git_format_patch_options"
  1178. return
  1179. ;;
  1180. esac
  1181. __git_complete_revlist
  1182. }
  1183. _git_fsck ()
  1184. {
  1185. case "$cur" in
  1186. --*)
  1187. __gitcomp "
  1188. --tags --root --unreachable --cache --no-reflogs --full
  1189. --strict --verbose --lost-found
  1190. "
  1191. return
  1192. ;;
  1193. esac
  1194. }
  1195. _git_gc ()
  1196. {
  1197. case "$cur" in
  1198. --*)
  1199. __gitcomp "--prune --aggressive"
  1200. return
  1201. ;;
  1202. esac
  1203. }
  1204. _git_gitk ()
  1205. {
  1206. _gitk
  1207. }
  1208. __git_match_ctag() {
  1209. awk "/^${1////\\/}/ { print \$1 }" "$2"
  1210. }
  1211. _git_grep ()
  1212. {
  1213. __git_has_doubledash && return
  1214. case "$cur" in
  1215. --*)
  1216. __gitcomp "
  1217. --cached
  1218. --text --ignore-case --word-regexp --invert-match
  1219. --full-name --line-number
  1220. --extended-regexp --basic-regexp --fixed-strings
  1221. --perl-regexp
  1222. --files-with-matches --name-only
  1223. --files-without-match
  1224. --max-depth
  1225. --count
  1226. --and --or --not --all-match
  1227. "
  1228. return
  1229. ;;
  1230. esac
  1231. case "$cword,$prev" in
  1232. 2,*|*,-*)
  1233. if test -r tags; then
  1234. __gitcomp_nl "$(__git_match_ctag "$cur" tags)"
  1235. return
  1236. fi
  1237. ;;
  1238. esac
  1239. __gitcomp_nl "$(__git_refs)"
  1240. }
  1241. _git_help ()
  1242. {
  1243. case "$cur" in
  1244. --*)
  1245. __gitcomp "--all --info --man --web"
  1246. return
  1247. ;;
  1248. esac
  1249. __git_compute_all_commands
  1250. __gitcomp "$__git_all_commands $(__git_aliases)
  1251. attributes cli core-tutorial cvs-migration
  1252. diffcore gitk glossary hooks ignore modules
  1253. namespaces repository-layout tutorial tutorial-2
  1254. workflows
  1255. "
  1256. }
  1257. _git_init ()
  1258. {
  1259. case "$cur" in
  1260. --shared=*)
  1261. __gitcomp "
  1262. false true umask group all world everybody
  1263. " "" "${cur##--shared=}"
  1264. return
  1265. ;;
  1266. --*)
  1267. __gitcomp "--quiet --bare --template= --shared --shared="
  1268. return
  1269. ;;
  1270. esac
  1271. }
  1272. _git_ls_files ()
  1273. {
  1274. case "$cur" in
  1275. --*)
  1276. __gitcomp "--cached --deleted --modified --others --ignored
  1277. --stage --directory --no-empty-directory --unmerged
  1278. --killed --exclude= --exclude-from=
  1279. --exclude-per-directory= --exclude-standard
  1280. --error-unmatch --with-tree= --full-name
  1281. --abbrev --ignored --exclude-per-directory
  1282. "
  1283. return
  1284. ;;
  1285. esac
  1286. # XXX ignore options like --modified and always suggest all cached
  1287. # files.
  1288. __git_complete_index_file "--cached"
  1289. }
  1290. _git_ls_remote ()
  1291. {
  1292. __gitcomp_nl "$(__git_remotes)"
  1293. }
  1294. _git_ls_tree ()
  1295. {
  1296. __git_complete_file
  1297. }
  1298. # Options that go well for log, shortlog and gitk
  1299. __git_log_common_options="
  1300. --not --all
  1301. --branches --tags --remotes
  1302. --first-parent --merges --no-merges
  1303. --max-count=
  1304. --max-age= --since= --after=
  1305. --min-age= --until= --before=
  1306. --min-parents= --max-parents=
  1307. --no-min-parents --no-max-parents
  1308. "
  1309. # Options that go well for log and gitk (not shortlog)
  1310. __git_log_gitk_options="
  1311. --dense --sparse --full-history
  1312. --simplify-merges --simplify-by-decoration
  1313. --left-right --notes --no-notes
  1314. "
  1315. # Options that go well for log and shortlog (not gitk)
  1316. __git_log_shortlog_options="
  1317. --author= --committer= --grep=
  1318. --all-match
  1319. "
  1320. __git_log_pretty_formats="oneline short medium full fuller email raw format:"
  1321. __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
  1322. _git_log ()
  1323. {
  1324. __git_has_doubledash && return
  1325. local g="$(git rev-parse --git-dir 2>/dev/null)"
  1326. local merge=""
  1327. if [ -f "$g/MERGE_HEAD" ]; then
  1328. merge="--merge"
  1329. fi
  1330. case "$cur" in
  1331. --pretty=*|--format=*)
  1332. __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
  1333. " "" "${cur#*=}"
  1334. return
  1335. ;;
  1336. --date=*)
  1337. __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
  1338. return
  1339. ;;
  1340. --decorate=*)
  1341. __gitcomp "long short" "" "${cur##--decorate=}"
  1342. return
  1343. ;;
  1344. --*)
  1345. __gitcomp "
  1346. $__git_log_common_options
  1347. $__git_log_shortlog_options
  1348. $__git_log_gitk_options
  1349. --root --topo-order --date-order --reverse
  1350. --follow --full-diff
  1351. --abbrev-commit --abbrev=
  1352. --relative-date --date=
  1353. --pretty= --format= --oneline
  1354. --cherry-pick
  1355. --graph
  1356. --decorate --decorate=
  1357. --walk-reflogs
  1358. --parents --children
  1359. $merge
  1360. $__git_diff_common_options
  1361. --pickaxe-all --pickaxe-regex
  1362. "
  1363. return
  1364. ;;
  1365. esac
  1366. __git_complete_revlist
  1367. }
  1368. __git_merge_options="
  1369. --no-commit --no-stat --log --no-log --squash --strategy
  1370. --commit --stat --no-squash --ff --no-ff --ff-only --edit --no-edit
  1371. "
  1372. _git_merge ()
  1373. {
  1374. __git_complete_strategy && return
  1375. case "$cur" in
  1376. --*)
  1377. __gitcomp "$__git_merge_options"
  1378. return
  1379. esac
  1380. __gitcomp_nl "$(__git_refs)"
  1381. }
  1382. _git_mergetool ()
  1383. {
  1384. case "$cur" in
  1385. --tool=*)
  1386. __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
  1387. return
  1388. ;;
  1389. --*)
  1390. __gitcomp "--tool="
  1391. return
  1392. ;;
  1393. esac
  1394. }
  1395. _git_merge_base ()
  1396. {
  1397. case "$cur" in
  1398. --*)
  1399. __gitcomp "--octopus --independent --is-ancestor --fork-point"
  1400. return
  1401. ;;
  1402. esac
  1403. __gitcomp_nl "$(__git_refs)"
  1404. }
  1405. _git_mv ()
  1406. {
  1407. case "$cur" in
  1408. --*)
  1409. __gitcomp "--dry-run"
  1410. return
  1411. ;;
  1412. esac
  1413. if [ $(__git_count_arguments "mv") -gt 0 ]; then
  1414. # We need to show both cached and untracked files (including
  1415. # empty directories) since this may not be the last argument.
  1416. __git_complete_index_file "--cached --others --directory"
  1417. else
  1418. __git_complete_index_file "--cached"
  1419. fi
  1420. }
  1421. _git_name_rev ()
  1422. {
  1423. __gitcomp "--tags --all --stdin"
  1424. }
  1425. _git_notes ()
  1426. {
  1427. local subcommands='add append copy edit list prune remove show'
  1428. local subcommand="$(__git_find_on_cmdline "$subcommands")"
  1429. case "$subcommand,$cur" in
  1430. ,--*)
  1431. __gitcomp '--ref'
  1432. ;;
  1433. ,*)
  1434. case "$prev" in
  1435. --ref)
  1436. __gitcomp_nl "$(__git_refs)"
  1437. ;;
  1438. *)
  1439. __gitcomp "$subcommands --ref"
  1440. ;;
  1441. esac
  1442. ;;
  1443. add,--reuse-message=*|append,--reuse-message=*|\
  1444. add,--reedit-message=*|append,--reedit-message=*)
  1445. __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
  1446. ;;
  1447. add,--*|append,--*)
  1448. __gitcomp '--file= --message= --reedit-message=
  1449. --reuse-message='
  1450. ;;
  1451. copy,--*)
  1452. __gitcomp '--stdin'
  1453. ;;
  1454. prune,--*)
  1455. __gitcomp '--dry-run --verbose'
  1456. ;;
  1457. prune,*)
  1458. ;;
  1459. *)
  1460. case "$prev" in
  1461. -m|-F)
  1462. ;;
  1463. *)
  1464. __gitcomp_nl "$(__git_refs)"
  1465. ;;
  1466. esac
  1467. ;;
  1468. esac
  1469. }
  1470. _git_pull ()
  1471. {
  1472. __git_complete_strategy && return
  1473. case "$cur" in
  1474. --recurse-submodules=*)
  1475. __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
  1476. return
  1477. ;;
  1478. --*)
  1479. __gitcomp "
  1480. --rebase --no-rebase
  1481. $__git_merge_options
  1482. $__git_fetch_options
  1483. "
  1484. return
  1485. ;;
  1486. esac
  1487. __git_complete_remote_or_refspec
  1488. }
  1489. __git_push_recurse_submodules="check on-demand"
  1490. _git_push ()
  1491. {
  1492. case "$prev" in
  1493. --repo)
  1494. __gitcomp_nl "$(__git_remotes)"
  1495. return
  1496. esac
  1497. case "$cur" in
  1498. --repo=*)
  1499. __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
  1500. return
  1501. ;;
  1502. --recurse-submodules=*)
  1503. __gitcomp "$__git_push_recurse_submodules" "" "${cur##--recurse-submodules=}"
  1504. return
  1505. ;;
  1506. --*)
  1507. __gitcomp "
  1508. --all --mirror --tags --dry-run --force --verbose
  1509. --receive-pack= --repo= --set-upstream
  1510. --recurse-submodules=
  1511. "
  1512. return
  1513. ;;
  1514. esac
  1515. __git_complete_remote_or_refspec
  1516. }
  1517. _git_rebase ()
  1518. {
  1519. local dir="$(__gitdir)"
  1520. if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
  1521. __gitcomp "--continue --skip --abort"
  1522. return
  1523. fi
  1524. __git_complete_strategy && return
  1525. case "$cur" in
  1526. --whitespace=*)
  1527. __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
  1528. return
  1529. ;;
  1530. --*)
  1531. __gitcomp "
  1532. --onto --merge --strategy --interactive
  1533. --preserve-merges --stat --no-stat
  1534. --committer-date-is-author-date --ignore-date
  1535. --ignore-whitespace --whitespace=
  1536. --autosquash --fork-point --no-fork-point
  1537. "
  1538. return
  1539. esac
  1540. __gitcomp_nl "$(__git_refs)"
  1541. }
  1542. _git_reflog ()
  1543. {
  1544. local subcommands="show delete expire"
  1545. local subcommand="$(__git_find_on_cmdline "$subcommands")"
  1546. if [ -z "$subcommand" ]; then
  1547. __gitcomp "$subcommands"
  1548. else
  1549. __gitcomp_nl "$(__git_refs)"
  1550. fi
  1551. }
  1552. __git_send_email_confirm_options="always never auto cc compose"
  1553. __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
  1554. _git_send_email ()
  1555. {
  1556. case "$cur" in
  1557. --confirm=*)
  1558. __gitcomp "
  1559. $__git_send_email_confirm_options
  1560. " "" "${cur##--confirm=}"
  1561. return
  1562. ;;
  1563. --suppress-cc=*)
  1564. __gitcomp "
  1565. $__git_send_email_suppresscc_options
  1566. " "" "${cur##--suppress-cc=}"
  1567. return
  1568. ;;
  1569. --smtp-encryption=*)
  1570. __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
  1571. return
  1572. ;;
  1573. --thread=*)
  1574. __gitcomp "
  1575. deep shallow
  1576. " "" "${cur##--thread=}"
  1577. return
  1578. ;;
  1579. --*)
  1580. __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
  1581. --compose --confirm= --dry-run --envelope-sender
  1582. --from --identity
  1583. --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
  1584. --no-suppress-from --no-thread --quiet
  1585. --signed-off-by-cc --smtp-pass --smtp-server
  1586. --smtp-server-port --smtp-encryption= --smtp-user
  1587. --subject --suppress-cc= --suppress-from --thread --to
  1588. --validate --no-validate
  1589. $__git_format_patch_options"
  1590. return
  1591. ;;
  1592. esac
  1593. __git_complete_revlist
  1594. }
  1595. _git_stage ()
  1596. {
  1597. _git_add
  1598. }
  1599. __git_config_get_set_variables ()
  1600. {
  1601. local prevword word config_file= c=$cword
  1602. while [ $c -gt 1 ]; do
  1603. word="${words[c]}"
  1604. case "$word" in
  1605. --system|--global|--local|--file=*)
  1606. config_file="$word"
  1607. break
  1608. ;;
  1609. -f|--file)
  1610. config_file="$word $prevword"
  1611. break
  1612. ;;
  1613. esac
  1614. prevword=$word
  1615. c=$((--c))
  1616. done
  1617. git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
  1618. while read -r line
  1619. do
  1620. case "$line" in
  1621. *.*=*)
  1622. echo "${line/=*/}"
  1623. ;;
  1624. esac
  1625. done
  1626. }
  1627. _git_config ()
  1628. {
  1629. case "$prev" in
  1630. branch.*.remote|branch.*.pushremote)
  1631. __gitcomp_nl "$(__git_remotes)"
  1632. return
  1633. ;;
  1634. branch.*.merge)
  1635. __gitcomp_nl "$(__git_refs)"
  1636. return
  1637. ;;
  1638. branch.*.rebase)
  1639. __gitcomp "false true"
  1640. return
  1641. ;;
  1642. remote.pushdefault)
  1643. __gitcomp_nl "$(__git_remotes)"
  1644. return
  1645. ;;
  1646. remote.*.fetch)
  1647. local remote="${prev#remote.}"
  1648. remote="${remote%.fetch}"
  1649. if [ -z "$cur" ]; then
  1650. __gitcomp_nl "refs/heads/" "" "" ""
  1651. return
  1652. fi
  1653. __gitcomp_nl "$(__git_refs_remotes "$remote")"
  1654. return
  1655. ;;
  1656. remote.*.push)
  1657. local remote="${prev#remote.}"
  1658. remote="${remote%.push}"
  1659. __gitcomp_nl "$(git --git-dir="$(__gitdir)" \
  1660. for-each-ref --format='%(refname):%(refname)' \
  1661. refs/heads)"
  1662. return
  1663. ;;
  1664. pull.twohead|pull.octopus)
  1665. __git_compute_merge_strategies
  1666. __gitcomp "$__git_merge_strategies"
  1667. return
  1668. ;;
  1669. color.branch|color.diff|color.interactive|\
  1670. color.showbranch|color.status|color.ui)
  1671. __gitcomp "always never auto"
  1672. return
  1673. ;;
  1674. color.pager)
  1675. __gitcomp "false true"
  1676. return
  1677. ;;
  1678. color.*.*)
  1679. __gitcomp "
  1680. normal black red green yellow blue magenta cyan white
  1681. bold dim ul blink reverse
  1682. "
  1683. return
  1684. ;;
  1685. diff.submodule)
  1686. __gitcomp "log short"
  1687. return
  1688. ;;
  1689. help.format)
  1690. __gitcomp "man info web html"
  1691. return
  1692. ;;
  1693. log.date)
  1694. __gitcomp "$__git_log_date_formats"
  1695. return
  1696. ;;
  1697. sendemail.aliasesfiletype)
  1698. __gitcomp "mutt mailrc pine elm gnus"
  1699. return
  1700. ;;
  1701. sendemail.confirm)
  1702. __gitcomp "$__git_send_email_confirm_options"
  1703. return
  1704. ;;
  1705. sendemail.suppresscc)
  1706. __gitcomp "$__git_send_email_suppresscc_options"
  1707. return
  1708. ;;
  1709. --get|--get-all|--unset|--unset-all)
  1710. __gitcomp_nl "$(__git_config_get_set_variables)"
  1711. return
  1712. ;;
  1713. *.*)
  1714. return
  1715. ;;
  1716. esac
  1717. case "$cur" in
  1718. --*)
  1719. __gitcomp "
  1720. --system --global --local --file=
  1721. --list --replace-all
  1722. --get --get-all --get-regexp
  1723. --add --unset --unset-all
  1724. --remove-section --rename-section
  1725. "
  1726. return
  1727. ;;
  1728. branch.*.*)
  1729. local pfx="${cur%.*}." cur_="${cur##*.}"
  1730. __gitcomp "remote pushremote merge mergeoptions rebase" "$pfx" "$cur_"
  1731. return
  1732. ;;
  1733. branch.*)
  1734. local pfx="${cur%.*}." cur_="${cur#*.}"
  1735. __gitcomp_nl "$(__git_heads)" "$pfx" "$cur_" "."
  1736. __gitcomp_nl_append $'autosetupmerge\nautosetuprebase\n' "$pfx" "$cur_"
  1737. return
  1738. ;;
  1739. guitool.*.*)
  1740. local pfx="${cur%.*}." cur_="${cur##*.}"
  1741. __gitcomp "
  1742. argprompt cmd confirm needsfile noconsole norescan
  1743. prompt revprompt revunmerged title
  1744. " "$pfx" "$cur_"
  1745. return
  1746. ;;
  1747. difftool.*.*)
  1748. local pfx="${cur%.*}." cur_="${cur##*.}"
  1749. __gitcomp "cmd path" "$pfx" "$cur_"
  1750. return
  1751. ;;
  1752. man.*.*)
  1753. local pfx="${cur%.*}." cur_="${cur##*.}"
  1754. __gitcomp "cmd path" "$pfx" "$cur_"
  1755. return
  1756. ;;
  1757. mergetool.*.*)
  1758. local pfx="${cur%.*}." cur_="${cur##*.}"
  1759. __gitcomp "cmd path trustExitCode" "$pfx" "$cur_"
  1760. return
  1761. ;;
  1762. pager.*)
  1763. local pfx="${cur%.*}." cur_="${cur#*.}"
  1764. __git_compute_all_commands
  1765. __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_"
  1766. return
  1767. ;;
  1768. remote.*.*)
  1769. local pfx="${cur%.*}." cur_="${cur##*.}"
  1770. __gitcomp "
  1771. url proxy fetch push mirror skipDefaultUpdate
  1772. receivepack uploadpack tagopt pushurl
  1773. " "$pfx" "$cur_"
  1774. return
  1775. ;;
  1776. remote.*)
  1777. local pfx="${cur%.*}." cur_="${cur#*.}"
  1778. __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
  1779. __gitcomp_nl_append "pushdefault" "$pfx" "$cur_"
  1780. return
  1781. ;;
  1782. url.*.*)
  1783. local pfx="${cur%.*}." cur_="${cur##*.}"
  1784. __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_"
  1785. return
  1786. ;;
  1787. esac
  1788. __gitcomp "
  1789. add.ignoreErrors
  1790. advice.commitBeforeMerge
  1791. advice.detachedHead
  1792. advice.implicitIdentity
  1793. advice.pushNonFastForward
  1794. advice.resolveConflict
  1795. advice.statusHints
  1796. alias.
  1797. am.keepcr
  1798. apply.ignorewhitespace
  1799. apply.whitespace
  1800. branch.autosetupmerge
  1801. branch.autosetuprebase
  1802. browser.
  1803. clean.requireForce
  1804. color.branch
  1805. color.branch.current
  1806. color.branch.local
  1807. color.branch.plain
  1808. color.branch.remote
  1809. color.decorate.HEAD
  1810. color.decorate.branch
  1811. color.decorate.remoteBranch
  1812. color.decorate.stash
  1813. color.decorate.tag
  1814. color.diff
  1815. color.diff.commit
  1816. color.diff.frag
  1817. color.diff.func
  1818. color.diff.meta
  1819. color.diff.new
  1820. color.diff.old
  1821. color.diff.plain
  1822. color.diff.whitespace
  1823. color.grep
  1824. color.grep.context
  1825. color.grep.filename
  1826. color.grep.function
  1827. color.grep.linenumber
  1828. color.grep.match
  1829. color.grep.selected
  1830. color.grep.separator
  1831. color.interactive
  1832. color.interactive.error
  1833. color.interactive.header
  1834. color.interactive.help
  1835. color.interactive.prompt
  1836. color.pager
  1837. color.showbranch
  1838. color.status
  1839. color.status.added
  1840. color.status.changed
  1841. color.status.header
  1842. color.status.nobranch
  1843. color.status.untracked
  1844. color.status.updated
  1845. color.ui
  1846. commit.status
  1847. commit.template
  1848. core.abbrev
  1849. core.askpass
  1850. core.attributesfile
  1851. core.autocrlf
  1852. core.bare
  1853. core.bigFileThreshold
  1854. core.compression
  1855. core.createObject
  1856. core.deltaBaseCacheLimit
  1857. core.editor
  1858. core.eol
  1859. core.excludesfile
  1860. core.fileMode
  1861. core.fsyncobjectfiles
  1862. core.gitProxy
  1863. core.ignoreStat
  1864. core.ignorecase
  1865. core.logAllRefUpdates
  1866. core.loosecompression
  1867. core.notesRef
  1868. core.packedGitLimit
  1869. core.packedGitWindowSize
  1870. core.pager
  1871. core.preferSymlinkRefs
  1872. core.preloadindex
  1873. core.quotepath
  1874. core.repositoryFormatVersion
  1875. core.safecrlf
  1876. core.sharedRepository
  1877. core.sparseCheckout
  1878. core.symlinks
  1879. core.trustctime
  1880. core.warnAmbiguousRefs
  1881. core.whitespace
  1882. core.worktree
  1883. diff.autorefreshindex
  1884. diff.external
  1885. diff.ignoreSubmodules
  1886. diff.mnemonicprefix
  1887. diff.noprefix
  1888. diff.renameLimit
  1889. diff.renames
  1890. diff.statGraphWidth
  1891. diff.submodule
  1892. diff.suppressBlankEmpty
  1893. diff.tool
  1894. diff.wordRegex
  1895. diff.algorithm
  1896. difftool.
  1897. difftool.prompt
  1898. fetch.recurseSubmodules
  1899. fetch.unpackLimit
  1900. format.attach
  1901. format.cc
  1902. format.coverLetter
  1903. format.headers
  1904. format.numbered
  1905. format.pretty
  1906. format.signature
  1907. format.signoff
  1908. format.subjectprefix
  1909. format.suffix
  1910. format.thread
  1911. format.to
  1912. gc.
  1913. gc.aggressiveWindow
  1914. gc.auto
  1915. gc.autopacklimit
  1916. gc.packrefs
  1917. gc.pruneexpire
  1918. gc.reflogexpire
  1919. gc.reflogexpireunreachable
  1920. gc.rerereresolved
  1921. gc.rerereunresolved
  1922. gitcvs.allbinary
  1923. gitcvs.commitmsgannotation
  1924. gitcvs.dbTableNamePrefix
  1925. gitcvs.dbdriver
  1926. gitcvs.dbname
  1927. gitcvs.dbpass
  1928. gitcvs.dbuser
  1929. gitcvs.enabled
  1930. gitcvs.logfile
  1931. gitcvs.usecrlfattr
  1932. guitool.
  1933. gui.blamehistoryctx
  1934. gui.commitmsgwidth
  1935. gui.copyblamethreshold
  1936. gui.diffcontext
  1937. gui.encoding
  1938. gui.fastcopyblame
  1939. gui.matchtrackingbranch
  1940. gui.newbranchtemplate
  1941. gui.pruneduringfetch
  1942. gui.spellingdictionary
  1943. gui.trustmtime
  1944. help.autocorrect
  1945. help.browser
  1946. help.format
  1947. http.lowSpeedLimit
  1948. http.lowSpeedTime
  1949. http.maxRequests
  1950. http.minSessions
  1951. http.noEPSV
  1952. http.postBuffer
  1953. http.proxy
  1954. http.sslCAInfo
  1955. http.sslCAPath
  1956. http.sslCert
  1957. http.sslCertPasswordProtected
  1958. http.sslKey
  1959. http.sslVerify
  1960. http.useragent
  1961. i18n.commitEncoding
  1962. i18n.logOutputEncoding
  1963. imap.authMethod
  1964. imap.folder
  1965. imap.host
  1966. imap.pass
  1967. imap.port
  1968. imap.preformattedHTML
  1969. imap.sslverify
  1970. imap.tunnel
  1971. imap.user
  1972. init.templatedir
  1973. instaweb.browser
  1974. instaweb.httpd
  1975. instaweb.local
  1976. instaweb.modulepath
  1977. instaweb.port
  1978. interactive.singlekey
  1979. log.date
  1980. log.decorate
  1981. log.showroot
  1982. mailmap.file
  1983. man.
  1984. man.viewer
  1985. merge.
  1986. merge.conflictstyle
  1987. merge.log
  1988. merge.renameLimit
  1989. merge.renormalize
  1990. merge.stat
  1991. merge.tool
  1992. merge.verbosity
  1993. mergetool.
  1994. mergetool.keepBackup
  1995. mergetool.keepTemporaries
  1996. mergetool.prompt
  1997. notes.displayRef
  1998. notes.rewrite.
  1999. notes.rewrite.amend
  2000. notes.rewrite.rebase
  2001. notes.rewriteMode
  2002. notes.rewriteRef
  2003. pack.compression
  2004. pack.deltaCacheLimit
  2005. pack.deltaCacheSize
  2006. pack.depth
  2007. pack.indexVersion
  2008. pack.packSizeLimit
  2009. pack.threads
  2010. pack.window
  2011. pack.windowMemory
  2012. pager.
  2013. pretty.
  2014. pull.octopus
  2015. pull.twohead
  2016. push.default
  2017. rebase.autosquash
  2018. rebase.stat
  2019. receive.autogc
  2020. receive.denyCurrentBranch
  2021. receive.denyDeleteCurrent
  2022. receive.denyDeletes
  2023. receive.denyNonFastForwards
  2024. receive.fsckObjects
  2025. receive.unpackLimit
  2026. receive.updateserverinfo
  2027. remote.pushdefault
  2028. remotes.
  2029. repack.usedeltabaseoffset
  2030. rerere.autoupdate
  2031. rerere.enabled
  2032. sendemail.
  2033. sendemail.aliasesfile
  2034. sendemail.aliasfiletype
  2035. sendemail.bcc
  2036. sendemail.cc
  2037. sendemail.cccmd
  2038. sendemail.chainreplyto
  2039. sendemail.confirm
  2040. sendemail.envelopesender
  2041. sendemail.from
  2042. sendemail.identity
  2043. sendemail.multiedit
  2044. sendemail.signedoffbycc
  2045. sendemail.smtpdomain
  2046. sendemail.smtpencryption
  2047. sendemail.smtppass
  2048. sendemail.smtpserver
  2049. sendemail.smtpserveroption
  2050. sendemail.smtpserverport
  2051. sendemail.smtpuser
  2052. sendemail.suppresscc
  2053. sendemail.suppressfrom
  2054. sendemail.thread
  2055. sendemail.to
  2056. sendemail.validate
  2057. showbranch.default
  2058. status.relativePaths
  2059. status.showUntrackedFiles
  2060. status.submodulesummary
  2061. submodule.
  2062. tar.umask
  2063. transfer.unpackLimit
  2064. url.
  2065. user.email
  2066. user.name
  2067. user.signingkey
  2068. web.browser
  2069. branch. remote.
  2070. "
  2071. }
  2072. _git_remote ()
  2073. {
  2074. local subcommands="add rename remove set-head set-branches set-url show prune update"
  2075. local subcommand="$(__git_find_on_cmdline "$subcommands")"
  2076. if [ -z "$subcommand" ]; then
  2077. __gitcomp "$subcommands"
  2078. return
  2079. fi
  2080. case "$subcommand" in
  2081. rename|remove|set-url|show|prune)
  2082. __gitcomp_nl "$(__git_remotes)"
  2083. ;;
  2084. set-head|set-branches)
  2085. __git_complete_remote_or_refspec
  2086. ;;
  2087. update)
  2088. local i c='' IFS=$'\n'
  2089. for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do
  2090. i="${i#remotes.}"
  2091. c="$c ${i/ */}"
  2092. done
  2093. __gitcomp "$c"
  2094. ;;
  2095. *)
  2096. ;;
  2097. esac
  2098. }
  2099. _git_replace ()
  2100. {
  2101. __gitcomp_nl "$(__git_refs)"
  2102. }
  2103. _git_reset ()
  2104. {
  2105. __git_has_doubledash && return
  2106. case "$cur" in
  2107. --*)
  2108. __gitcomp "--merge --mixed --hard --soft --patch"
  2109. return
  2110. ;;
  2111. esac
  2112. __gitcomp_nl "$(__git_refs)"
  2113. }
  2114. _git_revert ()
  2115. {
  2116. case "$cur" in
  2117. --*)
  2118. __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
  2119. return
  2120. ;;
  2121. esac
  2122. __gitcomp_nl "$(__git_refs)"
  2123. }
  2124. _git_rm ()
  2125. {
  2126. case "$cur" in
  2127. --*)
  2128. __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
  2129. return
  2130. ;;
  2131. esac
  2132. __git_complete_index_file "--cached"
  2133. }
  2134. _git_shortlog ()
  2135. {
  2136. __git_has_doubledash && return
  2137. case "$cur" in
  2138. --*)
  2139. __gitcomp "
  2140. $__git_log_common_options
  2141. $__git_log_shortlog_options
  2142. --numbered --summary
  2143. "
  2144. return
  2145. ;;
  2146. esac
  2147. __git_complete_revlist
  2148. }
  2149. _git_show ()
  2150. {
  2151. __git_has_doubledash && return
  2152. case "$cur" in
  2153. --pretty=*|--format=*)
  2154. __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
  2155. " "" "${cur#*=}"
  2156. return
  2157. ;;
  2158. --diff-algorithm=*)
  2159. __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
  2160. return
  2161. ;;
  2162. --*)
  2163. __gitcomp "--pretty= --format= --abbrev-commit --oneline
  2164. $__git_diff_common_options
  2165. "
  2166. return
  2167. ;;
  2168. esac
  2169. __git_complete_revlist_file
  2170. }
  2171. _git_show_branch ()
  2172. {
  2173. case "$cur" in
  2174. --*)
  2175. __gitcomp "
  2176. --all --remotes --topo-order --current --more=
  2177. --list --independent --merge-base --no-name
  2178. --color --no-color
  2179. --sha1-name --sparse --topics --reflog
  2180. "
  2181. return
  2182. ;;
  2183. esac
  2184. __git_complete_revlist
  2185. }
  2186. _git_stash ()
  2187. {
  2188. local save_opts='--keep-index --no-keep-index --quiet --patch'
  2189. local subcommands='save list show apply clear drop pop create branch'
  2190. local subcommand="$(__git_find_on_cmdline "$subcommands")"
  2191. if [ -z "$subcommand" ]; then
  2192. case "$cur" in
  2193. --*)
  2194. __gitcomp "$save_opts"
  2195. ;;
  2196. *)
  2197. if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
  2198. __gitcomp "$subcommands"
  2199. fi
  2200. ;;
  2201. esac
  2202. else
  2203. case "$subcommand,$cur" in
  2204. save,--*)
  2205. __gitcomp "$save_opts"
  2206. ;;
  2207. apply,--*|pop,--*)
  2208. __gitcomp "--index --quiet"
  2209. ;;
  2210. show,--*|drop,--*|branch,--*)
  2211. ;;
  2212. show,*|apply,*|drop,*|pop,*|branch,*)
  2213. __gitcomp_nl "$(git --git-dir="$(__gitdir)" stash list \
  2214. | sed -n -e 's/:.*//p')"
  2215. ;;
  2216. *)
  2217. ;;
  2218. esac
  2219. fi
  2220. }
  2221. _git_submodule ()
  2222. {
  2223. __git_has_doubledash && return
  2224. local subcommands="add status init deinit update summary foreach sync"
  2225. if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
  2226. case "$cur" in
  2227. --*)
  2228. __gitcomp "--quiet --cached"
  2229. ;;
  2230. *)
  2231. __gitcomp "$subcommands"
  2232. ;;
  2233. esac
  2234. return
  2235. fi
  2236. }
  2237. _git_svn ()
  2238. {
  2239. local subcommands="
  2240. init fetch clone rebase dcommit log find-rev
  2241. set-tree commit-diff info create-ignore propget
  2242. proplist show-ignore show-externals branch tag blame
  2243. migrate mkdirs reset gc
  2244. "
  2245. local subcommand="$(__git_find_on_cmdline "$subcommands")"
  2246. if [ -z "$subcommand" ]; then
  2247. __gitcomp "$subcommands"
  2248. else
  2249. local remote_opts="--username= --config-dir= --no-auth-cache"
  2250. local fc_opts="
  2251. --follow-parent --authors-file= --repack=
  2252. --no-metadata --use-svm-props --use-svnsync-props
  2253. --log-window-size= --no-checkout --quiet
  2254. --repack-flags --use-log-author --localtime
  2255. --ignore-paths= --include-paths= $remote_opts
  2256. "
  2257. local init_opts="
  2258. --template= --shared= --trunk= --tags=
  2259. --branches= --stdlayout --minimize-url
  2260. --no-metadata --use-svm-props --use-svnsync-props
  2261. --rewrite-root= --prefix= --use-log-author
  2262. --add-author-from $remote_opts
  2263. "
  2264. local cmt_opts="
  2265. --edit --rmdir --find-copies-harder --copy-similarity=
  2266. "
  2267. case "$subcommand,$cur" in
  2268. fetch,--*)
  2269. __gitcomp "--revision= --fetch-all $fc_opts"
  2270. ;;
  2271. clone,--*)
  2272. __gitcomp "--revision= $fc_opts $init_opts"
  2273. ;;
  2274. init,--*)
  2275. __gitcomp "$init_opts"
  2276. ;;
  2277. dcommit,--*)
  2278. __gitcomp "
  2279. --merge --strategy= --verbose --dry-run
  2280. --fetch-all --no-rebase --commit-url
  2281. --revision --interactive $cmt_opts $fc_opts
  2282. "
  2283. ;;
  2284. set-tree,--*)
  2285. __gitcomp "--stdin $cmt_opts $fc_opts"
  2286. ;;
  2287. create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
  2288. show-externals,--*|mkdirs,--*)
  2289. __gitcomp "--revision="
  2290. ;;
  2291. log,--*)
  2292. __gitcomp "
  2293. --limit= --revision= --verbose --incremental
  2294. --oneline --show-commit --non-recursive
  2295. --authors-file= --color
  2296. "
  2297. ;;
  2298. rebase,--*)
  2299. __gitcomp "
  2300. --merge --verbose --strategy= --local
  2301. --fetch-all --dry-run $fc_opts
  2302. "
  2303. ;;
  2304. commit-diff,--*)
  2305. __gitcomp "--message= --file= --revision= $cmt_opts"
  2306. ;;
  2307. info,--*)
  2308. __gitcomp "--url"
  2309. ;;
  2310. branch,--*)
  2311. __gitcomp "--dry-run --message --tag"
  2312. ;;
  2313. tag,--*)
  2314. __gitcomp "--dry-run --message"
  2315. ;;
  2316. blame,--*)
  2317. __gitcomp "--git-format"
  2318. ;;
  2319. migrate,--*)
  2320. __gitcomp "
  2321. --config-dir= --ignore-paths= --minimize
  2322. --no-auth-cache --username=
  2323. "
  2324. ;;
  2325. reset,--*)
  2326. __gitcomp "--revision= --parent"
  2327. ;;
  2328. *)
  2329. ;;
  2330. esac
  2331. fi
  2332. }
  2333. _git_tag ()
  2334. {
  2335. local i c=1 f=0
  2336. while [ $c -lt $cword ]; do
  2337. i="${words[c]}"
  2338. case "$i" in
  2339. -d|-v)
  2340. __gitcomp_nl "$(__git_tags)"
  2341. return
  2342. ;;
  2343. -f)
  2344. f=1
  2345. ;;
  2346. esac
  2347. ((c++))
  2348. done
  2349. case "$prev" in
  2350. -m|-F)
  2351. ;;
  2352. -*|tag)
  2353. if [ $f = 1 ]; then
  2354. __gitcomp_nl "$(__git_tags)"
  2355. fi
  2356. ;;
  2357. *)
  2358. __gitcomp_nl "$(__git_refs)"
  2359. ;;
  2360. esac
  2361. }
  2362. _git_whatchanged ()
  2363. {
  2364. _git_log
  2365. }
  2366. __git_main ()
  2367. {
  2368. local i c=1 command __git_dir
  2369. while [ $c -lt $cword ]; do
  2370. i="${words[c]}"
  2371. case "$i" in
  2372. --git-dir=*) __git_dir="${i#--git-dir=}" ;;
  2373. --git-dir) ((c++)) ; __git_dir="${words[c]}" ;;
  2374. --bare) __git_dir="." ;;
  2375. --help) command="help"; break ;;
  2376. -c|--work-tree|--namespace) ((c++)) ;;
  2377. -*) ;;
  2378. *) command="$i"; break ;;
  2379. esac
  2380. ((c++))
  2381. done
  2382. if [ -z "$command" ]; then
  2383. case "$cur" in
  2384. --*) __gitcomp "
  2385. --paginate
  2386. --no-pager
  2387. --git-dir=
  2388. --bare
  2389. --version
  2390. --exec-path
  2391. --exec-path=
  2392. --html-path
  2393. --man-path
  2394. --info-path
  2395. --work-tree=
  2396. --namespace=
  2397. --no-replace-objects
  2398. --help
  2399. "
  2400. ;;
  2401. *) __git_compute_porcelain_commands
  2402. __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
  2403. esac
  2404. return
  2405. fi
  2406. local completion_func="_git_${command//-/_}"
  2407. declare -f $completion_func >/dev/null && $completion_func && return
  2408. local expansion=$(__git_aliased_command "$command")
  2409. if [ -n "$expansion" ]; then
  2410. completion_func="_git_${expansion//-/_}"
  2411. declare -f $completion_func >/dev/null && $completion_func
  2412. fi
  2413. }
  2414. __gitk_main ()
  2415. {
  2416. __git_has_doubledash && return
  2417. local g="$(__gitdir)"
  2418. local merge=""
  2419. if [ -f "$g/MERGE_HEAD" ]; then
  2420. merge="--merge"
  2421. fi
  2422. case "$cur" in
  2423. --*)
  2424. __gitcomp "
  2425. $__git_log_common_options
  2426. $__git_log_gitk_options
  2427. $merge
  2428. "
  2429. return
  2430. ;;
  2431. esac
  2432. __git_complete_revlist
  2433. }
  2434. if [[ -n ${ZSH_VERSION-} ]]; then
  2435. echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
  2436. autoload -U +X compinit && compinit
  2437. __gitcomp ()
  2438. {
  2439. emulate -L zsh
  2440. local cur_="${3-$cur}"
  2441. case "$cur_" in
  2442. --*=)
  2443. ;;
  2444. *)
  2445. local c IFS=$' \t\n'
  2446. local -a array
  2447. for c in ${=1}; do
  2448. c="$c${4-}"
  2449. case $c in
  2450. --*=*|*.) ;;
  2451. *) c="$c " ;;
  2452. esac
  2453. array[${#array[@]}+1]="$c"
  2454. done
  2455. compset -P '*[=:]'
  2456. compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
  2457. ;;
  2458. esac
  2459. }
  2460. __gitcomp_nl ()
  2461. {
  2462. emulate -L zsh
  2463. local IFS=$'\n'
  2464. compset -P '*[=:]'
  2465. compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
  2466. }
  2467. __gitcomp_file ()
  2468. {
  2469. emulate -L zsh
  2470. local IFS=$'\n'
  2471. compset -P '*[=:]'
  2472. compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
  2473. }
  2474. _git ()
  2475. {
  2476. local _ret=1 cur cword prev
  2477. cur=${words[CURRENT]}
  2478. prev=${words[CURRENT-1]}
  2479. let cword=CURRENT-1
  2480. emulate ksh -c __${service}_main
  2481. let _ret && _default && _ret=0
  2482. return _ret
  2483. }
  2484. compdef _git git gitk
  2485. return
  2486. fi
  2487. __git_func_wrap ()
  2488. {
  2489. local cur words cword prev
  2490. _get_comp_words_by_ref -n =: cur words cword prev
  2491. $1
  2492. }
  2493. # Setup completion for certain functions defined above by setting common
  2494. # variables and workarounds.
  2495. # This is NOT a public function; use at your own risk.
  2496. __git_complete ()
  2497. {
  2498. local wrapper="__git_wrap${2}"
  2499. eval "$wrapper () { __git_func_wrap $2 ; }"
  2500. complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
  2501. || complete -o default -o nospace -F $wrapper $1
  2502. }
  2503. # wrapper for backwards compatibility
  2504. _git ()
  2505. {
  2506. __git_wrap__git_main
  2507. }
  2508. # wrapper for backwards compatibility
  2509. _gitk ()
  2510. {
  2511. __git_wrap__gitk_main
  2512. }
  2513. __git_complete git __git_main
  2514. __git_complete gitk __gitk_main
  2515. # The following are necessary only for Cygwin, and only are needed
  2516. # when the user has tab-completed the executable name and consequently
  2517. # included the '.exe' suffix.
  2518. #
  2519. if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
  2520. __git_complete git.exe __git_main
  2521. fi
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注