The aptly named.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2739 lines
67 KiB

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