1
0
Fork 0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-11-25 15:20:08 +00:00

Merge pull request #5104 from felipec/fc/gitfast

gitfast: update to the latest upstream Git and a couple of fixes
This commit is contained in:
Marc Cornellà 2016-05-21 17:12:04 +02:00
commit 970f11d1c4
3 changed files with 277 additions and 106 deletions

View file

@ -104,6 +104,7 @@ __git_zsh_bash_func ()
local expansion=$(__git_aliased_command "$command") local expansion=$(__git_aliased_command "$command")
if [ -n "$expansion" ]; then if [ -n "$expansion" ]; then
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 && $completion_func
fi fi
@ -213,8 +214,10 @@ _git ()
if (( $+functions[__${service}_zsh_main] )); then if (( $+functions[__${service}_zsh_main] )); then
__${service}_zsh_main __${service}_zsh_main
else elif (( $+functions[__${service}_main] )); then
emulate ksh -c __${service}_main emulate ksh -c __${service}_main
elif (( $+functions[_${service}] )); then
emulate ksh -c _${service}
fi fi
let _ret && _default && _ret=0 let _ret && _default && _ret=0

View file

@ -10,17 +10,24 @@
# *) local and remote tag names # *) local and remote tag names
# *) .git/remotes file names # *) .git/remotes file names
# *) git 'subcommands' # *) git 'subcommands'
# *) git email aliases for git-send-email
# *) tree paths within 'ref:path/to/file' expressions # *) tree paths within 'ref:path/to/file' expressions
# *) file paths within current working directory and index # *) file paths within current working directory and index
# *) common --long-options # *) common --long-options
# #
# To use these routines: # To use these routines:
# #
# 1) Copy this file to somewhere (e.g. ~/.git-completion.sh). # 1) Copy this file to somewhere (e.g. ~/.git-completion.bash).
# 2) Add the following line to your .bashrc/.zshrc: # 2) Add the following line to your .bashrc/.zshrc:
# source ~/.git-completion.sh # source ~/.git-completion.bash
# 3) Consider changing your PS1 to also show the current branch, # 3) Consider changing your PS1 to also show the current branch,
# see git-prompt.sh for details. # see git-prompt.sh for details.
#
# If you use complex aliases of form '!f() { ... }; f', you can use the null
# command ':' as the first command in the function body to declare the desired
# completion style. For example '!f() { : git commit ; ... }; f' will
# tell the completion to use commit completion. This also works with aliases
# of form "!sh -c '...'". For example, "!sh -c ': git commit ; ... '".
case "$COMP_WORDBREAKS" in case "$COMP_WORDBREAKS" in
*:*) : great ;; *:*) : great ;;
@ -180,7 +187,7 @@ fi
__gitcompappend () __gitcompappend ()
{ {
local i=${#COMPREPLY[@]} local x i=${#COMPREPLY[@]}
for x in $1; do for x in $1; do
if [[ "$x" == "$3"* ]]; then if [[ "$x" == "$3"* ]]; then
COMPREPLY[i++]="$2$x$4" COMPREPLY[i++]="$2$x$4"
@ -275,16 +282,12 @@ __gitcomp_file ()
# argument, and using the options specified in the second argument. # argument, and using the options specified in the second argument.
__git_ls_files_helper () __git_ls_files_helper ()
{ {
( if [ "$2" == "--committable" ]; then
test -n "${CDPATH+set}" && unset CDPATH git -C "$1" diff-index --name-only --relative HEAD
cd "$1" else
if [ "$2" == "--committable" ]; then # NOTE: $2 is not quoted in order to support multiple options
git diff-index --name-only --relative HEAD git -C "$1" ls-files --exclude-standard $2
else fi 2>/dev/null
# NOTE: $2 is not quoted in order to support multiple options
git ls-files --exclude-standard $2
fi
) 2>/dev/null
} }
@ -382,7 +385,8 @@ __git_refs ()
;; ;;
*) *)
echo "HEAD" echo "HEAD"
git for-each-ref --format="%(refname:short)" -- "refs/remotes/$dir/" | sed -e "s#^$dir/##" git for-each-ref --format="%(refname:short)" -- \
"refs/remotes/$dir/" 2>/dev/null | sed -e "s#^$dir/##"
;; ;;
esac esac
} }
@ -408,12 +412,9 @@ __git_refs_remotes ()
__git_remotes () __git_remotes ()
{ {
local i IFS=$'\n' d="$(__gitdir)" local d="$(__gitdir)"
test -d "$d/remotes" && ls -1 "$d/remotes" test -d "$d/remotes" && ls -1 "$d/remotes"
for i in $(git --git-dir="$d" config --get-regexp 'remote\..*\.url' 2>/dev/null); do git --git-dir="$d" remote
i="${i#remote.}"
echo "${i/.url*/}"
done
} }
__git_list_merge_strategies () __git_list_merge_strategies ()
@ -516,7 +517,7 @@ __git_complete_index_file ()
;; ;;
esac esac
__gitcomp_file "$(__git_index_files "$1" "$pfx")" "$pfx" "$cur_" __gitcomp_file "$(__git_index_files "$1" ${pfx:+"$pfx"})" "$pfx" "$cur_"
} }
__git_complete_file () __git_complete_file ()
@ -663,10 +664,11 @@ __git_list_porcelain_commands ()
check-mailmap) : plumbing;; check-mailmap) : plumbing;;
check-ref-format) : plumbing;; check-ref-format) : plumbing;;
checkout-index) : plumbing;; checkout-index) : plumbing;;
column) : internal helper;;
commit-tree) : plumbing;; commit-tree) : plumbing;;
count-objects) : infrequent;; count-objects) : infrequent;;
credential-cache) : credentials helper;; credential) : credentials;;
credential-store) : credentials helper;; credential-*) : credentials helper;;
cvsexportcommit) : export;; cvsexportcommit) : export;;
cvsimport) : import;; cvsimport) : import;;
cvsserver) : daemon;; cvsserver) : daemon;;
@ -735,35 +737,28 @@ __git_list_porcelain_commands ()
__git_porcelain_commands= __git_porcelain_commands=
__git_compute_porcelain_commands () __git_compute_porcelain_commands ()
{ {
__git_compute_all_commands
test -n "$__git_porcelain_commands" || test -n "$__git_porcelain_commands" ||
__git_porcelain_commands=$(__git_list_porcelain_commands) __git_porcelain_commands=$(__git_list_porcelain_commands)
} }
# Lists all set config variables starting with the given section prefix,
# with the prefix removed.
__git_get_config_variables ()
{
local section="$1" i IFS=$'\n'
for i in $(git --git-dir="$(__gitdir)" config --name-only --get-regexp "^$section\..*" 2>/dev/null); do
echo "${i#$section.}"
done
}
__git_pretty_aliases () __git_pretty_aliases ()
{ {
local i IFS=$'\n' __git_get_config_variables "pretty"
for i in $(git --git-dir="$(__gitdir)" config --get-regexp "pretty\..*" 2>/dev/null); do
case "$i" in
pretty.*)
i="${i#pretty.}"
echo "${i/ */}"
;;
esac
done
} }
__git_aliases () __git_aliases ()
{ {
local i IFS=$'\n' __git_get_config_variables "alias"
for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do
case "$i" in
alias.*)
i="${i#alias.}"
echo "${i/ */}"
;;
esac
done
} }
# __git_aliased_command requires 1 argument # __git_aliased_command requires 1 argument
@ -781,6 +776,10 @@ __git_aliased_command ()
-*) : option ;; -*) : option ;;
*=*) : setting env ;; *=*) : setting env ;;
git) : git itself ;; git) : git itself ;;
\(\)) : skip parens of shell function definition ;;
{) : skip start of shell helper function ;;
:) : skip null command ;;
\'*) : skip opening quote after sh -c ;;
*) *)
echo "$word" echo "$word"
return return
@ -973,7 +972,7 @@ _git_branch ()
case "$cur" in case "$cur" in
--set-upstream-to=*) --set-upstream-to=*)
__gitcomp "$(__git_refs)" "" "${cur##--set-upstream-to=}" __gitcomp_nl "$(__git_refs)" "" "${cur##--set-upstream-to=}"
;; ;;
--*) --*)
__gitcomp " __gitcomp "
@ -1041,7 +1040,7 @@ _git_checkout ()
_git_cherry () _git_cherry ()
{ {
__gitcomp "$(__git_refs)" __gitcomp_nl "$(__git_refs)"
} }
_git_cherry_pick () _git_cherry_pick ()
@ -1110,7 +1109,7 @@ _git_commit ()
case "$cur" in case "$cur" in
--cleanup=*) --cleanup=*)
__gitcomp "default strip verbatim whitespace __gitcomp "default scissors strip verbatim whitespace
" "" "${cur##--cleanup=}" " "" "${cur##--cleanup=}"
return return
;; ;;
@ -1165,12 +1164,12 @@ __git_diff_common_options="--stat --numstat --shortstat --summary
--full-index --binary --abbrev --diff-filter= --full-index --binary --abbrev --diff-filter=
--find-copies-harder --find-copies-harder
--text --ignore-space-at-eol --ignore-space-change --text --ignore-space-at-eol --ignore-space-change
--ignore-all-space --exit-code --quiet --ext-diff --ignore-all-space --ignore-blank-lines --exit-code
--no-ext-diff --quiet --ext-diff --no-ext-diff
--no-prefix --src-prefix= --dst-prefix= --no-prefix --src-prefix= --dst-prefix=
--inter-hunk-context= --inter-hunk-context=
--patience --histogram --minimal --patience --histogram --minimal
--raw --word-diff --raw --word-diff --word-diff-regex=
--dirstat --dirstat= --dirstat-by-file --dirstat --dirstat= --dirstat-by-file
--dirstat-by-file= --cumulative --dirstat-by-file= --cumulative
--diff-algorithm= --diff-algorithm=
@ -1197,7 +1196,7 @@ _git_diff ()
} }
__git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff __git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff
tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc3 codecompare tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc codecompare
" "
_git_difftool () _git_difftool ()
@ -1221,14 +1220,20 @@ _git_difftool ()
__git_complete_revlist_file __git_complete_revlist_file
} }
__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 --tags --no-tags --all --prune --dry-run --recurse-submodules=
" "
_git_fetch () _git_fetch ()
{ {
case "$cur" in case "$cur" in
--recurse-submodules=*)
__gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
return
;;
--*) --*)
__gitcomp "$__git_fetch_options" __gitcomp "$__git_fetch_options"
return return
@ -1292,7 +1297,7 @@ _git_gitk ()
} }
__git_match_ctag() { __git_match_ctag() {
awk "/^${1////\\/}/ { print \$1 }" "$2" awk "/^${1//\//\\/}/ { print \$1 }" "$2"
} }
_git_grep () _git_grep ()
@ -1307,6 +1312,7 @@ _git_grep ()
--full-name --line-number --full-name --line-number
--extended-regexp --basic-regexp --fixed-strings --extended-regexp --basic-regexp --fixed-strings
--perl-regexp --perl-regexp
--threads
--files-with-matches --name-only --files-with-matches --name-only
--files-without-match --files-without-match
--max-depth --max-depth
@ -1412,7 +1418,7 @@ __git_log_gitk_options="
# Options that go well for log and shortlog (not gitk) # Options that go well for log and shortlog (not gitk)
__git_log_shortlog_options=" __git_log_shortlog_options="
--author= --committer= --grep= --author= --committer= --grep=
--all-match --all-match --invert-grep
" "
__git_log_pretty_formats="oneline short medium full fuller email raw format:" __git_log_pretty_formats="oneline short medium full fuller email raw format:"
@ -1438,7 +1444,7 @@ _git_log ()
return return
;; ;;
--decorate=*) --decorate=*)
__gitcomp "long short" "" "${cur##--decorate=}" __gitcomp "full short no" "" "${cur##--decorate=}"
return return
;; ;;
--*) --*)
@ -1451,6 +1457,7 @@ _git_log ()
--abbrev-commit --abbrev= --abbrev-commit --abbrev=
--relative-date --date= --relative-date --date=
--pretty= --format= --oneline --pretty= --format= --oneline
--show-signature
--cherry-pick --cherry-pick
--graph --graph
--decorate --decorate= --decorate --decorate=
@ -1466,9 +1473,12 @@ _git_log ()
__git_complete_revlist __git_complete_revlist
} }
# Common merge options shared by git-merge(1) and git-pull(1).
__git_merge_options=" __git_merge_options="
--no-commit --no-stat --log --no-log --squash --strategy --no-commit --no-stat --log --no-log --squash --strategy
--commit --stat --no-squash --ff --no-ff --ff-only --edit --no-edit --commit --stat --no-squash --ff --no-ff --ff-only --edit --no-edit
--verify-signatures --no-verify-signatures --gpg-sign
--quiet --verbose --progress --no-progress
" "
_git_merge () _git_merge ()
@ -1477,7 +1487,8 @@ _git_merge ()
case "$cur" in case "$cur" in
--*) --*)
__gitcomp "$__git_merge_options" __gitcomp "$__git_merge_options
--rerere-autoupdate --no-rerere-autoupdate --abort"
return return
esac esac
__gitcomp_nl "$(__git_refs)" __gitcomp_nl "$(__git_refs)"
@ -1583,6 +1594,10 @@ _git_pull ()
__git_complete_strategy && return __git_complete_strategy && return
case "$cur" in case "$cur" in
--recurse-submodules=*)
__gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
return
;;
--*) --*)
__gitcomp " __gitcomp "
--rebase --no-rebase --rebase --no-rebase
@ -1595,22 +1610,55 @@ _git_pull ()
__git_complete_remote_or_refspec __git_complete_remote_or_refspec
} }
__git_push_recurse_submodules="check on-demand"
__git_complete_force_with_lease ()
{
local cur_=$1
case "$cur_" in
--*=)
;;
*:*)
__gitcomp_nl "$(__git_refs)" "" "${cur_#*:}"
;;
*)
__gitcomp_nl "$(__git_refs)" "" "$cur_"
;;
esac
}
_git_push () _git_push ()
{ {
case "$prev" in case "$prev" in
--repo) --repo)
__gitcomp_nl "$(__git_remotes)" __gitcomp_nl "$(__git_remotes)"
return return
;;
--recurse-submodules)
__gitcomp "$__git_push_recurse_submodules"
return
;;
esac esac
case "$cur" in case "$cur" in
--repo=*) --repo=*)
__gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}" __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
return return
;; ;;
--recurse-submodules=*)
__gitcomp "$__git_push_recurse_submodules" "" "${cur##--recurse-submodules=}"
return
;;
--force-with-lease=*)
__git_complete_force_with_lease "${cur##--force-with-lease=}"
return
;;
--*) --*)
__gitcomp " __gitcomp "
--all --mirror --tags --dry-run --force --verbose --all --mirror --tags --dry-run --force --verbose
--quiet --prune --delete --follow-tags
--receive-pack= --repo= --set-upstream --receive-pack= --repo= --set-upstream
--force-with-lease --force-with-lease= --recurse-submodules=
" "
return return
;; ;;
@ -1621,7 +1669,10 @@ _git_push ()
_git_rebase () _git_rebase ()
{ {
local dir="$(__gitdir)" local dir="$(__gitdir)"
if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then if [ -f "$dir"/rebase-merge/interactive ]; then
__gitcomp "--continue --skip --abort --edit-todo"
return
elif [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
__gitcomp "--continue --skip --abort" __gitcomp "--continue --skip --abort"
return return
fi fi
@ -1637,7 +1688,12 @@ _git_rebase ()
--preserve-merges --stat --no-stat --preserve-merges --stat --no-stat
--committer-date-is-author-date --ignore-date --committer-date-is-author-date --ignore-date
--ignore-whitespace --whitespace= --ignore-whitespace --whitespace=
--autosquash --fork-point --no-fork-point --autosquash --no-autosquash
--fork-point --no-fork-point
--autostash --no-autostash
--verify --no-verify
--keep-empty --root --force-rebase --no-ff
--exec
" "
return return
@ -1662,6 +1718,15 @@ __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
_git_send_email () _git_send_email ()
{ {
case "$prev" in
--to|--cc|--bcc|--from)
__gitcomp "
$(git --git-dir="$(__gitdir)" send-email --dump-aliases 2>/dev/null)
"
return
;;
esac
case "$cur" in case "$cur" in
--confirm=*) --confirm=*)
__gitcomp " __gitcomp "
@ -1686,6 +1751,12 @@ _git_send_email ()
" "" "${cur##--thread=}" " "" "${cur##--thread=}"
return return
;; ;;
--to=*|--cc=*|--bcc=*|--from=*)
__gitcomp "
$(git --git-dir="$(__gitdir)" send-email --dump-aliases 2>/dev/null)
" "" "${cur#--*=}"
return
;;
--*) --*)
__gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
--compose --confirm= --dry-run --envelope-sender --compose --confirm= --dry-run --envelope-sender
@ -1727,15 +1798,7 @@ __git_config_get_set_variables ()
c=$((--c)) c=$((--c))
done done
git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null | git --git-dir="$(__gitdir)" config $config_file --name-only --list 2>/dev/null
while read -r line
do
case "$line" in
*.*=*)
echo "${line/=*/}"
;;
esac
done
} }
_git_config () _git_config ()
@ -1750,7 +1813,7 @@ _git_config ()
return return
;; ;;
branch.*.rebase) branch.*.rebase)
__gitcomp "false true" __gitcomp "false true preserve interactive"
return return
;; ;;
remote.pushdefault) remote.pushdefault)
@ -1820,6 +1883,10 @@ _git_config ()
__gitcomp "$__git_send_email_suppresscc_options" __gitcomp "$__git_send_email_suppresscc_options"
return return
;; ;;
sendemail.transferencoding)
__gitcomp "7bit 8bit quoted-printable base64"
return
;;
--get|--get-all|--unset|--unset-all) --get|--get-all|--unset|--unset-all)
__gitcomp_nl "$(__git_config_get_set_variables)" __gitcomp_nl "$(__git_config_get_set_variables)"
return return
@ -1836,6 +1903,7 @@ _git_config ()
--get --get-all --get-regexp --get --get-all --get-regexp
--add --unset --unset-all --add --unset --unset-all
--remove-section --rename-section --remove-section --rename-section
--name-only
" "
return return
;; ;;
@ -1954,6 +2022,7 @@ _git_config ()
color.status.changed color.status.changed
color.status.header color.status.header
color.status.nobranch color.status.nobranch
color.status.unmerged
color.status.untracked color.status.untracked
color.status.updated color.status.updated
color.ui color.ui
@ -1991,6 +2060,7 @@ _git_config ()
core.sparseCheckout core.sparseCheckout
core.symlinks core.symlinks
core.trustctime core.trustctime
core.untrackedCache
core.warnAmbiguousRefs core.warnAmbiguousRefs
core.whitespace core.whitespace
core.worktree core.worktree
@ -2065,6 +2135,8 @@ _git_config ()
http.noEPSV http.noEPSV
http.postBuffer http.postBuffer
http.proxy http.proxy
http.sslCipherList
http.sslVersion
http.sslCAInfo http.sslCAInfo
http.sslCAPath http.sslCAPath
http.sslCert http.sslCert
@ -2128,6 +2200,7 @@ _git_config ()
pull.octopus pull.octopus
pull.twohead pull.twohead
push.default push.default
push.followTags
rebase.autosquash rebase.autosquash
rebase.stat rebase.stat
receive.autogc receive.autogc
@ -2201,12 +2274,7 @@ _git_remote ()
__git_complete_remote_or_refspec __git_complete_remote_or_refspec
;; ;;
update) update)
local i c='' IFS=$'\n' __gitcomp "$(__git_get_config_variables "remotes")"
for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do
i="${i#remotes.}"
c="$c ${i/ */}"
done
__gitcomp "$c"
;; ;;
*) *)
;; ;;
@ -2233,6 +2301,11 @@ _git_reset ()
_git_revert () _git_revert ()
{ {
local dir="$(__gitdir)"
if [ -f "$dir"/REVERT_HEAD ]; then
__gitcomp "--continue --quit --abort"
return
fi
case "$cur" in case "$cur" in
--*) --*)
__gitcomp "--edit --mainline --no-edit --no-commit --signoff" __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
@ -2287,6 +2360,7 @@ _git_show ()
;; ;;
--*) --*)
__gitcomp "--pretty= --format= --abbrev-commit --oneline __gitcomp "--pretty= --format= --abbrev-commit --oneline
--show-signature
$__git_diff_common_options $__git_diff_common_options
" "
return return
@ -2300,7 +2374,7 @@ _git_show_branch ()
case "$cur" in case "$cur" in
--*) --*)
__gitcomp " __gitcomp "
--all --remotes --topo-order --current --more= --all --remotes --topo-order --date-order --current --more=
--list --independent --merge-base --no-name --list --independent --merge-base --no-name
--color --no-color --color --no-color
--sha1-name --sparse --topics --reflog --sha1-name --sparse --topics --reflog
@ -2313,7 +2387,7 @@ _git_show_branch ()
_git_stash () _git_stash ()
{ {
local save_opts='--keep-index --no-keep-index --quiet --patch' 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='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
@ -2335,9 +2409,20 @@ _git_stash ()
apply,--*|pop,--*) apply,--*|pop,--*)
__gitcomp "--index --quiet" __gitcomp "--index --quiet"
;; ;;
show,--*|drop,--*|branch,--*) drop,--*)
__gitcomp "--quiet"
;; ;;
show,*|apply,*|drop,*|pop,*|branch,*) show,--*|branch,--*)
;;
branch,*)
if [ $cword -eq 3 ]; then
__gitcomp_nl "$(__git_refs)";
else
__gitcomp_nl "$(git --git-dir="$(__gitdir)" stash list \
| sed -n -e 's/:.*//p')"
fi
;;
show,*|apply,*|drop,*|pop,*)
__gitcomp_nl "$(git --git-dir="$(__gitdir)" stash list \ __gitcomp_nl "$(git --git-dir="$(__gitdir)" stash list \
| sed -n -e 's/:.*//p')" | sed -n -e 's/:.*//p')"
;; ;;
@ -2492,6 +2577,16 @@ _git_tag ()
__gitcomp_nl "$(__git_refs)" __gitcomp_nl "$(__git_refs)"
;; ;;
esac esac
case "$cur" in
--*)
__gitcomp "
--list --delete --verify --annotate --message --file
--sign --cleanup --local-user --force --column --sort
--contains --points-at
"
;;
esac
} }
_git_whatchanged () _git_whatchanged ()
@ -2547,6 +2642,7 @@ __git_main ()
local expansion=$(__git_aliased_command "$command") local expansion=$(__git_aliased_command "$command")
if [ -n "$expansion" ]; then if [ -n "$expansion" ]; then
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 && $completion_func
fi fi

View file

@ -66,6 +66,10 @@
# git always compare HEAD to @{upstream} # git always compare HEAD to @{upstream}
# svn always compare HEAD to your SVN upstream # svn always compare HEAD to your SVN upstream
# #
# You can change the separator between the branch name and the above
# state symbols by setting GIT_PS1_STATESEPARATOR. The default separator
# is SP.
#
# By default, __git_ps1 will compare HEAD to your SVN upstream if it can # By default, __git_ps1 will compare HEAD to your SVN upstream if it can
# find one, or @{upstream} otherwise. Once you have set # find one, or @{upstream} otherwise. Once you have set
# GIT_PS1_SHOWUPSTREAM, you can override it on a per-repository basis by # GIT_PS1_SHOWUPSTREAM, you can override it on a per-repository basis by
@ -84,6 +88,11 @@
# GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on # GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on
# the colored output of "git status -sb" and are available only when # the colored output of "git status -sb" and are available only when
# using __git_ps1 for PROMPT_COMMAND or precmd. # using __git_ps1 for PROMPT_COMMAND or precmd.
#
# If you would like __git_ps1 to do nothing in the case when the current
# directory is set up to be ignored by git, then set
# GIT_PS1_HIDE_IF_PWD_IGNORED to a nonempty value. Override this on the
# repository level by setting bash.hideIfPwdIgnored to "false".
# check whether printf supports -v # check whether printf supports -v
__git_printf_supports_v= __git_printf_supports_v=
@ -207,7 +216,16 @@ __git_ps1_show_upstream ()
p=" u+${count#* }-${count% *}" ;; p=" u+${count#* }-${count% *}" ;;
esac esac
if [[ -n "$count" && -n "$name" ]]; then if [[ -n "$count" && -n "$name" ]]; then
p="$p $(git rev-parse --abbrev-ref "$upstream" 2>/dev/null)" __git_ps1_upstream_name=$(git rev-parse \
--abbrev-ref "$upstream" 2>/dev/null)
if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then
p="$p \${__git_ps1_upstream_name}"
else
p="$p ${__git_ps1_upstream_name}"
# not needed anymore; keep user's
# environment clean
unset __git_ps1_upstream_name
fi
fi fi
fi fi
@ -259,9 +277,9 @@ __git_ps1_colorize_gitstring ()
r="$c_clear$r" r="$c_clear$r"
} }
eread () __git_eread ()
{ {
f="$1" local f="$1"
shift shift
test -r "$f" && read "$@" <"$f" test -r "$f" && read "$@" <"$f"
} }
@ -279,6 +297,8 @@ eread ()
# In this mode you can request colored hints using GIT_PS1_SHOWCOLORHINTS=true # In this mode you can request colored hints using GIT_PS1_SHOWCOLORHINTS=true
__git_ps1 () __git_ps1 ()
{ {
# preserve exit status
local exit=$?
local pcmode=no local pcmode=no
local detached=no local detached=no
local ps1pc_start='\u@\h:\w ' local ps1pc_start='\u@\h:\w '
@ -290,13 +310,54 @@ __git_ps1 ()
ps1pc_start="$1" ps1pc_start="$1"
ps1pc_end="$2" ps1pc_end="$2"
printf_format="${3:-$printf_format}" printf_format="${3:-$printf_format}"
# set PS1 to a plain prompt so that we can
# simply return early if the prompt should not
# be decorated
PS1="$ps1pc_start$ps1pc_end"
;; ;;
0|1) printf_format="${1:-$printf_format}" 0|1) printf_format="${1:-$printf_format}"
;; ;;
*) return *) return $exit
;; ;;
esac esac
# ps1_expanded: This variable is set to 'yes' if the shell
# subjects the value of PS1 to parameter expansion:
#
# * bash does unless the promptvars option is disabled
# * zsh does not unless the PROMPT_SUBST option is set
# * POSIX shells always do
#
# If the shell would expand the contents of PS1 when drawing
# the prompt, a raw ref name must not be included in PS1.
# This protects the user from arbitrary code execution via
# specially crafted ref names. For example, a ref named
# 'refs/heads/$(IFS=_;cmd=sudo_rm_-rf_/;$cmd)' might cause the
# shell to execute 'sudo rm -rf /' when the prompt is drawn.
#
# Instead, the ref name should be placed in a separate global
# variable (in the __git_ps1_* namespace to avoid colliding
# with the user's environment) and that variable should be
# referenced from PS1. For example:
#
# __git_ps1_foo=$(do_something_to_get_ref_name)
# PS1="...stuff...\${__git_ps1_foo}...stuff..."
#
# If the shell does not expand the contents of PS1, the raw
# ref name must be included in PS1.
#
# The value of this variable is only relevant when in pcmode.
#
# Assume that the shell follows the POSIX specification and
# expands PS1 unless determined otherwise. (This is more
# likely to be correct if the user has a non-bash, non-zsh
# shell and safer than the alternative if the assumption is
# incorrect.)
#
local ps1_expanded=yes
[ -z "$ZSH_VERSION" ] || [[ -o PROMPT_SUBST ]] || 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 \
--is-bare-repository --is-inside-work-tree \ --is-bare-repository --is-inside-work-tree \
@ -304,11 +365,7 @@ __git_ps1 ()
rev_parse_exit_code="$?" rev_parse_exit_code="$?"
if [ -z "$repo_info" ]; then if [ -z "$repo_info" ]; then
if [ $pcmode = yes ]; then return $exit
#In PC mode PS1 always needs to be set
PS1="$ps1pc_start$ps1pc_end"
fi
return
fi fi
local short_sha local short_sha
@ -323,14 +380,22 @@ __git_ps1 ()
local inside_gitdir="${repo_info##*$'\n'}" local inside_gitdir="${repo_info##*$'\n'}"
local g="${repo_info%$'\n'*}" local g="${repo_info%$'\n'*}"
if [ "true" = "$inside_worktree" ] &&
[ -n "${GIT_PS1_HIDE_IF_PWD_IGNORED-}" ] &&
[ "$(git config --bool bash.hideIfPwdIgnored)" != "false" ] &&
git check-ignore -q .
then
return $exit
fi
local r="" local r=""
local b="" local b=""
local step="" local step=""
local total="" local total=""
if [ -d "$g/rebase-merge" ]; then if [ -d "$g/rebase-merge" ]; then
eread "$g/rebase-merge/head-name" b __git_eread "$g/rebase-merge/head-name" b
eread "$g/rebase-merge/msgnum" step __git_eread "$g/rebase-merge/msgnum" step
eread "$g/rebase-merge/end" total __git_eread "$g/rebase-merge/end" total
if [ -f "$g/rebase-merge/interactive" ]; then if [ -f "$g/rebase-merge/interactive" ]; then
r="|REBASE-i" r="|REBASE-i"
else else
@ -338,10 +403,10 @@ __git_ps1 ()
fi fi
else else
if [ -d "$g/rebase-apply" ]; then if [ -d "$g/rebase-apply" ]; then
eread "$g/rebase-apply/next" step __git_eread "$g/rebase-apply/next" step
eread "$g/rebase-apply/last" total __git_eread "$g/rebase-apply/last" total
if [ -f "$g/rebase-apply/rebasing" ]; then if [ -f "$g/rebase-apply/rebasing" ]; then
eread "$g/rebase-apply/head-name" b __git_eread "$g/rebase-apply/head-name" b
r="|REBASE" r="|REBASE"
elif [ -f "$g/rebase-apply/applying" ]; then elif [ -f "$g/rebase-apply/applying" ]; then
r="|AM" r="|AM"
@ -365,11 +430,8 @@ __git_ps1 ()
b="$(git symbolic-ref HEAD 2>/dev/null)" b="$(git symbolic-ref HEAD 2>/dev/null)"
else else
local head="" local head=""
if ! eread "$g/HEAD" head; then if ! __git_eread "$g/HEAD" head; then
if [ $pcmode = yes ]; then return $exit
PS1="$ps1pc_start$ps1pc_end"
fi
return
fi fi
# is it a symbolic ref? # is it a symbolic ref?
b="${head#ref: }" b="${head#ref: }"
@ -414,21 +476,21 @@ __git_ps1 ()
if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ] && if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ] &&
[ "$(git config --bool bash.showDirtyState)" != "false" ] [ "$(git config --bool bash.showDirtyState)" != "false" ]
then then
git diff --no-ext-diff --quiet --exit-code || w="*" git diff --no-ext-diff --quiet || w="*"
if [ -n "$short_sha" ]; then git diff --no-ext-diff --cached --quiet || i="+"
git diff-index --cached --quiet HEAD -- || i="+" if [ -z "$short_sha" ] && [ -z "$i" ]; then
else
i="#" i="#"
fi fi
fi fi
if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ] && if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ] &&
[ -r "$g/refs/stash" ]; then git rev-parse --verify --quiet refs/stash >/dev/null
then
s="$" s="$"
fi fi
if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ] && if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ] &&
[ "$(git config --bool bash.showUntrackedFiles)" != "false" ] && [ "$(git config --bool bash.showUntrackedFiles)" != "false" ] &&
git ls-files --others --exclude-standard --error-unmatch -- '*' >/dev/null 2>/dev/null git ls-files --others --exclude-standard --directory --no-empty-directory --error-unmatch -- ':/*' >/dev/null 2>/dev/null
then then
u="%${ZSH_VERSION+%}" u="%${ZSH_VERSION+%}"
fi fi
@ -440,13 +502,21 @@ __git_ps1 ()
local z="${GIT_PS1_STATESEPARATOR-" "}" local z="${GIT_PS1_STATESEPARATOR-" "}"
# NO color option unless in PROMPT_COMMAND mode # NO color option unless in PROMPT_COMMAND mode or it's Zsh
if [ $pcmode = yes ] && [ -n "${GIT_PS1_SHOWCOLORHINTS-}" ]; then if [ -n "${GIT_PS1_SHOWCOLORHINTS-}" ]; then
__git_ps1_colorize_gitstring if [ $pcmode = yes ] || [ -n "${ZSH_VERSION-}" ]; then
__git_ps1_colorize_gitstring
fi
fi
b=${b##refs/heads/}
if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then
__git_ps1_branch_name=$b
b="\${__git_ps1_branch_name}"
fi fi
local f="$w$i$s$u" local f="$w$i$s$u"
local gitstring="$c${b##refs/heads/}${f:+$z$f}$r$p" local gitstring="$c$b${f:+$z$f}$r$p"
if [ $pcmode = yes ]; then if [ $pcmode = yes ]; then
if [ "${__git_printf_supports_v-}" != yes ]; then if [ "${__git_printf_supports_v-}" != yes ]; then
@ -458,4 +528,6 @@ __git_ps1 ()
else else
printf -- "$printf_format" "$gitstring" printf -- "$printf_format" "$gitstring"
fi fi
return $exit
} }