| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 1e2a895 commit 34ec40d
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -450,7 +450,7 @@ def trailers_list(self) -> List[Tuple[str, str]]: | |||
| 450 | 450 | :return: | |
| 451 | 451 | List containing key-value tuples of whitespace stripped trailer information. | |
| 452 | 452 | """ | |
| 453 | - trailer = self._interpret_trailers(self.repo, self.message, ["--parse"]).strip() | ||
| 453 | + trailer = self._interpret_trailers(self.repo, self.message, ["--parse"], encoding=self.encoding).strip() | ||
| 454 | 454 | ||
| 455 | 455 | if not trailer: | |
| 456 | 456 | return [] | |
@@ -463,17 +463,23 @@ def trailers_list(self) -> List[Tuple[str, str]]: | |||
| 463 | 463 | return trailer_list | |
| 464 | 464 | ||
| 465 | 465 | @classmethod | |
| 466 | - def _interpret_trailers(cls, repo: "Repo", message: Union[str, bytes], trailer_args: Sequence[str]) -> str: | ||
| 466 | + def _interpret_trailers( | ||
| 467 | + cls, | ||
| 468 | + repo: "Repo", | ||
| 469 | + message: Union[str, bytes], | ||
| 470 | + trailer_args: Sequence[str], | ||
| 471 | + encoding: str = default_encoding, | ||
| 472 | + ) -> str: | ||
| 467 | 473 | cmd = [repo.git.GIT_PYTHON_GIT_EXECUTABLE, "interpret-trailers", *trailer_args] | |
| 468 | 474 | proc: Git.AutoInterrupt = repo.git.execute( # type: ignore[call-overload] | |
| 469 | 475 | cmd, | |
| 470 | 476 | as_process=True, | |
| 471 | 477 | istream=PIPE, | |
| 472 | 478 | ) | |
| 473 | - message_bytes = message if isinstance(message, bytes) else message.encode(cls.default_encoding, errors="strict") | ||
| 479 | + message_bytes = message if isinstance(message, bytes) else message.encode(encoding, errors="strict") | ||
| 474 | 480 | stdout_bytes, _ = proc.communicate(message_bytes) | |
| 475 | 481 | finalize_process(proc) | |
| 476 | - return stdout_bytes.decode(cls.default_encoding, errors="strict") | ||
| 482 | + return stdout_bytes.decode(encoding, errors="strict") | ||
| 477 | 483 | ||
| 478 | 484 | @property | |
| 479 | 485 | def trailers_dict(self) -> Dict[str, List[str]]: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -647,6 +647,30 @@ def test_create_from_tree_with_non_utf8_trailers(self, rw_dir): | |||
| 647 | 647 | assert "Reviewed-by: André <andre@example.com>" in commit.message | |
| 648 | 648 | assert commit.trailers_list == [("Reviewed-by", "André <andre@example.com>")] | |
| 649 | 649 | ||
| 650 | + @with_rw_directory | ||
| 651 | + def test_trailers_list_with_non_utf8_message_bytes(self, rw_dir): | ||
| 652 | + """Test that trailer parsing handles non-UTF-8 commit message bytes.""" | ||
| 653 | + rw_repo = Repo.init(osp.join(rw_dir, "test_trailers_non_utf8_bytes")) | ||
| 654 | + with rw_repo.config_writer() as writer: | ||
| 655 | + writer.set_value("i18n", "commitencoding", "ISO-8859-1") | ||
| 656 | + | ||
| 657 | + path = osp.join(str(rw_repo.working_tree_dir), "hello.txt") | ||
| 658 | + touch(path) | ||
| 659 | + rw_repo.index.add([path]) | ||
| 660 | + tree = rw_repo.index.write_tree() | ||
| 661 | + | ||
| 662 | + commit = Commit.create_from_tree( | ||
| 663 | + rw_repo, | ||
| 664 | + tree, | ||
| 665 | + "Résumé", | ||
| 666 | + head=True, | ||
| 667 | + trailers={"Reviewed-by": "André <andre@example.com>"}, | ||
| 668 | + ) | ||
| 669 | + | ||
| 670 | + commit.message = commit.message.encode(commit.encoding) | ||
| 671 | + | ||
| 672 | + assert commit.trailers_list == [("Reviewed-by", "André <andre@example.com>")] | ||
| 673 | + | ||
| 650 | 674 | @with_rw_directory | |
| 651 | 675 | def test_index_commit_with_trailers(self, rw_dir): | |
| 652 | 676 | """Test that IndexFile.commit() supports adding trailers.""" | |
| Back | FazBrowse Home | New Git URL |
0 commit comments