0b5d18a247c440891251f9a80e7301b42c0dc981
- Author
- Felipe Contreras <felipe.contreras@gmail.com>
- Committer
- Felipe Contreras <felipe.contreras@gmail.com>
- Date
Message
Diff
This diff is truncated to protect this page.
1diff --git a/plugins/gitfast/git-prompt.sh b/plugins/gitfast/git-prompt.sh
2index 54489080f8ae25a4483cd4bae076942f47f53031..9d684b10a67ea663410db3ba68482c1a52bbc367 100644
3--- a/plugins/gitfast/git-prompt.sh
4+++ b/plugins/gitfast/git-prompt.sh
5@@ -207,7 +207,16 @@ __git_ps1_show_upstream ()
6 p=" u+${count#* }-${count% *}" ;;
7 esac
8 if [[ -n "$count" && -n "$name" ]]; then
9- p="$p $(git rev-parse --abbrev-ref "$upstream" 2>/dev/null)"
10+ __git_ps1_upstream_name=$(git rev-parse \
11+ --abbrev-ref "$upstream" 2>/dev/null)
12+ if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then
13+ p="$p \${__git_ps1_upstream_name}"
14+ else
15+ p="$p ${__git_ps1_upstream_name}"
16+ # not needed anymore; keep user's
17+ # environment clean
18+ unset __git_ps1_upstream_name
19+ fi
20 fi
21 fi
22
23@@ -259,7 +268,7 @@ __git_ps1_colorize_gitstring ()
24 r="$c_clear$r"
25 }
26
27-eread ()
28+__git_eread ()
29 {
30 f="$1"
31 shift
32@@ -297,6 +306,43 @@ __git_ps1 ()
33 ;;
34 esac
35
36+ # ps1_expanded: This variable is set to 'yes' if the shell
37+ # subjects the value of PS1 to parameter expansion:
38+ #
39+ # * bash does unless the promptvars option is disabled
40+ # * zsh does not unless the PROMPT_SUBST option is set
41+ # * POSIX shells always do
42+ #
43+ # If the shell would expand the contents of PS1 when drawing
44+ # the prompt, a raw ref name must not be included in PS1.
45+ # This protects the user from arbitrary code execution via
46+ # specially crafted ref names. For example, a ref named
47+ # 'refs/heads/$(IFS=_;cmd=sudo_rm_-rf_/;$cmd)' might cause the
48+ # shell to execute 'sudo rm -rf /' when the prompt is drawn.
49+ #
50+ # Instead, the ref name should be placed in a separate global
51+ # variable (in the __git_ps1_* namespace to avoid colliding
52+ # with the user's environment) and that variable should be
53+ # referenced from PS1. For example:
54+ #
55+ # __git_ps1_foo=$(do_something_to_get_ref_name)
56+ # PS1="...stuff...\${__git_ps1_foo}...stuff..."
57+ #
58+ # If the shell does not expand the contents of PS1, the raw
59+ # ref name must be included in PS1.
60+ #
61+ # The value of this variable is only relevant when in pcmode.
62+ #
63+ # Assume that the shell follows the POSIX specification and
64+ # expands PS1 unless determined otherwise. (This is more
65+ # likely to be correct if the user has a non-bash, non-zsh
66+ # shell and safer than the alternative if the assumption is
67+ # incorrect.)
68+ #
69+ local ps1_expanded=yes
70+ [ -z "$ZSH_VERSION" ] || [[ -o PROMPT_SUBST ]] || ps1_expanded=no
71+ [ -z "$BASH_VERSION" ] || shopt -q promptvars || ps1_expanded=no
72+
73 local repo_info rev_parse_exit_code
74 repo_info="$(git rev-parse --git-dir --is-inside-git-dir \
75 --is-bare-repository --is-inside-work-tree \
76@@ -328,9 +374,9 @@ __git_ps1 ()
77 local step=""
78 local total=""
79 if [ -d "$g/rebase-merge" ]; then
80- eread "$g/rebase-merge/head-name" b
81- eread "$g/rebase-merge/msgnum" step
82- eread "$g/rebase-merge/end" total
83+ __git_eread "$g/rebase-merge/head-name" b
84+ __git_eread "$g/rebase-merge/msgnum" step
85+ __git_eread "$g/rebase-merge/end" total
86 if [ -f "$g/rebase-merge/interactive" ]; then
87 r="|REBASE-i"
88 else
89@@ -338,10 +384,10 @@ __git_ps1 ()
90 fi
91 else
92 if [ -d "$g/rebase-apply" ]; then
93- eread "$g/rebase-apply/next" step
94- eread "$g/rebase-apply/last" total
95+ __git_eread "$g/rebase-apply/next" step
96+ __git_eread "$g/rebase-apply/last" total
97 if [ -f "$g/rebase-apply/rebasing" ]; then
98- eread "$g/rebase-apply/head-name" b
99+ __git_eread "$g/rebase-apply/head-name" b
100 r="|REBASE"
101 elif [ -f "$g/rebase-apply/applying" ]; then
102 r="|AM"
103@@ -365,7 +411,7 @@ __git_ps1 ()
104 b="$(git symbolic-ref HEAD 2>/dev/null)"