Skip to content

Commit

Permalink
implement numstat
Browse files Browse the repository at this point in the history
  • Loading branch information
Spitfire1900 committed Mar 28, 2024
1 parent 1be57da commit 4a5f7eb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
'gitstatus.deleted': <Prompt: gitstatus.deleted>, # DONE
'gitstatus.conflicts': <Prompt: gitstatus.conflicts>, # DONE
'gitstatus.staged': <Prompt: gitstatus.staged>, # DONE
'gitstatus.numstat': <Prompt: gitstatus.numstat>, # TODO
'gitstatus.numstat': <Prompt: gitstatus.numstat>, # DONE
'gitstatus.lines_added': <Prompt: gitstatus.lines_added>, # TODO
'gitstatus.lines_removed': <Prompt: gitstatus.lines_removed> # TODO ,
'gitstatus.clean': <Prompt: gitstatus.clean>, # DONE
Expand Down
3 changes: 2 additions & 1 deletion xontrib/pygitstatus/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down Expand Up @@ -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
Expand Down
37 changes: 26 additions & 11 deletions xontrib/pygitstatus/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 = ''
Expand All @@ -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()
Expand Down

0 comments on commit 4a5f7eb

Please sign in to comment.