6443626a6beedc1135402e0fdd4646ba1e7ae35a

Author
Marc Cornellà <marc.cornella@live.com>
Committer
Marc Cornellà <marc.cornella@live.com>
Date

Message

Pull in latest version from olivierverdier/zsh-git-prompt

Diff

This diff is truncated to protect this page.

  1diff --git a/plugins/git-prompt/git-prompt.plugin.zsh b/plugins/git-prompt/git-prompt.plugin.zsh
  2index d868a5fe1d1bf6b6117db674b093d1a632f5d0d7..ccba22dc51ba7d860deb9ccecf6a581410b7457b 100644
  3--- a/plugins/git-prompt/git-prompt.plugin.zsh
  4+++ b/plugins/git-prompt/git-prompt.plugin.zsh
  5@@ -1,32 +1,34 @@
  6 # ZSH Git Prompt Plugin from:
  7 # http://github.com/olivierverdier/zsh-git-prompt
  8-#
  9-export __GIT_PROMPT_DIR=$ZSH/plugins/git-prompt
 10+
 11+export __GIT_PROMPT_DIR=${0:A:h}
 12+
 13+export GIT_PROMPT_EXECUTABLE=${GIT_PROMPT_USE_PYTHON:-"python"}
 14+
 15+# Initialize colors.
 16+autoload -U colors
 17+colors
 18 
 19 # Allow for functions in the prompt.
 20 setopt PROMPT_SUBST
 21 
 22-## Enable auto-execution of functions.
 23-typeset -ga preexec_functions
 24-typeset -ga precmd_functions
 25-typeset -ga chpwd_functions
 26+autoload -U add-zsh-hook
 27 
 28-# Append git functions needed for prompt.
 29-preexec_functions+='preexec_update_git_vars'
 30-precmd_functions+='precmd_update_git_vars'
 31-chpwd_functions+='chpwd_update_git_vars'
 32+add-zsh-hook chpwd chpwd_update_git_vars
 33+add-zsh-hook preexec preexec_update_git_vars
 34+add-zsh-hook precmd precmd_update_git_vars
 35 
 36 ## Function definitions
 37 function preexec_update_git_vars() {
 38     case "$2" in
 39-        git*)
 40+        git*|hub*|gh*|stg*)
 41         __EXECUTED_GIT_COMMAND=1
 42         ;;
 43     esac
 44 }
 45 
 46 function precmd_update_git_vars() {
 47-    if [ -n "$__EXECUTED_GIT_COMMAND" ]; then
 48+    if [ -n "$__EXECUTED_GIT_COMMAND" ] || [ ! -n "$ZSH_THEME_GIT_PROMPT_CACHE" ]; then
 49         update_current_git_vars
 50         unset __EXECUTED_GIT_COMMAND
 51     fi
 52@@ -39,19 +41,68 @@ function chpwd_update_git_vars() {
 53 function update_current_git_vars() {
 54     unset __CURRENT_GIT_STATUS
 55 
 56-    local gitstatus="$__GIT_PROMPT_DIR/gitstatus.py"
 57-    _GIT_STATUS=`python ${gitstatus}`
 58-    __CURRENT_GIT_STATUS=("${(f)_GIT_STATUS}")
 59+    if [[ "$GIT_PROMPT_EXECUTABLE" == "python" ]]; then
 60+        local gitstatus="$__GIT_PROMPT_DIR/gitstatus.py"
 61+        _GIT_STATUS=`python ${gitstatus} 2>/dev/null`
 62+    fi
 63+    if [[ "$GIT_PROMPT_EXECUTABLE" == "haskell" ]]; then
 64+        local gitstatus="$__GIT_PROMPT_DIR/dist/build/gitstatus/gitstatus"
 65+        _GIT_STATUS=`${gitstatus}`
 66+    fi
 67+     __CURRENT_GIT_STATUS=("${(@s: :)_GIT_STATUS}")
 68+	GIT_BRANCH=$__CURRENT_GIT_STATUS[1]
 69+	GIT_AHEAD=$__CURRENT_GIT_STATUS[2]
 70+	GIT_BEHIND=$__CURRENT_GIT_STATUS[3]
 71+	GIT_STAGED=$__CURRENT_GIT_STATUS[4]
 72+	GIT_CONFLICTS=$__CURRENT_GIT_STATUS[5]
 73+	GIT_CHANGED=$__CURRENT_GIT_STATUS[6]
 74+	GIT_UNTRACKED=$__CURRENT_GIT_STATUS[7]
 75 }
 76 
 77-function prompt_git_info() {
 78+
 79+git_super_status() {
 80+	precmd_update_git_vars
 81     if [ -n "$__CURRENT_GIT_STATUS" ]; then
 82-        echo "(%{${fg[red]}%}$__CURRENT_GIT_STATUS[1]%{${fg[default]}%}$__CURRENT_GIT_STATUS[2]%{${fg[magenta]}%}$__CURRENT_GIT_STATUS[3]%{${fg[default]}%})"
 83-    fi
 84+	  STATUS="$ZSH_THEME_GIT_PROMPT_PREFIX$ZSH_THEME_GIT_PROMPT_BRANCH$GIT_BRANCH%{${reset_color}%}"
 85+	  if [ "$GIT_BEHIND" -ne "0" ]; then
 86+		  STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_BEHIND$GIT_BEHIND%{${reset_color}%}"
 87+	  fi
 88+	  if [ "$GIT_AHEAD" -ne "0" ]; then
 89+		  STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_AHEAD$GIT_AHEAD%{${reset_color}%}"
 90+	  fi
 91+	  STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_SEPARATOR"
 92+	  if [ "$GIT_STAGED" -ne "0" ]; then
 93+		  STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_STAGED$GIT_STAGED%{${reset_color}%}"
 94+	  fi
 95+	  if [ "$GIT_CONFLICTS" -ne "0" ]; then
 96+		  STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_CONFLICTS$GIT_CONFLICTS%{${reset_color}%}"
 97+	  fi
 98+	  if [ "$GIT_CHANGED" -ne "0" ]; then
 99+		  STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_CHANGED$GIT_CHANGED%{${reset_color}%}"
100+	  fi
101+	  if [ "$GIT_UNTRACKED" -ne "0" ]; then
102+		  STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_UNTRACKED%{${reset_color}%}"
103+	  fi
104+	  if [ "$GIT_CHANGED" -eq "0" ] && [ "$GIT_CONFLICTS" -eq "0" ] && [ "$GIT_STAGED" -eq "0" ] && [ "$GIT_UNTRACKED" -eq "0" ]; then
105diff --git a/plugins/git-prompt/gitstatus.py b/plugins/git-prompt/gitstatus.py
106index 2568414320a79140ab387ad4fe788d8cd78367fd..d944fd4edb7cc018b40c152788266c5f77c66176 100644
107--- a/plugins/git-prompt/gitstatus.py
108+++ b/plugins/git-prompt/gitstatus.py
109@@ -1,82 +1,65 @@
110 #!/usr/bin/env python
111-# -*- coding: UTF-8 -*-
112-from subprocess import Popen, PIPE
113-import re
114-
115-# change those symbols to whatever you prefer
116-symbols = {
117-    'ahead of': '↑',
118-    'behind': '↓',
119-    'staged': '♦',
120-    'changed': '‣',
121-    'untracked': '…',
122-    'clean': '⚡',
123-    'unmerged': '≠',
124-    'sha1': ':'
125-}
126+from __future__ import print_function
127 
128-output, error = Popen(
129-    ['git', 'status'], stdout=PIPE, stderr=PIPE, universal_newlines=True).communicate()
130+# change this symbol to whatever you prefer
131+prehash = ':'
132 
133-if error:
134-    import sys
135-    sys.exit(0)
136-lines = output.splitlines()
137+from subprocess import Popen, PIPE
138 
139-behead_re = re.compile(
140-    r"^# Your branch is (ahead of|behind) '(.*)' by (\d+) commit")
141-diverge_re = re.compile(r"^# and have (\d+) and (\d+) different")
142+import sys
143+gitsym = Popen(['git', 'symbolic-ref', 'HEAD'], stdout=PIPE, stderr=PIPE)
144+branch, error = gitsym.communicate()
145 
146-status = ''
147-staged = re.compile(r'^# Changes to be committed:$', re.MULTILINE)
148-changed = re.compile(r'^# Changed but not updated:$', re.MULTILINE)
149-untracked = re.compile(r'^# Untracked files:$', re.MULTILINE)
150-unmerged = re.compile(r'^# Unmerged paths:$', re.MULTILINE)
151+error_string = error.decode('utf-8')
152 
153+if 'fatal: Not a git repository' in error_string:
154+	sys.exit(0)
155 
156-def execute(*command):
157-    out, err = Popen(stdout=PIPE, stderr=PIPE, *command).communicate()
158-    if not err:
159-        nb = len(out.splitlines())
160-    else:
161-        nb = '?'
162-    return nb
163+branch = branch.decode("utf-8").strip()[11:]
164 
165-if staged.search(output):
166-    nb = execute(
167-        ['git', 'diff', '--staged', '--name-only', '--diff-filter=ACDMRT'])
168-    status += '%s%s' % (symbols['staged'], nb)
169-if unmerged.search(output):
170-    nb = execute(['git', 'diff', '--staged', '--name-only', '--diff-filter=U'])
171-    status += '%s%s' % (symbols['unmerged'], nb)
172-if changed.search(output):
173-    nb = execute(['git', 'diff', '--name-only', '--diff-filter=ACDMRT'])
174-    status += '%s%s' % (symbols['changed'], nb)
175-if untracked.search(output):
176-    status += symbols['untracked']
177-if status == '':
178-    status = symbols['clean']
179+res, err = Popen(['git','diff','--name-status'], stdout=PIPE, stderr=PIPE).communicate()
180+err_string = err.decode('utf-8')
181+if 'fatal' in err_string:
182+	sys.exit(0)
183+changed_files = [namestat[0] for namestat in res.decode("utf-8").splitlines()]
184+staged_files = [namestat[0] for namestat in Popen(['git','diff', '--staged','--name-status'], stdout=PIPE).communicate()[0].splitlines()]
185+nb_changed = len(changed_files) - changed_files.count('U')
186+nb_U = staged_files.count('U')
187+nb_staged = len(staged_files) - nb_U
188+staged = str(nb_staged)
189+conflicts = str(nb_U)
190+changed = str(nb_changed)
191+nb_untracked = len([0 for status in Popen(['git','status','--porcelain',],stdout=PIPE).communicate()[0].decode("utf-8").splitlines() if status.startswith('??')])
192+untracked = str(nb_untracked)
193 
194-remote = ''
195+ahead, behind = 0,0
196 
197-bline = lines[0]
198-if bline.find('Not currently on any branch') != -1:
199-    branch = symbols['sha1'] + Popen([
200-        'git',
201-        'rev-parse',
202-        '--short',
203-        'HEAD'], stdout=PIPE).communicate()[0][:-1]
204+if not branch: # not on any branch
205+	branch = prehash + Popen(['git','rev-parse','--short','HEAD'], stdout=PIPE).communicate()[0].decode("utf-8")[:-1]
206 else:
207-    branch = bline.split(' ')[-1]
208-    bstatusline = lines[1]