|
17 | 17 |
|
18 | 18 | branch = branch.decode("utf-8").strip()[11:]
|
19 | 19 |
|
20 |
| -res, err = Popen(['git','diff','--name-status'], stdout=PIPE, stderr=PIPE).communicate() |
| 20 | +# Get git status (staged, change, conflicts and untracked) |
| 21 | +res, err = Popen(['git', 'status', '--porcelain'], |
| 22 | + stdout=PIPE, stderr=PIPE).communicate() |
21 | 23 | err_string = err.decode('utf-8')
|
22 | 24 | if 'fatal' in err_string:
|
23 | 25 | sys.exit(0)
|
24 |
| -changed_files = [namestat[0] for namestat in res.decode("utf-8").splitlines()] |
25 |
| -staged_files = [namestat[0] for namestat in Popen(['git','diff', '--staged','--name-status'], stdout=PIPE).communicate()[0].splitlines()] |
26 |
| -nb_changed = len(changed_files) - changed_files.count('U') |
27 |
| -nb_U = staged_files.count('U') |
28 |
| -nb_staged = len(staged_files) - nb_U |
29 |
| -staged = str(nb_staged) |
30 |
| -conflicts = str(nb_U) |
31 |
| -changed = str(nb_changed) |
32 |
| -nb_untracked = len([0 for status in Popen(['git','status','--porcelain',],stdout=PIPE).communicate()[0].decode("utf-8").splitlines() if status.startswith('??')]) |
33 |
| -untracked = str(nb_untracked) |
| 26 | +status = [(st[0], st[1], st[2:]) for st in res.splitlines()] |
| 27 | +tracked, untracked = [], [] |
| 28 | +for st in status: |
| 29 | + if st[0] == '?' and st[1] == '?': |
| 30 | + untracked.append(st) |
| 31 | + else: |
| 32 | + tracked.append(st) |
| 33 | +staged = filter(lambda x: x[0] != ' ' and x[0] != 'U', tracked) |
| 34 | +changed = filter(lambda x: x[1] == 'M', tracked) |
| 35 | +conflicts = filter(lambda x: x[0] == 'U', tracked) |
| 36 | +n_staged = len(staged) |
| 37 | +n_changed = len(changed) |
| 38 | +n_conflicts = len(conflicts) |
| 39 | +n_untracked = len(untracked) |
34 | 40 |
|
35 | 41 | ahead, behind = 0,0
|
36 | 42 |
|
|
56 | 62 | branch,
|
57 | 63 | str(ahead),
|
58 | 64 | str(behind),
|
59 |
| - staged, |
60 |
| - conflicts, |
61 |
| - changed, |
62 |
| - untracked, |
| 65 | + str(n_staged), |
| 66 | + str(n_conflicts), |
| 67 | + str(n_changed), |
| 68 | + str(n_untracked), |
63 | 69 | ])
|
64 | 70 | print(out, end='')
|
65 | 71 |
|
0 commit comments