Skip to content

Commit

Permalink
implement repo_path
Browse files Browse the repository at this point in the history
  • Loading branch information
Spitfire1900 committed Mar 27, 2024
1 parent 2abefe3 commit fa83601
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
```python
'gitstatus.repo_path': <Prompt: gitstatus.repo_path>, # TODO
'gitstatus.repo_path': <Prompt: gitstatus.repo_path>, # DONE
'gitstatus.short_head': <Prompt: gitstatus.short_head>, # DONE
'gitstatus.tag': <Prompt: gitstatus.tag>, # TODO
'gitstatus.tag_or_hash': <Prompt: gitstatus.tag_or_hash>, # 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, clean, short_head
from .prompt import ahead, behind, clean, repo_path, short_head


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.clean'] = clean
prompt_fields['pygitstatus.repo_path'] = repo_path
prompt_fields['pygitstatus.short_head'] = short_head


Expand Down
9 changes: 9 additions & 0 deletions xontrib/pygitstatus/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ def clean(fld: PromptField, ctx: PromptFields):
fld.value = value


@PromptField.wrap()
def repo_path(fld: PromptField, ctx: PromptFields):
with contextlib.suppress(GitError):
repo = Repo('.')

# this returns `.git` in most cases, should it
# just return the relative basedir?
fld.value = os.path.relpath(repo.path)

@PromptField.wrap(prefix=':')
def short_head(fld: PromptField, ctx: PromptFields):
with contextlib.suppress(GitError):
Expand Down

0 comments on commit fa83601

Please sign in to comment.