Git fork
at reftables-rust 4019 lines 95 kB view raw
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# *) 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# Note that "git" is optional --- '!f() { : commit; ...}; f' would complete 32# just like the 'git commit' command. 33# 34# To add completion for git subcommands that are implemented in external 35# scripts, define a function of the form '_git_${subcommand}' while replacing 36# all dashes with underscores, and the main git completion will make use of it. 37# For example, to add completion for 'git do-stuff' (which could e.g. live 38# in /usr/bin/git-do-stuff), name the completion function '_git_do_stuff'. 39# See _git_show, _git_bisect etc. below for more examples. 40# 41# If you have a shell command that is not part of git (and is not called as a 42# git subcommand), but you would still like git-style completion for it, use 43# __git_complete. For example, to use the same completion as for 'git log' also 44# for the 'gl' command: 45# 46# __git_complete gl git_log 47# 48# Or if the 'gk' command should be completed the same as 'gitk': 49# 50# __git_complete gk gitk 51# 52# The second parameter of __git_complete gives the completion function; it is 53# resolved as a function named "$2", or "__$2_main", or "_$2" in that order. 54# In the examples above, the actual functions used for completion will be 55# _git_log and __gitk_main. 56# 57# Compatible with bash 3.2.57. 58# 59# You can set the following environment variables to influence the behavior of 60# the completion routines: 61# 62# GIT_COMPLETION_CHECKOUT_NO_GUESS 63# 64# When set to "1", do not include "DWIM" suggestions in git-checkout 65# and git-switch completion (e.g., completing "foo" when "origin/foo" 66# exists). 67# 68# GIT_COMPLETION_SHOW_ALL_COMMANDS 69# 70# When set to "1" suggest all commands, including plumbing commands 71# which are hidden by default (e.g. "cat-file" on "git ca<TAB>"). 72# 73# GIT_COMPLETION_SHOW_ALL 74# 75# When set to "1" suggest all options, including options which are 76# typically hidden (e.g. '--allow-empty' for 'git commit'). 77# 78# GIT_COMPLETION_IGNORE_CASE 79# 80# When set, uses for-each-ref '--ignore-case' to find refs that match 81# case insensitively, even on systems with case sensitive file systems 82# (e.g., completing tag name "FOO" on "git checkout f<TAB>"). 83 84case "$COMP_WORDBREAKS" in 85*:*) : great ;; 86*) COMP_WORDBREAKS="$COMP_WORDBREAKS:" 87esac 88 89# Discovers the path to the git repository taking any '--git-dir=<path>' and 90# '-C <path>' options into account and stores it in the $__git_repo_path 91# variable. 92__git_find_repo_path () 93{ 94 if [ -n "${__git_repo_path-}" ]; then 95 # we already know where it is 96 return 97 fi 98 99 if [ -n "${__git_C_args-}" ]; then 100 __git_repo_path="$(git "${__git_C_args[@]}" \ 101 ${__git_dir:+--git-dir="$__git_dir"} \ 102 rev-parse --absolute-git-dir 2>/dev/null)" 103 elif [ -n "${__git_dir-}" ]; then 104 test -d "$__git_dir" && 105 __git_repo_path="$__git_dir" 106 elif [ -n "${GIT_DIR-}" ]; then 107 test -d "$GIT_DIR" && 108 __git_repo_path="$GIT_DIR" 109 elif [ -d .git ]; then 110 __git_repo_path=.git 111 else 112 __git_repo_path="$(git rev-parse --git-dir 2>/dev/null)" 113 fi 114} 115 116# Deprecated: use __git_find_repo_path() and $__git_repo_path instead 117# __gitdir accepts 0 or 1 arguments (i.e., location) 118# returns location of .git repo 119__gitdir () 120{ 121 if [ -z "${1-}" ]; then 122 __git_find_repo_path || return 1 123 echo "$__git_repo_path" 124 elif [ -d "$1/.git" ]; then 125 echo "$1/.git" 126 else 127 echo "$1" 128 fi 129} 130 131# Runs git with all the options given as argument, respecting any 132# '--git-dir=<path>' and '-C <path>' options present on the command line 133__git () 134{ 135 git ${__git_C_args:+"${__git_C_args[@]}"} \ 136 ${__git_dir:+--git-dir="$__git_dir"} "$@" 2>/dev/null 137} 138 139# Helper function to read the first line of a file into a variable. 140# __git_eread requires 2 arguments, the file path and the name of the 141# variable, in that order. 142# 143# This is taken from git-prompt.sh. 144__git_eread () 145{ 146 test -r "$1" && IFS=$'\r\n' read -r "$2" <"$1" 147} 148 149# Runs git in $__git_repo_path to determine whether a pseudoref exists. 150# 1: The pseudo-ref to search 151__git_pseudoref_exists () 152{ 153 local ref=$1 154 local head 155 156 __git_find_repo_path 157 158 # If the reftable is in use, we have to shell out to 'git rev-parse' 159 # to determine whether the ref exists instead of looking directly in 160 # the filesystem to determine whether the ref exists. Otherwise, use 161 # Bash builtins since executing Git commands are expensive on some 162 # platforms. 163 if __git_eread "$__git_repo_path/HEAD" head; then 164 if [ "$head" == "ref: refs/heads/.invalid" ]; then 165 __git show-ref --exists "$ref" 166 return $? 167 fi 168 fi 169 170 [ -f "$__git_repo_path/$ref" ] 171} 172 173# Removes backslash escaping, single quotes and double quotes from a word, 174# stores the result in the variable $dequoted_word. 175# 1: The word to dequote. 176__git_dequote () 177{ 178 local rest="$1" len ch 179 180 dequoted_word="" 181 182 while test -n "$rest"; do 183 len=${#dequoted_word} 184 dequoted_word="$dequoted_word${rest%%[\\\'\"]*}" 185 rest="${rest:$((${#dequoted_word}-$len))}" 186 187 case "${rest:0:1}" in 188 \\) 189 ch="${rest:1:1}" 190 case "$ch" in 191 $'\n') 192 ;; 193 *) 194 dequoted_word="$dequoted_word$ch" 195 ;; 196 esac 197 rest="${rest:2}" 198 ;; 199 \') 200 rest="${rest:1}" 201 len=${#dequoted_word} 202 dequoted_word="$dequoted_word${rest%%\'*}" 203 rest="${rest:$((${#dequoted_word}-$len+1))}" 204 ;; 205 \") 206 rest="${rest:1}" 207 while test -n "$rest" ; do 208 len=${#dequoted_word} 209 dequoted_word="$dequoted_word${rest%%[\\\"]*}" 210 rest="${rest:$((${#dequoted_word}-$len))}" 211 case "${rest:0:1}" in 212 \\) 213 ch="${rest:1:1}" 214 case "$ch" in 215 \"|\\|\$|\`) 216 dequoted_word="$dequoted_word$ch" 217 ;; 218 $'\n') 219 ;; 220 *) 221 dequoted_word="$dequoted_word\\$ch" 222 ;; 223 esac 224 rest="${rest:2}" 225 ;; 226 \") 227 rest="${rest:1}" 228 break 229 ;; 230 esac 231 done 232 ;; 233 esac 234 done 235} 236 237# Prints the number of slash-separated components in a path. 238# 1: Path to count components of. 239__git_count_path_components () 240{ 241 local path="$1" 242 local relative="${path#/}" 243 relative="${relative%/}" 244 local slashes="/${relative//[^\/]}" 245 echo "${#slashes}" 246} 247 248# The following function is based on code from: 249# 250# bash_completion - programmable completion functions for bash 3.2+ 251# 252# Copyright © 2006-2008, Ian Macdonald <ian@caliban.org> 253# © 2009-2010, Bash Completion Maintainers 254# <bash-completion-devel@lists.alioth.debian.org> 255# 256# This program is free software; you can redistribute it and/or modify 257# it under the terms of the GNU General Public License as published by 258# the Free Software Foundation; either version 2, or (at your option) 259# any later version. 260# 261# This program is distributed in the hope that it will be useful, 262# but WITHOUT ANY WARRANTY; without even the implied warranty of 263# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 264# GNU General Public License for more details. 265# 266# You should have received a copy of the GNU General Public License 267# along with this program; if not, see <http://www.gnu.org/licenses/>. 268# 269# The latest version of this software can be obtained here: 270# 271# http://bash-completion.alioth.debian.org/ 272# 273# RELEASE: 2.x 274 275# This function can be used to access a tokenized list of words 276# on the command line: 277# 278# __git_reassemble_comp_words_by_ref '=:' 279# if test "${words_[cword_-1]}" = -w 280# then 281# ... 282# fi 283# 284# The argument should be a collection of characters from the list of 285# word completion separators (COMP_WORDBREAKS) to treat as ordinary 286# characters. 287# 288# This is roughly equivalent to going back in time and setting 289# COMP_WORDBREAKS to exclude those characters. The intent is to 290# make option types like --date=<type> and <rev>:<path> easy to 291# recognize by treating each shell word as a single token. 292# 293# It is best not to set COMP_WORDBREAKS directly because the value is 294# shared with other completion scripts. By the time the completion 295# function gets called, COMP_WORDS has already been populated so local 296# changes to COMP_WORDBREAKS have no effect. 297# 298# Output: words_, cword_, cur_. 299 300__git_reassemble_comp_words_by_ref() 301{ 302 local exclude i j first 303 # Which word separators to exclude? 304 exclude="${1//[^$COMP_WORDBREAKS]}" 305 cword_=$COMP_CWORD 306 if [ -z "$exclude" ]; then 307 words_=("${COMP_WORDS[@]}") 308 return 309 fi 310 # List of word completion separators has shrunk; 311 # re-assemble words to complete. 312 for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do 313 # Append each nonempty word consisting of just 314 # word separator characters to the current word. 315 first=t 316 while 317 [ $i -gt 0 ] && 318 [ -n "${COMP_WORDS[$i]}" ] && 319 # word consists of excluded word separators 320 [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ] 321 do 322 # Attach to the previous token, 323 # unless the previous token is the command name. 324 if [ $j -ge 2 ] && [ -n "$first" ]; then 325 ((j--)) 326 fi 327 first= 328 words_[$j]=${words_[j]}${COMP_WORDS[i]} 329 if [ $i = $COMP_CWORD ]; then 330 cword_=$j 331 fi 332 if (($i < ${#COMP_WORDS[@]} - 1)); then 333 ((i++)) 334 else 335 # Done. 336 return 337 fi 338 done 339 words_[$j]=${words_[j]}${COMP_WORDS[i]} 340 if [ $i = $COMP_CWORD ]; then 341 cword_=$j 342 fi 343 done 344} 345 346if ! type _get_comp_words_by_ref >/dev/null 2>&1; then 347_get_comp_words_by_ref () 348{ 349 local exclude cur_ words_ cword_ 350 if [ "$1" = "-n" ]; then 351 exclude=$2 352 shift 2 353 fi 354 __git_reassemble_comp_words_by_ref "$exclude" 355 cur_=${words_[cword_]} 356 while [ $# -gt 0 ]; do 357 case "$1" in 358 cur) 359 cur=$cur_ 360 ;; 361 prev) 362 prev=${words_[$cword_-1]} 363 ;; 364 words) 365 words=("${words_[@]}") 366 ;; 367 cword) 368 cword=$cword_ 369 ;; 370 esac 371 shift 372 done 373} 374fi 375 376# Fills the COMPREPLY array with prefiltered words without any additional 377# processing. 378# Callers must take care of providing only words that match the current word 379# to be completed and adding any prefix and/or suffix (trailing space!), if 380# necessary. 381# 1: List of newline-separated matching completion words, complete with 382# prefix and suffix. 383__gitcomp_direct () 384{ 385 local IFS=$'\n' 386 387 COMPREPLY=($1) 388} 389 390# Similar to __gitcomp_direct, but appends to COMPREPLY instead. 391# Callers must take care of providing only words that match the current word 392# to be completed and adding any prefix and/or suffix (trailing space!), if 393# necessary. 394# 1: List of newline-separated matching completion words, complete with 395# prefix and suffix. 396__gitcomp_direct_append () 397{ 398 local IFS=$'\n' 399 400 COMPREPLY+=($1) 401} 402 403__gitcompappend () 404{ 405 local x i=${#COMPREPLY[@]} 406 for x in $1; do 407 if [[ "$x" == "$3"* ]]; then 408 COMPREPLY[i++]="$2$x$4" 409 fi 410 done 411} 412 413__gitcompadd () 414{ 415 COMPREPLY=() 416 __gitcompappend "$@" 417} 418 419# Generates completion reply, appending a space to possible completion words, 420# if necessary. 421# It accepts 1 to 4 arguments: 422# 1: List of possible completion words. 423# 2: A prefix to be added to each possible completion word (optional). 424# 3: Generate possible completion matches for this word (optional). 425# 4: A suffix to be appended to each possible completion word (optional). 426__gitcomp () 427{ 428 local cur_="${3-$cur}" 429 430 case "$cur_" in 431 *=) 432 ;; 433 --no-*) 434 local c i=0 IFS=$' \t\n' 435 for c in $1; do 436 if [[ $c == "--" ]]; then 437 continue 438 fi 439 c="$c${4-}" 440 if [[ $c == "$cur_"* ]]; then 441 case $c in 442 --*=|*.) ;; 443 *) c="$c " ;; 444 esac 445 COMPREPLY[i++]="${2-}$c" 446 fi 447 done 448 ;; 449 *) 450 local c i=0 IFS=$' \t\n' 451 for c in $1; do 452 if [[ $c == "--" ]]; then 453 c="--no-...${4-}" 454 if [[ $c == "$cur_"* ]]; then 455 COMPREPLY[i++]="${2-}$c " 456 fi 457 break 458 fi 459 c="$c${4-}" 460 if [[ $c == "$cur_"* ]]; then 461 case $c in 462 *=|*.) ;; 463 *) c="$c " ;; 464 esac 465 COMPREPLY[i++]="${2-}$c" 466 fi 467 done 468 ;; 469 esac 470} 471 472# Clear the variables caching builtins' options when (re-)sourcing 473# the completion script. 474if [[ -n ${ZSH_VERSION-} ]]; then 475 unset ${(M)${(k)parameters[@]}:#__gitcomp_builtin_*} 2>/dev/null 476else 477 unset $(compgen -v __gitcomp_builtin_) 478fi 479 480# This function is equivalent to 481# 482# ___git_resolved_builtins=$(git xxx --git-completion-helper) 483# 484# except that the result of the execution is cached. 485# 486# Accept 1-3 arguments: 487# 1: the git command to execute, this is also the cache key 488# (use "_" when the command contains spaces, e.g. "remote add" 489# becomes "remote_add") 490# 2: extra options to be added on top (e.g. negative forms) 491# 3: options to be excluded 492__git_resolve_builtins () 493{ 494 local cmd="$1" 495 local incl="${2-}" 496 local excl="${3-}" 497 498 local var=__gitcomp_builtin_"${cmd//-/_}" 499 local options 500 eval "options=\${$var-}" 501 502 if [ -z "$options" ]; then 503 local completion_helper 504 if [ "${GIT_COMPLETION_SHOW_ALL-}" = "1" ]; then 505 completion_helper="--git-completion-helper-all" 506 else 507 completion_helper="--git-completion-helper" 508 fi 509 # leading and trailing spaces are significant to make 510 # option removal work correctly. 511 options=" $incl $(__git ${cmd/_/ } $completion_helper) " || return 512 513 for i in $excl; do 514 options="${options/ $i / }" 515 done 516 eval "$var=\"$options\"" 517 fi 518 519 ___git_resolved_builtins="$options" 520} 521 522# This function is equivalent to 523# 524# __gitcomp "$(git xxx --git-completion-helper) ..." 525# 526# except that the output is cached. Accept 1-3 arguments: 527# 1: the git command to execute, this is also the cache key 528# (use "_" when the command contains spaces, e.g. "remote add" 529# becomes "remote_add") 530# 2: extra options to be added on top (e.g. negative forms) 531# 3: options to be excluded 532__gitcomp_builtin () 533{ 534 __git_resolve_builtins "$1" "$2" "$3" 535 536 __gitcomp "$___git_resolved_builtins" 537} 538 539# Variation of __gitcomp_nl () that appends to the existing list of 540# completion candidates, COMPREPLY. 541__gitcomp_nl_append () 542{ 543 local IFS=$'\n' 544 __gitcompappend "$1" "${2-}" "${3-$cur}" "${4- }" 545} 546 547# Generates completion reply from newline-separated possible completion words 548# by appending a space to all of them. 549# It accepts 1 to 4 arguments: 550# 1: List of possible completion words, separated by a single newline. 551# 2: A prefix to be added to each possible completion word (optional). 552# 3: Generate possible completion matches for this word (optional). 553# 4: A suffix to be appended to each possible completion word instead of 554# the default space (optional). If specified but empty, nothing is 555# appended. 556__gitcomp_nl () 557{ 558 COMPREPLY=() 559 __gitcomp_nl_append "$@" 560} 561 562# Fills the COMPREPLY array with prefiltered paths without any additional 563# processing. 564# Callers must take care of providing only paths that match the current path 565# to be completed and adding any prefix path components, if necessary. 566# 1: List of newline-separated matching paths, complete with all prefix 567# path components. 568__gitcomp_file_direct () 569{ 570 local IFS=$'\n' 571 572 COMPREPLY=($1) 573 574 # use a hack to enable file mode in bash < 4 575 compopt -o filenames +o nospace 2>/dev/null || 576 compgen -f /non-existing-dir/ >/dev/null || 577 true 578} 579 580# Generates completion reply with compgen from newline-separated possible 581# completion filenames. 582# It accepts 1 to 3 arguments: 583# 1: List of possible completion filenames, separated by a single newline. 584# 2: A directory prefix to be added to each possible completion filename 585# (optional). 586# 3: Generate possible completion matches for this word (optional). 587__gitcomp_file () 588{ 589 local IFS=$'\n' 590 591 # XXX does not work when the directory prefix contains a tilde, 592 # since tilde expansion is not applied. 593 # This means that COMPREPLY will be empty and Bash default 594 # completion will be used. 595 __gitcompadd "$1" "${2-}" "${3-$cur}" "" 596 597 # use a hack to enable file mode in bash < 4 598 compopt -o filenames +o nospace 2>/dev/null || 599 compgen -f /non-existing-dir/ >/dev/null || 600 true 601} 602 603# Find the current subcommand for commands that follow the syntax: 604# 605# git <command> <subcommand> 606# 607# 1: List of possible subcommands. 608# 2: Optional subcommand to return when none is found. 609__git_find_subcommand () 610{ 611 local subcommand subcommands="$1" default_subcommand="$2" 612 613 for subcommand in $subcommands; do 614 if [ "$subcommand" = "${words[__git_cmd_idx+1]}" ]; then 615 echo $subcommand 616 return 617 fi 618 done 619 620 echo $default_subcommand 621} 622 623# Execute 'git ls-files', unless the --committable option is specified, in 624# which case it runs 'git diff-index' to find out the files that can be 625# committed. It return paths relative to the directory specified in the first 626# argument, and using the options specified in the second argument. 627__git_ls_files_helper () 628{ 629 if [ "$2" = "--committable" ]; then 630 __git -C "$1" -c core.quotePath=false diff-index \ 631 --name-only --relative HEAD -- "${3//\\/\\\\}*" 632 else 633 # NOTE: $2 is not quoted in order to support multiple options 634 __git -C "$1" -c core.quotePath=false ls-files \ 635 --exclude-standard $2 -- "${3//\\/\\\\}*" 636 fi 637} 638 639 640# __git_index_files accepts 1 or 2 arguments: 641# 1: Options to pass to ls-files (required). 642# 2: A directory path (optional). 643# If provided, only files within the specified directory are listed. 644# Sub directories are never recursed. Path must have a trailing 645# slash. 646# 3: List only paths matching this path component (optional). 647__git_index_files () 648{ 649 local root="$2" match="$3" 650 651 __git_ls_files_helper "$root" "$1" "${match:-?}" | 652 awk -F / -v pfx="${2//\\/\\\\}" '{ 653 paths[$1] = 1 654 } 655 END { 656 for (p in paths) { 657 if (substr(p, 1, 1) != "\"") { 658 # No special characters, easy! 659 print pfx p 660 continue 661 } 662 663 # The path is quoted. 664 p = dequote(p) 665 if (p == "") 666 continue 667 668 # Even when a directory name itself does not contain 669 # any special characters, it will still be quoted if 670 # any of its (stripped) trailing path components do. 671 # Because of this we may have seen the same directory 672 # both quoted and unquoted. 673 if (p in paths) 674 # We have seen the same directory unquoted, 675 # skip it. 676 continue 677 else 678 print pfx p 679 } 680 } 681 function dequote(p, bs_idx, out, esc, esc_idx, dec) { 682 # Skip opening double quote. 683 p = substr(p, 2) 684 685 # Interpret backslash escape sequences. 686 while ((bs_idx = index(p, "\\")) != 0) { 687 out = out substr(p, 1, bs_idx - 1) 688 esc = substr(p, bs_idx + 1, 1) 689 p = substr(p, bs_idx + 2) 690 691 if ((esc_idx = index("abtvfr\"\\", esc)) != 0) { 692 # C-style one-character escape sequence. 693 out = out substr("\a\b\t\v\f\r\"\\", 694 esc_idx, 1) 695 } else if (esc == "n") { 696 # Uh-oh, a newline character. 697 # We cannot reliably put a pathname 698 # containing a newline into COMPREPLY, 699 # and the newline would create a mess. 700 # Skip this path. 701 return "" 702 } else { 703 # Must be a \nnn octal value, then. 704 dec = esc * 64 + \ 705 substr(p, 1, 1) * 8 + \ 706 substr(p, 2, 1) 707 out = out sprintf("%c", dec) 708 p = substr(p, 3) 709 } 710 } 711 # Drop closing double quote, if there is one. 712 # (There is not any if this is a directory, as it was 713 # already stripped with the trailing path components.) 714 if (substr(p, length(p), 1) == "\"") 715 out = out substr(p, 1, length(p) - 1) 716 else 717 out = out p 718 719 return out 720 }' 721} 722 723# __git_complete_index_file requires 1 argument: 724# 1: the options to pass to ls-file 725# 726# The exception is --committable, which finds the files appropriate commit. 727__git_complete_index_file () 728{ 729 local dequoted_word pfx="" cur_ 730 731 __git_dequote "$cur" 732 733 case "$dequoted_word" in 734 ?*/*) 735 pfx="${dequoted_word%/*}/" 736 cur_="${dequoted_word##*/}" 737 ;; 738 *) 739 cur_="$dequoted_word" 740 esac 741 742 __gitcomp_file_direct "$(__git_index_files "$1" "$pfx" "$cur_")" 743} 744 745# Lists branches from the local repository. 746# 1: A prefix to be added to each listed branch (optional). 747# 2: List only branches matching this word (optional; list all branches if 748# unset or empty). 749# 3: A suffix to be appended to each listed branch (optional). 750__git_heads () 751{ 752 local pfx="${1-}" cur_="${2-}" sfx="${3-}" 753 754 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \ 755 ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \ 756 "refs/heads/$cur_*" "refs/heads/$cur_*/**" 757} 758 759# Lists branches from remote repositories. 760# 1: A prefix to be added to each listed branch (optional). 761# 2: List only branches matching this word (optional; list all branches if 762# unset or empty). 763# 3: A suffix to be appended to each listed branch (optional). 764__git_remote_heads () 765{ 766 local pfx="${1-}" cur_="${2-}" sfx="${3-}" 767 768 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \ 769 ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \ 770 "refs/remotes/$cur_*" "refs/remotes/$cur_*/**" 771} 772 773# Lists tags from the local repository. 774# Accepts the same positional parameters as __git_heads() above. 775__git_tags () 776{ 777 local pfx="${1-}" cur_="${2-}" sfx="${3-}" 778 779 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \ 780 ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \ 781 "refs/tags/$cur_*" "refs/tags/$cur_*/**" 782} 783 784# List unique branches from refs/remotes used for 'git checkout' and 'git 785# switch' tracking DWIMery. 786# 1: A prefix to be added to each listed branch (optional) 787# 2: List only branches matching this word (optional; list all branches if 788# unset or empty). 789# 3: A suffix to be appended to each listed branch (optional). 790__git_dwim_remote_heads () 791{ 792 local pfx="${1-}" cur_="${2-}" sfx="${3-}" 793 794 # employ the heuristic used by git checkout and git switch 795 # Try to find a remote branch that cur_es the completion word 796 # but only output if the branch name is unique 797 local awk_script=' 798 function casemap(s) { 799 if (ENVIRON["IGNORE_CASE"]) 800 return tolower(s) 801 else 802 return s 803 } 804 BEGIN { 805 split(ENVIRON["REMOTES"], remotes, /\n/) 806 for (i in remotes) 807 remotes[i] = "refs/remotes/" casemap(remotes[i]) 808 cur_ = casemap(ENVIRON["CUR_"]) 809 } 810 { 811 ref_case = casemap($0) 812 for (i in remotes) { 813 if (index(ref_case, remotes[i] "/" cur_) == 1) { 814 branch = substr($0, length(remotes[i] "/") + 1) 815 print ENVIRON["PFX"] branch ENVIRON["SFX"] 816 break 817 } 818 } 819 } 820 ' 821 __git for-each-ref --format='%(refname)' refs/remotes/ | 822 PFX="$pfx" SFX="$sfx" CUR_="$cur_" \ 823 IGNORE_CASE=${GIT_COMPLETION_IGNORE_CASE+1} \ 824 REMOTES="$(__git_remotes | sort -r)" awk "$awk_script" | 825 sort | uniq -u 826} 827 828# Lists refs from the local (by default) or from a remote repository. 829# It accepts 0, 1 or 2 arguments: 830# 1: The remote to list refs from (optional; ignored, if set but empty). 831# Can be the name of a configured remote, a path, or a URL. 832# 2: In addition to local refs, list unique branches from refs/remotes/ for 833# 'git checkout's tracking DWIMery (optional; ignored, if set but empty). 834# 3: A prefix to be added to each listed ref (optional). 835# 4: List only refs matching this word (optional; list all refs if unset or 836# empty). 837# 5: A suffix to be appended to each listed ref (optional; ignored, if set 838# but empty). 839# 840# Use __git_complete_refs() instead. 841__git_refs () 842{ 843 local i hash dir track="${2-}" 844 local list_refs_from=path remote="${1-}" 845 local format refs 846 local pfx="${3-}" cur_="${4-$cur}" sfx="${5-}" 847 local match="${4-}" 848 local umatch="${4-}" 849 local fer_pfx="${pfx//\%/%%}" # "escape" for-each-ref format specifiers 850 851 __git_find_repo_path 852 dir="$__git_repo_path" 853 854 if [ -z "$remote" ]; then 855 if [ -z "$dir" ]; then 856 return 857 fi 858 else 859 if __git_is_configured_remote "$remote"; then 860 # configured remote takes precedence over a 861 # local directory with the same name 862 list_refs_from=remote 863 elif [ -d "$remote/.git" ]; then 864 dir="$remote/.git" 865 elif [ -d "$remote" ]; then 866 dir="$remote" 867 else 868 list_refs_from=url 869 fi 870 fi 871 872 if test "${GIT_COMPLETION_IGNORE_CASE:+1}" = "1" 873 then 874 # uppercase with tr instead of ${match,^^} for bash 3.2 compatibility 875 umatch=$(echo "$match" | tr a-z A-Z 2>/dev/null || echo "$match") 876 fi 877 878 if [ "$list_refs_from" = path ]; then 879 if [[ "$cur_" == ^* ]]; then 880 pfx="$pfx^" 881 fer_pfx="$fer_pfx^" 882 cur_=${cur_#^} 883 match=${match#^} 884 umatch=${umatch#^} 885 fi 886 case "$cur_" in 887 refs|refs/*) 888 format="refname" 889 refs=("$match*" "$match*/**") 890 track="" 891 ;; 892 *) 893 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD REBASE_HEAD CHERRY_PICK_HEAD REVERT_HEAD BISECT_HEAD AUTO_MERGE; do 894 case "$i" in 895 $match*|$umatch*) 896 if [ -e "$dir/$i" ]; then 897 echo "$pfx$i$sfx" 898 fi 899 ;; 900 esac 901 done 902 format="refname:strip=2" 903 refs=("refs/tags/$match*" "refs/tags/$match*/**" 904 "refs/heads/$match*" "refs/heads/$match*/**" 905 "refs/remotes/$match*" "refs/remotes/$match*/**") 906 ;; 907 esac 908 __git_dir="$dir" __git for-each-ref --format="$fer_pfx%($format)$sfx" \ 909 ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \ 910 "${refs[@]}" 911 if [ -n "$track" ]; then 912 __git_dwim_remote_heads "$pfx" "$match" "$sfx" 913 fi 914 return 915 fi 916 case "$cur_" in 917 refs|refs/*) 918 __git ls-remote "$remote" "$match*" | \ 919 while read -r hash i; do 920 case "$i" in 921 *^{}) ;; 922 *) echo "$pfx$i$sfx" ;; 923 esac 924 done 925 ;; 926 *) 927 if [ "$list_refs_from" = remote ]; then 928 case "HEAD" in 929 $match*|$umatch*) echo "${pfx}HEAD$sfx" ;; 930 esac 931 local strip="$(__git_count_path_components "refs/remotes/$remote")" 932 __git for-each-ref --format="$fer_pfx%(refname:strip=$strip)$sfx" \ 933 ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \ 934 "refs/remotes/$remote/$match*" \ 935 "refs/remotes/$remote/$match*/**" 936 else 937 local query_symref 938 case "HEAD" in 939 $match*|$umatch*) query_symref="HEAD" ;; 940 esac 941 __git ls-remote "$remote" $query_symref \ 942 "refs/tags/$match*" "refs/heads/$match*" \ 943 "refs/remotes/$match*" | 944 while read -r hash i; do 945 case "$i" in 946 *^{}) ;; 947 refs/*) echo "$pfx${i#refs/*/}$sfx" ;; 948 *) echo "$pfx$i$sfx" ;; # symbolic refs 949 esac 950 done 951 fi 952 ;; 953 esac 954} 955 956# Completes refs, short and long, local and remote, symbolic and pseudo. 957# 958# Usage: __git_complete_refs [<option>]... 959# --remote=<remote>: The remote to list refs from, can be the name of a 960# configured remote, a path, or a URL. 961# --dwim: List unique remote branches for 'git switch's tracking DWIMery. 962# --pfx=<prefix>: A prefix to be added to each ref. 963# --cur=<word>: The current ref to be completed. Defaults to the current 964# word to be completed. 965# --sfx=<suffix>: A suffix to be appended to each ref instead of the default 966# space. 967# --mode=<mode>: What set of refs to complete, one of 'refs' (the default) to 968# complete all refs, 'heads' to complete only branches, or 969# 'remote-heads' to complete only remote branches. Note that 970# --remote is only compatible with --mode=refs. 971__git_complete_refs () 972{ 973 local remote= dwim= pfx= cur_="$cur" sfx=" " mode="refs" 974 975 while test $# != 0; do 976 case "$1" in 977 --remote=*) remote="${1##--remote=}" ;; 978 --dwim) dwim="yes" ;; 979 # --track is an old spelling of --dwim 980 --track) dwim="yes" ;; 981 --pfx=*) pfx="${1##--pfx=}" ;; 982 --cur=*) cur_="${1##--cur=}" ;; 983 --sfx=*) sfx="${1##--sfx=}" ;; 984 --mode=*) mode="${1##--mode=}" ;; 985 *) return 1 ;; 986 esac 987 shift 988 done 989 990 # complete references based on the specified mode 991 case "$mode" in 992 refs) 993 __gitcomp_direct "$(__git_refs "$remote" "" "$pfx" "$cur_" "$sfx")" ;; 994 heads) 995 __gitcomp_direct "$(__git_heads "$pfx" "$cur_" "$sfx")" ;; 996 remote-heads) 997 __gitcomp_direct "$(__git_remote_heads "$pfx" "$cur_" "$sfx")" ;; 998 *) 999 return 1 ;; 1000 esac 1001 1002 # Append DWIM remote branch names if requested 1003 if [ "$dwim" = "yes" ]; then 1004 __gitcomp_direct_append "$(__git_dwim_remote_heads "$pfx" "$cur_" "$sfx")" 1005 fi 1006} 1007 1008# __git_refs2 requires 1 argument (to pass to __git_refs) 1009# Deprecated: use __git_complete_fetch_refspecs() instead. 1010__git_refs2 () 1011{ 1012 local i 1013 for i in $(__git_refs "$1"); do 1014 echo "$i:$i" 1015 done 1016} 1017 1018# Completes refspecs for fetching from a remote repository. 1019# 1: The remote repository. 1020# 2: A prefix to be added to each listed refspec (optional). 1021# 3: The ref to be completed as a refspec instead of the current word to be 1022# completed (optional) 1023# 4: A suffix to be appended to each listed refspec instead of the default 1024# space (optional). 1025__git_complete_fetch_refspecs () 1026{ 1027 local i remote="$1" pfx="${2-}" cur_="${3-$cur}" sfx="${4- }" 1028 1029 __gitcomp_direct "$( 1030 for i in $(__git_refs "$remote" "" "" "$cur_") ; do 1031 echo "$pfx$i:$i$sfx" 1032 done 1033 )" 1034} 1035 1036# __git_refs_remotes requires 1 argument (to pass to ls-remote) 1037__git_refs_remotes () 1038{ 1039 local i hash 1040 __git ls-remote "$1" 'refs/heads/*' | \ 1041 while read -r hash i; do 1042 echo "$i:refs/remotes/$1/${i#refs/heads/}" 1043 done 1044} 1045 1046__git_remotes () 1047{ 1048 __git_find_repo_path 1049 test -d "$__git_repo_path/remotes" && ls -1 "$__git_repo_path/remotes" 1050 __git remote 1051} 1052 1053# Returns true if $1 matches the name of a configured remote, false otherwise. 1054__git_is_configured_remote () 1055{ 1056 local remote 1057 for remote in $(__git_remotes); do 1058 if [ "$remote" = "$1" ]; then 1059 return 0 1060 fi 1061 done 1062 return 1 1063} 1064 1065__git_list_merge_strategies () 1066{ 1067 LANG=C LC_ALL=C git merge -s help 2>&1 | 1068 sed -n -e '/[Aa]vailable strategies are: /,/^$/{ 1069 s/\.$// 1070 s/.*:// 1071 s/^[ ]*// 1072 s/[ ]*$// 1073 p 1074 }' 1075} 1076 1077__git_merge_strategies= 1078# 'git merge -s help' (and thus detection of the merge strategy 1079# list) fails, unfortunately, if run outside of any git working 1080# tree. __git_merge_strategies is set to the empty string in 1081# that case, and the detection will be repeated the next time it 1082# is needed. 1083__git_compute_merge_strategies () 1084{ 1085 test -n "$__git_merge_strategies" || 1086 __git_merge_strategies=$(__git_list_merge_strategies) 1087} 1088 1089__git_merge_strategy_options="ours theirs subtree subtree= patience 1090 histogram diff-algorithm= ignore-space-change ignore-all-space 1091 ignore-space-at-eol renormalize no-renormalize no-renames 1092 find-renames find-renames= rename-threshold=" 1093 1094__git_complete_revlist_file () 1095{ 1096 local dequoted_word pfx ls ref cur_="$cur" 1097 case "$cur_" in 1098 *..?*:*) 1099 return 1100 ;; 1101 ?*:*) 1102 ref="${cur_%%:*}" 1103 cur_="${cur_#*:}" 1104 1105 __git_dequote "$cur_" 1106 1107 case "$dequoted_word" in 1108 ?*/*) 1109 pfx="${dequoted_word%/*}" 1110 cur_="${dequoted_word##*/}" 1111 ls="$ref:$pfx" 1112 pfx="$pfx/" 1113 ;; 1114 *) 1115 cur_="$dequoted_word" 1116 ls="$ref" 1117 ;; 1118 esac 1119 1120 case "$COMP_WORDBREAKS" in 1121 *:*) : great ;; 1122 *) pfx="$ref:$pfx" ;; 1123 esac 1124 1125 __gitcomp_file "$(__git ls-tree "$ls" \ 1126 | sed 's/^.* // 1127 s/$//')" \ 1128 "$pfx" "$cur_" 1129 ;; 1130 *...*) 1131 pfx="${cur_%...*}..." 1132 cur_="${cur_#*...}" 1133 __git_complete_refs --pfx="$pfx" --cur="$cur_" 1134 ;; 1135 *..*) 1136 pfx="${cur_%..*}.." 1137 cur_="${cur_#*..}" 1138 __git_complete_refs --pfx="$pfx" --cur="$cur_" 1139 ;; 1140 *) 1141 __git_complete_refs 1142 ;; 1143 esac 1144} 1145 1146__git_complete_file () 1147{ 1148 __git_complete_revlist_file 1149} 1150 1151__git_complete_revlist () 1152{ 1153 __git_complete_revlist_file 1154} 1155 1156__git_complete_remote_or_refspec () 1157{ 1158 local cur_="$cur" cmd="${words[__git_cmd_idx]}" 1159 local i c=$((__git_cmd_idx+1)) remote="" pfx="" lhs=1 no_complete_refspec=0 1160 if [ "$cmd" = "remote" ]; then 1161 ((c++)) 1162 fi 1163 while [ $c -lt $cword ]; do 1164 i="${words[c]}" 1165 case "$i" in 1166 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;; 1167 -d|--delete) [ "$cmd" = "push" ] && lhs=0 ;; 1168 --all) 1169 case "$cmd" in 1170 push) no_complete_refspec=1 ;; 1171 fetch) 1172 return 1173 ;; 1174 *) ;; 1175 esac 1176 ;; 1177 --multiple) no_complete_refspec=1; break ;; 1178 -*) ;; 1179 *) remote="$i"; break ;; 1180 esac 1181 ((c++)) 1182 done 1183 if [ -z "$remote" ]; then 1184 __gitcomp_nl "$(__git_remotes)" 1185 return 1186 fi 1187 if [ $no_complete_refspec = 1 ]; then 1188 return 1189 fi 1190 [ "$remote" = "." ] && remote= 1191 case "$cur_" in 1192 *:*) 1193 case "$COMP_WORDBREAKS" in 1194 *:*) : great ;; 1195 *) pfx="${cur_%%:*}:" ;; 1196 esac 1197 cur_="${cur_#*:}" 1198 lhs=0 1199 ;; 1200 +*) 1201 pfx="+" 1202 cur_="${cur_#+}" 1203 ;; 1204 esac 1205 case "$cmd" in 1206 fetch) 1207 if [ $lhs = 1 ]; then 1208 __git_complete_fetch_refspecs "$remote" "$pfx" "$cur_" 1209 else 1210 __git_complete_refs --pfx="$pfx" --cur="$cur_" 1211 fi 1212 ;; 1213 pull|remote) 1214 if [ $lhs = 1 ]; then 1215 __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_" 1216 else 1217 __git_complete_refs --pfx="$pfx" --cur="$cur_" 1218 fi 1219 ;; 1220 push) 1221 if [ $lhs = 1 ]; then 1222 __git_complete_refs --pfx="$pfx" --cur="$cur_" 1223 else 1224 __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_" 1225 fi 1226 ;; 1227 esac 1228} 1229 1230__git_complete_strategy () 1231{ 1232 __git_compute_merge_strategies 1233 case "$prev" in 1234 -s|--strategy) 1235 __gitcomp "$__git_merge_strategies" 1236 return 0 1237 ;; 1238 -X) 1239 __gitcomp "$__git_merge_strategy_options" 1240 return 0 1241 ;; 1242 esac 1243 case "$cur" in 1244 --strategy=*) 1245 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}" 1246 return 0 1247 ;; 1248 --strategy-option=*) 1249 __gitcomp "$__git_merge_strategy_options" "" "${cur##--strategy-option=}" 1250 return 0 1251 ;; 1252 esac 1253 return 1 1254} 1255 1256__git_all_commands= 1257__git_compute_all_commands () 1258{ 1259 test -n "$__git_all_commands" || 1260 __git_all_commands=$(__git --list-cmds=main,others,alias,nohelpers) 1261} 1262 1263# Lists all set config variables starting with the given section prefix, 1264# with the prefix removed. 1265__git_get_config_variables () 1266{ 1267 local section="$1" i IFS=$'\n' 1268 for i in $(__git config --name-only --get-regexp "^$section\..*"); do 1269 echo "${i#$section.}" 1270 done 1271} 1272 1273__git_pretty_aliases () 1274{ 1275 __git_get_config_variables "pretty" 1276} 1277 1278# __git_aliased_command requires 1 argument 1279__git_aliased_command () 1280{ 1281 local cur=$1 last list= word cmdline 1282 1283 while [[ -n "$cur" ]]; do 1284 if [[ "$list" == *" $cur "* ]]; then 1285 # loop detected 1286 return 1287 fi 1288 1289 cmdline=$(__git config --get "alias.$cur") 1290 list=" $cur $list" 1291 last=$cur 1292 cur= 1293 1294 for word in $cmdline; do 1295 case "$word" in 1296 \!gitk|gitk) 1297 cur="gitk" 1298 break 1299 ;; 1300 \!*) : shell command alias ;; 1301 -*) : option ;; 1302 *=*) : setting env ;; 1303 git) : git itself ;; 1304 \(\)) : skip parens of shell function definition ;; 1305 {) : skip start of shell helper function ;; 1306 :) : skip null command ;; 1307 \'*) : skip opening quote after sh -c ;; 1308 *) 1309 cur="${word%;}" 1310 break 1311 esac 1312 done 1313 done 1314 1315 cur=$last 1316 if [[ "$cur" != "$1" ]]; then 1317 echo "$cur" 1318 fi 1319} 1320 1321# Check whether one of the given words is present on the command line, 1322# and print the first word found. 1323# 1324# Usage: __git_find_on_cmdline [<option>]... "<wordlist>" 1325# --show-idx: Optionally show the index of the found word in the $words array. 1326__git_find_on_cmdline () 1327{ 1328 local word c="$__git_cmd_idx" show_idx 1329 1330 while test $# -gt 1; do 1331 case "$1" in 1332 --show-idx) show_idx=y ;; 1333 *) return 1 ;; 1334 esac 1335 shift 1336 done 1337 local wordlist="$1" 1338 1339 while [ $c -lt $cword ]; do 1340 for word in $wordlist; do 1341 if [ "$word" = "${words[c]}" ]; then 1342 if [ -n "${show_idx-}" ]; then 1343 echo "$c $word" 1344 else 1345 echo "$word" 1346 fi 1347 return 1348 fi 1349 done 1350 ((c++)) 1351 done 1352} 1353 1354# Similar to __git_find_on_cmdline, except that it loops backwards and thus 1355# prints the *last* word found. Useful for finding which of two options that 1356# supersede each other came last, such as "--guess" and "--no-guess". 1357# 1358# Usage: __git_find_last_on_cmdline [<option>]... "<wordlist>" 1359# --show-idx: Optionally show the index of the found word in the $words array. 1360__git_find_last_on_cmdline () 1361{ 1362 local word c=$cword show_idx 1363 1364 while test $# -gt 1; do 1365 case "$1" in 1366 --show-idx) show_idx=y ;; 1367 *) return 1 ;; 1368 esac 1369 shift 1370 done 1371 local wordlist="$1" 1372 1373 while [ $c -gt "$__git_cmd_idx" ]; do 1374 ((c--)) 1375 for word in $wordlist; do 1376 if [ "$word" = "${words[c]}" ]; then 1377 if [ -n "$show_idx" ]; then 1378 echo "$c $word" 1379 else 1380 echo "$word" 1381 fi 1382 return 1383 fi 1384 done 1385 done 1386} 1387 1388# Echo the value of an option set on the command line or config 1389# 1390# $1: short option name 1391# $2: long option name including = 1392# $3: list of possible values 1393# $4: config string (optional) 1394# 1395# example: 1396# result="$(__git_get_option_value "-d" "--do-something=" \ 1397# "yes no" "core.doSomething")" 1398# 1399# result is then either empty (no option set) or "yes" or "no" 1400# 1401# __git_get_option_value requires 3 arguments 1402__git_get_option_value () 1403{ 1404 local c short_opt long_opt val 1405 local result= values config_key word 1406 1407 short_opt="$1" 1408 long_opt="$2" 1409 values="$3" 1410 config_key="$4" 1411 1412 ((c = $cword - 1)) 1413 while [ $c -ge 0 ]; do 1414 word="${words[c]}" 1415 for val in $values; do 1416 if [ "$short_opt$val" = "$word" ] || 1417 [ "$long_opt$val" = "$word" ]; then 1418 result="$val" 1419 break 2 1420 fi 1421 done 1422 ((c--)) 1423 done 1424 1425 if [ -n "$config_key" ] && [ -z "$result" ]; then 1426 result="$(__git config "$config_key")" 1427 fi 1428 1429 echo "$result" 1430} 1431 1432__git_has_doubledash () 1433{ 1434 local c=1 1435 while [ $c -lt $cword ]; do 1436 if [ "--" = "${words[c]}" ]; then 1437 return 0 1438 fi 1439 ((c++)) 1440 done 1441 return 1 1442} 1443 1444# Try to count non option arguments passed on the command line for the 1445# specified git command. 1446# When options are used, it is necessary to use the special -- option to 1447# tell the implementation were non option arguments begin. 1448# XXX this can not be improved, since options can appear everywhere, as 1449# an example: 1450# git mv x -n y 1451# 1452# __git_count_arguments requires 1 argument: the git command executed. 1453__git_count_arguments () 1454{ 1455 local word i c=0 1456 1457 # Skip "git" (first argument) 1458 for ((i=$__git_cmd_idx; i < ${#words[@]}; i++)); do 1459 word="${words[i]}" 1460 1461 case "$word" in 1462 --) 1463 # Good; we can assume that the following are only non 1464 # option arguments. 1465 ((c = 0)) 1466 ;; 1467 "$1") 1468 # Skip the specified git command and discard git 1469 # main options 1470 ((c = 0)) 1471 ;; 1472 ?*) 1473 ((c++)) 1474 ;; 1475 esac 1476 done 1477 1478 printf "%d" $c 1479} 1480 1481__git_whitespacelist="nowarn warn error error-all fix" 1482__git_patchformat="mbox stgit stgit-series hg mboxrd" 1483__git_showcurrentpatch="diff raw" 1484__git_am_inprogress_options="--skip --continue --resolved --abort --quit --show-current-patch" 1485__git_quoted_cr="nowarn warn strip" 1486 1487_git_am () 1488{ 1489 __git_find_repo_path 1490 if [ -d "$__git_repo_path"/rebase-apply ]; then 1491 __gitcomp "$__git_am_inprogress_options" 1492 return 1493 fi 1494 case "$cur" in 1495 --whitespace=*) 1496 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}" 1497 return 1498 ;; 1499 --patch-format=*) 1500 __gitcomp "$__git_patchformat" "" "${cur##--patch-format=}" 1501 return 1502 ;; 1503 --show-current-patch=*) 1504 __gitcomp "$__git_showcurrentpatch" "" "${cur##--show-current-patch=}" 1505 return 1506 ;; 1507 --quoted-cr=*) 1508 __gitcomp "$__git_quoted_cr" "" "${cur##--quoted-cr=}" 1509 return 1510 ;; 1511 --*) 1512 __gitcomp_builtin am "" \ 1513 "$__git_am_inprogress_options" 1514 return 1515 esac 1516} 1517 1518_git_apply () 1519{ 1520 case "$cur" in 1521 --whitespace=*) 1522 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}" 1523 return 1524 ;; 1525 --*) 1526 __gitcomp_builtin apply 1527 return 1528 esac 1529} 1530 1531_git_add () 1532{ 1533 case "$cur" in 1534 --chmod=*) 1535 __gitcomp "+x -x" "" "${cur##--chmod=}" 1536 return 1537 ;; 1538 --*) 1539 __gitcomp_builtin add 1540 return 1541 esac 1542 1543 local complete_opt="--others --modified --directory --no-empty-directory" 1544 if test -n "$(__git_find_on_cmdline "-u --update")" 1545 then 1546 complete_opt="--modified" 1547 fi 1548 __git_complete_index_file "$complete_opt" 1549} 1550 1551_git_archive () 1552{ 1553 case "$cur" in 1554 --format=*) 1555 __gitcomp "$(git archive --list)" "" "${cur##--format=}" 1556 return 1557 ;; 1558 --remote=*) 1559 __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}" 1560 return 1561 ;; 1562 --*) 1563 __gitcomp_builtin archive "--format= --list --verbose --prefix= --worktree-attributes" 1564 return 1565 ;; 1566 esac 1567 __git_complete_file 1568} 1569 1570_git_bisect () 1571{ 1572 __git_has_doubledash && return 1573 1574 __git_find_repo_path 1575 1576 # If a bisection is in progress get the terms being used. 1577 local term_bad term_good 1578 if [ -f "$__git_repo_path"/BISECT_TERMS ]; then 1579 term_bad=$(__git bisect terms --term-bad) 1580 term_good=$(__git bisect terms --term-good) 1581 fi 1582 1583 # We will complete any custom terms, but still always complete the 1584 # more usual bad/new/good/old because git bisect gives a good error 1585 # message if these are given when not in use, and that's better than 1586 # silent refusal to complete if the user is confused. 1587 # 1588 # We want to recognize 'view' but not complete it, because it overlaps 1589 # with 'visualize' too much and is just an alias for it. 1590 # 1591 local completable_subcommands="start bad new $term_bad good old $term_good terms skip reset visualize replay log run help" 1592 local all_subcommands="$completable_subcommands view" 1593 1594 local subcommand="$(__git_find_on_cmdline "$all_subcommands")" 1595 1596 if [ -z "$subcommand" ]; then 1597 __git_find_repo_path 1598 if [ -f "$__git_repo_path"/BISECT_START ]; then 1599 __gitcomp "$completable_subcommands" 1600 else 1601 __gitcomp "replay start" 1602 fi 1603 return 1604 fi 1605 1606 case "$subcommand" in 1607 start) 1608 case "$cur" in 1609 --*) 1610 __gitcomp "--first-parent --no-checkout --term-new --term-bad --term-old --term-good" 1611 return 1612 ;; 1613 *) 1614 __git_complete_refs 1615 ;; 1616 esac 1617 ;; 1618 terms) 1619 __gitcomp "--term-good --term-old --term-bad --term-new" 1620 return 1621 ;; 1622 visualize|view) 1623 __git_complete_log_opts 1624 return 1625 ;; 1626 bad|new|"$term_bad"|good|old|"$term_good"|reset|skip) 1627 __git_complete_refs 1628 ;; 1629 *) 1630 ;; 1631 esac 1632} 1633 1634__git_ref_fieldlist="refname objecttype objectsize objectname upstream push HEAD symref" 1635 1636_git_branch () 1637{ 1638 local i c="$__git_cmd_idx" only_local_ref="n" has_r="n" 1639 1640 while [ $c -lt $cword ]; do 1641 i="${words[c]}" 1642 case "$i" in 1643 -d|-D|--delete|-m|-M|--move|-c|-C|--copy) 1644 only_local_ref="y" ;; 1645 -r|--remotes) 1646 has_r="y" ;; 1647 esac 1648 ((c++)) 1649 done 1650 1651 case "$cur" in 1652 --set-upstream-to=*) 1653 __git_complete_refs --cur="${cur##--set-upstream-to=}" 1654 ;; 1655 --*) 1656 __gitcomp_builtin branch 1657 ;; 1658 *) 1659 if [ $only_local_ref = "y" -a $has_r = "n" ]; then 1660 __gitcomp_direct "$(__git_heads "" "$cur" " ")" 1661 else 1662 __git_complete_refs 1663 fi 1664 ;; 1665 esac 1666} 1667 1668_git_bundle () 1669{ 1670 local cmd="${words[__git_cmd_idx+1]}" 1671 case "$cword" in 1672 $((__git_cmd_idx+1))) 1673 __gitcomp "create list-heads verify unbundle" 1674 ;; 1675 $((__git_cmd_idx+2))) 1676 # looking for a file 1677 ;; 1678 *) 1679 case "$cmd" in 1680 create) 1681 __git_complete_revlist 1682 ;; 1683 esac 1684 ;; 1685 esac 1686} 1687 1688# Helper function to decide whether or not we should enable DWIM logic for 1689# git-switch and git-checkout. 1690# 1691# To decide between the following rules in decreasing priority order: 1692# - the last provided of "--guess" or "--no-guess" explicitly enable or 1693# disable completion of DWIM logic respectively. 1694# - If checkout.guess is false, disable completion of DWIM logic. 1695# - If the --no-track option is provided, take this as a hint to disable the 1696# DWIM completion logic 1697# - If GIT_COMPLETION_CHECKOUT_NO_GUESS is set, disable the DWIM completion 1698# logic, as requested by the user. 1699# - Enable DWIM logic otherwise. 1700# 1701__git_checkout_default_dwim_mode () 1702{ 1703 local last_option dwim_opt="--dwim" 1704 1705 if [ "${GIT_COMPLETION_CHECKOUT_NO_GUESS-}" = "1" ]; then 1706 dwim_opt="" 1707 fi 1708 1709 # --no-track disables DWIM, but with lower priority than 1710 # --guess/--no-guess/checkout.guess 1711 if [ -n "$(__git_find_on_cmdline "--no-track")" ]; then 1712 dwim_opt="" 1713 fi 1714 1715 # checkout.guess = false disables DWIM, but with lower priority than 1716 # --guess/--no-guess 1717 if [ "$(__git config --type=bool checkout.guess)" = "false" ]; then 1718 dwim_opt="" 1719 fi 1720 1721 # Find the last provided --guess or --no-guess 1722 last_option="$(__git_find_last_on_cmdline "--guess --no-guess")" 1723 case "$last_option" in 1724 --guess) 1725 dwim_opt="--dwim" 1726 ;; 1727 --no-guess) 1728 dwim_opt="" 1729 ;; 1730 esac 1731 1732 echo "$dwim_opt" 1733} 1734 1735_git_checkout () 1736{ 1737 __git_has_doubledash && return 1738 1739 local dwim_opt="$(__git_checkout_default_dwim_mode)" 1740 1741 case "$prev" in 1742 -b|-B|--orphan) 1743 # Complete local branches (and DWIM branch 1744 # remote branch names) for an option argument 1745 # specifying a new branch name. This is for 1746 # convenience, assuming new branches are 1747 # possibly based on pre-existing branch names. 1748 __git_complete_refs $dwim_opt --mode="heads" 1749 return 1750 ;; 1751 *) 1752 ;; 1753 esac 1754 1755 case "$cur" in 1756 --conflict=*) 1757 __gitcomp "diff3 merge zdiff3" "" "${cur##--conflict=}" 1758 ;; 1759 --*) 1760 __gitcomp_builtin checkout 1761 ;; 1762 *) 1763 # At this point, we've already handled special completion for 1764 # the arguments to -b/-B, and --orphan. There are 3 main 1765 # things left we can possibly complete: 1766 # 1) a start-point for -b/-B, -d/--detach, or --orphan 1767 # 2) a remote head, for --track 1768 # 3) an arbitrary reference, possibly including DWIM names 1769 # 1770 1771 if [ -n "$(__git_find_on_cmdline "-b -B -d --detach --orphan")" ]; then 1772 __git_complete_refs --mode="refs" 1773 elif [ -n "$(__git_find_on_cmdline "-t --track")" ]; then 1774 __git_complete_refs --mode="remote-heads" 1775 else 1776 __git_complete_refs $dwim_opt --mode="refs" 1777 fi 1778 ;; 1779 esac 1780} 1781 1782__git_sequencer_inprogress_options="--continue --quit --abort --skip" 1783 1784__git_cherry_pick_inprogress_options=$__git_sequencer_inprogress_options 1785 1786_git_cherry_pick () 1787{ 1788 if __git_pseudoref_exists CHERRY_PICK_HEAD; then 1789 __gitcomp "$__git_cherry_pick_inprogress_options" 1790 return 1791 fi 1792 1793 __git_complete_strategy && return 1794 1795 case "$cur" in 1796 --*) 1797 __gitcomp_builtin cherry-pick "" \ 1798 "$__git_cherry_pick_inprogress_options" 1799 ;; 1800 *) 1801 __git_complete_refs 1802 ;; 1803 esac 1804} 1805 1806_git_clean () 1807{ 1808 case "$cur" in 1809 --*) 1810 __gitcomp_builtin clean 1811 return 1812 ;; 1813 esac 1814 1815 # XXX should we check for -x option ? 1816 __git_complete_index_file "--others --directory" 1817} 1818 1819_git_clone () 1820{ 1821 case "$prev" in 1822 -c|--config) 1823 __git_complete_config_variable_name_and_value 1824 return 1825 ;; 1826 esac 1827 case "$cur" in 1828 --config=*) 1829 __git_complete_config_variable_name_and_value \ 1830 --cur="${cur##--config=}" 1831 return 1832 ;; 1833 --*) 1834 __gitcomp_builtin clone 1835 return 1836 ;; 1837 esac 1838} 1839 1840__git_untracked_file_modes="all no normal" 1841 1842__git_trailer_tokens () 1843{ 1844 __git config --name-only --get-regexp '^trailer\..*\.key$' | cut -d. -f 2- | rev | cut -d. -f2- | rev 1845} 1846 1847_git_commit () 1848{ 1849 case "$prev" in 1850 -c|-C) 1851 __git_complete_refs 1852 return 1853 ;; 1854 esac 1855 1856 case "$cur" in 1857 --cleanup=*) 1858 __gitcomp "default scissors strip verbatim whitespace 1859 " "" "${cur##--cleanup=}" 1860 return 1861 ;; 1862 --reuse-message=*|--reedit-message=*|\ 1863 --fixup=*|--squash=*) 1864 __git_complete_refs --cur="${cur#*=}" 1865 return 1866 ;; 1867 --untracked-files=*) 1868 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}" 1869 return 1870 ;; 1871 --trailer=*) 1872 __gitcomp_nl "$(__git_trailer_tokens)" "" "${cur##--trailer=}" ":" 1873 return 1874 ;; 1875 --*) 1876 __gitcomp_builtin commit 1877 return 1878 esac 1879 1880 if __git rev-parse --verify --quiet HEAD >/dev/null; then 1881 __git_complete_index_file "--committable" 1882 else 1883 # This is the first commit 1884 __git_complete_index_file "--cached" 1885 fi 1886} 1887 1888_git_describe () 1889{ 1890 case "$cur" in 1891 --*) 1892 __gitcomp_builtin describe 1893 return 1894 esac 1895 __git_complete_refs 1896} 1897 1898__git_diff_algorithms="myers minimal patience histogram" 1899 1900__git_diff_submodule_formats="diff log short" 1901 1902__git_color_moved_opts="no default plain blocks zebra dimmed-zebra" 1903 1904__git_color_moved_ws_opts="no ignore-space-at-eol ignore-space-change 1905 ignore-all-space allow-indentation-change" 1906 1907__git_ws_error_highlight_opts="context old new all default" 1908 1909# Options for the diff machinery (diff, log, show, stash, range-diff, ...) 1910__git_diff_common_options="--stat --numstat --shortstat --summary 1911 --patch-with-stat --name-only --name-status --color 1912 --no-color --color-words --no-renames --check 1913 --color-moved --color-moved= --no-color-moved 1914 --color-moved-ws= --no-color-moved-ws 1915 --full-index --binary --abbrev --diff-filter= 1916 --find-copies --find-object --find-renames 1917 --no-relative --relative 1918 --find-copies-harder --ignore-cr-at-eol 1919 --text --ignore-space-at-eol --ignore-space-change 1920 --ignore-all-space --ignore-blank-lines --exit-code 1921 --quiet --ext-diff --no-ext-diff --unified= 1922 --no-prefix --src-prefix= --dst-prefix= 1923 --inter-hunk-context= --function-context 1924 --patience --histogram --minimal 1925 --raw --word-diff --word-diff-regex= 1926 --dirstat --dirstat= --dirstat-by-file 1927 --dirstat-by-file= --cumulative 1928 --diff-algorithm= --default-prefix 1929 --submodule --submodule= --ignore-submodules 1930 --indent-heuristic --no-indent-heuristic 1931 --textconv --no-textconv --break-rewrites 1932 --patch --no-patch --cc --combined-all-paths 1933 --anchored= --compact-summary --ignore-matching-lines= 1934 --irreversible-delete --line-prefix --no-stat 1935 --output= --output-indicator-context= 1936 --output-indicator-new= --output-indicator-old= 1937 --ws-error-highlight= 1938 --pickaxe-all --pickaxe-regex --patch-with-raw 1939" 1940 1941# Options for diff/difftool 1942__git_diff_difftool_options="--cached --staged 1943 --base --ours --theirs --no-index --merge-base 1944 --ita-invisible-in-index --ita-visible-in-index 1945 $__git_diff_common_options" 1946 1947_git_diff () 1948{ 1949 __git_has_doubledash && return 1950 1951 case "$cur" in 1952 --diff-algorithm=*) 1953 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}" 1954 return 1955 ;; 1956 --submodule=*) 1957 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}" 1958 return 1959 ;; 1960 --color-moved=*) 1961 __gitcomp "$__git_color_moved_opts" "" "${cur##--color-moved=}" 1962 return 1963 ;; 1964 --color-moved-ws=*) 1965 __gitcomp "$__git_color_moved_ws_opts" "" "${cur##--color-moved-ws=}" 1966 return 1967 ;; 1968 --ws-error-highlight=*) 1969 __gitcomp "$__git_ws_error_highlight_opts" "" "${cur##--ws-error-highlight=}" 1970 return 1971 ;; 1972 --*) 1973 __gitcomp "$__git_diff_difftool_options" 1974 return 1975 ;; 1976 esac 1977 __git_complete_revlist_file 1978} 1979 1980__git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff 1981 tkdiff vimdiff nvimdiff gvimdiff xxdiff araxis p4merge 1982 bc codecompare smerge 1983" 1984 1985_git_difftool () 1986{ 1987 __git_has_doubledash && return 1988 1989 case "$cur" in 1990 --tool=*) 1991 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}" 1992 return 1993 ;; 1994 --*) 1995 __gitcomp_builtin difftool "$__git_diff_difftool_options" 1996 return 1997 ;; 1998 esac 1999 __git_complete_revlist_file 2000} 2001 2002__git_fetch_recurse_submodules="yes on-demand no" 2003 2004_git_fetch () 2005{ 2006 case "$cur" in 2007 --recurse-submodules=*) 2008 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}" 2009 return 2010 ;; 2011 --filter=*) 2012 __gitcomp "blob:none blob:limit= sparse:oid=" "" "${cur##--filter=}" 2013 return 2014 ;; 2015 --*) 2016 __gitcomp_builtin fetch 2017 return 2018 ;; 2019 esac 2020 __git_complete_remote_or_refspec 2021} 2022 2023__git_format_patch_extra_options=" 2024 --full-index --not --all --no-prefix --src-prefix= 2025 --dst-prefix= --notes 2026" 2027 2028_git_format_patch () 2029{ 2030 case "$cur" in 2031 --thread=*) 2032 __gitcomp " 2033 deep shallow 2034 " "" "${cur##--thread=}" 2035 return 2036 ;; 2037 --base=*|--interdiff=*|--range-diff=*) 2038 __git_complete_refs --cur="${cur#--*=}" 2039 return 2040 ;; 2041 --*) 2042 __gitcomp_builtin format-patch "$__git_format_patch_extra_options" 2043 return 2044 ;; 2045 esac 2046 __git_complete_revlist 2047} 2048 2049_git_fsck () 2050{ 2051 case "$cur" in 2052 --*) 2053 __gitcomp_builtin fsck 2054 return 2055 ;; 2056 esac 2057} 2058 2059_git_gitk () 2060{ 2061 __gitk_main 2062} 2063 2064# Lists matching symbol names from a tag (as in ctags) file. 2065# 1: List symbol names matching this word. 2066# 2: The tag file to list symbol names from. 2067# 3: A prefix to be added to each listed symbol name (optional). 2068# 4: A suffix to be appended to each listed symbol name (optional). 2069__git_match_ctag () { 2070 awk -v pfx="${3-}" -v sfx="${4-}" " 2071 /^${1//\//\\/}/ { print pfx \$1 sfx } 2072 " "$2" 2073} 2074 2075# Complete symbol names from a tag file. 2076# Usage: __git_complete_symbol [<option>]... 2077# --tags=<file>: The tag file to list symbol names from instead of the 2078# default "tags". 2079# --pfx=<prefix>: A prefix to be added to each symbol name. 2080# --cur=<word>: The current symbol name to be completed. Defaults to 2081# the current word to be completed. 2082# --sfx=<suffix>: A suffix to be appended to each symbol name instead 2083# of the default space. 2084__git_complete_symbol () { 2085 local tags=tags pfx="" cur_="${cur-}" sfx=" " 2086 2087 while test $# != 0; do 2088 case "$1" in 2089 --tags=*) tags="${1##--tags=}" ;; 2090 --pfx=*) pfx="${1##--pfx=}" ;; 2091 --cur=*) cur_="${1##--cur=}" ;; 2092 --sfx=*) sfx="${1##--sfx=}" ;; 2093 *) return 1 ;; 2094 esac 2095 shift 2096 done 2097 2098 if test -r "$tags"; then 2099 __gitcomp_direct "$(__git_match_ctag "$cur_" "$tags" "$pfx" "$sfx")" 2100 fi 2101} 2102 2103_git_grep () 2104{ 2105 __git_has_doubledash && return 2106 2107 case "$cur" in 2108 --*) 2109 __gitcomp_builtin grep 2110 return 2111 ;; 2112 esac 2113 2114 case "$cword,$prev" in 2115 $((__git_cmd_idx+1)),*|*,-*) 2116 __git_complete_symbol && return 2117 ;; 2118 esac 2119 2120 __git_complete_refs 2121} 2122 2123_git_help () 2124{ 2125 case "$cur" in 2126 --*) 2127 __gitcomp_builtin help 2128 return 2129 ;; 2130 esac 2131 if test -n "${GIT_TESTING_ALL_COMMAND_LIST-}" 2132 then 2133 __gitcomp "$GIT_TESTING_ALL_COMMAND_LIST $(__git --list-cmds=alias,list-guide) gitk" 2134 else 2135 __gitcomp "$(__git --list-cmds=main,nohelpers,alias,list-guide) gitk" 2136 fi 2137} 2138 2139_git_init () 2140{ 2141 case "$cur" in 2142 --shared=*) 2143 __gitcomp " 2144 false true umask group all world everybody 2145 " "" "${cur##--shared=}" 2146 return 2147 ;; 2148 --*) 2149 __gitcomp_builtin init 2150 return 2151 ;; 2152 esac 2153} 2154 2155_git_ls_files () 2156{ 2157 case "$cur" in 2158 --*) 2159 __gitcomp_builtin ls-files 2160 return 2161 ;; 2162 esac 2163 2164 # XXX ignore options like --modified and always suggest all cached 2165 # files. 2166 __git_complete_index_file "--cached" 2167} 2168 2169_git_ls_remote () 2170{ 2171 case "$cur" in 2172 --*) 2173 __gitcomp_builtin ls-remote 2174 return 2175 ;; 2176 esac 2177 __gitcomp_nl "$(__git_remotes)" 2178} 2179 2180_git_ls_tree () 2181{ 2182 case "$cur" in 2183 --*) 2184 __gitcomp_builtin ls-tree 2185 return 2186 ;; 2187 esac 2188 2189 __git_complete_file 2190} 2191 2192# Options that go well for log, shortlog and gitk 2193__git_log_common_options=" 2194 --not --all 2195 --branches --tags --remotes 2196 --first-parent --merges --no-merges 2197 --max-count= 2198 --max-age= --since= --after= 2199 --min-age= --until= --before= 2200 --min-parents= --max-parents= 2201 --no-min-parents --no-max-parents 2202 --alternate-refs --ancestry-path 2203 --author-date-order --basic-regexp 2204 --bisect --boundary --exclude-first-parent-only 2205 --exclude-hidden --extended-regexp 2206 --fixed-strings --grep-reflog 2207 --ignore-missing --left-only --perl-regexp 2208 --reflog --regexp-ignore-case --remove-empty 2209 --right-only --show-linear-break 2210 --show-notes-by-default --show-pulls 2211 --since-as-filter --single-worktree 2212" 2213# Options that go well for log and gitk (not shortlog) 2214__git_log_gitk_options=" 2215 --dense --sparse --full-history 2216 --simplify-merges --simplify-by-decoration 2217 --left-right --notes --no-notes 2218" 2219# Options that go well for log and shortlog (not gitk) 2220__git_log_shortlog_options=" 2221 --author= --committer= --grep= 2222 --all-match --invert-grep 2223" 2224# Options accepted by log and show 2225__git_log_show_options=" 2226 --diff-merges --diff-merges= --no-diff-merges --dd --remerge-diff 2227 --encoding= 2228" 2229 2230__git_diff_merges_opts="off none on first-parent 1 separate m combined c dense-combined cc remerge r" 2231 2232__git_log_pretty_formats="oneline short medium full fuller reference email raw format: tformat: mboxrd" 2233__git_log_date_formats="relative iso8601 iso8601-strict rfc2822 short local default human raw unix auto: format:" 2234 2235# Complete porcelain (i.e. not git-rev-list) options and at least some 2236# option arguments accepted by git-log. Note that this same set of options 2237# are also accepted by some other git commands besides git-log. 2238__git_complete_log_opts () 2239{ 2240 COMPREPLY=() 2241 2242 local merge="" 2243 if __git_pseudoref_exists MERGE_HEAD; then 2244 merge="--merge" 2245 fi 2246 case "$prev,$cur" in 2247 -L,:*:*) 2248 return # fall back to Bash filename completion 2249 ;; 2250 -L,:*) 2251 __git_complete_symbol --cur="${cur#:}" --sfx=":" 2252 return 2253 ;; 2254 -G,*|-S,*) 2255 __git_complete_symbol 2256 return 2257 ;; 2258 esac 2259 case "$cur" in 2260 --pretty=*|--format=*) 2261 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases) 2262 " "" "${cur#*=}" 2263 return 2264 ;; 2265 --date=*) 2266 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}" 2267 return 2268 ;; 2269 --decorate=*) 2270 __gitcomp "full short no" "" "${cur##--decorate=}" 2271 return 2272 ;; 2273 --diff-algorithm=*) 2274 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}" 2275 return 2276 ;; 2277 --submodule=*) 2278 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}" 2279 return 2280 ;; 2281 --ws-error-highlight=*) 2282 __gitcomp "$__git_ws_error_highlight_opts" "" "${cur##--ws-error-highlight=}" 2283 return 2284 ;; 2285 --no-walk=*) 2286 __gitcomp "sorted unsorted" "" "${cur##--no-walk=}" 2287 return 2288 ;; 2289 --diff-merges=*) 2290 __gitcomp "$__git_diff_merges_opts" "" "${cur##--diff-merges=}" 2291 return 2292 ;; 2293 --*) 2294 __gitcomp " 2295 $__git_log_common_options 2296 $__git_log_shortlog_options 2297 $__git_log_gitk_options 2298 $__git_log_show_options 2299 --root --topo-order --date-order --reverse 2300 --follow --full-diff 2301 --abbrev-commit --no-abbrev-commit --abbrev= 2302 --relative-date --date= 2303 --pretty= --format= --oneline 2304 --show-signature 2305 --cherry-mark 2306 --cherry-pick 2307 --graph 2308 --decorate --decorate= --no-decorate 2309 --walk-reflogs 2310 --no-walk --no-walk= --do-walk 2311 --parents --children 2312 --expand-tabs --expand-tabs= --no-expand-tabs 2313 --clear-decorations --decorate-refs= 2314 --decorate-refs-exclude= 2315 $merge 2316 $__git_diff_common_options 2317 " 2318 return 2319 ;; 2320 -L:*:*) 2321 return # fall back to Bash filename completion 2322 ;; 2323 -L:*) 2324 __git_complete_symbol --cur="${cur#-L:}" --sfx=":" 2325 return 2326 ;; 2327 -G*) 2328 __git_complete_symbol --pfx="-G" --cur="${cur#-G}" 2329 return 2330 ;; 2331 -S*) 2332 __git_complete_symbol --pfx="-S" --cur="${cur#-S}" 2333 return 2334 ;; 2335 esac 2336} 2337 2338_git_log () 2339{ 2340 __git_has_doubledash && return 2341 __git_find_repo_path 2342 2343 __git_complete_log_opts 2344 [ ${#COMPREPLY[@]} -eq 0 ] || return 2345 2346 __git_complete_revlist 2347} 2348 2349_git_merge () 2350{ 2351 __git_complete_strategy && return 2352 2353 case "$cur" in 2354 --*) 2355 __gitcomp_builtin merge 2356 return 2357 esac 2358 __git_complete_refs 2359} 2360 2361_git_mergetool () 2362{ 2363 case "$cur" in 2364 --tool=*) 2365 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}" 2366 return 2367 ;; 2368 --*) 2369 __gitcomp "--tool= --tool-help --prompt --no-prompt --gui --no-gui" 2370 return 2371 ;; 2372 esac 2373} 2374 2375_git_merge_base () 2376{ 2377 case "$cur" in 2378 --*) 2379 __gitcomp_builtin merge-base 2380 return 2381 ;; 2382 esac 2383 __git_complete_refs 2384} 2385 2386_git_mv () 2387{ 2388 case "$cur" in 2389 --*) 2390 __gitcomp_builtin mv 2391 return 2392 ;; 2393 esac 2394 2395 if [ $(__git_count_arguments "mv") -gt 0 ]; then 2396 # We need to show both cached and untracked files (including 2397 # empty directories) since this may not be the last argument. 2398 __git_complete_index_file "--cached --others --directory" 2399 else 2400 __git_complete_index_file "--cached" 2401 fi 2402} 2403 2404_git_notes () 2405{ 2406 local subcommands='add append copy edit get-ref list merge prune remove show' 2407 local subcommand="$(__git_find_on_cmdline "$subcommands")" 2408 2409 case "$subcommand,$cur" in 2410 ,--*) 2411 __gitcomp_builtin notes 2412 ;; 2413 ,*) 2414 case "$prev" in 2415 --ref) 2416 __git_complete_refs 2417 ;; 2418 *) 2419 __gitcomp "$subcommands --ref" 2420 ;; 2421 esac 2422 ;; 2423 *,--reuse-message=*|*,--reedit-message=*) 2424 __git_complete_refs --cur="${cur#*=}" 2425 ;; 2426 *,--*) 2427 __gitcomp_builtin notes_$subcommand 2428 ;; 2429 prune,*|get-ref,*) 2430 # this command does not take a ref, do not complete it 2431 ;; 2432 *) 2433 case "$prev" in 2434 -m|-F) 2435 ;; 2436 *) 2437 __git_complete_refs 2438 ;; 2439 esac 2440 ;; 2441 esac 2442} 2443 2444_git_pull () 2445{ 2446 __git_complete_strategy && return 2447 2448 case "$cur" in 2449 --recurse-submodules=*) 2450 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}" 2451 return 2452 ;; 2453 --*) 2454 __gitcomp_builtin pull 2455 2456 return 2457 ;; 2458 esac 2459 __git_complete_remote_or_refspec 2460} 2461 2462__git_push_recurse_submodules="check on-demand only" 2463 2464__git_complete_force_with_lease () 2465{ 2466 local cur_=$1 2467 2468 case "$cur_" in 2469 --*=) 2470 ;; 2471 *:*) 2472 __git_complete_refs --cur="${cur_#*:}" 2473 ;; 2474 *) 2475 __git_complete_refs --cur="$cur_" 2476 ;; 2477 esac 2478} 2479 2480_git_push () 2481{ 2482 case "$prev" in 2483 --repo) 2484 __gitcomp_nl "$(__git_remotes)" 2485 return 2486 ;; 2487 --recurse-submodules) 2488 __gitcomp "$__git_push_recurse_submodules" 2489 return 2490 ;; 2491 esac 2492 case "$cur" in 2493 --repo=*) 2494 __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}" 2495 return 2496 ;; 2497 --recurse-submodules=*) 2498 __gitcomp "$__git_push_recurse_submodules" "" "${cur##--recurse-submodules=}" 2499 return 2500 ;; 2501 --force-with-lease=*) 2502 __git_complete_force_with_lease "${cur##--force-with-lease=}" 2503 return 2504 ;; 2505 --*) 2506 __gitcomp_builtin push 2507 return 2508 ;; 2509 esac 2510 __git_complete_remote_or_refspec 2511} 2512 2513_git_range_diff () 2514{ 2515 case "$cur" in 2516 --*) 2517 __gitcomp " 2518 --creation-factor= --no-dual-color 2519 $__git_diff_common_options 2520 " 2521 return 2522 ;; 2523 esac 2524 __git_complete_revlist 2525} 2526 2527__git_rebase_inprogress_options="--continue --skip --abort --quit --show-current-patch" 2528__git_rebase_interactive_inprogress_options="$__git_rebase_inprogress_options --edit-todo" 2529 2530_git_rebase () 2531{ 2532 __git_find_repo_path 2533 if [ -f "$__git_repo_path"/rebase-merge/interactive ]; then 2534 __gitcomp "$__git_rebase_interactive_inprogress_options" 2535 return 2536 elif [ -d "$__git_repo_path"/rebase-apply ] || \ 2537 [ -d "$__git_repo_path"/rebase-merge ]; then 2538 __gitcomp "$__git_rebase_inprogress_options" 2539 return 2540 fi 2541 __git_complete_strategy && return 2542 case "$cur" in 2543 --whitespace=*) 2544 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}" 2545 return 2546 ;; 2547 --onto=*) 2548 __git_complete_refs --cur="${cur##--onto=}" 2549 return 2550 ;; 2551 --*) 2552 __gitcomp_builtin rebase "" \ 2553 "$__git_rebase_interactive_inprogress_options" 2554 2555 return 2556 esac 2557 __git_complete_refs 2558} 2559 2560_git_reflog () 2561{ 2562 local subcommands subcommand 2563 2564 __git_resolve_builtins "reflog" 2565 2566 subcommands="$___git_resolved_builtins" 2567 subcommand="$(__git_find_subcommand "$subcommands" "show")" 2568 2569 case "$subcommand,$cur" in 2570 show,--*) 2571 __gitcomp " 2572 $__git_log_common_options 2573 " 2574 return 2575 ;; 2576 $subcommand,--*) 2577 __gitcomp_builtin "reflog_$subcommand" 2578 return 2579 ;; 2580 esac 2581 2582 __git_complete_refs 2583 2584 if [ $((cword - __git_cmd_idx)) -eq 1 ]; then 2585 __gitcompappend "$subcommands" "" "$cur" " " 2586 fi 2587} 2588 2589__git_send_email_confirm_options="always never auto cc compose" 2590__git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all" 2591 2592_git_send_email () 2593{ 2594 case "$prev" in 2595 --to|--cc|--bcc|--from) 2596 __gitcomp "$(__git send-email --dump-aliases)" 2597 return 2598 ;; 2599 esac 2600 2601 case "$cur" in 2602 --confirm=*) 2603 __gitcomp " 2604 $__git_send_email_confirm_options 2605 " "" "${cur##--confirm=}" 2606 return 2607 ;; 2608 --suppress-cc=*) 2609 __gitcomp " 2610 $__git_send_email_suppresscc_options 2611 " "" "${cur##--suppress-cc=}" 2612 2613 return 2614 ;; 2615 --smtp-encryption=*) 2616 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}" 2617 return 2618 ;; 2619 --thread=*) 2620 __gitcomp " 2621 deep shallow 2622 " "" "${cur##--thread=}" 2623 return 2624 ;; 2625 --to=*|--cc=*|--bcc=*|--from=*) 2626 __gitcomp "$(__git send-email --dump-aliases)" "" "${cur#--*=}" 2627 return 2628 ;; 2629 --*) 2630 __gitcomp_builtin send-email "$__git_format_patch_extra_options" 2631 return 2632 ;; 2633 esac 2634 __git_complete_revlist 2635} 2636 2637_git_stage () 2638{ 2639 _git_add 2640} 2641 2642_git_status () 2643{ 2644 local complete_opt 2645 local untracked_state 2646 2647 case "$cur" in 2648 --ignore-submodules=*) 2649 __gitcomp "none untracked dirty all" "" "${cur##--ignore-submodules=}" 2650 return 2651 ;; 2652 --untracked-files=*) 2653 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}" 2654 return 2655 ;; 2656 --column=*) 2657 __gitcomp " 2658 always never auto column row plain dense nodense 2659 " "" "${cur##--column=}" 2660 return 2661 ;; 2662 --*) 2663 __gitcomp_builtin status 2664 return 2665 ;; 2666 esac 2667 2668 untracked_state="$(__git_get_option_value "-u" "--untracked-files=" \ 2669 "$__git_untracked_file_modes" "status.showUntrackedFiles")" 2670 2671 case "$untracked_state" in 2672 no) 2673 # --ignored option does not matter 2674 complete_opt= 2675 ;; 2676 all|normal|*) 2677 complete_opt="--cached --directory --no-empty-directory --others" 2678 2679 if [ -n "$(__git_find_on_cmdline "--ignored")" ]; then 2680 complete_opt="$complete_opt --ignored --exclude=*" 2681 fi 2682 ;; 2683 esac 2684 2685 __git_complete_index_file "$complete_opt" 2686} 2687 2688_git_switch () 2689{ 2690 local dwim_opt="$(__git_checkout_default_dwim_mode)" 2691 2692 case "$prev" in 2693 -c|-C|--orphan) 2694 # Complete local branches (and DWIM branch 2695 # remote branch names) for an option argument 2696 # specifying a new branch name. This is for 2697 # convenience, assuming new branches are 2698 # possibly based on pre-existing branch names. 2699 __git_complete_refs $dwim_opt --mode="heads" 2700 return 2701 ;; 2702 *) 2703 ;; 2704 esac 2705 2706 case "$cur" in 2707 --conflict=*) 2708 __gitcomp "diff3 merge zdiff3" "" "${cur##--conflict=}" 2709 ;; 2710 --*) 2711 __gitcomp_builtin switch 2712 ;; 2713 *) 2714 # Unlike in git checkout, git switch --orphan does not take 2715 # a start point. Thus we really have nothing to complete after 2716 # the branch name. 2717 if [ -n "$(__git_find_on_cmdline "--orphan")" ]; then 2718 return 2719 fi 2720 2721 # At this point, we've already handled special completion for 2722 # -c/-C, and --orphan. There are 3 main things left to 2723 # complete: 2724 # 1) a start-point for -c/-C or -d/--detach 2725 # 2) a remote head, for --track 2726 # 3) a branch name, possibly including DWIM remote branches 2727 2728 if [ -n "$(__git_find_on_cmdline "-c -C -d --detach")" ]; then 2729 __git_complete_refs --mode="refs" 2730 elif [ -n "$(__git_find_on_cmdline "-t --track")" ]; then 2731 __git_complete_refs --mode="remote-heads" 2732 else 2733 __git_complete_refs $dwim_opt --mode="heads" 2734 fi 2735 ;; 2736 esac 2737} 2738 2739__git_config_get_set_variables () 2740{ 2741 local prevword word config_file= c=$cword 2742 while [ $c -gt "$__git_cmd_idx" ]; do 2743 word="${words[c]}" 2744 case "$word" in 2745 --system|--global|--local|--file=*) 2746 config_file="$word" 2747 break 2748 ;; 2749 -f|--file) 2750 config_file="$word $prevword" 2751 break 2752 ;; 2753 esac 2754 prevword=$word 2755 c=$((--c)) 2756 done 2757 2758 __git config $config_file --name-only --list 2759} 2760 2761__git_config_vars= 2762__git_compute_config_vars () 2763{ 2764 test -n "$__git_config_vars" || 2765 __git_config_vars="$(git help --config-for-completion)" 2766} 2767 2768__git_config_vars_all= 2769__git_compute_config_vars_all () 2770{ 2771 test -n "$__git_config_vars_all" || 2772 __git_config_vars_all="$(git --no-pager help --config)" 2773} 2774 2775__git_indirect() 2776{ 2777 eval printf '%s' "\"\$$1\"" 2778} 2779 2780__git_compute_first_level_config_vars_for_section () 2781{ 2782 local section="$1" 2783 __git_compute_config_vars 2784 local this_section="__git_first_level_config_vars_for_section_${section}" 2785 test -n "$(__git_indirect "${this_section}")" || 2786 printf -v "__git_first_level_config_vars_for_section_${section}" %s \ 2787 "$(echo "$__git_config_vars" | awk -F. "/^${section}\.[a-z]/ { print \$2 }")" 2788} 2789 2790__git_compute_second_level_config_vars_for_section () 2791{ 2792 local section="$1" 2793 __git_compute_config_vars_all 2794 local this_section="__git_second_level_config_vars_for_section_${section}" 2795 test -n "$(__git_indirect "${this_section}")" || 2796 printf -v "__git_second_level_config_vars_for_section_${section}" %s \ 2797 "$(echo "$__git_config_vars_all" | awk -F. "/^${section}\.</ { print \$3 }")" 2798} 2799 2800__git_config_sections= 2801__git_compute_config_sections () 2802{ 2803 test -n "$__git_config_sections" || 2804 __git_config_sections="$(git help --config-sections-for-completion)" 2805} 2806 2807# Completes possible values of various configuration variables. 2808# 2809# Usage: __git_complete_config_variable_value [<option>]... 2810# --varname=<word>: The name of the configuration variable whose value is 2811# to be completed. Defaults to the previous word on the 2812# command line. 2813# --cur=<word>: The current value to be completed. Defaults to the current 2814# word to be completed. 2815__git_complete_config_variable_value () 2816{ 2817 local varname="$prev" cur_="$cur" 2818 2819 while test $# != 0; do 2820 case "$1" in 2821 --varname=*) varname="${1##--varname=}" ;; 2822 --cur=*) cur_="${1##--cur=}" ;; 2823 *) return 1 ;; 2824 esac 2825 shift 2826 done 2827 2828 if [ "${BASH_VERSINFO[0]:-0}" -ge 4 ]; then 2829 varname="${varname,,}" 2830 else 2831 varname="$(echo "$varname" |tr A-Z a-z)" 2832 fi 2833 2834 case "$varname" in 2835 branch.*.remote|branch.*.pushremote) 2836 __gitcomp_nl "$(__git_remotes)" "" "$cur_" 2837 return 2838 ;; 2839 branch.*.merge) 2840 __git_complete_refs --cur="$cur_" 2841 return 2842 ;; 2843 branch.*.rebase) 2844 __gitcomp "false true merges interactive" "" "$cur_" 2845 return 2846 ;; 2847 remote.pushdefault) 2848 __gitcomp_nl "$(__git_remotes)" "" "$cur_" 2849 return 2850 ;; 2851 remote.*.fetch) 2852 local remote="${varname#remote.}" 2853 remote="${remote%.fetch}" 2854 if [ -z "$cur_" ]; then 2855 __gitcomp_nl "refs/heads/" "" "" "" 2856 return 2857 fi 2858 __gitcomp_nl "$(__git_refs_remotes "$remote")" "" "$cur_" 2859 return 2860 ;; 2861 remote.*.push) 2862 local remote="${varname#remote.}" 2863 remote="${remote%.push}" 2864 __gitcomp_nl "$(__git for-each-ref \ 2865 --format='%(refname):%(refname)' refs/heads)" "" "$cur_" 2866 return 2867 ;; 2868 pull.twohead|pull.octopus) 2869 __git_compute_merge_strategies 2870 __gitcomp "$__git_merge_strategies" "" "$cur_" 2871 return 2872 ;; 2873 color.pager) 2874 __gitcomp "false true" "" "$cur_" 2875 return 2876 ;; 2877 color.*.*) 2878 __gitcomp " 2879 normal black red green yellow blue magenta cyan white 2880 bold dim ul blink reverse 2881 " "" "$cur_" 2882 return 2883 ;; 2884 color.*) 2885 __gitcomp "false true always never auto" "" "$cur_" 2886 return 2887 ;; 2888 diff.submodule) 2889 __gitcomp "$__git_diff_submodule_formats" "" "$cur_" 2890 return 2891 ;; 2892 help.format) 2893 __gitcomp "man info web html" "" "$cur_" 2894 return 2895 ;; 2896 log.date) 2897 __gitcomp "$__git_log_date_formats" "" "$cur_" 2898 return 2899 ;; 2900 sendemail.aliasfiletype) 2901 __gitcomp "mutt mailrc pine elm gnus" "" "$cur_" 2902 return 2903 ;; 2904 sendemail.confirm) 2905 __gitcomp "$__git_send_email_confirm_options" "" "$cur_" 2906 return 2907 ;; 2908 sendemail.suppresscc) 2909 __gitcomp "$__git_send_email_suppresscc_options" "" "$cur_" 2910 return 2911 ;; 2912 sendemail.transferencoding) 2913 __gitcomp "7bit 8bit quoted-printable base64" "" "$cur_" 2914 return 2915 ;; 2916 *.*) 2917 return 2918 ;; 2919 esac 2920} 2921 2922# Completes configuration sections, subsections, variable names. 2923# 2924# Usage: __git_complete_config_variable_name [<option>]... 2925# --cur=<word>: The current configuration section/variable name to be 2926# completed. Defaults to the current word to be completed. 2927# --sfx=<suffix>: A suffix to be appended to each fully completed 2928# configuration variable name (but not to sections or 2929# subsections) instead of the default space. 2930__git_complete_config_variable_name () 2931{ 2932 local cur_="$cur" sfx 2933 2934 while test $# != 0; do 2935 case "$1" in 2936 --cur=*) cur_="${1##--cur=}" ;; 2937 --sfx=*) sfx="${1##--sfx=}" ;; 2938 *) return 1 ;; 2939 esac 2940 shift 2941 done 2942 2943 case "$cur_" in 2944 branch.*.*|guitool.*.*|difftool.*.*|man.*.*|mergetool.*.*|remote.*.*|submodule.*.*|url.*.*) 2945 local pfx="${cur_%.*}." 2946 cur_="${cur_##*.}" 2947 local section="${pfx%.*.}" 2948 __git_compute_second_level_config_vars_for_section "${section}" 2949 local this_section="__git_second_level_config_vars_for_section_${section}" 2950 __gitcomp "$(__git_indirect "${this_section}")" "$pfx" "$cur_" "$sfx" 2951 return 2952 ;; 2953 branch.*) 2954 local pfx="${cur_%.*}." 2955 cur_="${cur_#*.}" 2956 local section="${pfx%.}" 2957 __gitcomp_direct "$(__git_heads "$pfx" "$cur_" ".")" 2958 __git_compute_first_level_config_vars_for_section "${section}" 2959 local this_section="__git_first_level_config_vars_for_section_${section}" 2960 __gitcomp_nl_append "$(__git_indirect "${this_section}")" "$pfx" "$cur_" "${sfx:- }" 2961 return 2962 ;; 2963 pager.*) 2964 local pfx="${cur_%.*}." 2965 cur_="${cur_#*.}" 2966 __git_compute_all_commands 2967 __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_" "${sfx:- }" 2968 return 2969 ;; 2970 remote.*) 2971 local pfx="${cur_%.*}." 2972 cur_="${cur_#*.}" 2973 local section="${pfx%.}" 2974 __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "." 2975 __git_compute_first_level_config_vars_for_section "${section}" 2976 local this_section="__git_first_level_config_vars_for_section_${section}" 2977 __gitcomp_nl_append "$(__git_indirect "${this_section}")" "$pfx" "$cur_" "${sfx:- }" 2978 return 2979 ;; 2980 submodule.*) 2981 local pfx="${cur_%.*}." 2982 cur_="${cur_#*.}" 2983 local section="${pfx%.}" 2984 __gitcomp_nl "$(__git config -f "$(__git rev-parse --show-toplevel)/.gitmodules" --get-regexp 'submodule.*.path' | awk -F. '{print $2}')" "$pfx" "$cur_" "." 2985 __git_compute_first_level_config_vars_for_section "${section}" 2986 local this_section="__git_first_level_config_vars_for_section_${section}" 2987 __gitcomp_nl_append "$(__git_indirect "${this_section}")" "$pfx" "$cur_" "${sfx:- }" 2988 return 2989 ;; 2990 *.*) 2991 __git_compute_config_vars 2992 __gitcomp "$__git_config_vars" "" "$cur_" "$sfx" 2993 ;; 2994 *) 2995 __git_compute_config_sections 2996 __gitcomp "$__git_config_sections" "" "$cur_" "." 2997 ;; 2998 esac 2999} 3000 3001# Completes '='-separated configuration sections/variable names and values 3002# for 'git -c section.name=value'. 3003# 3004# Usage: __git_complete_config_variable_name_and_value [<option>]... 3005# --cur=<word>: The current configuration section/variable name/value to be 3006# completed. Defaults to the current word to be completed. 3007__git_complete_config_variable_name_and_value () 3008{ 3009 local cur_="$cur" 3010 3011 while test $# != 0; do 3012 case "$1" in 3013 --cur=*) cur_="${1##--cur=}" ;; 3014 *) return 1 ;; 3015 esac 3016 shift 3017 done 3018 3019 case "$cur_" in 3020 *=*) 3021 __git_complete_config_variable_value \ 3022 --varname="${cur_%%=*}" --cur="${cur_#*=}" 3023 ;; 3024 *) 3025 __git_complete_config_variable_name --cur="$cur_" --sfx='=' 3026 ;; 3027 esac 3028} 3029 3030_git_config () 3031{ 3032 local subcommands subcommand 3033 3034 __git_resolve_builtins "config" 3035 3036 subcommands="$___git_resolved_builtins" 3037 subcommand="$(__git_find_subcommand "$subcommands")" 3038 3039 if [ -z "$subcommand" ] 3040 then 3041 __gitcomp "$subcommands" 3042 return 3043 fi 3044 3045 case "$cur" in 3046 --*) 3047 __gitcomp_builtin "config_$subcommand" 3048 return 3049 ;; 3050 esac 3051 3052 case "$subcommand" in 3053 get) 3054 __gitcomp_nl "$(__git_config_get_set_variables)" 3055 ;; 3056 set) 3057 case "$prev" in 3058 *.*) 3059 __git_complete_config_variable_value 3060 ;; 3061 *) 3062 __git_complete_config_variable_name 3063 ;; 3064 esac 3065 ;; 3066 unset) 3067 __gitcomp_nl "$(__git_config_get_set_variables)" 3068 ;; 3069 esac 3070} 3071 3072_git_remote () 3073{ 3074 local subcommands=" 3075 add rename remove set-head set-branches 3076 get-url set-url show prune update 3077 " 3078 local subcommand="$(__git_find_on_cmdline "$subcommands")" 3079 if [ -z "$subcommand" ]; then 3080 case "$cur" in 3081 --*) 3082 __gitcomp_builtin remote 3083 ;; 3084 *) 3085 __gitcomp "$subcommands" 3086 ;; 3087 esac 3088 return 3089 fi 3090 3091 case "$subcommand,$cur" in 3092 add,--*) 3093 __gitcomp_builtin remote_add 3094 ;; 3095 add,*) 3096 ;; 3097 set-head,--*) 3098 __gitcomp_builtin remote_set-head 3099 ;; 3100 set-branches,--*) 3101 __gitcomp_builtin remote_set-branches 3102 ;; 3103 set-head,*|set-branches,*) 3104 __git_complete_remote_or_refspec 3105 ;; 3106 update,--*) 3107 __gitcomp_builtin remote_update 3108 ;; 3109 update,*) 3110 __gitcomp "$(__git_remotes) $(__git_get_config_variables "remotes")" 3111 ;; 3112 set-url,--*) 3113 __gitcomp_builtin remote_set-url 3114 ;; 3115 get-url,--*) 3116 __gitcomp_builtin remote_get-url 3117 ;; 3118 prune,--*) 3119 __gitcomp_builtin remote_prune 3120 ;; 3121 *) 3122 __gitcomp_nl "$(__git_remotes)" 3123 ;; 3124 esac 3125} 3126 3127_git_replace () 3128{ 3129 case "$cur" in 3130 --format=*) 3131 __gitcomp "short medium long" "" "${cur##--format=}" 3132 return 3133 ;; 3134 --*) 3135 __gitcomp_builtin replace 3136 return 3137 ;; 3138 esac 3139 __git_complete_refs 3140} 3141 3142_git_rerere () 3143{ 3144 local subcommands="clear forget diff remaining status gc" 3145 local subcommand="$(__git_find_on_cmdline "$subcommands")" 3146 if test -z "$subcommand" 3147 then 3148 __gitcomp "$subcommands" 3149 return 3150 fi 3151} 3152 3153_git_reset () 3154{ 3155 __git_has_doubledash && return 3156 3157 case "$cur" in 3158 --*) 3159 __gitcomp_builtin reset 3160 return 3161 ;; 3162 esac 3163 __git_complete_refs 3164} 3165 3166_git_restore () 3167{ 3168 case "$prev" in 3169 -s) 3170 __git_complete_refs 3171 return 3172 ;; 3173 esac 3174 3175 case "$cur" in 3176 --conflict=*) 3177 __gitcomp "diff3 merge zdiff3" "" "${cur##--conflict=}" 3178 ;; 3179 --source=*) 3180 __git_complete_refs --cur="${cur##--source=}" 3181 ;; 3182 --*) 3183 __gitcomp_builtin restore 3184 ;; 3185 *) 3186 if __git_pseudoref_exists HEAD; then 3187 __git_complete_index_file "--modified" 3188 fi 3189 esac 3190} 3191 3192__git_revert_inprogress_options=$__git_sequencer_inprogress_options 3193 3194_git_revert () 3195{ 3196 if __git_pseudoref_exists REVERT_HEAD; then 3197 __gitcomp "$__git_revert_inprogress_options" 3198 return 3199 fi 3200 __git_complete_strategy && return 3201 case "$cur" in 3202 --*) 3203 __gitcomp_builtin revert "" \ 3204 "$__git_revert_inprogress_options" 3205 return 3206 ;; 3207 esac 3208 __git_complete_refs 3209} 3210 3211_git_rm () 3212{ 3213 case "$cur" in 3214 --*) 3215 __gitcomp_builtin rm 3216 return 3217 ;; 3218 esac 3219 3220 __git_complete_index_file "--cached" 3221} 3222 3223_git_shortlog () 3224{ 3225 __git_has_doubledash && return 3226 3227 case "$cur" in 3228 --*) 3229 __gitcomp " 3230 $__git_log_common_options 3231 $__git_log_shortlog_options 3232 --numbered --summary --email 3233 " 3234 return 3235 ;; 3236 esac 3237 __git_complete_revlist 3238} 3239 3240_git_show () 3241{ 3242 __git_has_doubledash && return 3243 3244 case "$cur" in 3245 --pretty=*|--format=*) 3246 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases) 3247 " "" "${cur#*=}" 3248 return 3249 ;; 3250 --diff-algorithm=*) 3251 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}" 3252 return 3253 ;; 3254 --submodule=*) 3255 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}" 3256 return 3257 ;; 3258 --color-moved=*) 3259 __gitcomp "$__git_color_moved_opts" "" "${cur##--color-moved=}" 3260 return 3261 ;; 3262 --color-moved-ws=*) 3263 __gitcomp "$__git_color_moved_ws_opts" "" "${cur##--color-moved-ws=}" 3264 return 3265 ;; 3266 --ws-error-highlight=*) 3267 __gitcomp "$__git_ws_error_highlight_opts" "" "${cur##--ws-error-highlight=}" 3268 return 3269 ;; 3270 --diff-merges=*) 3271 __gitcomp "$__git_diff_merges_opts" "" "${cur##--diff-merges=}" 3272 return 3273 ;; 3274 --*) 3275 __gitcomp "--pretty= --format= --abbrev-commit --no-abbrev-commit 3276 --oneline --show-signature 3277 --expand-tabs --expand-tabs= --no-expand-tabs 3278 $__git_log_show_options 3279 $__git_diff_common_options 3280 " 3281 return 3282 ;; 3283 esac 3284 __git_complete_revlist_file 3285} 3286 3287_git_show_branch () 3288{ 3289 case "$cur" in 3290 --*) 3291 __gitcomp_builtin show-branch 3292 return 3293 ;; 3294 esac 3295 __git_complete_revlist 3296} 3297 3298__gitcomp_directories () 3299{ 3300 local _tmp_dir _tmp_completions _found=0 3301 3302 # Get the directory of the current token; this differs from dirname 3303 # in that it keeps up to the final trailing slash. If no slash found 3304 # that's fine too. 3305 [[ "$cur" =~ .*/ ]] 3306 _tmp_dir=$BASH_REMATCH 3307 3308 # Find possible directory completions, adding trailing '/' characters, 3309 # de-quoting, and handling unusual characters. 3310 while IFS= read -r -d $'\0' c ; do 3311 # If there are directory completions, find ones that start 3312 # with "$cur", the current token, and put those in COMPREPLY 3313 if [[ $c == "$cur"* ]]; then 3314 COMPREPLY+=("$c/") 3315 _found=1 3316 fi 3317 done < <(__git ls-tree -z -d --name-only HEAD $_tmp_dir) 3318 3319 if [[ $_found == 0 ]] && [[ "$cur" =~ /$ ]]; then 3320 # No possible further completions any deeper, so assume we're at 3321 # a leaf directory and just consider it complete 3322 __gitcomp_direct_append "$cur " 3323 elif [[ $_found == 0 ]]; then 3324 # No possible completions found. Avoid falling back to 3325 # bash's default file and directory completion, because all 3326 # valid completions have already been searched and the 3327 # fallbacks can do nothing but mislead. In fact, they can 3328 # mislead in three different ways: 3329 # 1) Fallback file completion makes no sense when asking 3330 # for directory completions, as this function does. 3331 # 2) Fallback directory completion is bad because 3332 # e.g. "/pro" is invalid and should NOT complete to 3333 # "/proc". 3334 # 3) Fallback file/directory completion only completes 3335 # on paths that exist in the current working tree, 3336 # i.e. which are *already* part of their 3337 # sparse-checkout. Thus, normal file and directory 3338 # completion is always useless for "git 3339 # sparse-checkout add" and is also problematic for 3340 # "git sparse-checkout set" unless using it to 3341 # strictly narrow the checkout. 3342 COMPREPLY=( "" ) 3343 fi 3344} 3345 3346# In non-cone mode, the arguments to {set,add} are supposed to be 3347# patterns, relative to the toplevel directory. These can be any kind 3348# of general pattern, like 'subdir/*.c' and we can't complete on all 3349# of those. However, if the user presses Tab to get tab completion, we 3350# presume that they are trying to provide a pattern that names a specific 3351# path. 3352__gitcomp_slash_leading_paths () 3353{ 3354 local dequoted_word pfx="" cur_ toplevel 3355 3356 # Since we are dealing with a sparse-checkout, subdirectories may not 3357 # exist in the local working copy. Therefore, we want to run all 3358 # ls-files commands relative to the repository toplevel. 3359 toplevel="$(git rev-parse --show-toplevel)/" 3360 3361 __git_dequote "$cur" 3362 3363 # If the paths provided by the user already start with '/', then 3364 # they are considered relative to the toplevel of the repository 3365 # already. If they do not start with /, then we need to adjust 3366 # them to start with the appropriate prefix. 3367 case "$cur" in 3368 /*) 3369 cur="${cur:1}" 3370 ;; 3371 *) 3372 pfx="$(__git rev-parse --show-prefix)" 3373 esac 3374 3375 # Since sparse-index is limited to cone-mode, in non-cone-mode the 3376 # list of valid paths is precisely the cached files in the index. 3377 # 3378 # NEEDSWORK: 3379 # 1) We probably need to take care of cases where ls-files 3380 # responds with special quoting. 3381 # 2) We probably need to take care of cases where ${cur} has 3382 # some kind of special quoting. 3383 # 3) On top of any quoting from 1 & 2, we have to provide an extra 3384 # level of quoting for any paths that contain a '*', '?', '\', 3385 # '[', ']', or leading '#' or '!' since those will be 3386 # interpreted by sparse-checkout as something other than a 3387 # literal path character. 3388 # Since there are two types of quoting here, this might get really 3389 # complex. For now, just punt on all of this... 3390 completions="$(__git -C "${toplevel}" -c core.quotePath=false \ 3391 ls-files --cached -- "${pfx}${cur}*" \ 3392 | sed -e s%^%/% -e 's%$% %')" 3393 # Note, above, though that we needed all of the completions to be 3394 # prefixed with a '/', and we want to add a space so that bash 3395 # completion will actually complete an entry and let us move on to 3396 # the next one. 3397 3398 # Return what we've found. 3399 if test -n "$completions"; then 3400 # We found some completions; return them 3401 local IFS=$'\n' 3402 COMPREPLY=($completions) 3403 else 3404 # Do NOT fall back to bash-style all-local-files-and-dirs 3405 # when we find no match. Such options are worse than 3406 # useless: 3407 # 1. "git sparse-checkout add" needs paths that are NOT 3408 # currently in the working copy. "git 3409 # sparse-checkout set" does as well, except in the 3410 # special cases when users are only trying to narrow 3411 # their sparse checkout to a subset of what they 3412 # already have. 3413 # 3414 # 2. A path like '.config' is ambiguous as to whether 3415 # the user wants all '.config' files throughout the 3416 # tree, or just the one under the current directory. 3417 # It would result in a warning from the 3418 # sparse-checkout command due to this. As such, all 3419 # completions of paths should be prefixed with a 3420 # '/'. 3421 # 3422 # 3. We don't want paths prefixed with a '/' to 3423 # complete files in the system root directory, we 3424 # want it to complete on files relative to the 3425 # repository root. 3426 # 3427 # As such, make sure that NO completions are offered rather 3428 # than falling back to bash's default completions. 3429 COMPREPLY=( "" ) 3430 fi 3431} 3432 3433_git_sparse_checkout () 3434{ 3435 local subcommands="list init set disable add reapply" 3436 local subcommand="$(__git_find_on_cmdline "$subcommands")" 3437 local using_cone=true 3438 if [ -z "$subcommand" ]; then 3439 __gitcomp "$subcommands" 3440 return 3441 fi 3442 3443 case "$subcommand,$cur" in 3444 *,--*) 3445 __gitcomp_builtin sparse-checkout_$subcommand "" "--" 3446 ;; 3447 set,*|add,*) 3448 if [[ "$(__git config core.sparseCheckout)" == "true" && 3449 "$(__git config core.sparseCheckoutCone)" == "false" && 3450 -z "$(__git_find_on_cmdline --cone)" ]]; then 3451 using_cone=false 3452 fi 3453 if [[ -n "$(__git_find_on_cmdline --no-cone)" ]]; then 3454 using_cone=false 3455 fi 3456 if [[ "$using_cone" == "true" ]]; then 3457 __gitcomp_directories 3458 else 3459 __gitcomp_slash_leading_paths 3460 fi 3461 esac 3462} 3463 3464_git_stash () 3465{ 3466 local subcommands='push list show apply clear drop pop create branch' 3467 local subcommand="$(__git_find_on_cmdline "$subcommands save")" 3468 3469 if [ -z "$subcommand" ]; then 3470 case "$((cword - __git_cmd_idx)),$cur" in 3471 *,--*) 3472 __gitcomp_builtin stash_push 3473 ;; 3474 1,sa*) 3475 __gitcomp "save" 3476 ;; 3477 1,*) 3478 __gitcomp "$subcommands" 3479 ;; 3480 esac 3481 return 3482 fi 3483 3484 case "$subcommand,$cur" in 3485 list,--*) 3486 # NEEDSWORK: can we somehow unify this with the options in _git_log() and _git_show() 3487 __gitcomp_builtin stash_list "$__git_log_common_options $__git_diff_common_options" 3488 ;; 3489 show,--*) 3490 __gitcomp_builtin stash_show "$__git_diff_common_options" 3491 ;; 3492 *,--*) 3493 __gitcomp_builtin "stash_$subcommand" 3494 ;; 3495 branch,*) 3496 if [ $cword -eq $((__git_cmd_idx+2)) ]; then 3497 __git_complete_refs 3498 else 3499 __gitcomp_nl "$(__git stash list \ 3500 | sed -n -e 's/:.*//p')" 3501 fi 3502 ;; 3503 show,*|apply,*|drop,*|pop,*) 3504 __gitcomp_nl "$(__git stash list \ 3505 | sed -n -e 's/:.*//p')" 3506 ;; 3507 esac 3508} 3509 3510_git_submodule () 3511{ 3512 __git_has_doubledash && return 3513 3514 local subcommands="add status init deinit update set-branch set-url summary foreach sync absorbgitdirs" 3515 local subcommand="$(__git_find_on_cmdline "$subcommands")" 3516 if [ -z "$subcommand" ]; then 3517 case "$cur" in 3518 --*) 3519 __gitcomp "--quiet" 3520 ;; 3521 *) 3522 __gitcomp "$subcommands" 3523 ;; 3524 esac 3525 return 3526 fi 3527 3528 case "$subcommand,$cur" in 3529 add,--*) 3530 __gitcomp "--branch --force --name --reference --depth" 3531 ;; 3532 status,--*) 3533 __gitcomp "--cached --recursive" 3534 ;; 3535 deinit,--*) 3536 __gitcomp "--force --all" 3537 ;; 3538 update,--*) 3539 __gitcomp " 3540 --init --remote --no-fetch 3541 --recommend-shallow --no-recommend-shallow 3542 --force --rebase --merge --reference --depth --recursive --jobs 3543 " 3544 ;; 3545 set-branch,--*) 3546 __gitcomp "--default --branch" 3547 ;; 3548 summary,--*) 3549 __gitcomp "--cached --files --summary-limit" 3550 ;; 3551 foreach,--*|sync,--*) 3552 __gitcomp "--recursive" 3553 ;; 3554 *) 3555 ;; 3556 esac 3557} 3558 3559_git_svn () 3560{ 3561 local subcommands=" 3562 init fetch clone rebase dcommit log find-rev 3563 set-tree commit-diff info create-ignore propget 3564 proplist show-ignore show-externals branch tag blame 3565 migrate mkdirs reset gc 3566 " 3567 local subcommand="$(__git_find_on_cmdline "$subcommands")" 3568 if [ -z "$subcommand" ]; then 3569 __gitcomp "$subcommands" 3570 else 3571 local remote_opts="--username= --config-dir= --no-auth-cache" 3572 local fc_opts=" 3573 --follow-parent --authors-file= --repack= 3574 --no-metadata --use-svm-props --use-svnsync-props 3575 --log-window-size= --no-checkout --quiet 3576 --repack-flags --use-log-author --localtime 3577 --add-author-from 3578 --recursive 3579 --ignore-paths= --include-paths= $remote_opts 3580 " 3581 local init_opts=" 3582 --template= --shared= --trunk= --tags= 3583 --branches= --stdlayout --minimize-url 3584 --no-metadata --use-svm-props --use-svnsync-props 3585 --rewrite-root= --prefix= $remote_opts 3586 " 3587 local cmt_opts=" 3588 --edit --rmdir --find-copies-harder --copy-similarity= 3589 " 3590 3591 case "$subcommand,$cur" in 3592 fetch,--*) 3593 __gitcomp "--revision= --fetch-all $fc_opts" 3594 ;; 3595 clone,--*) 3596 __gitcomp "--revision= $fc_opts $init_opts" 3597 ;; 3598 init,--*) 3599 __gitcomp "$init_opts" 3600 ;; 3601 dcommit,--*) 3602 __gitcomp " 3603 --merge --strategy= --verbose --dry-run 3604 --fetch-all --no-rebase --commit-url 3605 --revision --interactive $cmt_opts $fc_opts 3606 " 3607 ;; 3608 set-tree,--*) 3609 __gitcomp "--stdin $cmt_opts $fc_opts" 3610 ;; 3611 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\ 3612 show-externals,--*|mkdirs,--*) 3613 __gitcomp "--revision=" 3614 ;; 3615 log,--*) 3616 __gitcomp " 3617 --limit= --revision= --verbose --incremental 3618 --oneline --show-commit --non-recursive 3619 --authors-file= --color 3620 " 3621 ;; 3622 rebase,--*) 3623 __gitcomp " 3624 --merge --verbose --strategy= --local 3625 --fetch-all --dry-run $fc_opts 3626 " 3627 ;; 3628 commit-diff,--*) 3629 __gitcomp "--message= --file= --revision= $cmt_opts" 3630 ;; 3631 info,--*) 3632 __gitcomp "--url" 3633 ;; 3634 branch,--*) 3635 __gitcomp "--dry-run --message --tag" 3636 ;; 3637 tag,--*) 3638 __gitcomp "--dry-run --message" 3639 ;; 3640 blame,--*) 3641 __gitcomp "--git-format" 3642 ;; 3643 migrate,--*) 3644 __gitcomp " 3645 --config-dir= --ignore-paths= --minimize 3646 --no-auth-cache --username= 3647 " 3648 ;; 3649 reset,--*) 3650 __gitcomp "--revision= --parent" 3651 ;; 3652 *) 3653 ;; 3654 esac 3655 fi 3656} 3657 3658_git_symbolic_ref () { 3659 case "$cur" in 3660 --*) 3661 __gitcomp_builtin symbolic-ref 3662 return 3663 ;; 3664 esac 3665 3666 __git_complete_refs 3667} 3668 3669_git_tag () 3670{ 3671 local i c="$__git_cmd_idx" f=0 3672 while [ $c -lt $cword ]; do 3673 i="${words[c]}" 3674 case "$i" in 3675 -d|--delete|-v|--verify) 3676 __gitcomp_direct "$(__git_tags "" "$cur" " ")" 3677 return 3678 ;; 3679 -f) 3680 f=1 3681 ;; 3682 esac 3683 ((c++)) 3684 done 3685 3686 case "$prev" in 3687 -m|-F) 3688 ;; 3689 -*|tag) 3690 if [ $f = 1 ]; then 3691 __gitcomp_direct "$(__git_tags "" "$cur" " ")" 3692 fi 3693 ;; 3694 *) 3695 __git_complete_refs 3696 ;; 3697 esac 3698 3699 case "$cur" in 3700 --*) 3701 __gitcomp_builtin tag 3702 ;; 3703 esac 3704} 3705 3706_git_whatchanged () 3707{ 3708 _git_log 3709} 3710 3711__git_complete_worktree_paths () 3712{ 3713 local IFS=$'\n' 3714 # Generate completion reply from worktree list skipping the first 3715 # entry: it's the path of the main worktree, which can't be moved, 3716 # removed, locked, etc. 3717 __gitcomp_nl "$(__git worktree list --porcelain | 3718 sed -n -e '2,$ s/^worktree //p')" 3719} 3720 3721_git_worktree () 3722{ 3723 local subcommands="add list lock move prune remove unlock" 3724 local subcommand subcommand_idx 3725 3726 subcommand="$(__git_find_on_cmdline --show-idx "$subcommands")" 3727 subcommand_idx="${subcommand% *}" 3728 subcommand="${subcommand#* }" 3729 3730 case "$subcommand,$cur" in 3731 ,*) 3732 __gitcomp "$subcommands" 3733 ;; 3734 *,--*) 3735 __gitcomp_builtin worktree_$subcommand 3736 ;; 3737 add,*) # usage: git worktree add [<options>] <path> [<commit-ish>] 3738 # Here we are not completing an --option, it's either the 3739 # path or a ref. 3740 case "$prev" in 3741 -b|-B) # Complete refs for branch to be created/reset. 3742 __git_complete_refs 3743 ;; 3744 -*) # The previous word is an -o|--option without an 3745 # unstuck argument: have to complete the path for 3746 # the new worktree, so don't list anything, but let 3747 # Bash fall back to filename completion. 3748 ;; 3749 *) # The previous word is not an --option, so it must 3750 # be either the 'add' subcommand, the unstuck 3751 # argument of an option (e.g. branch for -b|-B), or 3752 # the path for the new worktree. 3753 if [ $cword -eq $((subcommand_idx+1)) ]; then 3754 # Right after the 'add' subcommand: have to 3755 # complete the path, so fall back to Bash 3756 # filename completion. 3757 : 3758 else 3759 case "${words[cword-2]}" in 3760 -b|-B) # After '-b <branch>': have to 3761 # complete the path, so fall back 3762 # to Bash filename completion. 3763 ;; 3764 *) # After the path: have to complete 3765 # the ref to be checked out. 3766 __git_complete_refs 3767 ;; 3768 esac 3769 fi 3770 ;; 3771 esac 3772 ;; 3773 lock,*|remove,*|unlock,*) 3774 __git_complete_worktree_paths 3775 ;; 3776 move,*) 3777 if [ $cword -eq $((subcommand_idx+1)) ]; then 3778 # The first parameter must be an existing working 3779 # tree to be moved. 3780 __git_complete_worktree_paths 3781 else 3782 # The second parameter is the destination: it could 3783 # be any path, so don't list anything, but let Bash 3784 # fall back to filename completion. 3785 : 3786 fi 3787 ;; 3788 esac 3789} 3790 3791__git_complete_common () { 3792 local command="$1" 3793 3794 case "$cur" in 3795 --*) 3796 __gitcomp_builtin "$command" 3797 ;; 3798 esac 3799} 3800 3801__git_cmds_with_parseopt_helper= 3802__git_support_parseopt_helper () { 3803 test -n "$__git_cmds_with_parseopt_helper" || 3804 __git_cmds_with_parseopt_helper="$(__git --list-cmds=parseopt)" 3805 3806 case " $__git_cmds_with_parseopt_helper " in 3807 *" $1 "*) 3808 return 0 3809 ;; 3810 *) 3811 return 1 3812 ;; 3813 esac 3814} 3815 3816__git_have_func () { 3817 declare -f -- "$1" >/dev/null 2>&1 3818} 3819 3820__git_complete_command () { 3821 local command="$1" 3822 local completion_func="_git_${command//-/_}" 3823 if ! __git_have_func $completion_func && 3824 __git_have_func _completion_loader 3825 then 3826 _completion_loader "git-$command" 3827 fi 3828 if __git_have_func $completion_func 3829 then 3830 $completion_func 3831 return 0 3832 elif __git_support_parseopt_helper "$command" 3833 then 3834 __git_complete_common "$command" 3835 return 0 3836 else 3837 return 1 3838 fi 3839} 3840 3841__git_main () 3842{ 3843 local i c=1 command __git_dir __git_repo_path 3844 local __git_C_args C_args_count=0 3845 local __git_cmd_idx 3846 3847 while [ $c -lt $cword ]; do 3848 i="${words[c]}" 3849 case "$i" in 3850 --git-dir=*) 3851 __git_dir="${i#--git-dir=}" 3852 ;; 3853 --git-dir) 3854 ((c++)) 3855 __git_dir="${words[c]}" 3856 ;; 3857 --bare) 3858 __git_dir="." 3859 ;; 3860 --help) 3861 command="help" 3862 break 3863 ;; 3864 -c|--work-tree|--namespace) 3865 ((c++)) 3866 ;; 3867 -C) 3868 __git_C_args[C_args_count++]=-C 3869 ((c++)) 3870 __git_C_args[C_args_count++]="${words[c]}" 3871 ;; 3872 -*) 3873 ;; 3874 *) 3875 command="$i" 3876 __git_cmd_idx="$c" 3877 break 3878 ;; 3879 esac 3880 ((c++)) 3881 done 3882 3883 if [ -z "${command-}" ]; then 3884 case "$prev" in 3885 --git-dir|-C|--work-tree) 3886 # these need a path argument, let's fall back to 3887 # Bash filename completion 3888 return 3889 ;; 3890 -c) 3891 __git_complete_config_variable_name_and_value 3892 return 3893 ;; 3894 --namespace) 3895 # we don't support completing these options' arguments 3896 return 3897 ;; 3898 esac 3899 case "$cur" in 3900 --*) 3901 __gitcomp " 3902 --paginate 3903 --no-pager 3904 --git-dir= 3905 --bare 3906 --version 3907 --exec-path 3908 --exec-path= 3909 --html-path 3910 --man-path 3911 --info-path 3912 --work-tree= 3913 --namespace= 3914 --no-replace-objects 3915 --help 3916 " 3917 ;; 3918 *) 3919 if test -n "${GIT_TESTING_PORCELAIN_COMMAND_LIST-}" 3920 then 3921 __gitcomp "$GIT_TESTING_PORCELAIN_COMMAND_LIST" 3922 else 3923 local list_cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config 3924 3925 if test "${GIT_COMPLETION_SHOW_ALL_COMMANDS-}" = "1" 3926 then 3927 list_cmds=builtins,$list_cmds 3928 fi 3929 __gitcomp "$(__git --list-cmds=$list_cmds)" 3930 fi 3931 ;; 3932 esac 3933 return 3934 fi 3935 3936 __git_complete_command "$command" && return 3937 3938 local expansion=$(__git_aliased_command "$command") 3939 if [ -n "$expansion" ]; then 3940 words[1]=$expansion 3941 __git_complete_command "$expansion" 3942 fi 3943} 3944 3945__gitk_main () 3946{ 3947 __git_has_doubledash && return 3948 3949 local __git_repo_path 3950 __git_find_repo_path 3951 3952 local merge="" 3953 if __git_pseudoref_exists MERGE_HEAD; then 3954 merge="--merge" 3955 fi 3956 case "$cur" in 3957 --*) 3958 __gitcomp " 3959 $__git_log_common_options 3960 $__git_log_gitk_options 3961 $merge 3962 " 3963 return 3964 ;; 3965 esac 3966 __git_complete_revlist 3967} 3968 3969if [[ -n ${ZSH_VERSION-} && -z ${GIT_SOURCING_ZSH_COMPLETION-} ]]; then 3970 echo "ERROR: this script is obsolete, please see git-completion.zsh" 1>&2 3971 return 3972fi 3973 3974__git_func_wrap () 3975{ 3976 local cur words cword prev 3977 local __git_cmd_idx=0 3978 _get_comp_words_by_ref -n =: cur words cword prev 3979 $1 3980} 3981 3982___git_complete () 3983{ 3984 local wrapper="__git_wrap${2}" 3985 eval "$wrapper () { __git_func_wrap $2 ; }" 3986 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \ 3987 || complete -o default -o nospace -F $wrapper $1 3988} 3989 3990# Setup the completion for git commands 3991# 1: command or alias 3992# 2: function to call (e.g. `git`, `gitk`, `git_fetch`) 3993__git_complete () 3994{ 3995 local func 3996 3997 if __git_have_func $2; then 3998 func=$2 3999 elif __git_have_func __$2_main; then 4000 func=__$2_main 4001 elif __git_have_func _$2; then 4002 func=_$2 4003 else 4004 echo "ERROR: could not find function '$2'" 1>&2 4005 return 1 4006 fi 4007 ___git_complete $1 $func 4008} 4009 4010___git_complete git __git_main 4011___git_complete gitk __gitk_main 4012 4013# The following are necessary only for Cygwin, and only are needed 4014# when the user has tab-completed the executable name and consequently 4015# included the '.exe' suffix. 4016# 4017if [ "$OSTYPE" = cygwin ]; then 4018 ___git_complete git.exe __git_main 4019fi