MCPcopy
hub / github.com/jisaacks/GitGutter / git_branch_status

Method git_branch_status

modules/handler.py:646–682  ·  view source on GitHub ↗

Query the current status of the file's repository.

(self)

Source from the content-addressed store, hash-verified

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.

Callers 2

update_git_statusMethod · 0.80
set_against_originFunction · 0.80

Calls 2

execute_asyncMethod · 0.95
thenMethod · 0.80

Tested by

no test coverage detected