3 # Those can be used, for instance to construct the prompt:
10 __ZSH_GIT_VARS_INVALID=1
11 __ZSH_GIT_STATUS_INVALID=1
15 # On cd, invalidate git status in prompt
16 __ZSH_GIT_VARS_INVALID=1
22 # On git command, invalidate git status in prompt
25 __ZSH_GIT_VARS_INVALID=1
29 # *any* command could invalidate the repository status (new file, ...)
30 __ZSH_GIT_STATUS_INVALID=1
34 # Return only git status
35 local gitstat gitstatus
37 gitstat=$(LANG=C git status 2> /dev/null | grep '\(Untracked\|Changes\|Changed but not updated:\)')
38 # 'fix for mcedit parser
41 if [[ $(echo ${gitstat} | grep -c "^Changes to be committed:$") > 0 ]]; then
45 if [[ $(echo ${gitstat} | grep -c "^Changed but not updated:$") > 0 || \
46 $(echo ${gitstat} | grep -c "^Changes not staged for commit:$") > 0 ]]; then
47 gitstatus="${gitstatus}✹"
50 if [[ $(echo ${gitstat} | grep -c "^Untracked files:$") > 0 ]]; then
51 gitstatus="${gitstatus}★"
54 if [[ -z $gitstatus ]]; then
55 gitstatus="%{${fg_bold[green]}%}✔%{$reset_color%}"
57 gitstatus="%{${fg_bold[yellow]}%}$gitstatus%{$reset_color%}"
65 local git_dir ref base_dir sub_dir action branch gitstat gitstatus
67 # If nothing has been invalidated
68 if [[ "${__ZSH_GIT_VARS_INVALID}" == "0" && "${__ZSH_GIT_STATUS_INVALID}" == "0" ]]; then
72 # If only status has been invalidated
73 if [[ "${__ZSH_GIT_VARS_INVALID}" == "0" && "${__ZSH_GIT_STATUS_INVALID}" == "1" ]]; then
74 __ZSH_GIT_STATUS=$(git_get_status)
75 __ZSH_GIT_STATUS_INVALID=0
80 # Git prompt variables are invalid. Update them.
82 git_dir=$(git rev-parse --git-dir 2> /dev/null) || return
84 if [[ "$(git rev-parse --is-bare-repository)" == "true" ]]; then
85 base_dir=${$(readlink -f "$git_dir")/$HOME/'~'}
86 sub_dir=${$(pwd)#$(readlink -f "$git_dir")}
88 base_dir=${$(readlink -f "$git_dir/..")/$HOME/'~'}
89 sub_dir=${$(pwd)#$(readlink -f "$git_dir/..")}
93 ref=$(git symbolic-ref HEAD 2> /dev/null) || return
97 if [ -d "$git_dir/../.dotest" ]; then
98 if [ -f "$git_dir/../.dotest/rebasing" ]; then
100 elif [ -f "$git_dir/../.dotest/applying" ]; then
106 elif [ -f "$git_dir/.dotest-merge/interactive" ]; then
108 branch="$(cat "$git_dir/.dotest-merge/head-name")"
109 elif [ -d "$git_dir/.dotest-merge" ]; then
111 branch="$(cat "$git_dir/.dotest-merge/head-name")"
112 elif [ -f "$git_dir/MERGE_HEAD" ]; then
116 test -f "$git_dir/BISECT_LOG" && action="-bisect"
117 branch="$(git symbolic-ref HEAD 2>/dev/null)" || \
118 branch="$(git describe --exact-match HEAD 2>/dev/null)" || \
119 branch="$(cut -c1-7 "$git_dir/HEAD")..."
123 __ZSH_GIT_BASEDIR="${base_dir}"
124 __ZSH_GIT_SUBDIR="${sub_dir}"
125 __ZSH_GIT_BRANCH="${branch#refs/heads/}"
126 __ZSH_GIT_ACTION="${action}"
127 __ZSH_GIT_STATUS=`git_get_status`
129 __ZSH_GIT_VARS_INVALID=0
130 __ZSH_GIT_STATUS_INVALID=0
134 chpwd_functions+='git_chpwd'
135 preexec_functions+='git_preexec'
136 precmd_functions+='git_parse'