Query the current status of the file's repository.
(self)
| 644 | ]) |
| 645 | |
| 646 | def git_branch_status(self): |
| 647 | """Query the current status of the file's repository.""" |
| 648 | def parse_output(output): |
| 649 | """Parse output of git status and cache the value.""" |
| 650 | added, deleted, modified, staged = 0, 0, 0, 0 |
| 651 | try: |
| 652 | lines = output.split('\n') |
| 653 | # parse branch line |
| 654 | match = _STATUS_RE.match(lines[0]) |
| 655 | branch, remote, ahead, behind = match.groups() |
| 656 | # parse file stats |
| 657 | for line in lines: |
| 658 | if line: |
| 659 | w = line[1] |
| 660 | added += w == '?' |
| 661 | deleted += w == 'D' |
| 662 | modified += w == 'M' |
| 663 | staged += line[0] in 'ADMR' |
| 664 | except: |
| 665 | branch, remote, ahead, behind = 'unknown', None, 0, 0 |
| 666 | |
| 667 | return { |
| 668 | 'branch': branch, |
| 669 | 'remote': remote, |
| 670 | 'ahead': int(ahead or 0), |
| 671 | 'behind': int(behind or 0), |
| 672 | 'added_files': added, |
| 673 | 'deleted_files': deleted, |
| 674 | 'modified_files': modified, |
| 675 | 'staged_files': staged |
| 676 | } |
| 677 | |
| 678 | return self.execute_async([ |
| 679 | self._git_binary, |
| 680 | '-c', 'color.status=never', |
| 681 | 'status', '-b', '-s', '-u' |
| 682 | ]).then(parse_output) |
| 683 | |
| 684 | def git_compare_commit(self, compare_against): |
| 685 | """Query the commit hash of the compare target. |
no test coverage detected