From fa836018981d5253ae20524d7220b295d927d902 Mon Sep 17 00:00:00 2001 From: Kyle Gottfried <6462596+Spitfire1900@users.noreply.github.com> Date: Tue, 26 Mar 2024 21:48:28 -0400 Subject: [PATCH] implement repo_path --- TODO.md | 2 +- xontrib/pygitstatus/entrypoint.py | 3 ++- xontrib/pygitstatus/prompt.py | 9 +++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/TODO.md b/TODO.md index ccada4c..d97e96c 100644 --- a/TODO.md +++ b/TODO.md @@ -1,5 +1,5 @@ ```python -'gitstatus.repo_path': , # TODO +'gitstatus.repo_path': , # DONE 'gitstatus.short_head': , # DONE 'gitstatus.tag': , # TODO 'gitstatus.tag_or_hash': , # TODO diff --git a/xontrib/pygitstatus/entrypoint.py b/xontrib/pygitstatus/entrypoint.py index 2bf82bc..6180b85 100644 --- a/xontrib/pygitstatus/entrypoint.py +++ b/xontrib/pygitstatus/entrypoint.py @@ -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, **_): @@ -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 diff --git a/xontrib/pygitstatus/prompt.py b/xontrib/pygitstatus/prompt.py index 6a1f2c1..6feeea1 100644 --- a/xontrib/pygitstatus/prompt.py +++ b/xontrib/pygitstatus/prompt.py @@ -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):