diff --git a/bin/statusline.py b/bin/statusline.py index e593164e..00451d14 100755 --- a/bin/statusline.py +++ b/bin/statusline.py @@ -140,7 +140,7 @@ def current_branch(where: str) -> str: if not where: return "" try: - found = subprocess.run(["git", "-C", where, "branch", "--show-current"], capture_output=True, text=True) + found = subprocess.run(["git", "-C", where, "branch", "--show-current"], errors="replace", stderr=subprocess.DEVNULL, stdout=subprocess.PIPE, text=True) except OSError: return "" return found.stdout.strip() if found.returncode == 0 else "" diff --git a/bin/test_statusline.py b/bin/test_statusline.py index d0890733..07d94e92 100644 --- a/bin/test_statusline.py +++ b/bin/test_statusline.py @@ -103,8 +103,9 @@ class Script(unittest.TestCase): ran = self.run_script(stdin) self.assertEqual((ran.returncode, ran.stdout, ran.stderr), (0, f"{RED}warning: statusline.py could not parse its input as a JSON object{RESET}", "")) - def test_shows_the_branch_of_the_directory(self): - with tempfile.TemporaryDirectory() as checkout: - subprocess.run(["git", "init", "-q", "-b", "trunk", checkout], check=True) - ran = self.run_script(json.dumps({"cwd": checkout})) - self.assertEqual(ran.stdout, SEP.join([f"{CYAN}{checkout}{RESET}", f"{DIM}trunk{RESET}"])) + def test_shows_the_branch_of_the_directory_even_when_it_is_not_utf_8(self): + for branch, shown in ((b"trunk", "trunk"), (b"f\xe5", "f\ufffd")): + with tempfile.TemporaryDirectory() as checkout: + subprocess.run([b"git", b"init", b"-q", b"-b", branch, checkout.encode()], check=True) + ran = self.run_script(json.dumps({"cwd": checkout})) + self.assertEqual((ran.stdout, ran.stderr), (SEP.join([f"{CYAN}{checkout}{RESET}", f"{DIM}{shown}{RESET}"]), ""))