Commit 970f11d1 authored by Marc Cornellà's avatar Marc Cornellà

Merge pull request #5104 from felipec/fc/gitfast

gitfast: update to the latest upstream Git and a couple of fixes
parents 841d2b92 36e29fbc
...@@ -104,6 +104,7 @@ __git_zsh_bash_func () ...@@ -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 () ...@@ -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
......
This diff is collapsed.
...@@ -66,6 +66,10 @@ ...@@ -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 @@ ...@@ -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 () ...@@ -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 () ...@@ -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 () ...@@ -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 () ...@@ -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 () ...@@ -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 () ...@@ -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 () ...@@ -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 () ...@@ -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 () ...@@ -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 () ...@@ -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
if [ $pcmode = yes ] || [ -n "${ZSH_VERSION-}" ]; then
__git_ps1_colorize_gitstring __git_ps1_colorize_gitstring
fi fi
fi
b=${b##refs/heads/}
if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then
__git_ps1_branch_name=$b
b="\${__git_ps1_branch_name}"
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 () ...@@ -458,4 +528,6 @@ __git_ps1 ()
else else
printf -- "$printf_format" "$gitstring" printf -- "$printf_format" "$gitstring"
fi fi
return $exit
} }
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