Skip to content

Commit

Permalink
implement tag_or_hash
Browse files Browse the repository at this point in the history
  • Loading branch information
Spitfire1900 committed Mar 28, 2024
1 parent 57aa077 commit 13f521e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
'gitstatus.repo_path': <Prompt: gitstatus.repo_path>, # DONE
'gitstatus.short_head': <Prompt: gitstatus.short_head>, # DONE
'gitstatus.tag': <Prompt: gitstatus.tag>, # DONE
'gitstatus.tag_or_hash': <Prompt: gitstatus.tag_or_hash>, # TODO
'gitstatus.tag_or_hash': <Prompt: gitstatus.tag_or_hash>, # DONE
'gitstatus.stash_count': <Prompt: gitstatus.stash_count>, # DONE
'gitstatus.operations': <Prompt: gitstatus.operations>, # TODO
'gitstatus.porcelain': <Prompt: gitstatus.porcelain>, # 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 @@ -3,7 +3,7 @@
from xonsh.built_ins import XonshSession

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


def _load_xontrib_(xsh: XonshSession, **_) -> dict:
Expand Down Expand Up @@ -39,6 +39,7 @@ def _load_xontrib_(xsh: XonshSession, **_) -> dict:
prompt_fields['pygitstatus.staged'] = staged
prompt_fields['pygitstatus.stash_count'] = stash_count
prompt_fields['pygitstatus.tag'] = tag
prompt_fields['pygitstatus.tag_or_hash'] = tag_or_hash
prompt_fields['pygitstatus.untracked'] = untracked
return {}

Expand Down
13 changes: 13 additions & 0 deletions xontrib/pygitstatus/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,19 @@ def tag(fld: PromptField, ctx: PromptFields):
fld.value = repo.describe()


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

fld.value = repo.describe()

if not fld.value:
with contextlib.suppress(GitError):
fld.value = repo.lookup_reference(repo.head.name).peel(Commit).short_id


@PromptField.wrap(prefix="…", info="untracked")
def untracked(fld: PromptField, ctx: PromptFields):
fld.value = ''
Expand Down

0 comments on commit 13f521e

Please sign in to comment.