Unverified Commit 8c95c2b6 authored by Marc Cornellà's avatar Marc Cornellà Committed by GitHub
Browse files

gitfast: update plugin (#7152)

* Stop loading git plugin
* Update completion and git-prompt to v2.10
* Update completion to v2.14
parent 728c8e71
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
# #
# If your script is somewhere else, you can configure it on your ~/.zshrc: # If your script is somewhere else, you can configure it on your ~/.zshrc:
# #
# zstyle ':completion:*:*:git:*' script ~/.git-completion.sh # zstyle ':completion:*:*:git:*' script ~/.git-completion.zsh
# #
# The recommended way to install this script is to copy to '~/.zsh/_git', and # The recommended way to install this script is to copy to '~/.zsh/_git', and
# then add the following to your ~/.zshrc file: # then add the following to your ~/.zshrc file:
...@@ -67,6 +67,15 @@ __gitcomp () ...@@ -67,6 +67,15 @@ __gitcomp ()
esac esac
} }
__gitcomp_direct ()
{
emulate -L zsh
local IFS=$'\n'
compset -P '*[=:]'
compadd -Q -- ${=1} && _ret=0
}
__gitcomp_nl () __gitcomp_nl ()
{ {
emulate -L zsh emulate -L zsh
......
...@@ -28,27 +28,55 @@ ...@@ -28,27 +28,55 @@
# completion style. For example '!f() { : git commit ; ... }; f' will # completion style. For example '!f() { : git commit ; ... }; f' will
# tell the completion to use commit completion. This also works with aliases # tell the completion to use commit completion. This also works with aliases
# of form "!sh -c '...'". For example, "!sh -c ': git commit ; ... '". # of form "!sh -c '...'". For example, "!sh -c ': git commit ; ... '".
#
# You can set the following environment variables to influence the behavior of
# the completion routines:
#
# GIT_COMPLETION_CHECKOUT_NO_GUESS
#
# When set to "1", do not include "DWIM" suggestions in git-checkout
# completion (e.g., completing "foo" when "origin/foo" exists).
case "$COMP_WORDBREAKS" in case "$COMP_WORDBREAKS" in
*:*) : great ;; *:*) : great ;;
*) COMP_WORDBREAKS="$COMP_WORDBREAKS:" *) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
esac esac
# __gitdir accepts 0 or 1 arguments (i.e., location) # Discovers the path to the git repository taking any '--git-dir=<path>' and
# returns location of .git repo # '-C <path>' options into account and stores it in the $__git_repo_path
__gitdir () # variable.
__git_find_repo_path ()
{ {
if [ -z "${1-}" ]; then if [ -n "$__git_repo_path" ]; then
if [ -n "${__git_dir-}" ]; then # we already know where it is
echo "$__git_dir" return
fi
if [ -n "${__git_C_args-}" ]; then
__git_repo_path="$(git "${__git_C_args[@]}" \
${__git_dir:+--git-dir="$__git_dir"} \
rev-parse --absolute-git-dir 2>/dev/null)"
elif [ -n "${__git_dir-}" ]; then
test -d "$__git_dir" &&
__git_repo_path="$__git_dir"
elif [ -n "${GIT_DIR-}" ]; then elif [ -n "${GIT_DIR-}" ]; then
test -d "${GIT_DIR-}" || return 1 test -d "${GIT_DIR-}" &&
echo "$GIT_DIR" __git_repo_path="$GIT_DIR"
elif [ -d .git ]; then elif [ -d .git ]; then
echo .git __git_repo_path=.git
else else
git rev-parse --git-dir 2>/dev/null __git_repo_path="$(git rev-parse --git-dir 2>/dev/null)"
fi fi
}
# Deprecated: use __git_find_repo_path() and $__git_repo_path instead
# __gitdir accepts 0 or 1 arguments (i.e., location)
# returns location of .git repo
__gitdir ()
{
if [ -z "${1-}" ]; then
__git_find_repo_path || return 1
echo "$__git_repo_path"
elif [ -d "$1/.git" ]; then elif [ -d "$1/.git" ]; then
echo "$1/.git" echo "$1/.git"
else else
...@@ -56,6 +84,14 @@ __gitdir () ...@@ -56,6 +84,14 @@ __gitdir ()
fi fi
} }
# Runs git with all the options given as argument, respecting any
# '--git-dir=<path>' and '-C <path>' options present on the command line
__git ()
{
git ${__git_C_args:+"${__git_C_args[@]}"} \
${__git_dir:+--git-dir="$__git_dir"} "$@" 2>/dev/null
}
# The following function is based on code from: # The following function is based on code from:
# #
# bash_completion - programmable completion functions for bash 3.2+ # bash_completion - programmable completion functions for bash 3.2+
...@@ -185,6 +221,20 @@ _get_comp_words_by_ref () ...@@ -185,6 +221,20 @@ _get_comp_words_by_ref ()
} }
fi fi
# Fills the COMPREPLY array with prefiltered words without any additional
# processing.
# Callers must take care of providing only words that match the current word
# to be completed and adding any prefix and/or suffix (trailing space!), if
# necessary.
# 1: List of newline-separated matching completion words, complete with
# prefix and suffix.
__gitcomp_direct ()
{
local IFS=$'\n'
COMPREPLY=($1)
}
__gitcompappend () __gitcompappend ()
{ {
local x i=${#COMPREPLY[@]} local x i=${#COMPREPLY[@]}
...@@ -283,11 +333,11 @@ __gitcomp_file () ...@@ -283,11 +333,11 @@ __gitcomp_file ()
__git_ls_files_helper () __git_ls_files_helper ()
{ {
if [ "$2" == "--committable" ]; then if [ "$2" == "--committable" ]; then
git -C "$1" diff-index --name-only --relative HEAD __git -C "$1" diff-index --name-only --relative HEAD
else else
# NOTE: $2 is not quoted in order to support multiple options # NOTE: $2 is not quoted in order to support multiple options
git -C "$1" ls-files --exclude-standard $2 __git -C "$1" ls-files --exclude-standard $2
fi 2>/dev/null fi
} }
...@@ -299,9 +349,8 @@ __git_ls_files_helper () ...@@ -299,9 +349,8 @@ __git_ls_files_helper ()
# slash. # slash.
__git_index_files () __git_index_files ()
{ {
local dir="$(__gitdir)" root="${2-.}" file local root="${2-.}" file
if [ -d "$dir" ]; then
__git_ls_files_helper "$root" "$1" | __git_ls_files_helper "$root" "$1" |
while read -r file; do while read -r file; do
case "$file" in case "$file" in
...@@ -309,89 +358,186 @@ __git_index_files () ...@@ -309,89 +358,186 @@ __git_index_files ()
*) echo "$file" ;; *) echo "$file" ;;
esac esac
done | sort | uniq done | sort | uniq
fi
} }
# Lists branches from the local repository.
# 1: A prefix to be added to each listed branch (optional).
# 2: List only branches matching this word (optional; list all branches if
# unset or empty).
# 3: A suffix to be appended to each listed branch (optional).
__git_heads () __git_heads ()
{ {
local dir="$(__gitdir)" local pfx="${1-}" cur_="${2-}" sfx="${3-}"
if [ -d "$dir" ]; then
git --git-dir="$dir" for-each-ref --format='%(refname:short)' \ __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
refs/heads "refs/heads/$cur_*" "refs/heads/$cur_*/**"
return
fi
} }
# Lists tags from the local repository.
# Accepts the same positional parameters as __git_heads() above.
__git_tags () __git_tags ()
{ {
local dir="$(__gitdir)" local pfx="${1-}" cur_="${2-}" sfx="${3-}"
if [ -d "$dir" ]; then
git --git-dir="$dir" for-each-ref --format='%(refname:short)' \ __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
refs/tags "refs/tags/$cur_*" "refs/tags/$cur_*/**"
return
fi
} }
# __git_refs accepts 0, 1 (to pass to __gitdir), or 2 arguments # Lists refs from the local (by default) or from a remote repository.
# presence of 2nd argument means use the guess heuristic employed # It accepts 0, 1 or 2 arguments:
# by checkout for tracking branches # 1: The remote to list refs from (optional; ignored, if set but empty).
# Can be the name of a configured remote, a path, or a URL.
# 2: In addition to local refs, list unique branches from refs/remotes/ for
# 'git checkout's tracking DWIMery (optional; ignored, if set but empty).
# 3: A prefix to be added to each listed ref (optional).
# 4: List only refs matching this word (optional; list all refs if unset or
# empty).
# 5: A suffix to be appended to each listed ref (optional; ignored, if set
# but empty).
#
# Use __git_complete_refs() instead.
__git_refs () __git_refs ()
{ {
local i hash dir="$(__gitdir "${1-}")" track="${2-}" local i hash dir track="${2-}"
local list_refs_from=path remote="${1-}"
local format refs local format refs
if [ -d "$dir" ]; then local pfx="${3-}" cur_="${4-$cur}" sfx="${5-}"
case "$cur" in local match="${4-}"
local fer_pfx="${pfx//\%/%%}" # "escape" for-each-ref format specifiers
__git_find_repo_path
dir="$__git_repo_path"
if [ -z "$remote" ]; then
if [ -z "$dir" ]; then
return
fi
else
if __git_is_configured_remote "$remote"; then
# configured remote takes precedence over a
# local directory with the same name
list_refs_from=remote
elif [ -d "$remote/.git" ]; then
dir="$remote/.git"
elif [ -d "$remote" ]; then
dir="$remote"
else
list_refs_from=url
fi
fi
if [ "$list_refs_from" = path ]; then
if [[ "$cur_" == ^* ]]; then
pfx="$pfx^"
fer_pfx="$fer_pfx^"
cur_=${cur_#^}
match=${match#^}
fi
case "$cur_" in
refs|refs/*) refs|refs/*)
format="refname" format="refname"
refs="${cur%/*}" refs=("$match*" "$match*/**")
track="" track=""
;; ;;
*) *)
for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
if [ -e "$dir/$i" ]; then echo $i; fi case "$i" in
$match*)
if [ -e "$dir/$i" ]; then
echo "$pfx$i$sfx"
fi
;;
esac
done done
format="refname:short" format="refname:strip=2"
refs="refs/tags refs/heads refs/remotes" refs=("refs/tags/$match*" "refs/tags/$match*/**"
"refs/heads/$match*" "refs/heads/$match*/**"
"refs/remotes/$match*" "refs/remotes/$match*/**")
;; ;;
esac esac
git --git-dir="$dir" for-each-ref --format="%($format)" \ __git_dir="$dir" __git for-each-ref --format="$fer_pfx%($format)$sfx" \
$refs "${refs[@]}"
if [ -n "$track" ]; then if [ -n "$track" ]; then
# employ the heuristic used by git checkout # employ the heuristic used by git checkout
# Try to find a remote branch that matches the completion word # Try to find a remote branch that matches the completion word
# but only output if the branch name is unique # but only output if the branch name is unique
local ref entry __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
git --git-dir="$dir" for-each-ref --shell --format="ref=%(refname:short)" \ --sort="refname:strip=3" \
"refs/remotes/" | \ "refs/remotes/*/$match*" "refs/remotes/*/$match*/**" | \
while read -r entry; do uniq -u
eval "$entry"
ref="${ref#*/}"
if [[ "$ref" == "$cur"* ]]; then
echo "$ref"
fi
done | sort | uniq -u
fi fi
return return
fi fi
case "$cur" in case "$cur_" in
refs|refs/*) refs|refs/*)
git ls-remote "$dir" "$cur*" 2>/dev/null | \ __git ls-remote "$remote" "$match*" | \
while read -r hash i; do while read -r hash i; do
case "$i" in case "$i" in
*^{}) ;; *^{}) ;;
*) echo "$i" ;; *) echo "$pfx$i$sfx" ;;
esac esac
done done
;; ;;
*) *)
echo "HEAD" if [ "$list_refs_from" = remote ]; then
git for-each-ref --format="%(refname:short)" -- \ case "HEAD" in
"refs/remotes/$dir/" 2>/dev/null | sed -e "s#^$dir/##" $match*) echo "${pfx}HEAD$sfx" ;;
esac
__git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
"refs/remotes/$remote/$match*" \
"refs/remotes/$remote/$match*/**"
else
local query_symref
case "HEAD" in
$match*) query_symref="HEAD" ;;
esac
__git ls-remote "$remote" $query_symref \
"refs/tags/$match*" "refs/heads/$match*" \
"refs/remotes/$match*" |
while read -r hash i; do
case "$i" in
*^{}) ;;
refs/*) echo "$pfx${i#refs/*/}$sfx" ;;
*) echo "$pfx$i$sfx" ;; # symbolic refs
esac
done
fi
;; ;;
esac esac
} }
# Completes refs, short and long, local and remote, symbolic and pseudo.
#
# Usage: __git_complete_refs [<option>]...
# --remote=<remote>: The remote to list refs from, can be the name of a
# configured remote, a path, or a URL.
# --track: List unique remote branches for 'git checkout's tracking DWIMery.
# --pfx=<prefix>: A prefix to be added to each ref.
# --cur=<word>: The current ref to be completed. Defaults to the current
# word to be completed.
# --sfx=<suffix>: A suffix to be appended to each ref instead of the default
# space.
__git_complete_refs ()
{
local remote track pfx cur_="$cur" sfx=" "
while test $# != 0; do
case "$1" in
--remote=*) remote="${1##--remote=}" ;;
--track) track="yes" ;;
--pfx=*) pfx="${1##--pfx=}" ;;
--cur=*) cur_="${1##--cur=}" ;;
--sfx=*) sfx="${1##--sfx=}" ;;
*) return 1 ;;
esac
shift
done
__gitcomp_direct "$(__git_refs "$remote" "$track" "$pfx" "$cur_" "$sfx")"
}
# __git_refs2 requires 1 argument (to pass to __git_refs) # __git_refs2 requires 1 argument (to pass to __git_refs)
# Deprecated: use __git_complete_fetch_refspecs() instead.
__git_refs2 () __git_refs2 ()
{ {
local i local i
...@@ -400,11 +546,29 @@ __git_refs2 () ...@@ -400,11 +546,29 @@ __git_refs2 ()
done done
} }
# Completes refspecs for fetching from a remote repository.
# 1: The remote repository.
# 2: A prefix to be added to each listed refspec (optional).
# 3: The ref to be completed as a refspec instead of the current word to be
# completed (optional)
# 4: A suffix to be appended to each listed refspec instead of the default
# space (optional).
__git_complete_fetch_refspecs ()
{
local i remote="$1" pfx="${2-}" cur_="${3-$cur}" sfx="${4- }"
__gitcomp_direct "$(
for i in $(__git_refs "$remote" "" "" "$cur_") ; do
echo "$pfx$i:$i$sfx"
done
)"
}
# __git_refs_remotes requires 1 argument (to pass to ls-remote) # __git_refs_remotes requires 1 argument (to pass to ls-remote)
__git_refs_remotes () __git_refs_remotes ()
{ {
local i hash local i hash
git ls-remote "$1" 'refs/heads/*' 2>/dev/null | \ __git ls-remote "$1" 'refs/heads/*' | \
while read -r hash i; do while read -r hash i; do
echo "$i:refs/remotes/$1/${i#refs/heads/}" echo "$i:refs/remotes/$1/${i#refs/heads/}"
done done
...@@ -412,9 +576,21 @@ __git_refs_remotes () ...@@ -412,9 +576,21 @@ __git_refs_remotes ()
__git_remotes () __git_remotes ()
{ {
local d="$(__gitdir)" __git_find_repo_path
test -d "$d/remotes" && ls -1 "$d/remotes" test -d "$__git_repo_path/remotes" && ls -1 "$__git_repo_path/remotes"
git --git-dir="$d" remote __git remote
}
# Returns true if $1 matches the name of a configured remote, false otherwise.
__git_is_configured_remote ()
{
local remote
for remote in $(__git_remotes); do
if [ "$remote" = "$1" ]; then
return 0
fi
done
return 1
} }
__git_list_merge_strategies () __git_list_merge_strategies ()
...@@ -468,7 +644,7 @@ __git_complete_revlist_file () ...@@ -468,7 +644,7 @@ __git_complete_revlist_file ()
*) pfx="$ref:$pfx" ;; *) pfx="$ref:$pfx" ;;
esac esac
__gitcomp_nl "$(git --git-dir="$(__gitdir)" ls-tree "$ls" 2>/dev/null \ __gitcomp_nl "$(__git ls-tree "$ls" \
| sed '/^100... blob /{ | sed '/^100... blob /{
s,^.* ,, s,^.* ,,
s,$, , s,$, ,
...@@ -487,15 +663,15 @@ __git_complete_revlist_file () ...@@ -487,15 +663,15 @@ __git_complete_revlist_file ()
*...*) *...*)
pfx="${cur_%...*}..." pfx="${cur_%...*}..."
cur_="${cur_#*...}" cur_="${cur_#*...}"
__gitcomp_nl "$(__git_refs)" "$pfx" "$cur_" __git_complete_refs --pfx="$pfx" --cur="$cur_"
;; ;;
*..*) *..*)
pfx="${cur_%..*}.." pfx="${cur_%..*}.."
cur_="${cur_#*..}" cur_="${cur_#*..}"
__gitcomp_nl "$(__git_refs)" "$pfx" "$cur_" __git_complete_refs --pfx="$pfx" --cur="$cur_"
;; ;;
*) *)
__gitcomp_nl "$(__git_refs)" __git_complete_refs
;; ;;
esac esac
} }
...@@ -541,6 +717,7 @@ __git_complete_remote_or_refspec () ...@@ -541,6 +717,7 @@ __git_complete_remote_or_refspec ()
i="${words[c]}" i="${words[c]}"
case "$i" in case "$i" in
--mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;; --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
-d|--delete) [ "$cmd" = "push" ] && lhs=0 ;;
--all) --all)
case "$cmd" in case "$cmd" in
push) no_complete_refspec=1 ;; push) no_complete_refspec=1 ;;
...@@ -580,23 +757,23 @@ __git_complete_remote_or_refspec () ...@@ -580,23 +757,23 @@ __git_complete_remote_or_refspec ()
case "$cmd" in case "$cmd" in
fetch) fetch)
if [ $lhs = 1 ]; then if [ $lhs = 1 ]; then
__gitcomp_nl "$(__git_refs2 "$remote")" "$pfx" "$cur_" __git_complete_fetch_refspecs "$remote" "$pfx" "$cur_"
else else
__gitcomp_nl "$(__git_refs)" "$pfx" "$cur_" __git_complete_refs --pfx="$pfx" --cur="$cur_"
fi fi
;; ;;
pull|remote) pull|remote)
if [ $lhs = 1 ]; then if [ $lhs = 1 ]; then
__gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_" __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
else else
__gitcomp_nl "$(__git_refs)" "$pfx" "$cur_" __git_complete_refs --pfx="$pfx" --cur="$cur_"
fi fi
;; ;;
push) push)
if [ $lhs = 1 ]; then if [ $lhs = 1 ]; then
__gitcomp_nl "$(__git_refs)" "$pfx" "$cur_" __git_complete_refs --pfx="$pfx" --cur="$cur_"
else else
__gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_" __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
fi fi
;; ;;
esac esac
...@@ -746,7 +923,7 @@ __git_compute_porcelain_commands () ...@@ -746,7 +923,7 @@ __git_compute_porcelain_commands ()
__git_get_config_variables () __git_get_config_variables ()
{ {
local section="$1" i IFS=$'\n' local section="$1" i IFS=$'\n'
for i in $(git --git-dir="$(__gitdir)" config --name-only --get-regexp "^$section\..*" 2>/dev/null); do for i in $(__git config --name-only --get-regexp "^$section\..*"); do
echo "${i#$section.}" echo "${i#$section.}"
done done
} }
...@@ -764,8 +941,7 @@ __git_aliases () ...@@ -764,8 +941,7 @@ __git_aliases ()
# __git_aliased_command requires 1 argument # __git_aliased_command requires 1 argument
__git_aliased_command () __git_aliased_command ()
{ {
local word cmdline=$(git --git-dir="$(__gitdir)" \ local word cmdline=$(__git config --get "alias.$1")
config --get "alias.$1")
for word in $cmdline; do for word in $cmdline; do
case "$word" in case "$word" in
\!gitk|gitk) \!gitk|gitk)
...@@ -803,6 +979,50 @@ __git_find_on_cmdline () ...@@ -803,6 +979,50 @@ __git_find_on_cmdline ()
done done
} }
# Echo the value of an option set on the command line or config
#
# $1: short option name
# $2: long option name including =
# $3: list of possible values
# $4: config string (optional)
#
# example:
# result="$(__git_get_option_value "-d" "--do-something=" \
# "yes no" "core.doSomething")"
#
# result is then either empty (no option set) or "yes" or "no"
#
# __git_get_option_value requires 3 arguments
__git_get_option_value ()
{
local c short_opt long_opt val
local result= values config_key word
short_opt="$1"
long_opt="$2"
values="$3"
config_key="$4"
((c = $cword - 1))
while [ $c -ge 0 ]; do
word="${words[c]}"
for val in $values; do
if [ "$short_opt$val" = "$word" ] ||
[ "$long_opt$val" = "$word" ]; then
result="$val"
break 2
fi
done
((c--))
done
if [ -n "$config_key" ] && [ -z "$result" ]; then
result="$(__git config "$config_key")"
fi
echo "$result"
}
__git_has_doubledash () __git_has_doubledash ()
{ {
local c=1 local c=1
...@@ -856,8 +1076,8 @@ __git_whitespacelist="nowarn warn error error-all fix" ...@@ -856,8 +1076,8 @@ __git_whitespacelist="nowarn warn error error-all fix"
_git_am () _git_am ()
{ {
local dir="$(__gitdir)" __git_find_repo_path
if [ -d "$dir"/rebase-apply ]; then if [ -d "$__git_repo_path"/rebase-apply ]; then
__gitcomp "--skip --continue --resolved --abort" __gitcomp "--skip --continue --resolved --abort"
return return
fi fi
...@@ -891,6 +1111,7 @@ _git_apply () ...@@ -891,6 +1111,7 @@ _git_apply ()
--apply --no-add --exclude= --apply --no-add --exclude=
--ignore-whitespace --ignore-space-change --ignore-whitespace --ignore-space-change
--whitespace= --inaccurate-eof --verbose --whitespace= --inaccurate-eof --verbose
--recount --directory=
" "
return return
esac esac
...@@ -902,13 +1123,17 @@ _git_add () ...@@ -902,13 +1123,17 @@ _git_add ()
--*) --*)
__gitcomp " __gitcomp "
--interactive --refresh --patch --update --dry-run --interactive --refresh --patch --update --dry-run
--ignore-errors --intent-to-add --ignore-errors --intent-to-add --force --edit --chmod=
" "
return return
esac esac
# XXX should we check for --update and --all options ? local complete_opt="--others --modified --directory --no-empty-directory"
__git_complete_index_file "--others --modified --directory --no-empty-directory" if test -n "$(__git_find_on_cmdline "-u --update")"
then
complete_opt="--modified"
fi
__git_complete_index_file "$complete_opt"
} }
_git_archive () _git_archive ()
...@@ -925,7 +1150,7 @@ _git_archive () ...@@ -925,7 +1150,7 @@ _git_archive ()
--*) --*)
__gitcomp " __gitcomp "
--format= --list --verbose --format= --list --verbose
--prefix= --remote= --exec= --prefix= --remote= --exec= --output
" "
return return
;; ;;
...@@ -940,7 +1165,8 @@ _git_bisect () ...@@ -940,7 +1165,8 @@ _git_bisect ()
local subcommands="start bad good skip reset visualize replay log run" local subcommands="start bad good skip reset visualize replay log run"
local subcommand="$(__git_find_on_cmdline "$subcommands")" local subcommand="$(__git_find_on_cmdline "$subcommands")"
if [ -z "$subcommand" ]; then if [ -z "$subcommand" ]; then
if [ -f "$(__gitdir)"/BISECT_START ]; then __git_find_repo_path
if [ -f "$__git_repo_path"/BISECT_START ]; then
__gitcomp "$subcommands" __gitcomp "$subcommands"
else else
__gitcomp "replay start" __gitcomp "replay start"
...@@ -950,7 +1176,7 @@ _git_bisect () ...@@ -950,7 +1176,7 @@ _git_bisect ()
case "$subcommand" in case "$subcommand" in
bad|good|reset|skip|start) bad|good|reset|skip|start)
__gitcomp_nl "$(__git_refs)" __git_complete_refs
;; ;;
*) *)
;; ;;
...@@ -964,29 +1190,30 @@ _git_branch () ...@@ -964,29 +1190,30 @@ _git_branch ()
while [ $c -lt $cword ]; do while [ $c -lt $cword ]; do
i="${words[c]}" i="${words[c]}"
case "$i" in case "$i" in
-d|-m) only_local_ref="y" ;; -d|--delete|-m|--move) only_local_ref="y" ;;
-r) has_r="y" ;; -r|--remotes) has_r="y" ;;
esac esac
((c++)) ((c++))
done done
case "$cur" in case "$cur" in
--set-upstream-to=*) --set-upstream-to=*)
__gitcomp_nl "$(__git_refs)" "" "${cur##--set-upstream-to=}" __git_complete_refs --cur="${cur##--set-upstream-to=}"
;; ;;
--*) --*)
__gitcomp " __gitcomp "
--color --no-color --verbose --abbrev= --no-abbrev --color --no-color --verbose --abbrev= --no-abbrev
--track --no-track --contains --merged --no-merged --track --no-track --contains --no-contains --merged --no-merged
--set-upstream-to= --edit-description --list --set-upstream-to= --edit-description --list
--unset-upstream --unset-upstream --delete --move --remotes
--column --no-column --sort= --points-at
" "
;; ;;
*) *)
if [ $only_local_ref = "y" -a $has_r = "n" ]; then if [ $only_local_ref = "y" -a $has_r = "n" ]; then
__gitcomp_nl "$(__git_heads)" __gitcomp_direct "$(__git_heads "" "$cur" " ")"
else else
__gitcomp_nl "$(__git_refs)" __git_complete_refs
fi fi
;; ;;
esac esac
...@@ -1029,24 +1256,25 @@ _git_checkout () ...@@ -1029,24 +1256,25 @@ _git_checkout ()
*) *)
# check if --track, --no-track, or --no-guess was specified # check if --track, --no-track, or --no-guess was specified
# if so, disable DWIM mode # if so, disable DWIM mode
local flags="--track --no-track --no-guess" track=1 local flags="--track --no-track --no-guess" track_opt="--track"
if [ -n "$(__git_find_on_cmdline "$flags")" ]; then if [ "$GIT_COMPLETION_CHECKOUT_NO_GUESS" = "1" ] ||
track='' [ -n "$(__git_find_on_cmdline "$flags")" ]; then
track_opt=''
fi fi
__gitcomp_nl "$(__git_refs '' $track)" __git_complete_refs $track_opt
;; ;;
esac esac
} }
_git_cherry () _git_cherry ()
{ {
__gitcomp_nl "$(__git_refs)" __git_complete_refs
} }
_git_cherry_pick () _git_cherry_pick ()
{ {
local dir="$(__gitdir)" __git_find_repo_path
if [ -f "$dir"/CHERRY_PICK_HEAD ]; then if [ -f "$__git_repo_path"/CHERRY_PICK_HEAD ]; then
__gitcomp "--continue --quit --abort" __gitcomp "--continue --quit --abort"
return return
fi fi
...@@ -1055,7 +1283,7 @@ _git_cherry_pick () ...@@ -1055,7 +1283,7 @@ _git_cherry_pick ()
__gitcomp "--edit --no-commit --signoff --strategy= --mainline" __gitcomp "--edit --no-commit --signoff --strategy= --mainline"
;; ;;
*) *)
__gitcomp_nl "$(__git_refs)" __git_complete_refs
;; ;;
esac esac
} }
...@@ -1091,18 +1319,24 @@ _git_clone () ...@@ -1091,18 +1319,24 @@ _git_clone ()
--template= --template=
--depth --depth
--single-branch --single-branch
--no-tags
--branch --branch
--recurse-submodules
--no-single-branch
--shallow-submodules
" "
return return
;; ;;
esac esac
} }
__git_untracked_file_modes="all no normal"
_git_commit () _git_commit ()
{ {
case "$prev" in case "$prev" in
-c|-C) -c|-C)
__gitcomp_nl "$(__git_refs)" "" "${cur}" __git_complete_refs
return return
;; ;;
esac esac
...@@ -1115,11 +1349,11 @@ _git_commit () ...@@ -1115,11 +1349,11 @@ _git_commit ()
;; ;;
--reuse-message=*|--reedit-message=*|\ --reuse-message=*|--reedit-message=*|\
--fixup=*|--squash=*) --fixup=*|--squash=*)
__gitcomp_nl "$(__git_refs)" "" "${cur#*=}" __git_complete_refs --cur="${cur#*=}"
return return
;; ;;
--untracked-files=*) --untracked-files=*)
__gitcomp "all no normal" "" "${cur##--untracked-files=}" __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
return return
;; ;;
--*) --*)
...@@ -1131,11 +1365,12 @@ _git_commit () ...@@ -1131,11 +1365,12 @@ _git_commit ()
--reset-author --file= --message= --template= --reset-author --file= --message= --template=
--cleanup= --untracked-files --untracked-files= --cleanup= --untracked-files --untracked-files=
--verbose --quiet --fixup= --squash= --verbose --quiet --fixup= --squash=
--patch --short --date --allow-empty
" "
return return
esac esac
if git rev-parse --verify --quiet HEAD >/dev/null; then if __git rev-parse --verify --quiet HEAD >/dev/null; then
__git_complete_index_file "--committable" __git_complete_index_file "--committable"
else else
# This is the first commit # This is the first commit
...@@ -1149,15 +1384,18 @@ _git_describe () ...@@ -1149,15 +1384,18 @@ _git_describe ()
--*) --*)
__gitcomp " __gitcomp "
--all --tags --contains --abbrev= --candidates= --all --tags --contains --abbrev= --candidates=
--exact-match --debug --long --match --always --exact-match --debug --long --match --always --first-parent
--exclude
" "
return return
esac esac
__gitcomp_nl "$(__git_refs)" __git_complete_refs
} }
__git_diff_algorithms="myers minimal patience histogram" __git_diff_algorithms="myers minimal patience histogram"
__git_diff_submodule_formats="diff log short"
__git_diff_common_options="--stat --numstat --shortstat --summary __git_diff_common_options="--stat --numstat --shortstat --summary
--patch-with-stat --name-only --name-status --color --patch-with-stat --name-only --name-status --color
--no-color --color-words --no-renames --check --no-color --color-words --no-renames --check
...@@ -1173,6 +1411,7 @@ __git_diff_common_options="--stat --numstat --shortstat --summary ...@@ -1173,6 +1411,7 @@ __git_diff_common_options="--stat --numstat --shortstat --summary
--dirstat --dirstat= --dirstat-by-file --dirstat --dirstat= --dirstat-by-file
--dirstat-by-file= --cumulative --dirstat-by-file= --cumulative
--diff-algorithm= --diff-algorithm=
--submodule --submodule=
" "
_git_diff () _git_diff ()
...@@ -1184,6 +1423,10 @@ _git_diff () ...@@ -1184,6 +1423,10 @@ _git_diff ()
__gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}" __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
return return
;; ;;
--submodule=*)
__gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
return
;;
--*) --*)
__gitcomp "--cached --staged --pickaxe-all --pickaxe-regex __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
--base --ours --theirs --no-index --base --ours --theirs --no-index
...@@ -1225,6 +1468,7 @@ __git_fetch_recurse_submodules="yes on-demand no" ...@@ -1225,6 +1468,7 @@ __git_fetch_recurse_submodules="yes on-demand no"
__git_fetch_options=" __git_fetch_options="
--quiet --verbose --append --upload-pack --force --keep --depth= --quiet --verbose --append --upload-pack --force --keep --depth=
--tags --no-tags --all --prune --dry-run --recurse-submodules= --tags --no-tags --all --prune --dry-run --recurse-submodules=
--unshallow --update-shallow
" "
_git_fetch () _git_fetch ()
...@@ -1274,7 +1518,7 @@ _git_fsck () ...@@ -1274,7 +1518,7 @@ _git_fsck ()
--*) --*)
__gitcomp " __gitcomp "
--tags --root --unreachable --cache --no-reflogs --full --tags --root --unreachable --cache --no-reflogs --full
--strict --verbose --lost-found --strict --verbose --lost-found --name-objects
" "
return return
;; ;;
...@@ -1296,8 +1540,43 @@ _git_gitk () ...@@ -1296,8 +1540,43 @@ _git_gitk ()
_gitk _gitk
} }
__git_match_ctag() { # Lists matching symbol names from a tag (as in ctags) file.
awk "/^${1//\//\\/}/ { print \$1 }" "$2" # 1: List symbol names matching this word.
# 2: The tag file to list symbol names from.
# 3: A prefix to be added to each listed symbol name (optional).
# 4: A suffix to be appended to each listed symbol name (optional).
__git_match_ctag () {
awk -v pfx="${3-}" -v sfx="${4-}" "
/^${1//\//\\/}/ { print pfx \$1 sfx }
" "$2"
}
# Complete symbol names from a tag file.
# Usage: __git_complete_symbol [<option>]...
# --tags=<file>: The tag file to list symbol names from instead of the
# default "tags".
# --pfx=<prefix>: A prefix to be added to each symbol name.
# --cur=<word>: The current symbol name to be completed. Defaults to
# the current word to be completed.
# --sfx=<suffix>: A suffix to be appended to each symbol name instead
# of the default space.
__git_complete_symbol () {
local tags=tags pfx="" cur_="${cur-}" sfx=" "
while test $# != 0; do
case "$1" in
--tags=*) tags="${1##--tags=}" ;;
--pfx=*) pfx="${1##--pfx=}" ;;
--cur=*) cur_="${1##--cur=}" ;;
--sfx=*) sfx="${1##--sfx=}" ;;
*) return 1 ;;
esac
shift
done
if test -r "$tags"; then
__gitcomp_direct "$(__git_match_ctag "$cur_" "$tags" "$pfx" "$sfx")"
fi
} }
_git_grep () _git_grep ()
...@@ -1318,6 +1597,8 @@ _git_grep () ...@@ -1318,6 +1597,8 @@ _git_grep ()
--max-depth --max-depth
--count --count
--and --or --not --all-match --and --or --not --all-match
--break --heading --show-function --function-context
--untracked --no-index
" "
return return
;; ;;
...@@ -1325,29 +1606,26 @@ _git_grep () ...@@ -1325,29 +1606,26 @@ _git_grep ()
case "$cword,$prev" in case "$cword,$prev" in
2,*|*,-*) 2,*|*,-*)
if test -r tags; then __git_complete_symbol && return
__gitcomp_nl "$(__git_match_ctag "$cur" tags)"
return
fi
;; ;;
esac esac
__gitcomp_nl "$(__git_refs)" __git_complete_refs
} }
_git_help () _git_help ()
{ {
case "$cur" in case "$cur" in
--*) --*)
__gitcomp "--all --info --man --web" __gitcomp "--all --guides --info --man --web"
return return
;; ;;
esac esac
__git_compute_all_commands __git_compute_all_commands
__gitcomp "$__git_all_commands $(__git_aliases) __gitcomp "$__git_all_commands $(__git_aliases)
attributes cli core-tutorial cvs-migration attributes cli core-tutorial cvs-migration
diffcore gitk glossary hooks ignore modules diffcore everyday gitk glossary hooks ignore modules
namespaces repository-layout tutorial tutorial-2 namespaces repository-layout revisions tutorial tutorial-2
workflows workflows
" "
} }
...@@ -1390,6 +1668,12 @@ _git_ls_files () ...@@ -1390,6 +1668,12 @@ _git_ls_files ()
_git_ls_remote () _git_ls_remote ()
{ {
case "$cur" in
--*)
__gitcomp "--heads --tags --refs --get-url --symref"
return
;;
esac
__gitcomp_nl "$(__git_remotes)" __gitcomp_nl "$(__git_remotes)"
} }
...@@ -1427,12 +1711,25 @@ __git_log_date_formats="relative iso8601 rfc2822 short local default raw" ...@@ -1427,12 +1711,25 @@ __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
_git_log () _git_log ()
{ {
__git_has_doubledash && return __git_has_doubledash && return
__git_find_repo_path
local g="$(git rev-parse --git-dir 2>/dev/null)"
local merge="" local merge=""
if [ -f "$g/MERGE_HEAD" ]; then if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
merge="--merge" merge="--merge"
fi fi
case "$prev,$cur" in
-L,:*:*)
return # fall back to Bash filename completion
;;
-L,:*)
__git_complete_symbol --cur="${cur#:}" --sfx=":"
return
;;
-G,*|-S,*)
__git_complete_symbol
return
;;
esac
case "$cur" in case "$cur" in
--pretty=*|--format=*) --pretty=*|--format=*)
__gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases) __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
...@@ -1447,6 +1744,14 @@ _git_log () ...@@ -1447,6 +1744,14 @@ _git_log ()
__gitcomp "full short no" "" "${cur##--decorate=}" __gitcomp "full short no" "" "${cur##--decorate=}"
return return
;; ;;
--diff-algorithm=*)
__gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
return
;;
--submodule=*)
__gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
return
;;
--*) --*)
__gitcomp " __gitcomp "
$__git_log_common_options $__git_log_common_options
...@@ -1458,6 +1763,7 @@ _git_log () ...@@ -1458,6 +1763,7 @@ _git_log ()
--relative-date --date= --relative-date --date=
--pretty= --format= --oneline --pretty= --format= --oneline
--show-signature --show-signature
--cherry-mark
--cherry-pick --cherry-pick
--graph --graph
--decorate --decorate= --decorate --decorate=
...@@ -1469,6 +1775,21 @@ _git_log () ...@@ -1469,6 +1775,21 @@ _git_log ()
" "
return return
;; ;;
-L:*:*)
return # fall back to Bash filename completion
;;
-L:*)
__git_complete_symbol --cur="${cur#-L:}" --sfx=":"
return
;;
-G*)
__git_complete_symbol --pfx="-G" --cur="${cur#-G}"
return
;;
-S*)
__git_complete_symbol --pfx="-S" --cur="${cur#-S}"
return
;;
esac esac
__git_complete_revlist __git_complete_revlist
} }
...@@ -1488,10 +1809,10 @@ _git_merge () ...@@ -1488,10 +1809,10 @@ _git_merge ()
case "$cur" in case "$cur" in
--*) --*)
__gitcomp "$__git_merge_options __gitcomp "$__git_merge_options
--rerere-autoupdate --no-rerere-autoupdate --abort" --rerere-autoupdate --no-rerere-autoupdate --abort --continue"
return return
esac esac
__gitcomp_nl "$(__git_refs)" __git_complete_refs
} }
_git_mergetool () _git_mergetool ()
...@@ -1502,7 +1823,7 @@ _git_mergetool () ...@@ -1502,7 +1823,7 @@ _git_mergetool ()
return return
;; ;;
--*) --*)
__gitcomp "--tool=" __gitcomp "--tool= --prompt --no-prompt"
return return
;; ;;
esac esac
...@@ -1516,7 +1837,7 @@ _git_merge_base () ...@@ -1516,7 +1837,7 @@ _git_merge_base ()
return return
;; ;;
esac esac
__gitcomp_nl "$(__git_refs)" __git_complete_refs
} }
_git_mv () _git_mv ()
...@@ -1554,7 +1875,7 @@ _git_notes () ...@@ -1554,7 +1875,7 @@ _git_notes ()
,*) ,*)
case "$prev" in case "$prev" in
--ref) --ref)
__gitcomp_nl "$(__git_refs)" __git_complete_refs
;; ;;
*) *)
__gitcomp "$subcommands --ref" __gitcomp "$subcommands --ref"
...@@ -1563,7 +1884,7 @@ _git_notes () ...@@ -1563,7 +1884,7 @@ _git_notes ()
;; ;;
add,--reuse-message=*|append,--reuse-message=*|\ add,--reuse-message=*|append,--reuse-message=*|\
add,--reedit-message=*|append,--reedit-message=*) add,--reedit-message=*|append,--reedit-message=*)
__gitcomp_nl "$(__git_refs)" "" "${cur#*=}" __git_complete_refs --cur="${cur#*=}"
;; ;;
add,--*|append,--*) add,--*|append,--*)
__gitcomp '--file= --message= --reedit-message= __gitcomp '--file= --message= --reedit-message=
...@@ -1582,7 +1903,7 @@ _git_notes () ...@@ -1582,7 +1903,7 @@ _git_notes ()
-m|-F) -m|-F)
;; ;;
*) *)
__gitcomp_nl "$(__git_refs)" __git_complete_refs
;; ;;
esac esac
;; ;;
...@@ -1610,7 +1931,7 @@ _git_pull () ...@@ -1610,7 +1931,7 @@ _git_pull ()
__git_complete_remote_or_refspec __git_complete_remote_or_refspec
} }
__git_push_recurse_submodules="check on-demand" __git_push_recurse_submodules="check on-demand only"
__git_complete_force_with_lease () __git_complete_force_with_lease ()
{ {
...@@ -1620,10 +1941,10 @@ __git_complete_force_with_lease () ...@@ -1620,10 +1941,10 @@ __git_complete_force_with_lease ()
--*=) --*=)
;; ;;
*:*) *:*)
__gitcomp_nl "$(__git_refs)" "" "${cur_#*:}" __git_complete_refs --cur="${cur_#*:}"
;; ;;
*) *)
__gitcomp_nl "$(__git_refs)" "" "$cur_" __git_complete_refs --cur="$cur_"
;; ;;
esac esac
} }
...@@ -1668,12 +1989,13 @@ _git_push () ...@@ -1668,12 +1989,13 @@ _git_push ()
_git_rebase () _git_rebase ()
{ {
local dir="$(__gitdir)" __git_find_repo_path
if [ -f "$dir"/rebase-merge/interactive ]; then if [ -f "$__git_repo_path"/rebase-merge/interactive ]; then
__gitcomp "--continue --skip --abort --edit-todo" __gitcomp "--continue --skip --abort --quit --edit-todo"
return return
elif [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then elif [ -d "$__git_repo_path"/rebase-apply ] || \
__gitcomp "--continue --skip --abort" [ -d "$__git_repo_path"/rebase-merge ]; then
__gitcomp "--continue --skip --abort --quit"
return return
fi fi
__git_complete_strategy && return __git_complete_strategy && return
...@@ -1698,7 +2020,7 @@ _git_rebase () ...@@ -1698,7 +2020,7 @@ _git_rebase ()
return return
esac esac
__gitcomp_nl "$(__git_refs)" __git_complete_refs
} }
_git_reflog () _git_reflog ()
...@@ -1709,7 +2031,7 @@ _git_reflog () ...@@ -1709,7 +2031,7 @@ _git_reflog ()
if [ -z "$subcommand" ]; then if [ -z "$subcommand" ]; then
__gitcomp "$subcommands" __gitcomp "$subcommands"
else else
__gitcomp_nl "$(__git_refs)" __git_complete_refs
fi fi
} }
...@@ -1720,9 +2042,7 @@ _git_send_email () ...@@ -1720,9 +2042,7 @@ _git_send_email ()
{ {
case "$prev" in case "$prev" in
--to|--cc|--bcc|--from) --to|--cc|--bcc|--from)
__gitcomp " __gitcomp "$(__git send-email --dump-aliases)"
$(git --git-dir="$(__gitdir)" send-email --dump-aliases 2>/dev/null)
"
return return
;; ;;
esac esac
...@@ -1752,9 +2072,7 @@ _git_send_email () ...@@ -1752,9 +2072,7 @@ _git_send_email ()
return return
;; ;;
--to=*|--cc=*|--bcc=*|--from=*) --to=*|--cc=*|--bcc=*|--from=*)
__gitcomp " __gitcomp "$(__git send-email --dump-aliases)" "" "${cur#--*=}"
$(git --git-dir="$(__gitdir)" send-email --dump-aliases 2>/dev/null)
" "" "${cur#--*=}"
return return
;; ;;
--*) --*)
...@@ -1779,6 +2097,56 @@ _git_stage () ...@@ -1779,6 +2097,56 @@ _git_stage ()
_git_add _git_add
} }
_git_status ()
{
local complete_opt
local untracked_state
case "$cur" in
--ignore-submodules=*)
__gitcomp "none untracked dirty all" "" "${cur##--ignore-submodules=}"
return
;;
--untracked-files=*)
__gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
return
;;
--column=*)
__gitcomp "
always never auto column row plain dense nodense
" "" "${cur##--column=}"
return
;;
--*)
__gitcomp "
--short --branch --porcelain --long --verbose
--untracked-files= --ignore-submodules= --ignored
--column= --no-column
"
return
;;
esac
untracked_state="$(__git_get_option_value "-u" "--untracked-files=" \
"$__git_untracked_file_modes" "status.showUntrackedFiles")"
case "$untracked_state" in
no)
# --ignored option does not matter
complete_opt=
;;
all|normal|*)
complete_opt="--cached --directory --no-empty-directory --others"
if [ -n "$(__git_find_on_cmdline "--ignored")" ]; then
complete_opt="$complete_opt --ignored --exclude=*"
fi
;;
esac
__git_complete_index_file "$complete_opt"
}
__git_config_get_set_variables () __git_config_get_set_variables ()
{ {
local prevword word config_file= c=$cword local prevword word config_file= c=$cword
...@@ -1798,7 +2166,7 @@ __git_config_get_set_variables () ...@@ -1798,7 +2166,7 @@ __git_config_get_set_variables ()
c=$((--c)) c=$((--c))
done done
git --git-dir="$(__gitdir)" config $config_file --name-only --list 2>/dev/null __git config $config_file --name-only --list
} }
_git_config () _git_config ()
...@@ -1809,7 +2177,7 @@ _git_config () ...@@ -1809,7 +2177,7 @@ _git_config ()
return return
;; ;;
branch.*.merge) branch.*.merge)
__gitcomp_nl "$(__git_refs)" __git_complete_refs
return return
;; ;;
branch.*.rebase) branch.*.rebase)
...@@ -1833,9 +2201,8 @@ _git_config () ...@@ -1833,9 +2201,8 @@ _git_config ()
remote.*.push) remote.*.push)
local remote="${prev#remote.}" local remote="${prev#remote.}"
remote="${remote%.push}" remote="${remote%.push}"
__gitcomp_nl "$(git --git-dir="$(__gitdir)" \ __gitcomp_nl "$(__git for-each-ref \
for-each-ref --format='%(refname):%(refname)' \ --format='%(refname):%(refname)' refs/heads)"
refs/heads)"
return return
;; ;;
pull.twohead|pull.octopus) pull.twohead|pull.octopus)
...@@ -1914,7 +2281,7 @@ _git_config () ...@@ -1914,7 +2281,7 @@ _git_config ()
;; ;;
branch.*) branch.*)
local pfx="${cur%.*}." cur_="${cur#*.}" local pfx="${cur%.*}." cur_="${cur#*.}"
__gitcomp_nl "$(__git_heads)" "$pfx" "$cur_" "." __gitcomp_direct "$(__git_heads "$pfx" "$cur_" ".")"
__gitcomp_nl_append $'autosetupmerge\nautosetuprebase\n' "$pfx" "$cur_" __gitcomp_nl_append $'autosetupmerge\nautosetuprebase\n' "$pfx" "$cur_"
return return
;; ;;
...@@ -1969,14 +2336,23 @@ _git_config () ...@@ -1969,14 +2336,23 @@ _git_config ()
esac esac
__gitcomp " __gitcomp "
add.ignoreErrors add.ignoreErrors
advice.amWorkDir
advice.commitBeforeMerge advice.commitBeforeMerge
advice.detachedHead advice.detachedHead
advice.implicitIdentity advice.implicitIdentity
advice.pushNonFastForward advice.pushAlreadyExists
advice.pushFetchFirst
advice.pushNeedsForce
advice.pushNonFFCurrent
advice.pushNonFFMatching
advice.pushUpdateRejected
advice.resolveConflict advice.resolveConflict
advice.rmHints
advice.statusHints advice.statusHints
advice.statusUoption
alias. alias.
am.keepcr am.keepcr
am.threeWay
apply.ignorewhitespace apply.ignorewhitespace
apply.whitespace apply.whitespace
branch.autosetupmerge branch.autosetupmerge
...@@ -2021,19 +2397,26 @@ _git_config () ...@@ -2021,19 +2397,26 @@ _git_config ()
color.status.added color.status.added
color.status.changed color.status.changed
color.status.header color.status.header
color.status.localBranch
color.status.nobranch color.status.nobranch
color.status.remoteBranch
color.status.unmerged color.status.unmerged
color.status.untracked color.status.untracked
color.status.updated color.status.updated
color.ui color.ui
commit.cleanup
commit.gpgSign
commit.status commit.status
commit.template commit.template
commit.verbose
core.abbrev core.abbrev
core.askpass core.askpass
core.attributesfile core.attributesfile
core.autocrlf core.autocrlf
core.bare core.bare
core.bigFileThreshold core.bigFileThreshold
core.checkStat
core.commentChar
core.compression core.compression
core.createObject core.createObject
core.deltaBaseCacheLimit core.deltaBaseCacheLimit
...@@ -2043,6 +2426,8 @@ _git_config () ...@@ -2043,6 +2426,8 @@ _git_config ()
core.fileMode core.fileMode
core.fsyncobjectfiles core.fsyncobjectfiles
core.gitProxy core.gitProxy
core.hideDotFiles
core.hooksPath
core.ignoreStat core.ignoreStat
core.ignorecase core.ignorecase
core.logAllRefUpdates core.logAllRefUpdates
...@@ -2050,20 +2435,30 @@ _git_config () ...@@ -2050,20 +2435,30 @@ _git_config ()
core.notesRef core.notesRef
core.packedGitLimit core.packedGitLimit
core.packedGitWindowSize core.packedGitWindowSize
core.packedRefsTimeout
core.pager core.pager
core.precomposeUnicode
core.preferSymlinkRefs core.preferSymlinkRefs
core.preloadindex core.preloadindex
core.protectHFS
core.protectNTFS
core.quotepath core.quotepath
core.repositoryFormatVersion core.repositoryFormatVersion
core.safecrlf core.safecrlf
core.sharedRepository core.sharedRepository
core.sparseCheckout core.sparseCheckout
core.splitIndex
core.sshCommand
core.symlinks core.symlinks
core.trustctime core.trustctime
core.untrackedCache core.untrackedCache
core.warnAmbiguousRefs core.warnAmbiguousRefs
core.whitespace core.whitespace
core.worktree core.worktree
credential.helper
credential.useHttpPath
credential.username
credentialCache.ignoreSIGHUP
diff.autorefreshindex diff.autorefreshindex
diff.external diff.external
diff.ignoreSubmodules diff.ignoreSubmodules
...@@ -2084,6 +2479,7 @@ _git_config () ...@@ -2084,6 +2479,7 @@ _git_config ()
format.attach format.attach
format.cc format.cc
format.coverLetter format.coverLetter
format.from
format.headers format.headers
format.numbered format.numbered
format.pretty format.pretty
...@@ -2094,15 +2490,19 @@ _git_config () ...@@ -2094,15 +2490,19 @@ _git_config ()
format.thread format.thread
format.to format.to
gc. gc.
gc.aggressiveDepth
gc.aggressiveWindow gc.aggressiveWindow
gc.auto gc.auto
gc.autoDetach
gc.autopacklimit gc.autopacklimit
gc.logExpiry
gc.packrefs gc.packrefs
gc.pruneexpire gc.pruneexpire
gc.reflogexpire gc.reflogexpire
gc.reflogexpireunreachable gc.reflogexpireunreachable
gc.rerereresolved gc.rerereresolved
gc.rerereunresolved gc.rerereunresolved
gc.worktreePruneExpire
gitcvs.allbinary gitcvs.allbinary
gitcvs.commitmsgannotation gitcvs.commitmsgannotation
gitcvs.dbTableNamePrefix gitcvs.dbTableNamePrefix
...@@ -2241,6 +2641,8 @@ _git_config () ...@@ -2241,6 +2641,8 @@ _git_config ()
sendemail.thread sendemail.thread
sendemail.to sendemail.to
sendemail.validate sendemail.validate
sendemail.smtpbatchsize
sendemail.smtprelogindelay
showbranch.default showbranch.default
status.relativePaths status.relativePaths
status.showUntrackedFiles status.showUntrackedFiles
...@@ -2259,31 +2661,79 @@ _git_config () ...@@ -2259,31 +2661,79 @@ _git_config ()
_git_remote () _git_remote ()
{ {
local subcommands="add rename remove set-head set-branches set-url show prune update" local subcommands="
add rename remove set-head set-branches
get-url set-url show prune update
"
local subcommand="$(__git_find_on_cmdline "$subcommands")" local subcommand="$(__git_find_on_cmdline "$subcommands")"
if [ -z "$subcommand" ]; then if [ -z "$subcommand" ]; then
case "$cur" in
--*)
__gitcomp "--verbose"
;;
*)
__gitcomp "$subcommands" __gitcomp "$subcommands"
;;
esac
return return
fi fi
case "$subcommand" in case "$subcommand,$cur" in
rename|remove|set-url|show|prune) add,--*)
__gitcomp_nl "$(__git_remotes)" __gitcomp "--track --master --fetch --tags --no-tags --mirror="
;;
add,*)
;;
set-head,--*)
__gitcomp "--auto --delete"
;; ;;
set-head|set-branches) set-branches,--*)
__gitcomp "--add"
;;
set-head,*|set-branches,*)
__git_complete_remote_or_refspec __git_complete_remote_or_refspec
;; ;;
update) update,--*)
__gitcomp "--prune"
;;
update,*)
__gitcomp "$(__git_get_config_variables "remotes")" __gitcomp "$(__git_get_config_variables "remotes")"
;; ;;
set-url,--*)
__gitcomp "--push --add --delete"
;;
get-url,--*)
__gitcomp "--push --all"
;;
prune,--*)
__gitcomp "--dry-run"
;;
*) *)
__gitcomp_nl "$(__git_remotes)"
;; ;;
esac esac
} }
_git_replace () _git_replace ()
{ {
__gitcomp_nl "$(__git_refs)" case "$cur" in
--*)
__gitcomp "--edit --graft --format= --list --delete"
return
;;
esac
__git_complete_refs
}
_git_rerere ()
{
local subcommands="clear forget diff remaining status gc"
local subcommand="$(__git_find_on_cmdline "$subcommands")"
if test -z "$subcommand"
then
__gitcomp "$subcommands"
return
fi
} }
_git_reset () _git_reset ()
...@@ -2292,27 +2742,30 @@ _git_reset () ...@@ -2292,27 +2742,30 @@ _git_reset ()
case "$cur" in case "$cur" in
--*) --*)
__gitcomp "--merge --mixed --hard --soft --patch" __gitcomp "--merge --mixed --hard --soft --patch --keep"
return return
;; ;;
esac esac
__gitcomp_nl "$(__git_refs)" __git_complete_refs
} }
_git_revert () _git_revert ()
{ {
local dir="$(__gitdir)" __git_find_repo_path
if [ -f "$dir"/REVERT_HEAD ]; then if [ -f "$__git_repo_path"/REVERT_HEAD ]; then
__gitcomp "--continue --quit --abort" __gitcomp "--continue --quit --abort"
return return
fi fi
case "$cur" in case "$cur" in
--*) --*)
__gitcomp "--edit --mainline --no-edit --no-commit --signoff" __gitcomp "
--edit --mainline --no-edit --no-commit --signoff
--strategy= --strategy-option=
"
return return
;; ;;
esac esac
__gitcomp_nl "$(__git_refs)" __git_complete_refs
} }
_git_rm () _git_rm ()
...@@ -2336,7 +2789,7 @@ _git_shortlog () ...@@ -2336,7 +2789,7 @@ _git_shortlog ()
__gitcomp " __gitcomp "
$__git_log_common_options $__git_log_common_options
$__git_log_shortlog_options $__git_log_shortlog_options
--numbered --summary --numbered --summary --email
" "
return return
;; ;;
...@@ -2358,6 +2811,10 @@ _git_show () ...@@ -2358,6 +2811,10 @@ _git_show ()
__gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}" __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
return return
;; ;;
--submodule=*)
__gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
return
;;
--*) --*)
__gitcomp "--pretty= --format= --abbrev-commit --oneline __gitcomp "--pretty= --format= --abbrev-commit --oneline
--show-signature --show-signature
...@@ -2388,7 +2845,7 @@ _git_show_branch () ...@@ -2388,7 +2845,7 @@ _git_show_branch ()
_git_stash () _git_stash ()
{ {
local save_opts='--all --keep-index --no-keep-index --quiet --patch --include-untracked' local save_opts='--all --keep-index --no-keep-index --quiet --patch --include-untracked'
local subcommands='save list show apply clear drop pop create branch' local subcommands='push save list show apply clear drop pop create branch'
local subcommand="$(__git_find_on_cmdline "$subcommands")" local subcommand="$(__git_find_on_cmdline "$subcommands")"
if [ -z "$subcommand" ]; then if [ -z "$subcommand" ]; then
case "$cur" in case "$cur" in
...@@ -2403,6 +2860,9 @@ _git_stash () ...@@ -2403,6 +2860,9 @@ _git_stash ()
esac esac
else else
case "$subcommand,$cur" in case "$subcommand,$cur" in
push,--*)
__gitcomp "$save_opts --message"
;;
save,--*) save,--*)
__gitcomp "$save_opts" __gitcomp "$save_opts"
;; ;;
...@@ -2416,14 +2876,14 @@ _git_stash () ...@@ -2416,14 +2876,14 @@ _git_stash ()
;; ;;
branch,*) branch,*)
if [ $cword -eq 3 ]; then if [ $cword -eq 3 ]; then
__gitcomp_nl "$(__git_refs)"; __git_complete_refs
else else
__gitcomp_nl "$(git --git-dir="$(__gitdir)" stash list \ __gitcomp_nl "$(__git stash list \
| sed -n -e 's/:.*//p')" | sed -n -e 's/:.*//p')"
fi fi
;; ;;
show,*|apply,*|drop,*|pop,*) show,*|apply,*|drop,*|pop,*)
__gitcomp_nl "$(git --git-dir="$(__gitdir)" stash list \ __gitcomp_nl "$(__git stash list \
| sed -n -e 's/:.*//p')" | sed -n -e 's/:.*//p')"
;; ;;
*) *)
...@@ -2437,10 +2897,11 @@ _git_submodule () ...@@ -2437,10 +2897,11 @@ _git_submodule ()
__git_has_doubledash && return __git_has_doubledash && return
local subcommands="add status init deinit update summary foreach sync" local subcommands="add status init deinit update summary foreach sync"
if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then local subcommand="$(__git_find_on_cmdline "$subcommands")"
if [ -z "$subcommand" ]; then
case "$cur" in case "$cur" in
--*) --*)
__gitcomp "--quiet --cached" __gitcomp "--quiet"
;; ;;
*) *)
__gitcomp "$subcommands" __gitcomp "$subcommands"
...@@ -2448,6 +2909,33 @@ _git_submodule () ...@@ -2448,6 +2909,33 @@ _git_submodule ()
esac esac
return return
fi fi
case "$subcommand,$cur" in
add,--*)
__gitcomp "--branch --force --name --reference --depth"
;;
status,--*)
__gitcomp "--cached --recursive"
;;
deinit,--*)
__gitcomp "--force --all"
;;
update,--*)
__gitcomp "
--init --remote --no-fetch
--recommend-shallow --no-recommend-shallow
--force --rebase --merge --reference --depth --recursive --jobs
"
;;
summary,--*)
__gitcomp "--cached --files --summary-limit"
;;
foreach,--*|sync,--*)
__gitcomp "--recursive"
;;
*)
;;
esac
} }
_git_svn () _git_svn ()
...@@ -2468,14 +2956,14 @@ _git_svn () ...@@ -2468,14 +2956,14 @@ _git_svn ()
--no-metadata --use-svm-props --use-svnsync-props --no-metadata --use-svm-props --use-svnsync-props
--log-window-size= --no-checkout --quiet --log-window-size= --no-checkout --quiet
--repack-flags --use-log-author --localtime --repack-flags --use-log-author --localtime
--add-author-from
--ignore-paths= --include-paths= $remote_opts --ignore-paths= --include-paths= $remote_opts
" "
local init_opts=" local init_opts="
--template= --shared= --trunk= --tags= --template= --shared= --trunk= --tags=
--branches= --stdlayout --minimize-url --branches= --stdlayout --minimize-url
--no-metadata --use-svm-props --use-svnsync-props --no-metadata --use-svm-props --use-svnsync-props
--rewrite-root= --prefix= --use-log-author --rewrite-root= --prefix= $remote_opts
--add-author-from $remote_opts
" "
local cmt_opts=" local cmt_opts="
--edit --rmdir --find-copies-harder --copy-similarity= --edit --rmdir --find-copies-harder --copy-similarity=
...@@ -2555,7 +3043,7 @@ _git_tag () ...@@ -2555,7 +3043,7 @@ _git_tag ()
i="${words[c]}" i="${words[c]}"
case "$i" in case "$i" in
-d|-v) -d|-v)
__gitcomp_nl "$(__git_tags)" __gitcomp_direct "$(__git_tags "" "$cur" " ")"
return return
;; ;;
-f) -f)
...@@ -2570,11 +3058,11 @@ _git_tag () ...@@ -2570,11 +3058,11 @@ _git_tag ()
;; ;;
-*|tag) -*|tag)
if [ $f = 1 ]; then if [ $f = 1 ]; then
__gitcomp_nl "$(__git_tags)" __gitcomp_direct "$(__git_tags "" "$cur" " ")"
fi fi
;; ;;
*) *)
__gitcomp_nl "$(__git_refs)" __git_complete_refs
;; ;;
esac esac
...@@ -2582,8 +3070,8 @@ _git_tag () ...@@ -2582,8 +3070,8 @@ _git_tag ()
--*) --*)
__gitcomp " __gitcomp "
--list --delete --verify --annotate --message --file --list --delete --verify --annotate --message --file
--sign --cleanup --local-user --force --column --sort --sign --cleanup --local-user --force --column --sort=
--contains --points-at --contains --no-contains --points-at --merged --no-merged --create-reflog
" "
;; ;;
esac esac
...@@ -2594,9 +3082,36 @@ _git_whatchanged () ...@@ -2594,9 +3082,36 @@ _git_whatchanged ()
_git_log _git_log
} }
_git_worktree ()
{
local subcommands="add list lock prune unlock"
local subcommand="$(__git_find_on_cmdline "$subcommands")"
if [ -z "$subcommand" ]; then
__gitcomp "$subcommands"
else
case "$subcommand,$cur" in
add,--*)
__gitcomp "--detach"
;;
list,--*)
__gitcomp "--porcelain"
;;
lock,--*)
__gitcomp "--reason"
;;
prune,--*)
__gitcomp "--dry-run --expire --verbose"
;;
*)
;;
esac
fi
}
__git_main () __git_main ()
{ {
local i c=1 command __git_dir local i c=1 command __git_dir __git_repo_path
local __git_C_args C_args_count=0
while [ $c -lt $cword ]; do while [ $c -lt $cword ]; do
i="${words[c]}" i="${words[c]}"
...@@ -2606,6 +3121,10 @@ __git_main () ...@@ -2606,6 +3121,10 @@ __git_main ()
--bare) __git_dir="." ;; --bare) __git_dir="." ;;
--help) command="help"; break ;; --help) command="help"; break ;;
-c|--work-tree|--namespace) ((c++)) ;; -c|--work-tree|--namespace) ((c++)) ;;
-C) __git_C_args[C_args_count++]=-C
((c++))
__git_C_args[C_args_count++]="${words[c]}"
;;
-*) ;; -*) ;;
*) command="$i"; break ;; *) command="$i"; break ;;
esac esac
...@@ -2613,6 +3132,17 @@ __git_main () ...@@ -2613,6 +3132,17 @@ __git_main ()
done done
if [ -z "$command" ]; then if [ -z "$command" ]; then
case "$prev" in
--git-dir|-C|--work-tree)
# these need a path argument, let's fall back to
# Bash filename completion
return
;;
-c|--namespace)
# we don't support completing these options' arguments
return
;;
esac
case "$cur" in case "$cur" in
--*) __gitcomp " --*) __gitcomp "
--paginate --paginate
...@@ -2638,13 +3168,13 @@ __git_main () ...@@ -2638,13 +3168,13 @@ __git_main ()
fi fi
local completion_func="_git_${command//-/_}" local completion_func="_git_${command//-/_}"
declare -f $completion_func >/dev/null && $completion_func && return declare -f $completion_func >/dev/null 2>/dev/null && $completion_func && return
local expansion=$(__git_aliased_command "$command") local expansion=$(__git_aliased_command "$command")
if [ -n "$expansion" ]; then if [ -n "$expansion" ]; then
words[1]=$expansion words[1]=$expansion
completion_func="_git_${expansion//-/_}" completion_func="_git_${expansion//-/_}"
declare -f $completion_func >/dev/null && $completion_func declare -f $completion_func >/dev/null 2>/dev/null && $completion_func
fi fi
} }
...@@ -2652,9 +3182,11 @@ __gitk_main () ...@@ -2652,9 +3182,11 @@ __gitk_main ()
{ {
__git_has_doubledash && return __git_has_doubledash && return
local g="$(__gitdir)" local __git_repo_path
__git_find_repo_path
local merge="" local merge=""
if [ -f "$g/MERGE_HEAD" ]; then if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
merge="--merge" merge="--merge"
fi fi
case "$cur" in case "$cur" in
...@@ -2701,6 +3233,15 @@ if [[ -n ${ZSH_VERSION-} ]]; then ...@@ -2701,6 +3233,15 @@ if [[ -n ${ZSH_VERSION-} ]]; then
esac esac
} }
__gitcomp_direct ()
{
emulate -L zsh
local IFS=$'\n'
compset -P '*[=:]'
compadd -Q -- ${=1} && _ret=0
}
__gitcomp_nl () __gitcomp_nl ()
{ {
emulate -L zsh emulate -L zsh
...@@ -2771,6 +3312,6 @@ __git_complete gitk __gitk_main ...@@ -2771,6 +3312,6 @@ __git_complete gitk __gitk_main
# when the user has tab-completed the executable name and consequently # when the user has tab-completed the executable name and consequently
# included the '.exe' suffix. # included the '.exe' suffix.
# #
if [[ "$OSTYPE" = cygwin* ]]; then if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
__git_complete git.exe __git_main __git_complete git.exe __git_main
fi fi
...@@ -82,6 +82,7 @@ ...@@ -82,6 +82,7 @@
# contains relative to newer annotated tag (v1.6.3.2~35) # contains relative to newer annotated tag (v1.6.3.2~35)
# branch relative to newer tag or branch (master~4) # branch relative to newer tag or branch (master~4)
# describe relative to older annotated tag (v1.6.3.1-13-gdd42c2f) # describe relative to older annotated tag (v1.6.3.1-13-gdd42c2f)
# tag relative to any older tag (v1.6.3.1-13-gdd42c2f)
# default exactly matching tag # default exactly matching tag
# #
# If you would like a colored hint about the current dirty state, set # If you would like a colored hint about the current dirty state, set
...@@ -355,8 +356,8 @@ __git_ps1 () ...@@ -355,8 +356,8 @@ __git_ps1 ()
# incorrect.) # incorrect.)
# #
local ps1_expanded=yes local ps1_expanded=yes
[ -z "$ZSH_VERSION" ] || [[ -o PROMPT_SUBST ]] || ps1_expanded=no [ -z "${ZSH_VERSION-}" ] || [[ -o PROMPT_SUBST ]] || ps1_expanded=no
[ -z "$BASH_VERSION" ] || shopt -q promptvars || ps1_expanded=no [ -z "${BASH_VERSION-}" ] || shopt -q promptvars || ps1_expanded=no
local repo_info rev_parse_exit_code local repo_info rev_parse_exit_code
repo_info="$(git rev-parse --git-dir --is-inside-git-dir \ repo_info="$(git rev-parse --git-dir --is-inside-git-dir \
...@@ -368,7 +369,7 @@ __git_ps1 () ...@@ -368,7 +369,7 @@ __git_ps1 ()
return $exit return $exit
fi fi
local short_sha local short_sha=""
if [ "$rev_parse_exit_code" = "0" ]; then if [ "$rev_parse_exit_code" = "0" ]; then
short_sha="${repo_info##*$'\n'}" short_sha="${repo_info##*$'\n'}"
repo_info="${repo_info%$'\n'*}" repo_info="${repo_info%$'\n'*}"
...@@ -443,6 +444,8 @@ __git_ps1 () ...@@ -443,6 +444,8 @@ __git_ps1 ()
git describe --contains HEAD ;; git describe --contains HEAD ;;
(branch) (branch)
git describe --contains --all HEAD ;; git describe --contains --all HEAD ;;
(tag)
git describe --tags HEAD ;;
(describe) (describe)
git describe HEAD ;; git describe HEAD ;;
(* | default) (* | default)
......
dir=$(dirname $0) dir="${0:A:h}"
source $dir/../git/git.plugin.zsh source "$dir/git-prompt.sh"
source $dir/git-prompt.sh
function git_prompt_info() { function git_prompt_info() {
dirty="$(parse_git_dirty)" dirty="$(parse_git_dirty)"
__git_ps1 "${ZSH_THEME_GIT_PROMPT_PREFIX//\%/%%}%s${dirty//\%/%%}${ZSH_THEME_GIT_PROMPT_SUFFIX//\%/%%}" __git_ps1 "${ZSH_THEME_GIT_PROMPT_PREFIX//\%/%%}%s${dirty//\%/%%}${ZSH_THEME_GIT_PROMPT_SUFFIX//\%/%%}"
} }
unset dir
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment