diff --git a/TODO.md b/TODO.md index 59bed40..12e0dec 100644 --- a/TODO.md +++ b/TODO.md @@ -14,7 +14,7 @@ 'gitstatus.deleted': , # DONE 'gitstatus.conflicts': , # DONE 'gitstatus.staged': , # DONE -'gitstatus.numstat': , # TODO +'gitstatus.numstat': , # DONE 'gitstatus.lines_added': , # TODO 'gitstatus.lines_removed': # TODO , 'gitstatus.clean': , # DONE diff --git a/xontrib/pygitstatus/entrypoint.py b/xontrib/pygitstatus/entrypoint.py index 130d7b6..7d9bc3d 100644 --- a/xontrib/pygitstatus/entrypoint.py +++ b/xontrib/pygitstatus/entrypoint.py @@ -3,7 +3,7 @@ from xonsh.built_ins import XonshSession from .prompts import (ahead, behind, branch, changed, clean, conflicts, curr_branch, - deleted, repo_path, short_head, staged, stash_count, tag, + deleted, numstat, repo_path, short_head, staged, stash_count, tag, tag_or_hash, untracked) @@ -36,6 +36,7 @@ def _load_xontrib_(xsh: XonshSession, **_) -> dict: prompt_fields['pygitstatus.clean'] = clean prompt_fields['pygitstatus.conflicts'] = conflicts prompt_fields['pygitstatus.deleted'] = deleted + prompt_fields['pygitstatus.numstat'] = numstat prompt_fields['pygitstatus.repo_path'] = repo_path prompt_fields['pygitstatus.short_head'] = short_head prompt_fields['pygitstatus.staged'] = staged diff --git a/xontrib/pygitstatus/prompts.py b/xontrib/pygitstatus/prompts.py index 81ee081..d03b25f 100644 --- a/xontrib/pygitstatus/prompts.py +++ b/xontrib/pygitstatus/prompts.py @@ -6,7 +6,7 @@ from pygit2 import (GIT_STATUS_CONFLICTED, GIT_STATUS_INDEX_MODIFIED, GIT_STATUS_INDEX_NEW, GIT_STATUS_INDEX_RENAMED, GIT_STATUS_INDEX_TYPECHANGE, GIT_STATUS_WT_DELETED, - GIT_STATUS_WT_MODIFIED, GIT_STATUS_WT_NEW, Commit, GitError) + GIT_STATUS_WT_MODIFIED, GIT_STATUS_WT_NEW, Commit, Diff, GitError) from pygit2 import Repository as Repo from xonsh.prompt.base import MultiPromptField, PromptField, PromptFields @@ -81,6 +81,21 @@ def conflicts(fld: PromptField, ctx: PromptFields): fld.value = str(conflicted_count) +@PromptField.wrap(prefix='{BOLD_GREEN}', suffix='{RESET}', symbol='✓') +def clean(fld: PromptField, ctx: PromptFields): + + # symbol attribute is auto-populated by wrap function + symbol: str + symbol = fld.symbol # type: ignore + + fld.value = '' + + with contextlib.suppress(GitError): + repo = Repo('.') + if len(repo.status()) == 0: + fld.value = symbol + + @PromptField.wrap(prefix="{RED}-", suffix="{RESET}", info="deleted") def deleted(fld: PromptField, ctx: PromptFields): fld.value = '' @@ -92,19 +107,19 @@ def deleted(fld: PromptField, ctx: PromptFields): fld.value = str(untracked_count) -@PromptField.wrap(prefix='{BOLD_GREEN}', suffix='{RESET}', symbol='✓') -def clean(fld: PromptField, ctx: PromptFields): - - # symbol attribute is auto-populated by wrap function - symbol: str - symbol = fld.symbol # type: ignore - - fld.value = '' +@PromptField.wrap() +def numstat(fld: PromptField, ctx: PromptFields): + fld.value = str((0, 0)) + insert = 0 + delete = 0 with contextlib.suppress(GitError): repo = Repo('.') - if len(repo.status()) == 0: - fld.value = symbol + diff = repo.diff() + if isinstance(diff, Diff): + insert = diff.stats.insertions + delete = diff.stats.deletions + fld.value = str((insert, delete)) @PromptField.wrap()