Skip to content

Commit

Permalink
implement WT added/deleted files, we don't care about index
Browse files Browse the repository at this point in the history
  • Loading branch information
Spitfire1900 committed Mar 28, 2024
1 parent 3af348a commit 5a74425
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
5 changes: 4 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
'gitstatus.ahead': <Prompt: gitstatus.ahead>, # DONE
'gitstatus.behind': <Prompt: gitstatus.behind>, # DONE
'gitstatus.untracked': <Prompt: gitstatus.untracked>, # DONE
'gitstatus.changed': <Prompt: gitstatus.changed>, # PARTIAL
'gitstatus.changed': <Prompt: gitstatus.changed>, # DONE
'gitstatus.deleted': <Prompt: gitstatus.deleted>, # DONE
'gitstatus.conflicts': <Prompt: gitstatus.conflicts>, # DONE
'gitstatus.staged': <Prompt: gitstatus.staged>, # DONE
Expand All @@ -31,6 +31,7 @@
- branch_color <!-- TODO -->
- ALL Prompts need the name field set. <!-- TODO -->
- Prompts like deleted, changed, etc. need to consider that status() combines the INDEX and WT status

```python
"""
GIT_STATUS_INDEX_DELETED: 4
Expand All @@ -40,6 +41,8 @@
GIT_STATUS_INDEX_TYPECHANGE: 16
GIT_STATUS_WT_DELETED: 512
GIT_STATUS_WT_MODIFIED: 256
GIT_STATUS_WT_NEW: 128
GIT_STATUS_WT_RENAMED: 2048
GIT_STATUS_WT_TYPECHANGE: 1024
Expand Down
35 changes: 18 additions & 17 deletions xontrib/pygitstatus/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,19 @@ def branch(fld: PromptField, ctx: PromptFields):
name='pygitstatus.changed')
def changed(fld: PromptField, ctx: PromptFields):
fld.value = ''
count = 0

with contextlib.suppress(GitError):
repo = Repo('.')
untracked_count = len(
[v for k, v in repo.status().items() if v == GIT_STATUS_WT_MODIFIED])
if untracked_count > 0:
fld.value = str(untracked_count)

for k, v in repo.status().items():
statuses = __git_status_calulator(v)
# We don't care about the index
is_true = GIT_STATUS_WT_MODIFIED in statuses
if is_true:
count = count + 1
if count > 0:
fld.value = str(count)


@PromptField.wrap(prefix="{RED}×", suffix="{RESET}", info="conflicts",
Expand Down Expand Up @@ -149,25 +156,19 @@ def curr_branch() -> Optional[str]:
name='pygitstatus.deleted')
def deleted(fld: PromptField, ctx: PromptFields):
fld.value = ''
deleted_count = 0
count = 0

with contextlib.suppress(GitError):
repo = Repo('.')

for k, v in repo.status().items():
statuses = __git_status_calulator(v)
is_deleted = False
for status in statuses:
if status in [
GIT_STATUS_INDEX_DELETED,
GIT_STATUS_WT_DELETED,
]:
is_deleted = True
break
if is_deleted:
deleted_count = deleted_count + 1
if deleted_count > 0:
fld.value = str(deleted_count)
# We don't care about the index.
is_true = GIT_STATUS_WT_DELETED in statuses
if is_true:
count = count + 1
if count > 0:
fld.value = str(count)


@PromptField.wrap(prefix="{CYAN}+", suffix="{RESET}", name='pygitstatus.lines_added')
Expand Down

0 comments on commit 5a74425

Please sign in to comment.