Skip to content

Commit ee26443

Browse files
committed
feat(git): Add extract_status
1 parent 248051f commit ee26443

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

libvcs/git.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,59 @@
4040
"""
4141

4242

43+
def extract_status(value):
44+
"""Returns `git status -sb --porcelain=2` extracted to a dict
45+
46+
:returns: Dictionary of git repo's status
47+
:rtype: str
48+
"""
49+
pattern = re.compile(
50+
r"""[\n\r]?
51+
(
52+
#
53+
\W+
54+
branch.oid\W+
55+
(?P<branch_oid>
56+
[a-f0-9]{40}
57+
)
58+
)?
59+
(
60+
#
61+
\W+
62+
branch.head
63+
[\W]+
64+
(?P<branch_head>
65+
[\w-]*
66+
)
67+
68+
)?
69+
(
70+
#
71+
\W+
72+
branch.upstream
73+
[\W]+
74+
(?P<branch_upstream>
75+
[/\w-]*
76+
)
77+
)?
78+
(
79+
#
80+
\W+
81+
branch.ab
82+
[\W]+
83+
(?P<branch_ab>
84+
\+(?P<branch_ahead>\d+)
85+
\W{1}
86+
\-(?P<branch_behind>\d+)
87+
)
88+
)?
89+
""",
90+
re.VERBOSE | re.MULTILINE,
91+
)
92+
matches = pattern.search(value)
93+
return matches.groupdict()
94+
95+
4396
class GitRepo(BaseRepo):
4497
bin_name = 'git'
4598
schemes = ('git', 'git+http', 'git+https', 'git+ssh', 'git+git', 'git+file')

0 commit comments

Comments
 (0)