Skip to content

Commit

Permalink
implement changed
Browse files Browse the repository at this point in the history
  • Loading branch information
Spitfire1900 committed Mar 28, 2024
1 parent eee7bf1 commit 305443b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion xontrib/pygitstatus/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from xonsh.built_ins import XonshSession

from .prompts import (ahead, behind, branch, clean, repo_path, short_head, stash_count, tag, untracked)
from .prompts import (ahead, behind, branch, changed, clean, repo_path, short_head, stash_count, tag, untracked)


def _load_xontrib_(xsh: XonshSession, **_):
Expand All @@ -20,6 +20,7 @@ def _load_xontrib_(xsh: XonshSession, **_):
prompt_fields['pygitstatus.ahead'] = ahead
prompt_fields['pygitstatus.behind'] = behind
prompt_fields['pygitstatus.branch'] = branch
prompt_fields['pygitstatus.changed'] = changed
prompt_fields['pygitstatus.clean'] = clean
prompt_fields['pygitstatus.repo_path'] = repo_path
prompt_fields['pygitstatus.short_head'] = short_head
Expand Down
14 changes: 12 additions & 2 deletions xontrib/pygitstatus/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os

# pylint: disable=no-name-in-module
from pygit2 import GIT_STATUS_WT_NEW, Commit, GitError
from pygit2 import GIT_STATUS_WT_MODIFIED, GIT_STATUS_WT_NEW, Commit, GitError
from pygit2 import Repository as Repo
from xonsh.prompt.base import MultiPromptField, PromptField, PromptFields

Expand Down Expand Up @@ -49,6 +49,16 @@ def branch(fld: PromptField, ctx: PromptFields):
fld.value = repo.head.shorthand


@PromptField.wrap(prefix="{BLUE}+", suffix="{RESET}", info="changed")
def changed(fld: PromptField, ctx: PromptFields):
fld.value = ''
with contextlib.suppress(GitError):
repo = Repo('.')
untracked_count = len([v for k, v in repo.status().items() if v == GIT_STATUS_WT_MODIFIED])
if untracked_count > 0:
fld.value = str(untracked_count)


@PromptField.wrap(prefix='{BOLD_GREEN}', suffix='{RESET}', symbol='✓')
def clean(fld: PromptField, ctx: PromptFields):

Expand Down Expand Up @@ -115,8 +125,8 @@ def tag(fld: PromptField, ctx: PromptFields):

@PromptField.wrap(prefix="…", info="untracked")
def untracked(fld: PromptField, ctx: PromptFields):
fld.value = ''
with contextlib.suppress(GitError):
fld.value = ''
repo = Repo('.')
untracked_count = len([v for k, v in repo.status().items() if v == GIT_STATUS_WT_NEW])
if untracked_count > 0:
Expand Down

0 comments on commit 305443b

Please sign in to comment.