Skip to content

Commit

Permalink
fix: show git stderr upon error
Browse files Browse the repository at this point in the history
  • Loading branch information
dairiki committed Jan 23, 2024
1 parent 43bd96f commit fdd7f97
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lektor_git_timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pickle
import re
import subprocess
import sys
from contextlib import suppress
from dataclasses import dataclass
from typing import Any
Expand Down Expand Up @@ -41,7 +42,12 @@

def run_git(*args: str | StrPath) -> str:
cmd = ("git", *args)
proc = subprocess.run(cmd, capture_output=True, text=True, check=True)
try:
proc = subprocess.run(cmd, capture_output=True, text=True, check=True)
except subprocess.CalledProcessError as exc:
if exc.stderr is not None:
sys.stderr.write(exc.stderr)
raise
return proc.stdout


Expand Down
8 changes: 8 additions & 0 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import datetime
import os
import re
import subprocess
from typing import Iterator
from typing import Mapping
from typing import TYPE_CHECKING
Expand Down Expand Up @@ -39,6 +40,13 @@ def test_run_git() -> None:
assert output.startswith("git version")


def test_run_git_output_stderr_on_error(capsys: pytest.CaptureFixture[str]) -> None:
with pytest.raises(subprocess.CalledProcessError):
run_git("unknown-command-xxx")
out, err = capsys.readouterr()
assert "unknown-command-xxx" in err


class Test__fs_mtime:
def test(self, git_repo: DummyGitRepo) -> None:
ts = 1589238180
Expand Down

0 comments on commit fdd7f97

Please sign in to comment.