Skip to content

Commit

Permalink
implement untracked
Browse files Browse the repository at this point in the history
  • Loading branch information
Spitfire1900 committed Mar 28, 2024
1 parent c35c25c commit 2a17812
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
'gitstatus.branch': <Prompt: gitstatus.branch>, # DONE
'gitstatus.ahead': <Prompt: gitstatus.ahead>, # DONE
'gitstatus.behind': <Prompt: gitstatus.behind>, # DONE
'gitstatus.untracked': <Prompt: gitstatus.untracked>, # TODO
'gitstatus.untracked': <Prompt: gitstatus.untracked>, # DONE
'gitstatus.changed': <Prompt: gitstatus.changed>, # TODO
'gitstatus.deleted': <Prompt: gitstatus.deleted>, # TODO
'gitstatus.conflicts': <Prompt: gitstatus.conflicts>, # TODO
Expand Down
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 .prompt import ahead, behind, branch, clean, repo_path, short_head, tag
from .prompt import (ahead, behind, branch, clean, repo_path, short_head, tag, untracked)


def _load_xontrib_(xsh: XonshSession, **_):
Expand All @@ -24,6 +24,7 @@ def _load_xontrib_(xsh: XonshSession, **_):
prompt_fields['pygitstatus.repo_path'] = repo_path
prompt_fields['pygitstatus.short_head'] = short_head
prompt_fields['pygitstatus.tag'] = tag
prompt_fields['pygitstatus.untracked'] = untracked


def _unload_xontrib_(xsh: XonshSession, **kwargs) -> dict:
Expand Down
10 changes: 10 additions & 0 deletions xontrib/pygitstatus/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,13 @@ def tag(fld: PromptField, ctx: PromptFields):
if head_commit == tag_commit:
fld.value = _tag.partition('refs/tags/')[-1]
break


@PromptField.wrap(prefix="…", info="untracked")
def untracked(fld: PromptField, ctx: PromptFields):
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:
fld.value = str(untracked_count)

0 comments on commit 2a17812

Please sign in to comment.