Skip to content

Commit

Permalink
implement conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Spitfire1900 committed Mar 28, 2024
1 parent 9b046e4 commit d7dd654
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
'gitstatus.untracked': <Prompt: gitstatus.untracked>, # DONE
'gitstatus.changed': <Prompt: gitstatus.changed>, # DONE
'gitstatus.deleted': <Prompt: gitstatus.deleted>, # DONE
'gitstatus.conflicts': <Prompt: gitstatus.conflicts>, # TODO
'gitstatus.conflicts': <Prompt: gitstatus.conflicts>, # DONE
'gitstatus.staged': <Prompt: gitstatus.staged>, # DONE
'gitstatus.numstat': <Prompt: gitstatus.numstat>, # TODO
'gitstatus.lines_added': <Prompt: gitstatus.lines_added>, # TODO
Expand Down
7 changes: 4 additions & 3 deletions xontrib/pygitstatus/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

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, tag_or_hash,
untracked)
from .prompts import (ahead, behind, branch, changed, clean, conflict, curr_branch,
deleted, repo_path, short_head, staged, stash_count, tag,
tag_or_hash, untracked)


def _load_xontrib_(xsh: XonshSession, **_) -> dict:
Expand Down Expand Up @@ -34,6 +34,7 @@ def _load_xontrib_(xsh: XonshSession, **_) -> dict:
prompt_fields['pygitstatus.branch'] = branch
prompt_fields['pygitstatus.changed'] = changed
prompt_fields['pygitstatus.clean'] = clean
prompt_fields['pygitstatus.conflicts'] = conflict
prompt_fields['pygitstatus.deleted'] = deleted
prompt_fields['pygitstatus.repo_path'] = repo_path
prompt_fields['pygitstatus.short_head'] = short_head
Expand Down
19 changes: 15 additions & 4 deletions xontrib/pygitstatus/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
from typing import Optional

# pylint: disable=no-name-in-module
from pygit2 import (GIT_STATUS_INDEX_MODIFIED, GIT_STATUS_INDEX_NEW,
GIT_STATUS_INDEX_RENAMED, GIT_STATUS_INDEX_TYPECHANGE,
GIT_STATUS_WT_DELETED, GIT_STATUS_WT_MODIFIED, GIT_STATUS_WT_NEW,
Commit, GitError)
from pygit2 import (GIT_STATUS_CONFLICTED, GIT_STATUS_INDEX_MODIFIED,
GIT_STATUS_INDEX_NEW, GIT_STATUS_INDEX_RENAMED,
GIT_STATUS_INDEX_TYPECHANGE, GIT_STATUS_WT_DELETED,
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 @@ -70,6 +70,17 @@ def changed(fld: PromptField, ctx: PromptFields):
fld.value = str(untracked_count)


@PromptField.wrap(prefix="{RED}-", suffix="{RESET}", info="deleted")
def conflict(fld: PromptField, ctx: PromptFields):
fld.value = ''
with contextlib.suppress(GitError):
repo = Repo('.')
conflicted_count = len(
[v for k, v in repo.status().items() if v == GIT_STATUS_CONFLICTED])
if conflicted_count > 0:
fld.value = str(conflicted_count)


@PromptField.wrap(prefix="{RED}-", suffix="{RESET}", info="deleted")
def deleted(fld: PromptField, ctx: PromptFields):
fld.value = ''
Expand Down

0 comments on commit d7dd654

Please sign in to comment.