mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
fix: empty gitstatus on paths without repo (#4907)
* fix: empty gitstatus on paths without repo fixes #4900 * docs: add news item * fix: failing test because of cache in git-dir per cwd
This commit is contained in:
parent
86e4f004e3
commit
dd6c873f3c
3 changed files with 53 additions and 0 deletions
23
news/fix-empty-gitstatus.rst
Normal file
23
news/fix-empty-gitstatus.rst
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
**Added:**
|
||||||
|
|
||||||
|
* <news item>
|
||||||
|
|
||||||
|
**Changed:**
|
||||||
|
|
||||||
|
* <news item>
|
||||||
|
|
||||||
|
**Deprecated:**
|
||||||
|
|
||||||
|
* <news item>
|
||||||
|
|
||||||
|
**Removed:**
|
||||||
|
|
||||||
|
* <news item>
|
||||||
|
|
||||||
|
**Fixed:**
|
||||||
|
|
||||||
|
* ``gitstatus`` Prompt-field would be empty on paths without git setup.
|
||||||
|
|
||||||
|
**Security:**
|
||||||
|
|
||||||
|
* <news item>
|
|
@ -1,3 +1,5 @@
|
||||||
|
import os
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from xonsh.prompt import gitstatus
|
from xonsh.prompt import gitstatus
|
||||||
|
@ -14,6 +16,7 @@ def prompts(xession):
|
||||||
fields = xession.env["PROMPT_FIELDS"]
|
fields = xession.env["PROMPT_FIELDS"]
|
||||||
yield fields
|
yield fields
|
||||||
fields.clear()
|
fields.clear()
|
||||||
|
fields.reset()
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
@ -71,3 +74,24 @@ def test_gitstatus_clean(prompts, fake_proc):
|
||||||
assert format(prompts.pick("gitstatus")) == exp
|
assert format(prompts.pick("gitstatus")) == exp
|
||||||
assert _format_value(prompts.pick("gitstatus"), None, None) == exp
|
assert _format_value(prompts.pick("gitstatus"), None, None) == exp
|
||||||
assert _format_value(prompts.pick("gitstatus"), "{}", None) == exp
|
assert _format_value(prompts.pick("gitstatus"), "{}", None) == exp
|
||||||
|
|
||||||
|
|
||||||
|
def test_no_git(prompts, fake_process, tmp_path):
|
||||||
|
os.chdir(tmp_path)
|
||||||
|
err = b"fatal: not a git repository (or any of the parent directories): .git"
|
||||||
|
for cmd in (
|
||||||
|
"git status --porcelain --branch",
|
||||||
|
"git rev-parse --git-dir",
|
||||||
|
"git diff --numstat",
|
||||||
|
):
|
||||||
|
fake_process.register_subprocess(
|
||||||
|
command=cmd,
|
||||||
|
stderr=err,
|
||||||
|
returncode=128,
|
||||||
|
)
|
||||||
|
|
||||||
|
exp = ""
|
||||||
|
assert prompts.pick_val("gitstatus.repo_path") == ""
|
||||||
|
assert format(prompts.pick("gitstatus")) == exp
|
||||||
|
assert _format_value(prompts.pick("gitstatus"), None, None) == exp
|
||||||
|
assert _format_value(prompts.pick("gitstatus"), "{}", None) == exp
|
||||||
|
|
|
@ -319,5 +319,11 @@ class GitStatus(MultiPromptField):
|
||||||
continue
|
continue
|
||||||
yield frag
|
yield frag
|
||||||
|
|
||||||
|
def _collect(self, ctx):
|
||||||
|
if not ctx.pick_val(repo_path):
|
||||||
|
# no need to display any other fragments
|
||||||
|
return
|
||||||
|
yield from super()._collect(ctx)
|
||||||
|
|
||||||
|
|
||||||
gitstatus = GitStatus()
|
gitstatus = GitStatus()
|
||||||
|
|
Loading…
Add table
Reference in a new issue