-
Notifications
You must be signed in to change notification settings - Fork 4
/
status.py
33 lines (26 loc) · 925 Bytes
/
status.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import re
class Status(object):
def __init__(self, status):
matches = re.search(r"^([MADRCU ?!]{2}) (.+?)(?: -> (.+?))?$", status)
self.x = matches[1][0]
self.y = matches[1][1]
self.path = matches[3] if matches[3] else matches[2]
self.original_path = matches[2] if matches[3] else None
def __str__(self):
status = "{}{}".format(self.x, self.y)
if self.original_path:
status = "{} {} -> {}".format(status, self.original_path, self.path)
else:
status = "{} {}".format(status, self.path)
return status
def __repr__(self): # pragma: no cover
return "<Status {}>".format(self.path)
@property
def is_staged(self):
return self.x not in (" ", "?", "!")
@property
def is_untracked(self):
return self.x == "?"
@property
def is_ignored(self):
return self.x == "!"