Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
oh-my-zsh
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
github
oh-my-zsh
Commits
5642014f
Commit
5642014f
authored
Aug 01, 2015
by
Marc Cornellà
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pull in simplified version from @wkentaro
This version uses `git status --porcelain` instead of making multiple calls to `git status`.
parent
6443626a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
38 deletions
+42
-38
gitstatus.py
plugins/git-prompt/gitstatus.py
+42
-38
No files found.
plugins/git-prompt/gitstatus.py
View file @
5642014f
...
@@ -4,6 +4,7 @@ from __future__ import print_function
...
@@ -4,6 +4,7 @@ from __future__ import print_function
# change this symbol to whatever you prefer
# change this symbol to whatever you prefer
prehash
=
':'
prehash
=
':'
import
subprocess
from
subprocess
import
Popen
,
PIPE
from
subprocess
import
Popen
,
PIPE
import
sys
import
sys
...
@@ -13,53 +14,56 @@ branch, error = gitsym.communicate()
...
@@ -13,53 +14,56 @@ branch, error = gitsym.communicate()
error_string
=
error
.
decode
(
'utf-8'
)
error_string
=
error
.
decode
(
'utf-8'
)
if
'fatal: Not a git repository'
in
error_string
:
if
'fatal: Not a git repository'
in
error_string
:
sys
.
exit
(
0
)
sys
.
exit
(
0
)
branch
=
branch
.
decode
(
"utf-8"
)
.
strip
()[
11
:]
branch
=
branch
.
decode
(
"utf-8"
)
.
strip
()[
11
:]
res
,
err
=
Popen
([
'git'
,
'diff'
,
'--name-status'
],
stdout
=
PIPE
,
stderr
=
PIPE
)
.
communicate
()
# Get git status (staged, change, conflicts and untracked)
err_string
=
err
.
decode
(
'utf-8'
)
try
:
if
'fatal'
in
err_string
:
res
=
subprocess
.
check_output
([
'git'
,
'status'
,
'--porcelain'
])
sys
.
exit
(
0
)
except
subprocess
.
CalledProcessError
:
changed_files
=
[
namestat
[
0
]
for
namestat
in
res
.
decode
(
"utf-8"
)
.
splitlines
()]
sys
.
exit
(
0
)
staged_files
=
[
namestat
[
0
]
for
namestat
in
Popen
([
'git'
,
'diff'
,
'--staged'
,
'--name-status'
],
stdout
=
PIPE
)
.
communicate
()[
0
]
.
splitlines
()]
status
=
[(
st
[
0
],
st
[
1
],
st
[
2
:])
for
st
in
res
.
splitlines
()]
nb_changed
=
len
(
changed_files
)
-
changed_files
.
count
(
'U'
)
untracked
,
staged
,
changed
,
conflicts
=
[],
[],
[],
[]
nb_U
=
staged_files
.
count
(
'U'
)
for
st
in
status
:
nb_staged
=
len
(
staged_files
)
-
nb_U
if
st
[
0
]
==
'?'
and
st
[
1
]
==
'?'
:
staged
=
str
(
nb_staged
)
untracked
.
append
(
st
)
conflicts
=
str
(
nb_U
)
else
:
changed
=
str
(
nb_changed
)
if
st
[
1
]
==
'M'
:
nb_untracked
=
len
([
0
for
status
in
Popen
([
'git'
,
'status'
,
'--porcelain'
,],
stdout
=
PIPE
)
.
communicate
()[
0
]
.
decode
(
"utf-8"
)
.
splitlines
()
if
status
.
startswith
(
'??'
)])
changed
.
append
(
st
)
untracked
=
str
(
nb_untracked
)
if
st
[
0
]
==
'U'
:
conflicts
.
append
(
st
)
elif
st
[
0
]
!=
' '
:
staged
.
append
(
st
)
ahead
,
behind
=
0
,
0
ahead
,
behind
=
0
,
0
if
not
branch
:
# not on any branch
if
not
branch
:
# not on any branch
branch
=
prehash
+
Popen
([
'git'
,
'rev-parse'
,
'--short'
,
'HEAD'
],
stdout
=
PIPE
)
.
communicate
()[
0
]
.
decode
(
"utf-8"
)[:
-
1
]
branch
=
prehash
+
Popen
([
'git'
,
'rev-parse'
,
'--short'
,
'HEAD'
],
stdout
=
PIPE
)
.
communicate
()[
0
]
.
decode
(
"utf-8"
)[:
-
1
]
else
:
else
:
remote_name
=
Popen
([
'git'
,
'config'
,
'branch.
%
s.remote'
%
branch
],
stdout
=
PIPE
)
.
communicate
()[
0
]
.
decode
(
"utf-8"
)
.
strip
()
remote_name
=
Popen
([
'git'
,
'config'
,
'branch.
%
s.remote'
%
branch
],
stdout
=
PIPE
)
.
communicate
()[
0
]
.
decode
(
"utf-8"
)
.
strip
()
if
remote_name
:
if
remote_name
:
merge_name
=
Popen
([
'git'
,
'config'
,
'branch.
%
s.merge'
%
branch
],
stdout
=
PIPE
)
.
communicate
()[
0
]
.
decode
(
"utf-8"
)
.
strip
()
merge_name
=
Popen
([
'git'
,
'config'
,
'branch.
%
s.merge'
%
branch
],
stdout
=
PIPE
)
.
communicate
()[
0
]
.
decode
(
"utf-8"
)
.
strip
()
if
remote_name
==
'.'
:
# local
if
remote_name
==
'.'
:
# local
remote_ref
=
merge_name
remote_ref
=
merge_name
else
:
else
:
remote_ref
=
'refs/remotes/
%
s/
%
s'
%
(
remote_name
,
merge_name
[
11
:])
remote_ref
=
'refs/remotes/
%
s/
%
s'
%
(
remote_name
,
merge_name
[
11
:])
revgit
=
Popen
([
'git'
,
'rev-list'
,
'--left-right'
,
'
%
s...HEAD'
%
remote_ref
],
stdout
=
PIPE
,
stderr
=
PIPE
)
revgit
=
Popen
([
'git'
,
'rev-list'
,
'--left-right'
,
'
%
s...HEAD'
%
remote_ref
],
stdout
=
PIPE
,
stderr
=
PIPE
)
revlist
=
revgit
.
communicate
()[
0
]
revlist
=
revgit
.
communicate
()[
0
]
if
revgit
.
poll
():
# fallback to local
if
revgit
.
poll
():
# fallback to local
revlist
=
Popen
([
'git'
,
'rev-list'
,
'--left-right'
,
'
%
s...HEAD'
%
merge_name
],
stdout
=
PIPE
,
stderr
=
PIPE
)
.
communicate
()[
0
]
revlist
=
Popen
([
'git'
,
'rev-list'
,
'--left-right'
,
'
%
s...HEAD'
%
merge_name
],
stdout
=
PIPE
,
stderr
=
PIPE
)
.
communicate
()[
0
]
behead
=
revlist
.
decode
(
"utf-8"
)
.
splitlines
()
behead
=
revlist
.
decode
(
"utf-8"
)
.
splitlines
()
ahead
=
len
([
x
for
x
in
behead
if
x
[
0
]
==
'>'
])
ahead
=
len
([
x
for
x
in
behead
if
x
[
0
]
==
'>'
])
behind
=
len
(
behead
)
-
ahead
behind
=
len
(
behead
)
-
ahead
out
=
' '
.
join
([
out
=
' '
.
join
([
branch
,
branch
,
str
(
ahead
),
str
(
ahead
),
str
(
behind
),
str
(
behind
),
staged
,
str
(
len
(
staged
))
,
conflicts
,
str
(
len
(
conflicts
))
,
changed
,
str
(
len
(
changed
))
,
untracked
,
str
(
len
(
untracked
))
,
])
])
print
(
out
,
end
=
''
)
print
(
out
,
end
=
''
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment