Skip to content

Commit 76e599d

Browse files
committed
GitRepo: Add status()
1 parent cf66cac commit 76e599d

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

libvcs/git.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242

4343
def extract_status(value):
44-
"""Returns `git status -sb --porcelain=2` extracted to a dict
44+
"""Returns ``git status -sb --porcelain=2`` extracted to a dict
4545
4646
:returns: Dictionary of git repo's status
4747
:rtype: str
@@ -516,12 +516,31 @@ def get_git_version(self):
516516
version = ''
517517
return '.'.join(version.split('.')[:3])
518518

519+
def status(self):
520+
"""Retrieve status of project in dict format.
521+
522+
Wraps ``git status --sb --porcelain=2``. Does not include changed files, yet.
523+
524+
.. code-block:: python
525+
526+
print(git_repo.status())
527+
{
528+
"branch_oid": 'de6185fde0806e5c7754ca05676325a1ea4d6348',
529+
"branch_head": 'fix-current-remote-name',
530+
"branch_upstream": 'origin/fix-current-remote-name',
531+
"branch_ab": '+0 -0',
532+
"branch_ahead": '0',
533+
"branch_behind": '0',
534+
}
535+
"""
536+
return extract_status(self.run(['status', '-sb', '--porcelain=2']))
537+
519538
def get_current_remote_name(self):
520539
"""Retrieve name of the remote / upstream of currently checked out branch.
521540
522541
:rtype: str, None if no remote set
523542
"""
524-
match = extract_status(self.run(['status', '-sb', '--porcelain=2']))
543+
match = self.status()
525544

526545
if match['branch_upstream'] is None: # no upstream set
527546
return match['branch_head']

0 commit comments

Comments
 (0)