Guest User

git-completion.bash

a guest
Dec 19th, 2019
415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 71.63 KB | None | 0 0
  1. # bash/zsh completion support for core Git.
  2. #
  3. # Copyright (C) 2006,2007 Shawn O. Pearce <[email protected]>
  4. # Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
  5. # Distributed under the GNU General Public License, version 2.0.
  6. #
  7. # The contained completion routines provide support for completing:
  8. #
  9. # *) local and remote branch names
  10. # *) local and remote tag names
  11. # *) .git/remotes file names
  12. # *) git 'subcommands'
  13. # *) git email aliases for git-send-email
  14. # *) tree paths within 'ref:path/to/file' expressions
  15. # *) file paths within current working directory and index
  16. # *) common --long-options
  17. #
  18. # To use these routines:
  19. #
  20. # 1) Copy this file to somewhere (e.g. ~/.git-completion.bash).
  21. # 2) Add the following line to your .bashrc/.zshrc:
  22. # source ~/.git-completion.bash
  23. # 3) Consider changing your PS1 to also show the current branch,
  24. # see git-prompt.sh for details.
  25. #
  26. # If you use complex aliases of form '!f() { ... }; f', you can use the null
  27. # command ':' as the first command in the function body to declare the desired
  28. # completion style. For example '!f() { : git commit ; ... }; f' will
  29. # tell the completion to use commit completion. This also works with aliases
  30. # of form "!sh -c '...'". For example, "!sh -c ': git commit ; ... '".
  31. #
  32. # Compatible with bash 3.2.57.
  33. #
  34. # You can set the following environment variables to influence the behavior of
  35. # the completion routines:
  36. #
  37. # GIT_COMPLETION_CHECKOUT_NO_GUESS
  38. #
  39. # When set to "1", do not include "DWIM" suggestions in git-checkout
  40. # and git-switch completion (e.g., completing "foo" when "origin/foo"
  41. # exists).
  42.  
  43. case "$COMP_WORDBREAKS" in
  44. *:*) : great ;;
  45. *) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
  46. esac
  47.  
  48. # Discovers the path to the git repository taking any '--git-dir=<path>' and
  49. # '-C <path>' options into account and stores it in the $__git_repo_path
  50. # variable.
  51. __git_find_repo_path ()
  52. {
  53. if [ -n "$__git_repo_path" ]; then
  54. # we already know where it is
  55. return
  56. fi
  57.  
  58. if [ -n "${__git_C_args-}" ]; then
  59. __git_repo_path="$(git "${__git_C_args[@]}" \
  60. ${__git_dir:+--git-dir="$__git_dir"} \
  61. rev-parse --absolute-git-dir 2>/dev/null)"
  62. elif [ -n "${__git_dir-}" ]; then
  63. test -d "$__git_dir" &&
  64. __git_repo_path="$__git_dir"
  65. elif [ -n "${GIT_DIR-}" ]; then
  66. test -d "${GIT_DIR-}" &&
  67. __git_repo_path="$GIT_DIR"
  68. elif [ -d .git ]; then
  69. __git_repo_path=.git
  70. else
  71. __git_repo_path="$(git rev-parse --git-dir 2>/dev/null)"
  72. fi
  73. }
  74.  
  75. # Deprecated: use __git_find_repo_path() and $__git_repo_path instead
  76. # __gitdir accepts 0 or 1 arguments (i.e., location)
  77. # returns location of .git repo
  78. __gitdir ()
  79. {
  80. if [ -z "${1-}" ]; then
  81. __git_find_repo_path || return 1
  82. echo "$__git_repo_path"
  83. elif [ -d "$1/.git" ]; then
  84. echo "$1/.git"
  85. else
  86. echo "$1"
  87. fi
  88. }
  89.  
  90. # Runs git with all the options given as argument, respecting any
  91. # '--git-dir=<path>' and '-C <path>' options present on the command line
  92. __git ()
  93. {
  94. git ${__git_C_args:+"${__git_C_args[@]}"} \
  95. ${__git_dir:+--git-dir="$__git_dir"} "$@" 2>/dev/null
  96. }
  97.  
  98. # Removes backslash escaping, single quotes and double quotes from a word,
  99. # stores the result in the variable $dequoted_word.
  100. # 1: The word to dequote.
  101. __git_dequote ()
  102. {
  103. local rest="$1" len ch
  104.  
  105. dequoted_word=""
  106.  
  107. while test -n "$rest"; do
  108. len=${#dequoted_word}
  109. dequoted_word="$dequoted_word${rest%%[\\\'\"]*}"
  110. rest="${rest:$((${#dequoted_word}-$len))}"
  111.  
  112. case "${rest:0:1}" in
  113. \\)
  114. ch="${rest:1:1}"
  115. case "$ch" in
  116. $'\n')
  117. ;;
  118. *)
  119. dequoted_word="$dequoted_word$ch"
  120. ;;
  121. esac
  122. rest="${rest:2}"
  123. ;;
  124. \')
  125. rest="${rest:1}"
  126. len=${#dequoted_word}
  127. dequoted_word="$dequoted_word${rest%%\'*}"
  128. rest="${rest:$((${#dequoted_word}-$len+1))}"
  129. ;;
  130. \")
  131. rest="${rest:1}"
  132. while test -n "$rest" ; do
  133. len=${#dequoted_word}
  134. dequoted_word="$dequoted_word${rest%%[\\\"]*}"
  135. rest="${rest:$((${#dequoted_word}-$len))}"
  136. case "${rest:0:1}" in
  137. \\)
  138. ch="${rest:1:1}"
  139. case "$ch" in
  140. \"|\\|\$|\`)
  141. dequoted_word="$dequoted_word$ch"
  142. ;;
  143. $'\n')
  144. ;;
  145. *)
  146. dequoted_word="$dequoted_word\\$ch"
  147. ;;
  148. esac
  149. rest="${rest:2}"
  150. ;;
  151. \")
  152. rest="${rest:1}"
  153. break
  154. ;;
  155. esac
  156. done
  157. ;;
  158. esac
  159. done
  160. }
  161.  
  162. # The following function is based on code from:
  163. #
  164. # bash_completion - programmable completion functions for bash 3.2+
  165. #
  166. # Copyright © 2006-2008, Ian Macdonald <[email protected]>
  167. # © 2009-2010, Bash Completion Maintainers
  168. #
  169. # This program is free software; you can redistribute it and/or modify
  170. # it under the terms of the GNU General Public License as published by
  171. # the Free Software Foundation; either version 2, or (at your option)
  172. # any later version.
  173. #
  174. # This program is distributed in the hope that it will be useful,
  175. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  176. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  177. # GNU General Public License for more details.
  178. #
  179. # You should have received a copy of the GNU General Public License
  180. # along with this program; if not, see <http://www.gnu.org/licenses/>.
  181. #
  182. # The latest version of this software can be obtained here:
  183. #
  184. # http://bash-completion.alioth.debian.org/
  185. #
  186. # RELEASE: 2.x
  187.  
  188. # This function can be used to access a tokenized list of words
  189. # on the command line:
  190. #
  191. # __git_reassemble_comp_words_by_ref '=:'
  192. # if test "${words_[cword_-1]}" = -w
  193. # then
  194. # ...
  195. # fi
  196. #
  197. # The argument should be a collection of characters from the list of
  198. # word completion separators (COMP_WORDBREAKS) to treat as ordinary
  199. # characters.
  200. #
  201. # This is roughly equivalent to going back in time and setting
  202. # COMP_WORDBREAKS to exclude those characters. The intent is to
  203. # make option types like --date=<type> and <rev>:<path> easy to
  204. # recognize by treating each shell word as a single token.
  205. #
  206. # It is best not to set COMP_WORDBREAKS directly because the value is
  207. # shared with other completion scripts. By the time the completion
  208. # function gets called, COMP_WORDS has already been populated so local
  209. # changes to COMP_WORDBREAKS have no effect.
  210. #
  211. # Output: words_, cword_, cur_.
  212.  
  213. __git_reassemble_comp_words_by_ref()
  214. {
  215. local exclude i j first
  216. # Which word separators to exclude?
  217. exclude="${1//[^$COMP_WORDBREAKS]}"
  218. cword_=$COMP_CWORD
  219. if [ -z "$exclude" ]; then
  220. words_=("${COMP_WORDS[@]}")
  221. return
  222. fi
  223. # List of word completion separators has shrunk;
  224. # re-assemble words to complete.
  225. for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
  226. # Append each nonempty word consisting of just
  227. # word separator characters to the current word.
  228. first=t
  229. while
  230. [ $i -gt 0 ] &&
  231. [ -n "${COMP_WORDS[$i]}" ] &&
  232. # word consists of excluded word separators
  233. [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
  234. do
  235. # Attach to the previous token,
  236. # unless the previous token is the command name.
  237. if [ $j -ge 2 ] && [ -n "$first" ]; then
  238. ((j--))
  239. fi
  240. first=
  241. words_[$j]=${words_[j]}${COMP_WORDS[i]}
  242. if [ $i = $COMP_CWORD ]; then
  243. cword_=$j
  244. fi
  245. if (($i < ${#COMP_WORDS[@]} - 1)); then
  246. ((i++))
  247. else
  248. # Done.
  249. return
  250. fi
  251. done
  252. words_[$j]=${words_[j]}${COMP_WORDS[i]}
  253. if [ $i = $COMP_CWORD ]; then
  254. cword_=$j
  255. fi
  256. done
  257. }
  258.  
  259. if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
  260. _get_comp_words_by_ref ()
  261. {
  262. local exclude cur_ words_ cword_
  263. if [ "$1" = "-n" ]; then
  264. exclude=$2
  265. shift 2
  266. fi
  267. __git_reassemble_comp_words_by_ref "$exclude"
  268. cur_=${words_[cword_]}
  269. while [ $# -gt 0 ]; do
  270. case "$1" in
  271. cur)
  272. cur=$cur_
  273. ;;
  274. prev)
  275. prev=${words_[$cword_-1]}
  276. ;;
  277. words)
  278. words=("${words_[@]}")
  279. ;;
  280. cword)
  281. cword=$cword_
  282. ;;
  283. esac
  284. shift
  285. done
  286. }
  287. fi
  288.  
  289. # Fills the COMPREPLY array with prefiltered words without any additional
  290. # processing.
  291. # Callers must take care of providing only words that match the current word
  292. # to be completed and adding any prefix and/or suffix (trailing space!), if
  293. # necessary.
  294. # 1: List of newline-separated matching completion words, complete with
  295. # prefix and suffix.
  296. __gitcomp_direct ()
  297. {
  298. local IFS=$'\n'
  299.  
  300. COMPREPLY=($1)
  301. }
  302.  
  303. __gitcompappend ()
  304. {
  305. local x i=${#COMPREPLY[@]}
  306. for x in $1; do
  307. if [[ "$x" == "$3"* ]]; then
  308. COMPREPLY[i++]="$2$x$4"
  309. fi
  310. done
  311. }
  312.  
  313. __gitcompadd ()
  314. {
  315. COMPREPLY=()
  316. __gitcompappend "$@"
  317. }
  318.  
  319. # Generates completion reply, appending a space to possible completion words,
  320. # if necessary.
  321. # It accepts 1 to 4 arguments:
  322. # 1: List of possible completion words.
  323. # 2: A prefix to be added to each possible completion word (optional).
  324. # 3: Generate possible completion matches for this word (optional).
  325. # 4: A suffix to be appended to each possible completion word (optional).
  326. __gitcomp ()
  327. {
  328. local cur_="${3-$cur}"
  329.  
  330. case "$cur_" in
  331. --*=)
  332. ;;
  333. --no-*)
  334. local c i=0 IFS=$' \t\n'
  335. for c in $1; do
  336. if [[ $c == "--" ]]; then
  337. continue
  338. fi
  339. c="$c${4-}"
  340. if [[ $c == "$cur_"* ]]; then
  341. case $c in
  342. --*=|*.) ;;
  343. *) c="$c " ;;
  344. esac
  345. COMPREPLY[i++]="${2-}$c"
  346. fi
  347. done
  348. ;;
  349. *)
  350. local c i=0 IFS=$' \t\n'
  351. for c in $1; do
  352. if [[ $c == "--" ]]; then
  353. c="--no-...${4-}"
  354. if [[ $c == "$cur_"* ]]; then
  355. COMPREPLY[i++]="${2-}$c "
  356. fi
  357. break
  358. fi
  359. c="$c${4-}"
  360. if [[ $c == "$cur_"* ]]; then
  361. case $c in
  362. *=|*.) ;;
  363. *) c="$c " ;;
  364. esac
  365. COMPREPLY[i++]="${2-}$c"
  366. fi
  367. done
  368. ;;
  369. esac
  370. }
  371.  
  372. # Clear the variables caching builtins' options when (re-)sourcing
  373. # the completion script.
  374. if [[ -n ${ZSH_VERSION-} ]]; then
  375. unset $(set |sed -ne 's/^\(__gitcomp_builtin_[a-zA-Z0-9_][a-zA-Z0-9_]*\)=.*/\1/p') 2>/dev/null
  376. else
  377. unset $(compgen -v __gitcomp_builtin_)
  378. fi
  379.  
  380. # This function is equivalent to
  381. #
  382. # __gitcomp "$(git xxx --git-completion-helper) ..."
  383. #
  384. # except that the output is cached. Accept 1-3 arguments:
  385. # 1: the git command to execute, this is also the cache key
  386. # 2: extra options to be added on top (e.g. negative forms)
  387. # 3: options to be excluded
  388. __gitcomp_builtin ()
  389. {
  390. # spaces must be replaced with underscore for multi-word
  391. # commands, e.g. "git remote add" becomes remote_add.
  392. local cmd="$1"
  393. local incl="$2"
  394. local excl="$3"
  395.  
  396. local var=__gitcomp_builtin_"${cmd/-/_}"
  397. local options
  398. eval "options=\$$var"
  399.  
  400. if [ -z "$options" ]; then
  401. # leading and trailing spaces are significant to make
  402. # option removal work correctly.
  403. options=" $incl $(__git ${cmd/_/ } --git-completion-helper) " || return
  404.  
  405. for i in $excl; do
  406. options="${options/ $i / }"
  407. done
  408. eval "$var=\"$options\""
  409. fi
  410.  
  411. __gitcomp "$options"
  412. }
  413.  
  414. # Variation of __gitcomp_nl () that appends to the existing list of
  415. # completion candidates, COMPREPLY.
  416. __gitcomp_nl_append ()
  417. {
  418. local IFS=$'\n'
  419. __gitcompappend "$1" "${2-}" "${3-$cur}" "${4- }"
  420. }
  421.  
  422. # Generates completion reply from newline-separated possible completion words
  423. # by appending a space to all of them.
  424. # It accepts 1 to 4 arguments:
  425. # 1: List of possible completion words, separated by a single newline.
  426. # 2: A prefix to be added to each possible completion word (optional).
  427. # 3: Generate possible completion matches for this word (optional).
  428. # 4: A suffix to be appended to each possible completion word instead of
  429. # the default space (optional). If specified but empty, nothing is
  430. # appended.
  431. __gitcomp_nl ()
  432. {
  433. COMPREPLY=()
  434. __gitcomp_nl_append "$@"
  435. }
  436.  
  437. # Fills the COMPREPLY array with prefiltered paths without any additional
  438. # processing.
  439. # Callers must take care of providing only paths that match the current path
  440. # to be completed and adding any prefix path components, if necessary.
  441. # 1: List of newline-separated matching paths, complete with all prefix
  442. # path components.
  443. __gitcomp_file_direct ()
  444. {
  445. local IFS=$'\n'
  446.  
  447. COMPREPLY=($1)
  448.  
  449. # use a hack to enable file mode in bash < 4
  450. compopt -o filenames +o nospace 2>/dev/null ||
  451. compgen -f /non-existing-dir/ >/dev/null ||
  452. true
  453. }
  454.  
  455. # Generates completion reply with compgen from newline-separated possible
  456. # completion filenames.
  457. # It accepts 1 to 3 arguments:
  458. # 1: List of possible completion filenames, separated by a single newline.
  459. # 2: A directory prefix to be added to each possible completion filename
  460. # (optional).
  461. # 3: Generate possible completion matches for this word (optional).
  462. __gitcomp_file ()
  463. {
  464. local IFS=$'\n'
  465.  
  466. # XXX does not work when the directory prefix contains a tilde,
  467. # since tilde expansion is not applied.
  468. # This means that COMPREPLY will be empty and Bash default
  469. # completion will be used.
  470. __gitcompadd "$1" "${2-}" "${3-$cur}" ""
  471.  
  472. # use a hack to enable file mode in bash < 4
  473. compopt -o filenames +o nospace 2>/dev/null ||
  474. compgen -f /non-existing-dir/ >/dev/null ||
  475. true
  476. }
  477.  
  478. # Execute 'git ls-files', unless the --committable option is specified, in
  479. # which case it runs 'git diff-index' to find out the files that can be
  480. # committed. It return paths relative to the directory specified in the first
  481. # argument, and using the options specified in the second argument.
  482. __git_ls_files_helper ()
  483. {
  484. if [ "$2" == "--committable" ]; then
  485. __git -C "$1" -c core.quotePath=false diff-index \
  486. --name-only --relative HEAD -- "${3//\\/\\\\}*"
  487. else
  488. # NOTE: $2 is not quoted in order to support multiple options
  489. __git -C "$1" -c core.quotePath=false ls-files \
  490. --exclude-standard $2 -- "${3//\\/\\\\}*"
  491. fi
  492. }
  493.  
  494.  
  495. # __git_index_files accepts 1 or 2 arguments:
  496. # 1: Options to pass to ls-files (required).
  497. # 2: A directory path (optional).
  498. # If provided, only files within the specified directory are listed.
  499. # Sub directories are never recursed. Path must have a trailing
  500. # slash.
  501. # 3: List only paths matching this path component (optional).
  502. __git_index_files ()
  503. {
  504. local root="$2" match="$3"
  505.  
  506. __git_ls_files_helper "$root" "$1" "$match" |
  507. awk -F / -v pfx="${2//\\/\\\\}" '{
  508. paths[$1] = 1
  509. }
  510. END {
  511. for (p in paths) {
  512. if (substr(p, 1, 1) != "\"") {
  513. # No special characters, easy!
  514. print pfx p
  515. continue
  516. }
  517.  
  518. # The path is quoted.
  519. p = dequote(p)
  520. if (p == "")
  521. continue
  522.  
  523. # Even when a directory name itself does not contain
  524. # any special characters, it will still be quoted if
  525. # any of its (stripped) trailing path components do.
  526. # Because of this we may have seen the same directory
  527. # both quoted and unquoted.
  528. if (p in paths)
  529. # We have seen the same directory unquoted,
  530. # skip it.
  531. continue
  532. else
  533. print pfx p
  534. }
  535. }
  536. function dequote(p, bs_idx, out, esc, esc_idx, dec) {
  537. # Skip opening double quote.
  538. p = substr(p, 2)
  539.  
  540. # Interpret backslash escape sequences.
  541. while ((bs_idx = index(p, "\\")) != 0) {
  542. out = out substr(p, 1, bs_idx - 1)
  543. esc = substr(p, bs_idx + 1, 1)
  544. p = substr(p, bs_idx + 2)
  545.  
  546. if ((esc_idx = index("abtvfr\"\\", esc)) != 0) {
  547. # C-style one-character escape sequence.
  548. out = out substr("\a\b\t\v\f\r\"\\",
  549. esc_idx, 1)
  550. } else if (esc == "n") {
  551. # Uh-oh, a newline character.
  552. # We cannot reliably put a pathname
  553. # containing a newline into COMPREPLY,
  554. # and the newline would create a mess.
  555. # Skip this path.
  556. return ""
  557. } else {
  558. # Must be a \nnn octal value, then.
  559. dec = esc * 64 + \
  560. substr(p, 1, 1) * 8 + \
  561. substr(p, 2, 1)
  562. out = out sprintf("%c", dec)
  563. p = substr(p, 3)
  564. }
  565. }
  566. # Drop closing double quote, if there is one.
  567. # (There is not any if this is a directory, as it was
  568. # already stripped with the trailing path components.)
  569. if (substr(p, length(p), 1) == "\"")
  570. out = out substr(p, 1, length(p) - 1)
  571. else
  572. out = out p
  573.  
  574. return out
  575. }'
  576. }
  577.  
  578. # __git_complete_index_file requires 1 argument:
  579. # 1: the options to pass to ls-file
  580. #
  581. # The exception is --committable, which finds the files appropriate commit.
  582. __git_complete_index_file ()
  583. {
  584. local dequoted_word pfx="" cur_
  585.  
  586. __git_dequote "$cur"
  587.  
  588. case "$dequoted_word" in
  589. ?*/*)
  590. pfx="${dequoted_word%/*}/"
  591. cur_="${dequoted_word##*/}"
  592. ;;
  593. *)
  594. cur_="$dequoted_word"
  595. esac
  596.  
  597. __gitcomp_file_direct "$(__git_index_files "$1" "$pfx" "$cur_")"
  598. }
  599.  
  600. # Lists branches from the local repository.
  601. # 1: A prefix to be added to each listed branch (optional).
  602. # 2: List only branches matching this word (optional; list all branches if
  603. # unset or empty).
  604. # 3: A suffix to be appended to each listed branch (optional).
  605. __git_heads ()
  606. {
  607. local pfx="${1-}" cur_="${2-}" sfx="${3-}"
  608.  
  609. __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
  610. "refs/heads/$cur_*" "refs/heads/$cur_*/**"
  611. }
  612.  
  613. # Lists tags from the local repository.
  614. # Accepts the same positional parameters as __git_heads() above.
  615. __git_tags ()
  616. {
  617. local pfx="${1-}" cur_="${2-}" sfx="${3-}"
  618.  
  619. __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
  620. "refs/tags/$cur_*" "refs/tags/$cur_*/**"
  621. }
  622.  
  623. # Lists refs from the local (by default) or from a remote repository.
  624. # It accepts 0, 1 or 2 arguments:
  625. # 1: The remote to list refs from (optional; ignored, if set but empty).
  626. # Can be the name of a configured remote, a path, or a URL.
  627. # 2: In addition to local refs, list unique branches from refs/remotes/ for
  628. # 'git checkout's tracking DWIMery (optional; ignored, if set but empty).
  629. # 3: A prefix to be added to each listed ref (optional).
  630. # 4: List only refs matching this word (optional; list all refs if unset or
  631. # empty).
  632. # 5: A suffix to be appended to each listed ref (optional; ignored, if set
  633. # but empty).
  634. #
  635. # Use __git_complete_refs() instead.
  636. __git_refs ()
  637. {
  638. local i hash dir track="${2-}"
  639. local list_refs_from=path remote="${1-}"
  640. local format refs
  641. local pfx="${3-}" cur_="${4-$cur}" sfx="${5-}"
  642. local match="${4-}"
  643. local fer_pfx="${pfx//\%/%%}" # "escape" for-each-ref format specifiers
  644.  
  645. __git_find_repo_path
  646. dir="$__git_repo_path"
  647.  
  648. if [ -z "$remote" ]; then
  649. if [ -z "$dir" ]; then
  650. return
  651. fi
  652. else
  653. if __git_is_configured_remote "$remote"; then
  654. # configured remote takes precedence over a
  655. # local directory with the same name
  656. list_refs_from=remote
  657. elif [ -d "$remote/.git" ]; then
  658. dir="$remote/.git"
  659. elif [ -d "$remote" ]; then
  660. dir="$remote"
  661. else
  662. list_refs_from=url
  663. fi
  664. fi
  665.  
  666. if [ "$list_refs_from" = path ]; then
  667. if [[ "$cur_" == ^* ]]; then
  668. pfx="$pfx^"
  669. fer_pfx="$fer_pfx^"
  670. cur_=${cur_#^}
  671. match=${match#^}
  672. fi
  673. case "$cur_" in
  674. refs|refs/*)
  675. format="refname"
  676. refs=("$match*" "$match*/**")
  677. track=""
  678. ;;
  679. *)
  680. for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD REBASE_HEAD; do
  681. case "$i" in
  682. $match*)
  683. if [ -e "$dir/$i" ]; then
  684. echo "$pfx$i$sfx"
  685. fi
  686. ;;
  687. esac
  688. done
  689. format="refname:strip=2"
  690. refs=("refs/tags/$match*" "refs/tags/$match*/**"
  691. "refs/heads/$match*" "refs/heads/$match*/**"
  692. "refs/remotes/$match*" "refs/remotes/$match*/**")
  693. ;;
  694. esac
  695. __git_dir="$dir" __git for-each-ref --format="$fer_pfx%($format)$sfx" \
  696. "${refs[@]}"
  697. if [ -n "$track" ]; then
  698. # employ the heuristic used by git checkout
  699. # Try to find a remote branch that matches the completion word
  700. # but only output if the branch name is unique
  701. __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
  702. --sort="refname:strip=3" \
  703. "refs/remotes/*/$match*" "refs/remotes/*/$match*/**" | \
  704. uniq -u
  705. fi
  706. return
  707. fi
  708. case "$cur_" in
  709. refs|refs/*)
  710. __git ls-remote "$remote" "$match*" | \
  711. while read -r hash i; do
  712. case "$i" in
  713. *^{}) ;;
  714. *) echo "$pfx$i$sfx" ;;
  715. esac
  716. done
  717. ;;
  718. *)
  719. if [ "$list_refs_from" = remote ]; then
  720. case "HEAD" in
  721. $match*) echo "${pfx}HEAD$sfx" ;;
  722. esac
  723. __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
  724. "refs/remotes/$remote/$match*" \
  725. "refs/remotes/$remote/$match*/**"
  726. else
  727. local query_symref
  728. case "HEAD" in
  729. $match*) query_symref="HEAD" ;;
  730. esac
  731. __git ls-remote "$remote" $query_symref \
  732. "refs/tags/$match*" "refs/heads/$match*" \
  733. "refs/remotes/$match*" |
  734. while read -r hash i; do
  735. case "$i" in
  736. *^{}) ;;
  737. refs/*) echo "$pfx${i#refs/*/}$sfx" ;;
  738. *) echo "$pfx$i$sfx" ;; # symbolic refs
  739. esac
  740. done
  741. fi
  742. ;;
  743. esac
  744. }
  745.  
  746. # Completes refs, short and long, local and remote, symbolic and pseudo.
  747. #
  748. # Usage: __git_complete_refs [<option>]...
  749. # --remote=<remote>: The remote to list refs from, can be the name of a
  750. # configured remote, a path, or a URL.
  751. # --track: List unique remote branches for 'git checkout's tracking DWIMery.
  752. # --pfx=<prefix>: A prefix to be added to each ref.
  753. # --cur=<word>: The current ref to be completed. Defaults to the current
  754. # word to be completed.
  755. # --sfx=<suffix>: A suffix to be appended to each ref instead of the default
  756. # space.
  757. __git_complete_refs ()
  758. {
  759. local remote track pfx cur_="$cur" sfx=" "
  760.  
  761. while test $# != 0; do
  762. case "$1" in
  763. --remote=*) remote="${1##--remote=}" ;;
  764. --track) track="yes" ;;
  765. --pfx=*) pfx="${1##--pfx=}" ;;
  766. --cur=*) cur_="${1##--cur=}" ;;
  767. --sfx=*) sfx="${1##--sfx=}" ;;
  768. *) return 1 ;;
  769. esac
  770. shift
  771. done
  772.  
  773. __gitcomp_direct "$(__git_refs "$remote" "$track" "$pfx" "$cur_" "$sfx")"
  774. }
  775.  
  776. # __git_refs2 requires 1 argument (to pass to __git_refs)
  777. # Deprecated: use __git_complete_fetch_refspecs() instead.
  778. __git_refs2 ()
  779. {
  780. local i
  781. for i in $(__git_refs "$1"); do
  782. echo "$i:$i"
  783. done
  784. }
  785.  
  786. # Completes refspecs for fetching from a remote repository.
  787. # 1: The remote repository.
  788. # 2: A prefix to be added to each listed refspec (optional).
  789. # 3: The ref to be completed as a refspec instead of the current word to be
  790. # completed (optional)
  791. # 4: A suffix to be appended to each listed refspec instead of the default
  792. # space (optional).
  793. __git_complete_fetch_refspecs ()
  794. {
  795. local i remote="$1" pfx="${2-}" cur_="${3-$cur}" sfx="${4- }"
  796.  
  797. __gitcomp_direct "$(
  798. for i in $(__git_refs "$remote" "" "" "$cur_") ; do
  799. echo "$pfx$i:$i$sfx"
  800. done
  801. )"
  802. }
  803.  
  804. # __git_refs_remotes requires 1 argument (to pass to ls-remote)
  805. __git_refs_remotes ()
  806. {
  807. local i hash
  808. __git ls-remote "$1" 'refs/heads/*' | \
  809. while read -r hash i; do
  810. echo "$i:refs/remotes/$1/${i#refs/heads/}"
  811. done
  812. }
  813.  
  814. __git_remotes ()
  815. {
  816. __git_find_repo_path
  817. test -d "$__git_repo_path/remotes" && ls -1 "$__git_repo_path/remotes"
  818. __git remote
  819. }
  820.  
  821. # Returns true if $1 matches the name of a configured remote, false otherwise.
  822. __git_is_configured_remote ()
  823. {
  824. local remote
  825. for remote in $(__git_remotes); do
  826. if [ "$remote" = "$1" ]; then
  827. return 0
  828. fi
  829. done
  830. return 1
  831. }
  832.  
  833. __git_list_merge_strategies ()
  834. {
  835. LANG=C LC_ALL=C git merge -s help 2>&1 |
  836. sed -n -e '/[Aa]vailable strategies are: /,/^$/{
  837. s/\.$//
  838. s/.*://
  839. s/^[ ]*//
  840. s/[ ]*$//
  841. p
  842. }'
  843. }
  844.  
  845. __git_merge_strategies=
  846. # 'git merge -s help' (and thus detection of the merge strategy
  847. # list) fails, unfortunately, if run outside of any git working
  848. # tree. __git_merge_strategies is set to the empty string in
  849. # that case, and the detection will be repeated the next time it
  850. # is needed.
  851. __git_compute_merge_strategies ()
  852. {
  853. test -n "$__git_merge_strategies" ||
  854. __git_merge_strategies=$(__git_list_merge_strategies)
  855. }
  856.  
  857. __git_merge_strategy_options="ours theirs subtree subtree= patience
  858. histogram diff-algorithm= ignore-space-change ignore-all-space
  859. ignore-space-at-eol renormalize no-renormalize no-renames
  860. find-renames find-renames= rename-threshold="
  861.  
  862. __git_complete_revlist_file ()
  863. {
  864. local dequoted_word pfx ls ref cur_="$cur"
  865. case "$cur_" in
  866. *..?*:*)
  867. return
  868. ;;
  869. ?*:*)
  870. ref="${cur_%%:*}"
  871. cur_="${cur_#*:}"
  872.  
  873. __git_dequote "$cur_"
  874.  
  875. case "$dequoted_word" in
  876. ?*/*)
  877. pfx="${dequoted_word%/*}"
  878. cur_="${dequoted_word##*/}"
  879. ls="$ref:$pfx"
  880. pfx="$pfx/"
  881. ;;
  882. *)
  883. cur_="$dequoted_word"
  884. ls="$ref"
  885. ;;
  886. esac
  887.  
  888. case "$COMP_WORDBREAKS" in
  889. *:*) : great ;;
  890. *) pfx="$ref:$pfx" ;;
  891. esac
  892.  
  893. __gitcomp_file "$(__git ls-tree "$ls" \
  894. | sed 's/^.* //
  895. s/$//')" \
  896. "$pfx" "$cur_"
  897. ;;
  898. *...*)
  899. pfx="${cur_%...*}..."
  900. cur_="${cur_#*...}"
  901. __git_complete_refs --pfx="$pfx" --cur="$cur_"
  902. ;;
  903. *..*)
  904. pfx="${cur_%..*}.."
  905. cur_="${cur_#*..}"
  906. __git_complete_refs --pfx="$pfx" --cur="$cur_"
  907. ;;
  908. *)
  909. __git_complete_refs
  910. ;;
  911. esac
  912. }
  913.  
  914. __git_complete_file ()
  915. {
  916. __git_complete_revlist_file
  917. }
  918.  
  919. __git_complete_revlist ()
  920. {
  921. __git_complete_revlist_file
  922. }
  923.  
  924. __git_complete_remote_or_refspec ()
  925. {
  926. local cur_="$cur" cmd="${words[1]}"
  927. local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
  928. if [ "$cmd" = "remote" ]; then
  929. ((c++))
  930. fi
  931. while [ $c -lt $cword ]; do
  932. i="${words[c]}"
  933. case "$i" in
  934. --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
  935. -d|--delete) [ "$cmd" = "push" ] && lhs=0 ;;
  936. --all)
  937. case "$cmd" in
  938. push) no_complete_refspec=1 ;;
  939. fetch)
  940. return
  941. ;;
  942. *) ;;
  943. esac
  944. ;;
  945. --multiple) no_complete_refspec=1; break ;;
  946. -*) ;;
  947. *) remote="$i"; break ;;
  948. esac
  949. ((c++))
  950. done
  951. if [ -z "$remote" ]; then
  952. __gitcomp_nl "$(__git_remotes)"
  953. return
  954. fi
  955. if [ $no_complete_refspec = 1 ]; then
  956. return
  957. fi
  958. [ "$remote" = "." ] && remote=
  959. case "$cur_" in
  960. *:*)
  961. case "$COMP_WORDBREAKS" in
  962. *:*) : great ;;
  963. *) pfx="${cur_%%:*}:" ;;
  964. esac
  965. cur_="${cur_#*:}"
  966. lhs=0
  967. ;;
  968. +*)
  969. pfx="+"
  970. cur_="${cur_#+}"
  971. ;;
  972. esac
  973. case "$cmd" in
  974. fetch)
  975. if [ $lhs = 1 ]; then
  976. __git_complete_fetch_refspecs "$remote" "$pfx" "$cur_"
  977. else
  978. __git_complete_refs --pfx="$pfx" --cur="$cur_"
  979. fi
  980. ;;
  981. pull|remote)
  982. if [ $lhs = 1 ]; then
  983. __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
  984. else
  985. __git_complete_refs --pfx="$pfx" --cur="$cur_"
  986. fi
  987. ;;
  988. push)
  989. if [ $lhs = 1 ]; then
  990. __git_complete_refs --pfx="$pfx" --cur="$cur_"
  991. else
  992. __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
  993. fi
  994. ;;
  995. esac
  996. }
  997.  
  998. __git_complete_strategy ()
  999. {
  1000. __git_compute_merge_strategies
  1001. case "$prev" in
  1002. -s|--strategy)
  1003. __gitcomp "$__git_merge_strategies"
  1004. return 0
  1005. ;;
  1006. -X)
  1007. __gitcomp "$__git_merge_strategy_options"
  1008. return 0
  1009. ;;
  1010. esac
  1011. case "$cur" in
  1012. --strategy=*)
  1013. __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
  1014. return 0
  1015. ;;
  1016. --strategy-option=*)
  1017. __gitcomp "$__git_merge_strategy_options" "" "${cur##--strategy-option=}"
  1018. return 0
  1019. ;;
  1020. esac
  1021. return 1
  1022. }
  1023.  
  1024. __git_all_commands=
  1025. __git_compute_all_commands ()
  1026. {
  1027. test -n "$__git_all_commands" ||
  1028. __git_all_commands=$(__git --list-cmds=main,others,alias,nohelpers)
  1029. }
  1030.  
  1031. # Lists all set config variables starting with the given section prefix,
  1032. # with the prefix removed.
  1033. __git_get_config_variables ()
  1034. {
  1035. local section="$1" i IFS=$'\n'
  1036. for i in $(__git config --name-only --get-regexp "^$section\..*"); do
  1037. echo "${i#$section.}"
  1038. done
  1039. }
  1040.  
  1041. __git_pretty_aliases ()
  1042. {
  1043. __git_get_config_variables "pretty"
  1044. }
  1045.  
  1046. # __git_aliased_command requires 1 argument
  1047. __git_aliased_command ()
  1048. {
  1049. local word cmdline=$(__git config --get "alias.$1")
  1050. for word in $cmdline; do
  1051. case "$word" in
  1052. \!gitk|gitk)
  1053. echo "gitk"
  1054. return
  1055. ;;
  1056. \!*) : shell command alias ;;
  1057. -*) : option ;;
  1058. *=*) : setting env ;;
  1059. git) : git itself ;;
  1060. \(\)) : skip parens of shell function definition ;;
  1061. {) : skip start of shell helper function ;;
  1062. :) : skip null command ;;
  1063. \'*) : skip opening quote after sh -c ;;
  1064. *)
  1065. echo "$word"
  1066. return
  1067. esac
  1068. done
  1069. }
  1070.  
  1071. # __git_find_on_cmdline requires 1 argument
  1072. __git_find_on_cmdline ()
  1073. {
  1074. local word subcommand c=1
  1075. while [ $c -lt $cword ]; do
  1076. word="${words[c]}"
  1077. for subcommand in $1; do
  1078. if [ "$subcommand" = "$word" ]; then
  1079. echo "$subcommand"
  1080. return
  1081. fi
  1082. done
  1083. ((c++))
  1084. done
  1085. }
  1086.  
  1087. # Echo the value of an option set on the command line or config
  1088. #
  1089. # $1: short option name
  1090. # $2: long option name including =
  1091. # $3: list of possible values
  1092. # $4: config string (optional)
  1093. #
  1094. # example:
  1095. # result="$(__git_get_option_value "-d" "--do-something=" \
  1096. # "yes no" "core.doSomething")"
  1097. #
  1098. # result is then either empty (no option set) or "yes" or "no"
  1099. #
  1100. # __git_get_option_value requires 3 arguments
  1101. __git_get_option_value ()
  1102. {
  1103. local c short_opt long_opt val
  1104. local result= values config_key word
  1105.  
  1106. short_opt="$1"
  1107. long_opt="$2"
  1108. values="$3"
  1109. config_key="$4"
  1110.  
  1111. ((c = $cword - 1))
  1112. while [ $c -ge 0 ]; do
  1113. word="${words[c]}"
  1114. for val in $values; do
  1115. if [ "$short_opt$val" = "$word" ] ||
  1116. [ "$long_opt$val" = "$word" ]; then
  1117. result="$val"
  1118. break 2
  1119. fi
  1120. done
  1121. ((c--))
  1122. done
  1123.  
  1124. if [ -n "$config_key" ] && [ -z "$result" ]; then
  1125. result="$(__git config "$config_key")"
  1126. fi
  1127.  
  1128. echo "$result"
  1129. }
  1130.  
  1131. __git_has_doubledash ()
  1132. {
  1133. local c=1
  1134. while [ $c -lt $cword ]; do
  1135. if [ "--" = "${words[c]}" ]; then
  1136. return 0
  1137. fi
  1138. ((c++))
  1139. done
  1140. return 1
  1141. }
  1142.  
  1143. # Try to count non option arguments passed on the command line for the
  1144. # specified git command.
  1145. # When options are used, it is necessary to use the special -- option to
  1146. # tell the implementation were non option arguments begin.
  1147. # XXX this can not be improved, since options can appear everywhere, as
  1148. # an example:
  1149. # git mv x -n y
  1150. #
  1151. # __git_count_arguments requires 1 argument: the git command executed.
  1152. __git_count_arguments ()
  1153. {
  1154. local word i c=0
  1155.  
  1156. # Skip "git" (first argument)
  1157. for ((i=1; i < ${#words[@]}; i++)); do
  1158. word="${words[i]}"
  1159.  
  1160. case "$word" in
  1161. --)
  1162. # Good; we can assume that the following are only non
  1163. # option arguments.
  1164. ((c = 0))
  1165. ;;
  1166. "$1")
  1167. # Skip the specified git command and discard git
  1168. # main options
  1169. ((c = 0))
  1170. ;;
  1171. ?*)
  1172. ((c++))
  1173. ;;
  1174. esac
  1175. done
  1176.  
  1177. printf "%d" $c
  1178. }
  1179.  
  1180. __git_whitespacelist="nowarn warn error error-all fix"
  1181. __git_patchformat="mbox stgit stgit-series hg mboxrd"
  1182. __git_am_inprogress_options="--skip --continue --resolved --abort --quit --show-current-patch"
  1183.  
  1184. _git_am ()
  1185. {
  1186. __git_find_repo_path
  1187. if [ -d "$__git_repo_path"/rebase-apply ]; then
  1188. __gitcomp "$__git_am_inprogress_options"
  1189. return
  1190. fi
  1191. case "$cur" in
  1192. --whitespace=*)
  1193. __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
  1194. return
  1195. ;;
  1196. --patch-format=*)
  1197. __gitcomp "$__git_patchformat" "" "${cur##--patch-format=}"
  1198. return
  1199. ;;
  1200. --*)
  1201. __gitcomp_builtin am "" \
  1202. "$__git_am_inprogress_options"
  1203. return
  1204. esac
  1205. }
  1206.  
  1207. _git_apply ()
  1208. {
  1209. case "$cur" in
  1210. --whitespace=*)
  1211. __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
  1212. return
  1213. ;;
  1214. --*)
  1215. __gitcomp_builtin apply
  1216. return
  1217. esac
  1218. }
  1219.  
  1220. _git_add ()
  1221. {
  1222. case "$cur" in
  1223. --chmod=*)
  1224. __gitcomp "+x -x" "" "${cur##--chmod=}"
  1225. return
  1226. ;;
  1227. --*)
  1228. __gitcomp_builtin add
  1229. return
  1230. esac
  1231.  
  1232. local complete_opt="--others --modified --directory --no-empty-directory"
  1233. if test -n "$(__git_find_on_cmdline "-u --update")"
  1234. then
  1235. complete_opt="--modified"
  1236. fi
  1237. __git_complete_index_file "$complete_opt"
  1238. }
  1239.  
  1240. _git_archive ()
  1241. {
  1242. case "$cur" in
  1243. --format=*)
  1244. __gitcomp "$(git archive --list)" "" "${cur##--format=}"
  1245. return
  1246. ;;
  1247. --remote=*)
  1248. __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
  1249. return
  1250. ;;
  1251. --*)
  1252. __gitcomp_builtin archive "--format= --list --verbose --prefix= --worktree-attributes"
  1253. return
  1254. ;;
  1255. esac
  1256. __git_complete_file
  1257. }
  1258.  
  1259. _git_bisect ()
  1260. {
  1261. __git_has_doubledash && return
  1262.  
  1263. local subcommands="start bad good skip reset visualize replay log run"
  1264. local subcommand="$(__git_find_on_cmdline "$subcommands")"
  1265. if [ -z "$subcommand" ]; then
  1266. __git_find_repo_path
  1267. if [ -f "$__git_repo_path"/BISECT_START ]; then
  1268. __gitcomp "$subcommands"
  1269. else
  1270. __gitcomp "replay start"
  1271. fi
  1272. return
  1273. fi
  1274.  
  1275. case "$subcommand" in
  1276. bad|good|reset|skip|start)
  1277. __git_complete_refs
  1278. ;;
  1279. *)
  1280. ;;
  1281. esac
  1282. }
  1283.  
  1284. __git_ref_fieldlist="refname objecttype objectsize objectname upstream push HEAD symref"
  1285.  
  1286. _git_branch ()
  1287. {
  1288. local i c=1 only_local_ref="n" has_r="n"
  1289.  
  1290. while [ $c -lt $cword ]; do
  1291. i="${words[c]}"
  1292. case "$i" in
  1293. -d|--delete|-m|--move) only_local_ref="y" ;;
  1294. -r|--remotes) has_r="y" ;;
  1295. esac
  1296. ((c++))
  1297. done
  1298.  
  1299. case "$cur" in
  1300. --set-upstream-to=*)
  1301. __git_complete_refs --cur="${cur##--set-upstream-to=}"
  1302. ;;
  1303. --*)
  1304. __gitcomp_builtin branch
  1305. ;;
  1306. *)
  1307. if [ $only_local_ref = "y" -a $has_r = "n" ]; then
  1308. __gitcomp_direct "$(__git_heads "" "$cur" " ")"
  1309. else
  1310. __git_complete_refs
  1311. fi
  1312. ;;
  1313. esac
  1314. }
  1315.  
  1316. _git_bundle ()
  1317. {
  1318. local cmd="${words[2]}"
  1319. case "$cword" in
  1320. 2)
  1321. __gitcomp "create list-heads verify unbundle"
  1322. ;;
  1323. 3)
  1324. # looking for a file
  1325. ;;
  1326. *)
  1327. case "$cmd" in
  1328. create)
  1329. __git_complete_revlist
  1330. ;;
  1331. esac
  1332. ;;
  1333. esac
  1334. }
  1335.  
  1336. _git_checkout ()
  1337. {
  1338. __git_has_doubledash && return
  1339.  
  1340. case "$cur" in
  1341. --conflict=*)
  1342. __gitcomp "diff3 merge" "" "${cur##--conflict=}"
  1343. ;;
  1344. --*)
  1345. __gitcomp_builtin checkout
  1346. ;;
  1347. *)
  1348. # check if --track, --no-track, or --no-guess was specified
  1349. # if so, disable DWIM mode
  1350. local flags="--track --no-track --no-guess" track_opt="--track"
  1351. if [ "$GIT_COMPLETION_CHECKOUT_NO_GUESS" = "1" ] ||
  1352. [ -n "$(__git_find_on_cmdline "$flags")" ]; then
  1353. track_opt=''
  1354. fi
  1355. __git_complete_refs $track_opt
  1356. ;;
  1357. esac
  1358. }
  1359.  
  1360. __git_sequencer_inprogress_options="--continue --quit --abort --skip"
  1361.  
  1362. __git_cherry_pick_inprogress_options=$__git_sequencer_inprogress_options
  1363.  
  1364. _git_cherry_pick ()
  1365. {
  1366. __git_find_repo_path
  1367. if [ -f "$__git_repo_path"/CHERRY_PICK_HEAD ]; then
  1368. __gitcomp "$__git_cherry_pick_inprogress_options"
  1369. return
  1370. fi
  1371.  
  1372. __git_complete_strategy && return
  1373.  
  1374. case "$cur" in
  1375. --*)
  1376. __gitcomp_builtin cherry-pick "" \
  1377. "$__git_cherry_pick_inprogress_options"
  1378. ;;
  1379. *)
  1380. __git_complete_refs
  1381. ;;
  1382. esac
  1383. }
  1384.  
  1385. _git_clean ()
  1386. {
  1387. case "$cur" in
  1388. --*)
  1389. __gitcomp_builtin clean
  1390. return
  1391. ;;
  1392. esac
  1393.  
  1394. # XXX should we check for -x option ?
  1395. __git_complete_index_file "--others --directory"
  1396. }
  1397.  
  1398. _git_clone ()
  1399. {
  1400. case "$prev" in
  1401. -c|--config)
  1402. __git_complete_config_variable_name_and_value
  1403. return
  1404. ;;
  1405. esac
  1406. case "$cur" in
  1407. --config=*)
  1408. __git_complete_config_variable_name_and_value \
  1409. --cur="${cur##--config=}"
  1410. return
  1411. ;;
  1412. --*)
  1413. __gitcomp_builtin clone
  1414. return
  1415. ;;
  1416. esac
  1417. }
  1418.  
  1419. __git_untracked_file_modes="all no normal"
  1420.  
  1421. _git_commit ()
  1422. {
  1423. case "$prev" in
  1424. -c|-C)
  1425. __git_complete_refs
  1426. return
  1427. ;;
  1428. esac
  1429.  
  1430. case "$cur" in
  1431. --cleanup=*)
  1432. __gitcomp "default scissors strip verbatim whitespace
  1433. " "" "${cur##--cleanup=}"
  1434. return
  1435. ;;
  1436. --reuse-message=*|--reedit-message=*|\
  1437. --fixup=*|--squash=*)
  1438. __git_complete_refs --cur="${cur#*=}"
  1439. return
  1440. ;;
  1441. --untracked-files=*)
  1442. __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
  1443. return
  1444. ;;
  1445. --*)
  1446. __gitcomp_builtin commit
  1447. return
  1448. esac
  1449.  
  1450. if __git rev-parse --verify --quiet HEAD >/dev/null; then
  1451. __git_complete_index_file "--committable"
  1452. else
  1453. # This is the first commit
  1454. __git_complete_index_file "--cached"
  1455. fi
  1456. }
  1457.  
  1458. _git_describe ()
  1459. {
  1460. case "$cur" in
  1461. --*)
  1462. __gitcomp_builtin describe
  1463. return
  1464. esac
  1465. __git_complete_refs
  1466. }
  1467.  
  1468. __git_diff_algorithms="myers minimal patience histogram"
  1469.  
  1470. __git_diff_submodule_formats="diff log short"
  1471.  
  1472. __git_diff_common_options="--stat --numstat --shortstat --summary
  1473. --patch-with-stat --name-only --name-status --color
  1474. --no-color --color-words --no-renames --check
  1475. --full-index --binary --abbrev --diff-filter=
  1476. --find-copies-harder --ignore-cr-at-eol
  1477. --text --ignore-space-at-eol --ignore-space-change
  1478. --ignore-all-space --ignore-blank-lines --exit-code
  1479. --quiet --ext-diff --no-ext-diff
  1480. --no-prefix --src-prefix= --dst-prefix=
  1481. --inter-hunk-context=
  1482. --patience --histogram --minimal
  1483. --raw --word-diff --word-diff-regex=
  1484. --dirstat --dirstat= --dirstat-by-file
  1485. --dirstat-by-file= --cumulative
  1486. --diff-algorithm=
  1487. --submodule --submodule= --ignore-submodules
  1488. --indent-heuristic --no-indent-heuristic
  1489. --textconv --no-textconv
  1490. "
  1491.  
  1492. _git_diff ()
  1493. {
  1494. __git_has_doubledash && return
  1495.  
  1496. case "$cur" in
  1497. --diff-algorithm=*)
  1498. __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
  1499. return
  1500. ;;
  1501. --submodule=*)
  1502. __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
  1503. return
  1504. ;;
  1505. --*)
  1506. __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
  1507. --base --ours --theirs --no-index
  1508. $__git_diff_common_options
  1509. "
  1510. return
  1511. ;;
  1512. esac
  1513. __git_complete_revlist_file
  1514. }
  1515.  
  1516. __git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff
  1517. tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc
  1518. codecompare smerge
  1519. "
  1520.  
  1521. _git_difftool ()
  1522. {
  1523. __git_has_doubledash && return
  1524.  
  1525. case "$cur" in
  1526. --tool=*)
  1527. __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
  1528. return
  1529. ;;
  1530. --*)
  1531. __gitcomp_builtin difftool "$__git_diff_common_options
  1532. --base --cached --ours --theirs
  1533. --pickaxe-all --pickaxe-regex
  1534. --relative --staged
  1535. "
  1536. return
  1537. ;;
  1538. esac
  1539. __git_complete_revlist_file
  1540. }
  1541.  
  1542. __git_fetch_recurse_submodules="yes on-demand no"
  1543.  
  1544. _git_fetch ()
  1545. {
  1546. case "$cur" in
  1547. --recurse-submodules=*)
  1548. __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
  1549. return
  1550. ;;
  1551. --filter=*)
  1552. __gitcomp "blob:none blob:limit= sparse:oid=" "" "${cur##--filter=}"
  1553. return
  1554. ;;
  1555. --*)
  1556. __gitcomp_builtin fetch
  1557. return
  1558. ;;
  1559. esac
  1560. __git_complete_remote_or_refspec
  1561. }
  1562.  
  1563. __git_format_patch_extra_options="
  1564. --full-index --not --all --no-prefix --src-prefix=
  1565. --dst-prefix= --notes
  1566. "
  1567.  
  1568. _git_format_patch ()
  1569. {
  1570. case "$cur" in
  1571. --thread=*)
  1572. __gitcomp "
  1573. deep shallow
  1574. " "" "${cur##--thread=}"
  1575. return
  1576. ;;
  1577. --*)
  1578. __gitcomp_builtin format-patch "$__git_format_patch_extra_options"
  1579. return
  1580. ;;
  1581. esac
  1582. __git_complete_revlist
  1583. }
  1584.  
  1585. _git_fsck ()
  1586. {
  1587. case "$cur" in
  1588. --*)
  1589. __gitcomp_builtin fsck
  1590. return
  1591. ;;
  1592. esac
  1593. }
  1594.  
  1595. _git_gitk ()
  1596. {
  1597. _gitk
  1598. }
  1599.  
  1600. # Lists matching symbol names from a tag (as in ctags) file.
  1601. # 1: List symbol names matching this word.
  1602. # 2: The tag file to list symbol names from.
  1603. # 3: A prefix to be added to each listed symbol name (optional).
  1604. # 4: A suffix to be appended to each listed symbol name (optional).
  1605. __git_match_ctag () {
  1606. awk -v pfx="${3-}" -v sfx="${4-}" "
  1607. /^${1//\//\\/}/ { print pfx \$1 sfx }
  1608. " "$2"
  1609. }
  1610.  
  1611. # Complete symbol names from a tag file.
  1612. # Usage: __git_complete_symbol [<option>]...
  1613. # --tags=<file>: The tag file to list symbol names from instead of the
  1614. # default "tags".
  1615. # --pfx=<prefix>: A prefix to be added to each symbol name.
  1616. # --cur=<word>: The current symbol name to be completed. Defaults to
  1617. # the current word to be completed.
  1618. # --sfx=<suffix>: A suffix to be appended to each symbol name instead
  1619. # of the default space.
  1620. __git_complete_symbol () {
  1621. local tags=tags pfx="" cur_="${cur-}" sfx=" "
  1622.  
  1623. while test $# != 0; do
  1624. case "$1" in
  1625. --tags=*) tags="${1##--tags=}" ;;
  1626. --pfx=*) pfx="${1##--pfx=}" ;;
  1627. --cur=*) cur_="${1##--cur=}" ;;
  1628. --sfx=*) sfx="${1##--sfx=}" ;;
  1629. *) return 1 ;;
  1630. esac
  1631. shift
  1632. done
  1633.  
  1634. if test -r "$tags"; then
  1635. __gitcomp_direct "$(__git_match_ctag "$cur_" "$tags" "$pfx" "$sfx")"
  1636. fi
  1637. }
  1638.  
  1639. _git_grep ()
  1640. {
  1641. __git_has_doubledash && return
  1642.  
  1643. case "$cur" in
  1644. --*)
  1645. __gitcomp_builtin grep
  1646. return
  1647. ;;
  1648. esac
  1649.  
  1650. case "$cword,$prev" in
  1651. 2,*|*,-*)
  1652. __git_complete_symbol && return
  1653. ;;
  1654. esac
  1655.  
  1656. __git_complete_refs
  1657. }
  1658.  
  1659. _git_help ()
  1660. {
  1661. case "$cur" in
  1662. --*)
  1663. __gitcomp_builtin help
  1664. return
  1665. ;;
  1666. esac
  1667. if test -n "$GIT_TESTING_ALL_COMMAND_LIST"
  1668. then
  1669. __gitcomp "$GIT_TESTING_ALL_COMMAND_LIST $(__git --list-cmds=alias,list-guide) gitk"
  1670. else
  1671. __gitcomp "$(__git --list-cmds=main,nohelpers,alias,list-guide) gitk"
  1672. fi
  1673. }
  1674.  
  1675. _git_init ()
  1676. {
  1677. case "$cur" in
  1678. --shared=*)
  1679. __gitcomp "
  1680. false true umask group all world everybody
  1681. " "" "${cur##--shared=}"
  1682. return
  1683. ;;
  1684. --*)
  1685. __gitcomp_builtin init
  1686. return
  1687. ;;
  1688. esac
  1689. }
  1690.  
  1691. _git_ls_files ()
  1692. {
  1693. case "$cur" in
  1694. --*)
  1695. __gitcomp_builtin ls-files
  1696. return
  1697. ;;
  1698. esac
  1699.  
  1700. # XXX ignore options like --modified and always suggest all cached
  1701. # files.
  1702. __git_complete_index_file "--cached"
  1703. }
  1704.  
  1705. _git_ls_remote ()
  1706. {
  1707. case "$cur" in
  1708. --*)
  1709. __gitcomp_builtin ls-remote
  1710. return
  1711. ;;
  1712. esac
  1713. __gitcomp_nl "$(__git_remotes)"
  1714. }
  1715.  
  1716. _git_ls_tree ()
  1717. {
  1718. case "$cur" in
  1719. --*)
  1720. __gitcomp_builtin ls-tree
  1721. return
  1722. ;;
  1723. esac
  1724.  
  1725. __git_complete_file
  1726. }
  1727.  
  1728. # Options that go well for log, shortlog and gitk
  1729. __git_log_common_options="
  1730. --not --all
  1731. --branches --tags --remotes
  1732. --first-parent --merges --no-merges
  1733. --max-count=
  1734. --max-age= --since= --after=
  1735. --min-age= --until= --before=
  1736. --min-parents= --max-parents=
  1737. --no-min-parents --no-max-parents
  1738. "
  1739. # Options that go well for log and gitk (not shortlog)
  1740. __git_log_gitk_options="
  1741. --dense --sparse --full-history
  1742. --simplify-merges --simplify-by-decoration
  1743. --left-right --notes --no-notes
  1744. "
  1745. # Options that go well for log and shortlog (not gitk)
  1746. __git_log_shortlog_options="
  1747. --author= --committer= --grep=
  1748. --all-match --invert-grep
  1749. "
  1750.  
  1751. __git_log_pretty_formats="oneline short medium full fuller reference email raw format: tformat: mboxrd"
  1752. __git_log_date_formats="relative iso8601 iso8601-strict rfc2822 short local default raw unix format:"
  1753.  
  1754. _git_log ()
  1755. {
  1756. __git_has_doubledash && return
  1757. __git_find_repo_path
  1758.  
  1759. local merge=""
  1760. if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
  1761. merge="--merge"
  1762. fi
  1763. case "$prev,$cur" in
  1764. -L,:*:*)
  1765. return # fall back to Bash filename completion
  1766. ;;
  1767. -L,:*)
  1768. __git_complete_symbol --cur="${cur#:}" --sfx=":"
  1769. return
  1770. ;;
  1771. -G,*|-S,*)
  1772. __git_complete_symbol
  1773. return
  1774. ;;
  1775. esac
  1776. case "$cur" in
  1777. --pretty=*|--format=*)
  1778. __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
  1779. " "" "${cur#*=}"
  1780. return
  1781. ;;
  1782. --date=*)
  1783. __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
  1784. return
  1785. ;;
  1786. --decorate=*)
  1787. __gitcomp "full short no" "" "${cur##--decorate=}"
  1788. return
  1789. ;;
  1790. --diff-algorithm=*)
  1791. __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
  1792. return
  1793. ;;
  1794. --submodule=*)
  1795. __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
  1796. return
  1797. ;;
  1798. --no-walk=*)
  1799. __gitcomp "sorted unsorted" "" "${cur##--no-walk=}"
  1800. return
  1801. ;;
  1802. --*)
  1803. __gitcomp "
  1804. $__git_log_common_options
  1805. $__git_log_shortlog_options
  1806. $__git_log_gitk_options
  1807. --root --topo-order --date-order --reverse
  1808. --follow --full-diff
  1809. --abbrev-commit --no-abbrev-commit --abbrev=
  1810. --relative-date --date=
  1811. --pretty= --format= --oneline
  1812. --show-signature
  1813. --cherry-mark
  1814. --cherry-pick
  1815. --graph
  1816. --decorate --decorate= --no-decorate
  1817. --walk-reflogs
  1818. --no-walk --no-walk= --do-walk
  1819. --parents --children
  1820. --expand-tabs --expand-tabs= --no-expand-tabs
  1821. --patch
  1822. $merge
  1823. $__git_diff_common_options
  1824. --pickaxe-all --pickaxe-regex
  1825. "
  1826. return
  1827. ;;
  1828. -L:*:*)
  1829. return # fall back to Bash filename completion
  1830. ;;
  1831. -L:*)
  1832. __git_complete_symbol --cur="${cur#-L:}" --sfx=":"
  1833. return
  1834. ;;
  1835. -G*)
  1836. __git_complete_symbol --pfx="-G" --cur="${cur#-G}"
  1837. return
  1838. ;;
  1839. -S*)
  1840. __git_complete_symbol --pfx="-S" --cur="${cur#-S}"
  1841. return
  1842. ;;
  1843. esac
  1844. __git_complete_revlist
  1845. }
  1846.  
  1847. _git_merge ()
  1848. {
  1849. __git_complete_strategy && return
  1850.  
  1851. case "$cur" in
  1852. --*)
  1853. __gitcomp_builtin merge
  1854. return
  1855. esac
  1856. __git_complete_refs
  1857. }
  1858.  
  1859. _git_mergetool ()
  1860. {
  1861. case "$cur" in
  1862. --tool=*)
  1863. __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
  1864. return
  1865. ;;
  1866. --*)
  1867. __gitcomp "--tool= --prompt --no-prompt --gui --no-gui"
  1868. return
  1869. ;;
  1870. esac
  1871. }
  1872.  
  1873. _git_merge_base ()
  1874. {
  1875. case "$cur" in
  1876. --*)
  1877. __gitcomp_builtin merge-base
  1878. return
  1879. ;;
  1880. esac
  1881. __git_complete_refs
  1882. }
  1883.  
  1884. _git_mv ()
  1885. {
  1886. case "$cur" in
  1887. --*)
  1888. __gitcomp_builtin mv
  1889. return
  1890. ;;
  1891. esac
  1892.  
  1893. if [ $(__git_count_arguments "mv") -gt 0 ]; then
  1894. # We need to show both cached and untracked files (including
  1895. # empty directories) since this may not be the last argument.
  1896. __git_complete_index_file "--cached --others --directory"
  1897. else
  1898. __git_complete_index_file "--cached"
  1899. fi
  1900. }
  1901.  
  1902. _git_notes ()
  1903. {
  1904. local subcommands='add append copy edit get-ref list merge prune remove show'
  1905. local subcommand="$(__git_find_on_cmdline "$subcommands")"
  1906.  
  1907. case "$subcommand,$cur" in
  1908. ,--*)
  1909. __gitcomp_builtin notes
  1910. ;;
  1911. ,*)
  1912. case "$prev" in
  1913. --ref)
  1914. __git_complete_refs
  1915. ;;
  1916. *)
  1917. __gitcomp "$subcommands --ref"
  1918. ;;
  1919. esac
  1920. ;;
  1921. *,--reuse-message=*|*,--reedit-message=*)
  1922. __git_complete_refs --cur="${cur#*=}"
  1923. ;;
  1924. *,--*)
  1925. __gitcomp_builtin notes_$subcommand
  1926. ;;
  1927. prune,*|get-ref,*)
  1928. # this command does not take a ref, do not complete it
  1929. ;;
  1930. *)
  1931. case "$prev" in
  1932. -m|-F)
  1933. ;;
  1934. *)
  1935. __git_complete_refs
  1936. ;;
  1937. esac
  1938. ;;
  1939. esac
  1940. }
  1941.  
  1942. _git_pull ()
  1943. {
  1944. __git_complete_strategy && return
  1945.  
  1946. case "$cur" in
  1947. --recurse-submodules=*)
  1948. __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
  1949. return
  1950. ;;
  1951. --*)
  1952. __gitcomp_builtin pull
  1953.  
  1954. return
  1955. ;;
  1956. esac
  1957. __git_complete_remote_or_refspec
  1958. }
  1959.  
  1960. __git_push_recurse_submodules="check on-demand only"
  1961.  
  1962. __git_complete_force_with_lease ()
  1963. {
  1964. local cur_=$1
  1965.  
  1966. case "$cur_" in
  1967. --*=)
  1968. ;;
  1969. *:*)
  1970. __git_complete_refs --cur="${cur_#*:}"
  1971. ;;
  1972. *)
  1973. __git_complete_refs --cur="$cur_"
  1974. ;;
  1975. esac
  1976. }
  1977.  
  1978. _git_push ()
  1979. {
  1980. case "$prev" in
  1981. --repo)
  1982. __gitcomp_nl "$(__git_remotes)"
  1983. return
  1984. ;;
  1985. --recurse-submodules)
  1986. __gitcomp "$__git_push_recurse_submodules"
  1987. return
  1988. ;;
  1989. esac
  1990. case "$cur" in
  1991. --repo=*)
  1992. __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
  1993. return
  1994. ;;
  1995. --recurse-submodules=*)
  1996. __gitcomp "$__git_push_recurse_submodules" "" "${cur##--recurse-submodules=}"
  1997. return
  1998. ;;
  1999. --force-with-lease=*)
  2000. __git_complete_force_with_lease "${cur##--force-with-lease=}"
  2001. return
  2002. ;;
  2003. --*)
  2004. __gitcomp_builtin push
  2005. return
  2006. ;;
  2007. esac
  2008. __git_complete_remote_or_refspec
  2009. }
  2010.  
  2011. _git_range_diff ()
  2012. {
  2013. case "$cur" in
  2014. --*)
  2015. __gitcomp "
  2016. --creation-factor= --no-dual-color
  2017. $__git_diff_common_options
  2018. "
  2019. return
  2020. ;;
  2021. esac
  2022. __git_complete_revlist
  2023. }
  2024.  
  2025. __git_rebase_inprogress_options="--continue --skip --abort --quit --show-current-patch"
  2026. __git_rebase_interactive_inprogress_options="$__git_rebase_inprogress_options --edit-todo"
  2027.  
  2028. _git_rebase ()
  2029. {
  2030. __git_find_repo_path
  2031. if [ -f "$__git_repo_path"/rebase-merge/interactive ]; then
  2032. __gitcomp "$__git_rebase_interactive_inprogress_options"
  2033. return
  2034. elif [ -d "$__git_repo_path"/rebase-apply ] || \
  2035. [ -d "$__git_repo_path"/rebase-merge ]; then
  2036. __gitcomp "$__git_rebase_inprogress_options"
  2037. return
  2038. fi
  2039. __git_complete_strategy && return
  2040. case "$cur" in
  2041. --whitespace=*)
  2042. __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
  2043. return
  2044. ;;
  2045. --onto=*)
  2046. __git_complete_refs --cur="${cur##--onto=}"
  2047. return
  2048. ;;
  2049. --*)
  2050. __gitcomp_builtin rebase "" \
  2051. "$__git_rebase_interactive_inprogress_options"
  2052.  
  2053. return
  2054. esac
  2055. __git_complete_refs
  2056. }
  2057.  
  2058. _git_reflog ()
  2059. {
  2060. local subcommands="show delete expire"
  2061. local subcommand="$(__git_find_on_cmdline "$subcommands")"
  2062.  
  2063. if [ -z "$subcommand" ]; then
  2064. __gitcomp "$subcommands"
  2065. else
  2066. __git_complete_refs
  2067. fi
  2068. }
  2069.  
  2070. __git_send_email_confirm_options="always never auto cc compose"
  2071. __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
  2072.  
  2073. _git_send_email ()
  2074. {
  2075. case "$prev" in
  2076. --to|--cc|--bcc|--from)
  2077. __gitcomp "$(__git send-email --dump-aliases)"
  2078. return
  2079. ;;
  2080. esac
  2081.  
  2082. case "$cur" in
  2083. --confirm=*)
  2084. __gitcomp "
  2085. $__git_send_email_confirm_options
  2086. " "" "${cur##--confirm=}"
  2087. return
  2088. ;;
  2089. --suppress-cc=*)
  2090. __gitcomp "
  2091. $__git_send_email_suppresscc_options
  2092. " "" "${cur##--suppress-cc=}"
  2093.  
  2094. return
  2095. ;;
  2096. --smtp-encryption=*)
  2097. __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
  2098. return
  2099. ;;
  2100. --thread=*)
  2101. __gitcomp "
  2102. deep shallow
  2103. " "" "${cur##--thread=}"
  2104. return
  2105. ;;
  2106. --to=*|--cc=*|--bcc=*|--from=*)
  2107. __gitcomp "$(__git send-email --dump-aliases)" "" "${cur#--*=}"
  2108. return
  2109. ;;
  2110. --*)
  2111. __gitcomp_builtin send-email "--annotate --bcc --cc --cc-cmd --chain-reply-to
  2112. --compose --confirm= --dry-run --envelope-sender
  2113. --from --identity
  2114. --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
  2115. --no-suppress-from --no-thread --quiet --reply-to
  2116. --signed-off-by-cc --smtp-pass --smtp-server
  2117. --smtp-server-port --smtp-encryption= --smtp-user
  2118. --subject --suppress-cc= --suppress-from --thread --to
  2119. --validate --no-validate
  2120. $__git_format_patch_extra_options"
  2121. return
  2122. ;;
  2123. esac
  2124. __git_complete_revlist
  2125. }
  2126.  
  2127. _git_stage ()
  2128. {
  2129. _git_add
  2130. }
  2131.  
  2132. _git_status ()
  2133. {
  2134. local complete_opt
  2135. local untracked_state
  2136.  
  2137. case "$cur" in
  2138. --ignore-submodules=*)
  2139. __gitcomp "none untracked dirty all" "" "${cur##--ignore-submodules=}"
  2140. return
  2141. ;;
  2142. --untracked-files=*)
  2143. __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
  2144. return
  2145. ;;
  2146. --column=*)
  2147. __gitcomp "
  2148. always never auto column row plain dense nodense
  2149. " "" "${cur##--column=}"
  2150. return
  2151. ;;
  2152. --*)
  2153. __gitcomp_builtin status
  2154. return
  2155. ;;
  2156. esac
  2157.  
  2158. untracked_state="$(__git_get_option_value "-u" "--untracked-files=" \
  2159. "$__git_untracked_file_modes" "status.showUntrackedFiles")"
  2160.  
  2161. case "$untracked_state" in
  2162. no)
  2163. # --ignored option does not matter
  2164. complete_opt=
  2165. ;;
  2166. all|normal|*)
  2167. complete_opt="--cached --directory --no-empty-directory --others"
  2168.  
  2169. if [ -n "$(__git_find_on_cmdline "--ignored")" ]; then
  2170. complete_opt="$complete_opt --ignored --exclude=*"
  2171. fi
  2172. ;;
  2173. esac
  2174.  
  2175. __git_complete_index_file "$complete_opt"
  2176. }
  2177.  
  2178. _git_switch ()
  2179. {
  2180. case "$cur" in
  2181. --conflict=*)
  2182. __gitcomp "diff3 merge" "" "${cur##--conflict=}"
  2183. ;;
  2184. --*)
  2185. __gitcomp_builtin switch
  2186. ;;
  2187. *)
  2188. # check if --track, --no-track, or --no-guess was specified
  2189. # if so, disable DWIM mode
  2190. local track_opt="--track" only_local_ref=n
  2191. if [ "$GIT_COMPLETION_CHECKOUT_NO_GUESS" = "1" ] ||
  2192. [ -n "$(__git_find_on_cmdline "--track --no-track --no-guess")" ]; then
  2193. track_opt=''
  2194. fi
  2195. # explicit --guess enables DWIM mode regardless of
  2196. # $GIT_COMPLETION_CHECKOUT_NO_GUESS
  2197. if [ -n "$(__git_find_on_cmdline "--guess")" ]; then
  2198. track_opt='--track'
  2199. fi
  2200. if [ -z "$(__git_find_on_cmdline "-d --detach")" ]; then
  2201. only_local_ref=y
  2202. else
  2203. # --guess --detach is invalid combination, no
  2204. # dwim will be done when --detach is specified
  2205. track_opt=
  2206. fi
  2207. if [ $only_local_ref = y -a -z "$track_opt" ]; then
  2208. __gitcomp_direct "$(__git_heads "" "$cur" " ")"
  2209. else
  2210. __git_complete_refs $track_opt
  2211. fi
  2212. ;;
  2213. esac
  2214. }
  2215.  
  2216. __git_config_get_set_variables ()
  2217. {
  2218. local prevword word config_file= c=$cword
  2219. while [ $c -gt 1 ]; do
  2220. word="${words[c]}"
  2221. case "$word" in
  2222. --system|--global|--local|--file=*)
  2223. config_file="$word"
  2224. break
  2225. ;;
  2226. -f|--file)
  2227. config_file="$word $prevword"
  2228. break
  2229. ;;
  2230. esac
  2231. prevword=$word
  2232. c=$((--c))
  2233. done
  2234.  
  2235. __git config $config_file --name-only --list
  2236. }
  2237.  
  2238. __git_config_vars=
  2239. __git_compute_config_vars ()
  2240. {
  2241. test -n "$__git_config_vars" ||
  2242. __git_config_vars="$(git help --config-for-completion | sort -u)"
  2243. }
  2244.  
  2245. # Completes possible values of various configuration variables.
  2246. #
  2247. # Usage: __git_complete_config_variable_value [<option>]...
  2248. # --varname=<word>: The name of the configuration variable whose value is
  2249. # to be completed. Defaults to the previous word on the
  2250. # command line.
  2251. # --cur=<word>: The current value to be completed. Defaults to the current
  2252. # word to be completed.
  2253. __git_complete_config_variable_value ()
  2254. {
  2255. local varname="$prev" cur_="$cur"
  2256.  
  2257. while test $# != 0; do
  2258. case "$1" in
  2259. --varname=*) varname="${1##--varname=}" ;;
  2260. --cur=*) cur_="${1##--cur=}" ;;
  2261. *) return 1 ;;
  2262. esac
  2263. shift
  2264. done
  2265.  
  2266. if [ "${BASH_VERSINFO[0]:-0}" -ge 4 ]; then
  2267. varname="${varname,,}"
  2268. else
  2269. varname="$(echo "$varname" |tr A-Z a-z)"
  2270. fi
  2271.  
  2272. case "$varname" in
  2273. branch.*.remote|branch.*.pushremote)
  2274. __gitcomp_nl "$(__git_remotes)" "" "$cur_"
  2275. return
  2276. ;;
  2277. branch.*.merge)
  2278. __git_complete_refs --cur="$cur_"
  2279. return
  2280. ;;
  2281. branch.*.rebase)
  2282. __gitcomp "false true merges preserve interactive" "" "$cur_"
  2283. return
  2284. ;;
  2285. remote.pushdefault)
  2286. __gitcomp_nl "$(__git_remotes)" "" "$cur_"
  2287. return
  2288. ;;
  2289. remote.*.fetch)
  2290. local remote="${varname#remote.}"
  2291. remote="${remote%.fetch}"
  2292. if [ -z "$cur_" ]; then
  2293. __gitcomp_nl "refs/heads/" "" "" ""
  2294. return
  2295. fi
  2296. __gitcomp_nl "$(__git_refs_remotes "$remote")" "" "$cur_"
  2297. return
  2298. ;;
  2299. remote.*.push)
  2300. local remote="${varname#remote.}"
  2301. remote="${remote%.push}"
  2302. __gitcomp_nl "$(__git for-each-ref \
  2303. --format='%(refname):%(refname)' refs/heads)" "" "$cur_"
  2304. return
  2305. ;;
  2306. pull.twohead|pull.octopus)
  2307. __git_compute_merge_strategies
  2308. __gitcomp "$__git_merge_strategies" "" "$cur_"
  2309. return
  2310. ;;
  2311. color.pager)
  2312. __gitcomp "false true" "" "$cur_"
  2313. return
  2314. ;;
  2315. color.*.*)
  2316. __gitcomp "
  2317. normal black red green yellow blue magenta cyan white
  2318. bold dim ul blink reverse
  2319. " "" "$cur_"
  2320. return
  2321. ;;
  2322. color.*)
  2323. __gitcomp "false true always never auto" "" "$cur_"
  2324. return
  2325. ;;
  2326. diff.submodule)
  2327. __gitcomp "$__git_diff_submodule_formats" "" "$cur_"
  2328. return
  2329. ;;
  2330. help.format)
  2331. __gitcomp "man info web html" "" "$cur_"
  2332. return
  2333. ;;
  2334. log.date)
  2335. __gitcomp "$__git_log_date_formats" "" "$cur_"
  2336. return
  2337. ;;
  2338. sendemail.aliasfiletype)
  2339. __gitcomp "mutt mailrc pine elm gnus" "" "$cur_"
  2340. return
  2341. ;;
  2342. sendemail.confirm)
  2343. __gitcomp "$__git_send_email_confirm_options" "" "$cur_"
  2344. return
  2345. ;;
  2346. sendemail.suppresscc)
  2347. __gitcomp "$__git_send_email_suppresscc_options" "" "$cur_"
  2348. return
  2349. ;;
  2350. sendemail.transferencoding)
  2351. __gitcomp "7bit 8bit quoted-printable base64" "" "$cur_"
  2352. return
  2353. ;;
  2354. *.*)
  2355. return
  2356. ;;
  2357. esac
  2358. }
  2359.  
  2360. # Completes configuration sections, subsections, variable names.
  2361. #
  2362. # Usage: __git_complete_config_variable_name [<option>]...
  2363. # --cur=<word>: The current configuration section/variable name to be
  2364. # completed. Defaults to the current word to be completed.
  2365. # --sfx=<suffix>: A suffix to be appended to each fully completed
  2366. # configuration variable name (but not to sections or
  2367. # subsections) instead of the default space.
  2368. __git_complete_config_variable_name ()
  2369. {
  2370. local cur_="$cur" sfx
  2371.  
  2372. while test $# != 0; do
  2373. case "$1" in
  2374. --cur=*) cur_="${1##--cur=}" ;;
  2375. --sfx=*) sfx="${1##--sfx=}" ;;
  2376. *) return 1 ;;
  2377. esac
  2378. shift
  2379. done
  2380.  
  2381. case "$cur_" in
  2382. branch.*.*)
  2383. local pfx="${cur_%.*}."
  2384. cur_="${cur_##*.}"
  2385. __gitcomp "remote pushRemote merge mergeOptions rebase" "$pfx" "$cur_" "$sfx"
  2386. return
  2387. ;;
  2388. branch.*)
  2389. local pfx="${cur%.*}."
  2390. cur_="${cur#*.}"
  2391. __gitcomp_direct "$(__git_heads "$pfx" "$cur_" ".")"
  2392. __gitcomp_nl_append $'autoSetupMerge\nautoSetupRebase\n' "$pfx" "$cur_" "$sfx"
  2393. return
  2394. ;;
  2395. guitool.*.*)
  2396. local pfx="${cur_%.*}."
  2397. cur_="${cur_##*.}"
  2398. __gitcomp "
  2399. argPrompt cmd confirm needsFile noConsole noRescan
  2400. prompt revPrompt revUnmerged title
  2401. " "$pfx" "$cur_" "$sfx"
  2402. return
  2403. ;;
  2404. difftool.*.*)
  2405. local pfx="${cur_%.*}."
  2406. cur_="${cur_##*.}"
  2407. __gitcomp "cmd path" "$pfx" "$cur_" "$sfx"
  2408. return
  2409. ;;
  2410. man.*.*)
  2411. local pfx="${cur_%.*}."
  2412. cur_="${cur_##*.}"
  2413. __gitcomp "cmd path" "$pfx" "$cur_" "$sfx"
  2414. return
  2415. ;;
  2416. mergetool.*.*)
  2417. local pfx="${cur_%.*}."
  2418. cur_="${cur_##*.}"
  2419. __gitcomp "cmd path trustExitCode" "$pfx" "$cur_" "$sfx"
  2420. return
  2421. ;;
  2422. pager.*)
  2423. local pfx="${cur_%.*}."
  2424. cur_="${cur_#*.}"
  2425. __git_compute_all_commands
  2426. __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_" "$sfx"
  2427. return
  2428. ;;
  2429. remote.*.*)
  2430. local pfx="${cur_%.*}."
  2431. cur_="${cur_##*.}"
  2432. __gitcomp "
  2433. url proxy fetch push mirror skipDefaultUpdate
  2434. receivepack uploadpack tagOpt pushurl
  2435. " "$pfx" "$cur_" "$sfx"
  2436. return
  2437. ;;
  2438. remote.*)
  2439. local pfx="${cur_%.*}."
  2440. cur_="${cur_#*.}"
  2441. __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
  2442. __gitcomp_nl_append "pushDefault" "$pfx" "$cur_" "$sfx"
  2443. return
  2444. ;;
  2445. url.*.*)
  2446. local pfx="${cur_%.*}."
  2447. cur_="${cur_##*.}"
  2448. __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_" "$sfx"
  2449. return
  2450. ;;
  2451. *.*)
  2452. __git_compute_config_vars
  2453. __gitcomp "$__git_config_vars" "" "$cur_" "$sfx"
  2454. ;;
  2455. *)
  2456. __git_compute_config_vars
  2457. __gitcomp "$(echo "$__git_config_vars" |
  2458. awk -F . '{
  2459. sections[$1] = 1
  2460. }
  2461. END {
  2462. for (s in sections)
  2463. print s "."
  2464. }
  2465. ')" "" "$cur_"
  2466. ;;
  2467. esac
  2468. }
  2469.  
  2470. # Completes '='-separated configuration sections/variable names and values
  2471. # for 'git -c section.name=value'.
  2472. #
  2473. # Usage: __git_complete_config_variable_name_and_value [<option>]...
  2474. # --cur=<word>: The current configuration section/variable name/value to be
  2475. # completed. Defaults to the current word to be completed.
  2476. __git_complete_config_variable_name_and_value ()
  2477. {
  2478. local cur_="$cur"
  2479.  
  2480. while test $# != 0; do
  2481. case "$1" in
  2482. --cur=*) cur_="${1##--cur=}" ;;
  2483. *) return 1 ;;
  2484. esac
  2485. shift
  2486. done
  2487.  
  2488. case "$cur_" in
  2489. *=*)
  2490. __git_complete_config_variable_value \
  2491. --varname="${cur_%%=*}" --cur="${cur_#*=}"
  2492. ;;
  2493. *)
  2494. __git_complete_config_variable_name --cur="$cur_" --sfx='='
  2495. ;;
  2496. esac
  2497. }
  2498.  
  2499. _git_config ()
  2500. {
  2501. case "$prev" in
  2502. --get|--get-all|--unset|--unset-all)
  2503. __gitcomp_nl "$(__git_config_get_set_variables)"
  2504. return
  2505. ;;
  2506. *.*)
  2507. __git_complete_config_variable_value
  2508. return
  2509. ;;
  2510. esac
  2511. case "$cur" in
  2512. --*)
  2513. __gitcomp_builtin config
  2514. ;;
  2515. *)
  2516. __git_complete_config_variable_name
  2517. ;;
  2518. esac
  2519. }
  2520.  
  2521. _git_remote ()
  2522. {
  2523. local subcommands="
  2524. add rename remove set-head set-branches
  2525. get-url set-url show prune update
  2526. "
  2527. local subcommand="$(__git_find_on_cmdline "$subcommands")"
  2528. if [ -z "$subcommand" ]; then
  2529. case "$cur" in
  2530. --*)
  2531. __gitcomp_builtin remote
  2532. ;;
  2533. *)
  2534. __gitcomp "$subcommands"
  2535. ;;
  2536. esac
  2537. return
  2538. fi
  2539.  
  2540. case "$subcommand,$cur" in
  2541. add,--*)
  2542. __gitcomp_builtin remote_add
  2543. ;;
  2544. add,*)
  2545. ;;
  2546. set-head,--*)
  2547. __gitcomp_builtin remote_set-head
  2548. ;;
  2549. set-branches,--*)
  2550. __gitcomp_builtin remote_set-branches
  2551. ;;
  2552. set-head,*|set-branches,*)
  2553. __git_complete_remote_or_refspec
  2554. ;;
  2555. update,--*)
  2556. __gitcomp_builtin remote_update
  2557. ;;
  2558. update,*)
  2559. __gitcomp "$(__git_remotes) $(__git_get_config_variables "remotes")"
  2560. ;;
  2561. set-url,--*)
  2562. __gitcomp_builtin remote_set-url
  2563. ;;
  2564. get-url,--*)
  2565. __gitcomp_builtin remote_get-url
  2566. ;;
  2567. prune,--*)
  2568. __gitcomp_builtin remote_prune
  2569. ;;
  2570. *)
  2571. __gitcomp_nl "$(__git_remotes)"
  2572. ;;
  2573. esac
  2574. }
  2575.  
  2576. _git_replace ()
  2577. {
  2578. case "$cur" in
  2579. --format=*)
  2580. __gitcomp "short medium long" "" "${cur##--format=}"
  2581. return
  2582. ;;
  2583. --*)
  2584. __gitcomp_builtin replace
  2585. return
  2586. ;;
  2587. esac
  2588. __git_complete_refs
  2589. }
  2590.  
  2591. _git_rerere ()
  2592. {
  2593. local subcommands="clear forget diff remaining status gc"
  2594. local subcommand="$(__git_find_on_cmdline "$subcommands")"
  2595. if test -z "$subcommand"
  2596. then
  2597. __gitcomp "$subcommands"
  2598. return
  2599. fi
  2600. }
  2601.  
  2602. _git_reset ()
  2603. {
  2604. __git_has_doubledash && return
  2605.  
  2606. case "$cur" in
  2607. --*)
  2608. __gitcomp_builtin reset
  2609. return
  2610. ;;
  2611. esac
  2612. __git_complete_refs
  2613. }
  2614.  
  2615. _git_restore ()
  2616. {
  2617. case "$cur" in
  2618. --conflict=*)
  2619. __gitcomp "diff3 merge" "" "${cur##--conflict=}"
  2620. ;;
  2621. --source=*)
  2622. __git_complete_refs --cur="${cur##--source=}"
  2623. ;;
  2624. --*)
  2625. __gitcomp_builtin restore
  2626. ;;
  2627. esac
  2628. }
  2629.  
  2630. __git_revert_inprogress_options=$__git_sequencer_inprogress_options
  2631.  
  2632. _git_revert ()
  2633. {
  2634. __git_find_repo_path
  2635. if [ -f "$__git_repo_path"/REVERT_HEAD ]; then
  2636. __gitcomp "$__git_revert_inprogress_options"
  2637. return
  2638. fi
  2639. __git_complete_strategy && return
  2640. case "$cur" in
  2641. --*)
  2642. __gitcomp_builtin revert "" \
  2643. "$__git_revert_inprogress_options"
  2644. return
  2645. ;;
  2646. esac
  2647. __git_complete_refs
  2648. }
  2649.  
  2650. _git_rm ()
  2651. {
  2652. case "$cur" in
  2653. --*)
  2654. __gitcomp_builtin rm
  2655. return
  2656. ;;
  2657. esac
  2658.  
  2659. __git_complete_index_file "--cached"
  2660. }
  2661.  
  2662. _git_shortlog ()
  2663. {
  2664. __git_has_doubledash && return
  2665.  
  2666. case "$cur" in
  2667. --*)
  2668. __gitcomp "
  2669. $__git_log_common_options
  2670. $__git_log_shortlog_options
  2671. --numbered --summary --email
  2672. "
  2673. return
  2674. ;;
  2675. esac
  2676. __git_complete_revlist
  2677. }
  2678.  
  2679. _git_show ()
  2680. {
  2681. __git_has_doubledash && return
  2682.  
  2683. case "$cur" in
  2684. --pretty=*|--format=*)
  2685. __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
  2686. " "" "${cur#*=}"
  2687. return
  2688. ;;
  2689. --diff-algorithm=*)
  2690. __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
  2691. return
  2692. ;;
  2693. --submodule=*)
  2694. __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
  2695. return
  2696. ;;
  2697. --*)
  2698. __gitcomp "--pretty= --format= --abbrev-commit --no-abbrev-commit
  2699. --oneline --show-signature --patch
  2700. --expand-tabs --expand-tabs= --no-expand-tabs
  2701. $__git_diff_common_options
  2702. "
  2703. return
  2704. ;;
  2705. esac
  2706. __git_complete_revlist_file
  2707. }
  2708.  
  2709. _git_show_branch ()
  2710. {
  2711. case "$cur" in
  2712. --*)
  2713. __gitcomp_builtin show-branch
  2714. return
  2715. ;;
  2716. esac
  2717. __git_complete_revlist
  2718. }
  2719.  
  2720. _git_stash ()
  2721. {
  2722. local save_opts='--all --keep-index --no-keep-index --quiet --patch --include-untracked'
  2723. local subcommands='push list show apply clear drop pop create branch'
  2724. local subcommand="$(__git_find_on_cmdline "$subcommands save")"
  2725. if [ -n "$(__git_find_on_cmdline "-p")" ]; then
  2726. subcommand="push"
  2727. fi
  2728. if [ -z "$subcommand" ]; then
  2729. case "$cur" in
  2730. --*)
  2731. __gitcomp "$save_opts"
  2732. ;;
  2733. sa*)
  2734. if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
  2735. __gitcomp "save"
  2736. fi
  2737. ;;
  2738. *)
  2739. if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
  2740. __gitcomp "$subcommands"
  2741. fi
  2742. ;;
  2743. esac
  2744. else
  2745. case "$subcommand,$cur" in
  2746. push,--*)
  2747. __gitcomp "$save_opts --message"
  2748. ;;
  2749. save,--*)
  2750. __gitcomp "$save_opts"
  2751. ;;
  2752. apply,--*|pop,--*)
  2753. __gitcomp "--index --quiet"
  2754. ;;
  2755. drop,--*)
  2756. __gitcomp "--quiet"
  2757. ;;
  2758. list,--*)
  2759. __gitcomp "--name-status --oneline --patch-with-stat"
  2760. ;;
  2761. show,--*|branch,--*)
  2762. ;;
  2763. branch,*)
  2764. if [ $cword -eq 3 ]; then
  2765. __git_complete_refs
  2766. else
  2767. __gitcomp_nl "$(__git stash list \
  2768. | sed -n -e 's/:.*//p')"
  2769. fi
  2770. ;;
  2771. show,*|apply,*|drop,*|pop,*)
  2772. __gitcomp_nl "$(__git stash list \
  2773. | sed -n -e 's/:.*//p')"
  2774. ;;
  2775. *)
  2776. ;;
  2777. esac
  2778. fi
  2779. }
  2780.  
  2781. _git_submodule ()
  2782. {
  2783. __git_has_doubledash && return
  2784.  
  2785. local subcommands="add status init deinit update set-branch set-url summary foreach sync absorbgitdirs"
  2786. local subcommand="$(__git_find_on_cmdline "$subcommands")"
  2787. if [ -z "$subcommand" ]; then
  2788. case "$cur" in
  2789. --*)
  2790. __gitcomp "--quiet"
  2791. ;;
  2792. *)
  2793. __gitcomp "$subcommands"
  2794. ;;
  2795. esac
  2796. return
  2797. fi
  2798.  
  2799. case "$subcommand,$cur" in
  2800. add,--*)
  2801. __gitcomp "--branch --force --name --reference --depth"
  2802. ;;
  2803. status,--*)
  2804. __gitcomp "--cached --recursive"
  2805. ;;
  2806. deinit,--*)
  2807. __gitcomp "--force --all"
  2808. ;;
  2809. update,--*)
  2810. __gitcomp "
  2811. --init --remote --no-fetch
  2812. --recommend-shallow --no-recommend-shallow
  2813. --force --rebase --merge --reference --depth --recursive --jobs
  2814. "
  2815. ;;
  2816. set-branch,--*)
  2817. __gitcomp "--default --branch"
  2818. ;;
  2819. summary,--*)
  2820. __gitcomp "--cached --files --summary-limit"
  2821. ;;
  2822. foreach,--*|sync,--*)
  2823. __gitcomp "--recursive"
  2824. ;;
  2825. *)
  2826. ;;
  2827. esac
  2828. }
  2829.  
  2830. _git_svn ()
  2831. {
  2832. local subcommands="
  2833. init fetch clone rebase dcommit log find-rev
  2834. set-tree commit-diff info create-ignore propget
  2835. proplist show-ignore show-externals branch tag blame
  2836. migrate mkdirs reset gc
  2837. "
  2838. local subcommand="$(__git_find_on_cmdline "$subcommands")"
  2839. if [ -z "$subcommand" ]; then
  2840. __gitcomp "$subcommands"
  2841. else
  2842. local remote_opts="--username= --config-dir= --no-auth-cache"
  2843. local fc_opts="
  2844. --follow-parent --authors-file= --repack=
  2845. --no-metadata --use-svm-props --use-svnsync-props
  2846. --log-window-size= --no-checkout --quiet
  2847. --repack-flags --use-log-author --localtime
  2848. --add-author-from
  2849. --recursive
  2850. --ignore-paths= --include-paths= $remote_opts
  2851. "
  2852. local init_opts="
  2853. --template= --shared= --trunk= --tags=
  2854. --branches= --stdlayout --minimize-url
  2855. --no-metadata --use-svm-props --use-svnsync-props
  2856. --rewrite-root= --prefix= $remote_opts
  2857. "
  2858. local cmt_opts="
  2859. --edit --rmdir --find-copies-harder --copy-similarity=
  2860. "
  2861.  
  2862. case "$subcommand,$cur" in
  2863. fetch,--*)
  2864. __gitcomp "--revision= --fetch-all $fc_opts"
  2865. ;;
  2866. clone,--*)
  2867. __gitcomp "--revision= $fc_opts $init_opts"
  2868. ;;
  2869. init,--*)
  2870. __gitcomp "$init_opts"
  2871. ;;
  2872. dcommit,--*)
  2873. __gitcomp "
  2874. --merge --strategy= --verbose --dry-run
  2875. --fetch-all --no-rebase --commit-url
  2876. --revision --interactive $cmt_opts $fc_opts
  2877. "
  2878. ;;
  2879. set-tree,--*)
  2880. __gitcomp "--stdin $cmt_opts $fc_opts"
  2881. ;;
  2882. create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
  2883. show-externals,--*|mkdirs,--*)
  2884. __gitcomp "--revision="
  2885. ;;
  2886. log,--*)
  2887. __gitcomp "
  2888. --limit= --revision= --verbose --incremental
  2889. --oneline --show-commit --non-recursive
  2890. --authors-file= --color
  2891. "
  2892. ;;
  2893. rebase,--*)
  2894. __gitcomp "
  2895. --merge --verbose --strategy= --local
  2896. --fetch-all --dry-run $fc_opts
  2897. "
  2898. ;;
  2899. commit-diff,--*)
  2900. __gitcomp "--message= --file= --revision= $cmt_opts"
  2901. ;;
  2902. info,--*)
  2903. __gitcomp "--url"
  2904. ;;
  2905. branch,--*)
  2906. __gitcomp "--dry-run --message --tag"
  2907. ;;
  2908. tag,--*)
  2909. __gitcomp "--dry-run --message"
  2910. ;;
  2911. blame,--*)
  2912. __gitcomp "--git-format"
  2913. ;;
  2914. migrate,--*)
  2915. __gitcomp "
  2916. --config-dir= --ignore-paths= --minimize
  2917. --no-auth-cache --username=
  2918. "
  2919. ;;
  2920. reset,--*)
  2921. __gitcomp "--revision= --parent"
  2922. ;;
  2923. *)
  2924. ;;
  2925. esac
  2926. fi
  2927. }
  2928.  
  2929. _git_tag ()
  2930. {
  2931. local i c=1 f=0
  2932. while [ $c -lt $cword ]; do
  2933. i="${words[c]}"
  2934. case "$i" in
  2935. -d|--delete|-v|--verify)
  2936. __gitcomp_direct "$(__git_tags "" "$cur" " ")"
  2937. return
  2938. ;;
  2939. -f)
  2940. f=1
  2941. ;;
  2942. esac
  2943. ((c++))
  2944. done
  2945.  
  2946. case "$prev" in
  2947. -m|-F)
  2948. ;;
  2949. -*|tag)
  2950. if [ $f = 1 ]; then
  2951. __gitcomp_direct "$(__git_tags "" "$cur" " ")"
  2952. fi
  2953. ;;
  2954. *)
  2955. __git_complete_refs
  2956. ;;
  2957. esac
  2958.  
  2959. case "$cur" in
  2960. --*)
  2961. __gitcomp_builtin tag
  2962. ;;
  2963. esac
  2964. }
  2965.  
  2966. _git_whatchanged ()
  2967. {
  2968. _git_log
  2969. }
  2970.  
  2971. _git_worktree ()
  2972. {
  2973. local subcommands="add list lock move prune remove unlock"
  2974. local subcommand="$(__git_find_on_cmdline "$subcommands")"
  2975. if [ -z "$subcommand" ]; then
  2976. __gitcomp "$subcommands"
  2977. else
  2978. case "$subcommand,$cur" in
  2979. add,--*)
  2980. __gitcomp_builtin worktree_add
  2981. ;;
  2982. list,--*)
  2983. __gitcomp_builtin worktree_list
  2984. ;;
  2985. lock,--*)
  2986. __gitcomp_builtin worktree_lock
  2987. ;;
  2988. prune,--*)
  2989. __gitcomp_builtin worktree_prune
  2990. ;;
  2991. remove,--*)
  2992. __gitcomp "--force"
  2993. ;;
  2994. *)
  2995. ;;
  2996. esac
  2997. fi
  2998. }
  2999.  
  3000. __git_complete_common () {
  3001. local command="$1"
  3002.  
  3003. case "$cur" in
  3004. --*)
  3005. __gitcomp_builtin "$command"
  3006. ;;
  3007. esac
  3008. }
  3009.  
  3010. __git_cmds_with_parseopt_helper=
  3011. __git_support_parseopt_helper () {
  3012. test -n "$__git_cmds_with_parseopt_helper" ||
  3013. __git_cmds_with_parseopt_helper="$(__git --list-cmds=parseopt)"
  3014.  
  3015. case " $__git_cmds_with_parseopt_helper " in
  3016. *" $1 "*)
  3017. return 0
  3018. ;;
  3019. *)
  3020. return 1
  3021. ;;
  3022. esac
  3023. }
  3024.  
  3025. __git_complete_command () {
  3026. local command="$1"
  3027. local completion_func="_git_${command//-/_}"
  3028. if ! declare -f $completion_func >/dev/null 2>/dev/null &&
  3029. declare -f _completion_loader >/dev/null 2>/dev/null
  3030. then
  3031. _completion_loader "git-$command"
  3032. fi
  3033. if declare -f $completion_func >/dev/null 2>/dev/null
  3034. then
  3035. $completion_func
  3036. return 0
  3037. elif __git_support_parseopt_helper "$command"
  3038. then
  3039. __git_complete_common "$command"
  3040. return 0
  3041. else
  3042. return 1
  3043. fi
  3044. }
  3045.  
  3046. __git_main ()
  3047. {
  3048. local i c=1 command __git_dir __git_repo_path
  3049. local __git_C_args C_args_count=0
  3050.  
  3051. while [ $c -lt $cword ]; do
  3052. i="${words[c]}"
  3053. case "$i" in
  3054. --git-dir=*) __git_dir="${i#--git-dir=}" ;;
  3055. --git-dir) ((c++)) ; __git_dir="${words[c]}" ;;
  3056. --bare) __git_dir="." ;;
  3057. --help) command="help"; break ;;
  3058. -c|--work-tree|--namespace) ((c++)) ;;
  3059. -C) __git_C_args[C_args_count++]=-C
  3060. ((c++))
  3061. __git_C_args[C_args_count++]="${words[c]}"
  3062. ;;
  3063. -*) ;;
  3064. *) command="$i"; break ;;
  3065. esac
  3066. ((c++))
  3067. done
  3068.  
  3069. if [ -z "$command" ]; then
  3070. case "$prev" in
  3071. --git-dir|-C|--work-tree)
  3072. # these need a path argument, let's fall back to
  3073. # Bash filename completion
  3074. return
  3075. ;;
  3076. -c)
  3077. __git_complete_config_variable_name_and_value
  3078. return
  3079. ;;
  3080. --namespace)
  3081. # we don't support completing these options' arguments
  3082. return
  3083. ;;
  3084. esac
  3085. case "$cur" in
  3086. --*) __gitcomp "
  3087. --paginate
  3088. --no-pager
  3089. --git-dir=
  3090. --bare
  3091. --version
  3092. --exec-path
  3093. --exec-path=
  3094. --html-path
  3095. --man-path
  3096. --info-path
  3097. --work-tree=
  3098. --namespace=
  3099. --no-replace-objects
  3100. --help
  3101. "
  3102. ;;
  3103. *)
  3104. if test -n "$GIT_TESTING_PORCELAIN_COMMAND_LIST"
  3105. then
  3106. __gitcomp "$GIT_TESTING_PORCELAIN_COMMAND_LIST"
  3107. else
  3108. __gitcomp "$(__git --list-cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config)"
  3109. fi
  3110. ;;
  3111. esac
  3112. return
  3113. fi
  3114.  
  3115. __git_complete_command "$command" && return
  3116.  
  3117. local expansion=$(__git_aliased_command "$command")
  3118. if [ -n "$expansion" ]; then
  3119. words[1]=$expansion
  3120. __git_complete_command "$expansion"
  3121. fi
  3122. }
  3123.  
  3124. __gitk_main ()
  3125. {
  3126. __git_has_doubledash && return
  3127.  
  3128. local __git_repo_path
  3129. __git_find_repo_path
  3130.  
  3131. local merge=""
  3132. if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
  3133. merge="--merge"
  3134. fi
  3135. case "$cur" in
  3136. --*)
  3137. __gitcomp "
  3138. $__git_log_common_options
  3139. $__git_log_gitk_options
  3140. $merge
  3141. "
  3142. return
  3143. ;;
  3144. esac
  3145. __git_complete_revlist
  3146. }
  3147.  
  3148. if [[ -n ${ZSH_VERSION-} ]] &&
  3149. # Don't define these functions when sourced from 'git-completion.zsh',
  3150. # it has its own implementations.
  3151. [[ -z ${GIT_SOURCING_ZSH_COMPLETION-} ]]; then
  3152. echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
  3153.  
  3154. autoload -U +X compinit && compinit
  3155.  
  3156. __gitcomp ()
  3157. {
  3158. emulate -L zsh
  3159.  
  3160. local cur_="${3-$cur}"
  3161.  
  3162. case "$cur_" in
  3163. --*=)
  3164. ;;
  3165. *)
  3166. local c IFS=$' \t\n'
  3167. local -a array
  3168. for c in ${=1}; do
  3169. c="$c${4-}"
  3170. case $c in
  3171. --*=*|*.) ;;
  3172. *) c="$c " ;;
  3173. esac
  3174. array[${#array[@]}+1]="$c"
  3175. done
  3176. compset -P '*[=:]'
  3177. compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
  3178. ;;
  3179. esac
  3180. }
  3181.  
  3182. __gitcomp_direct ()
  3183. {
  3184. emulate -L zsh
  3185.  
  3186. local IFS=$'\n'
  3187. compset -P '*[=:]'
  3188. compadd -Q -- ${=1} && _ret=0
  3189. }
  3190.  
  3191. __gitcomp_nl ()
  3192. {
  3193. emulate -L zsh
  3194.  
  3195. local IFS=$'\n'
  3196. compset -P '*[=:]'
  3197. compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
  3198. }
  3199.  
  3200. __gitcomp_file_direct ()
  3201. {
  3202. emulate -L zsh
  3203.  
  3204. local IFS=$'\n'
  3205. compset -P '*[=:]'
  3206. compadd -f -- ${=1} && _ret=0
  3207. }
  3208.  
  3209. __gitcomp_file ()
  3210. {
  3211. emulate -L zsh
  3212.  
  3213. local IFS=$'\n'
  3214. compset -P '*[=:]'
  3215. compadd -p "${2-}" -f -- ${=1} && _ret=0
  3216. }
  3217.  
  3218. _git ()
  3219. {
  3220. local _ret=1 cur cword prev
  3221. cur=${words[CURRENT]}
  3222. prev=${words[CURRENT-1]}
  3223. let cword=CURRENT-1
  3224. emulate ksh -c __${service}_main
  3225. let _ret && _default && _ret=0
  3226. return _ret
  3227. }
  3228.  
  3229. compdef _git git gitk
  3230. return
  3231. fi
  3232.  
  3233. __git_func_wrap ()
  3234. {
  3235. local cur words cword prev
  3236. _get_comp_words_by_ref -n =: cur words cword prev
  3237. $1
  3238. }
  3239.  
  3240. # Setup completion for certain functions defined above by setting common
  3241. # variables and workarounds.
  3242. # This is NOT a public function; use at your own risk.
  3243. __git_complete ()
  3244. {
  3245. local wrapper="__git_wrap${2}"
  3246. eval "$wrapper () { __git_func_wrap $2 ; }"
  3247. complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
  3248. || complete -o default -o nospace -F $wrapper $1
  3249. }
  3250.  
  3251. # wrapper for backwards compatibility
  3252. _git ()
  3253. {
  3254. __git_wrap__git_main
  3255. }
  3256.  
  3257. # wrapper for backwards compatibility
  3258. _gitk ()
  3259. {
  3260. __git_wrap__gitk_main
  3261. }
  3262.  
  3263. __git_complete git __git_main
  3264. __git_complete gitk __gitk_main
  3265.  
  3266. # The following are necessary only for Cygwin, and only are needed
  3267. # when the user has tab-completed the executable name and consequently
  3268. # included the '.exe' suffix.
  3269. #
  3270. if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
  3271. __git_complete git.exe __git_main
  3272. fi
Add Comment
Please, Sign In to add comment