Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
oh-my-zsh
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
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
c4ba3065
Commit
c4ba3065
authored
Aug 17, 2015
by
Kentaro Wada
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Show tag name when detached status if possible
parent
3c698743
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
2 deletions
+24
-2
gitstatus.py
plugins/git-prompt/gitstatus.py
+24
-2
No files found.
plugins/git-prompt/gitstatus.py
View file @
c4ba3065
...
@@ -3,9 +3,31 @@ from __future__ import print_function
...
@@ -3,9 +3,31 @@ from __future__ import print_function
import
sys
import
sys
import
re
import
re
import
shlex
from
subprocess
import
Popen
,
PIPE
,
check_output
from
subprocess
import
Popen
,
PIPE
,
check_output
def
get_tagname_or_hash
():
"""return tagname if exists else hash"""
cmd
=
'git log -1 --format="
%
h
%
d"'
output
=
check_output
(
shlex
.
split
(
cmd
))
.
decode
(
'utf-8'
)
.
strip
()
hash_
,
tagname
=
None
,
None
# get hash
m
=
re
.
search
(
'
\
(.*
\
)$'
,
output
)
if
m
:
hash_
=
output
[:
m
.
start
()
-
1
]
# get tagname
m
=
re
.
search
(
'tag: .*[,
\
)]'
,
output
)
if
m
:
tagname
=
'tags/'
+
output
[
m
.
start
()
+
len
(
'tag: '
):
m
.
end
()
-
1
]
if
tagname
:
return
tagname
elif
hash_
:
return
hash_
return
None
# `git status --porcelain --branch` can collect all information
# `git status --porcelain --branch` can collect all information
# branch, remote_branch, untracked, staged, changed, conflicts, ahead, behind
# branch, remote_branch, untracked, staged, changed, conflicts, ahead, behind
po
=
Popen
([
'git'
,
'status'
,
'--porcelain'
,
'--branch'
],
stdout
=
PIPE
,
stderr
=
PIPE
)
po
=
Popen
([
'git'
,
'status'
,
'--porcelain'
,
'--branch'
],
stdout
=
PIPE
,
stderr
=
PIPE
)
...
@@ -21,8 +43,8 @@ for st in status:
...
@@ -21,8 +43,8 @@ for st in status:
if
st
[
0
]
==
'#'
and
st
[
1
]
==
'#'
:
if
st
[
0
]
==
'#'
and
st
[
1
]
==
'#'
:
if
re
.
search
(
'Initial commit on'
,
st
[
2
]):
if
re
.
search
(
'Initial commit on'
,
st
[
2
]):
branch
=
st
[
2
]
.
split
(
' '
)[
-
1
]
branch
=
st
[
2
]
.
split
(
' '
)[
-
1
]
elif
re
.
search
(
'no branch'
,
st
[
2
]):
elif
re
.
search
(
'no branch'
,
st
[
2
]):
# detached status
branch
=
check_output
([
'git'
,
'rev-parse'
,
'--short'
,
'HEAD'
])
.
decode
(
'utf-8'
)
.
strip
()
branch
=
get_tagname_or_hash
()
elif
len
(
st
[
2
]
.
strip
()
.
split
(
'...'
))
==
1
:
elif
len
(
st
[
2
]
.
strip
()
.
split
(
'...'
))
==
1
:
branch
=
st
[
2
]
.
strip
()
branch
=
st
[
2
]
.
strip
()
else
:
else
:
...
...
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