| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b5b87dd commit bd58716
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -450,14 +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 | - cmd = ["git", "interpret-trailers", "--parse"] | ||
| 454 | - proc: Git.AutoInterrupt = self.repo.git.execute( # type: ignore[call-overload] | ||
| 455 | - cmd, | ||
| 456 | - as_process=True, | ||
| 457 | - istream=PIPE, | ||
| 458 | - ) | ||
| 459 | - trailer: str = proc.communicate(str(self.message).encode())[0].decode("utf8") | ||
| 460 | - trailer = trailer.strip() | ||
| 453 | + trailer = self._interpret_trailers(self.repo, self.message, ["--parse"], self.encoding).strip() | ||
| 461 | 454 | ||
| 462 | 455 | if not trailer: | |
| 463 | 456 | return [] | |
@@ -469,6 +462,18 @@ def trailers_list(self) -> List[Tuple[str, str]]: | |||
| 469 | 462 | ||
| 470 | 463 | return trailer_list | |
| 471 | 464 | ||
| 465 | + @staticmethod | ||
| 466 | + def _interpret_trailers(repo: "Repo", message: str, trailer_args: Sequence[str], encoding: str) -> str: | ||
| 467 | + cmd = [repo.git.GIT_PYTHON_GIT_EXECUTABLE, "interpret-trailers", *trailer_args] | ||
| 468 | + proc: Git.AutoInterrupt = repo.git.execute( # type: ignore[call-overload] | ||
| 469 | + cmd, | ||
| 470 | + as_process=True, | ||
| 471 | + istream=PIPE, | ||
| 472 | + ) | ||
| 473 | + stdout_bytes, _ = proc.communicate(message.encode(encoding, errors="strict")) | ||
| 474 | + finalize_process(proc) | ||
| 475 | + return stdout_bytes.decode(encoding, errors="strict") | ||
| 476 | + | ||
| 472 | 477 | @property | |
| 473 | 478 | def trailers_dict(self) -> Dict[str, List[str]]: | |
| 474 | 479 | """Get the trailers of the message as a dictionary. | |
@@ -699,15 +704,7 @@ def create_from_tree( | |||
| 699 | 704 | trailer_args.append("--trailer") | |
| 700 | 705 | trailer_args.append(f"{key}: {val}") | |
| 701 | 706 | ||
| 702 | - cmd = [repo.git.GIT_PYTHON_GIT_EXECUTABLE, "interpret-trailers"] + trailer_args | ||
| 703 | - proc: Git.AutoInterrupt = repo.git.execute( # type: ignore[call-overload] | ||
| 704 | - cmd, | ||
| 705 | - as_process=True, | ||
| 706 | - istream=PIPE, | ||
| 707 | - ) | ||
| 708 | - stdout_bytes, _ = proc.communicate(str(message).encode()) | ||
| 709 | - finalize_process(proc) | ||
| 710 | - message = stdout_bytes.decode("utf8") | ||
| 707 | + message = cls._interpret_trailers(repo, str(message), trailer_args, conf_encoding) | ||
| 711 | 708 | # END apply trailers | |
| 712 | 709 | ||
| 713 | 710 | # CREATE NEW COMMIT | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -622,6 +622,31 @@ def test_create_from_tree_with_trailers_list(self, rw_dir): | |||
| 622 | 622 | "Issue": ["456"], | |
| 623 | 623 | } | |
| 624 | 624 | ||
| 625 | + @with_rw_directory | ||
| 626 | + def test_create_from_tree_with_non_utf8_trailers(self, rw_dir): | ||
| 627 | + """Test that trailer creation and parsing respect the configured commit encoding.""" | ||
| 628 | + rw_repo = Repo.init(osp.join(rw_dir, "test_trailers_non_utf8")) | ||
| 629 | + with rw_repo.config_writer() as writer: | ||
| 630 | + writer.set_value("i18n", "commitencoding", "ISO-8859-1") | ||
| 631 | + | ||
| 632 | + path = osp.join(str(rw_repo.working_tree_dir), "hello.txt") | ||
| 633 | + touch(path) | ||
| 634 | + rw_repo.index.add([path]) | ||
| 635 | + tree = rw_repo.index.write_tree() | ||
| 636 | + | ||
| 637 | + commit = Commit.create_from_tree( | ||
| 638 | + rw_repo, | ||
| 639 | + tree, | ||
| 640 | + "Résumé", | ||
| 641 | + head=True, | ||
| 642 | + trailers={"Reviewed-by": "André <andre@example.com>"}, | ||
| 643 | + ) | ||
| 644 | + | ||
| 645 | + assert commit.encoding == "ISO-8859-1" | ||
| 646 | + assert "Résumé" in commit.message | ||
| 647 | + assert "Reviewed-by: André <andre@example.com>" in commit.message | ||
| 648 | + assert commit.trailers_list == [("Reviewed-by", "André <andre@example.com>")] | ||
| 649 | + | ||
| 625 | 650 | @with_rw_directory | |
| 626 | 651 | def test_index_commit_with_trailers(self, rw_dir): | |
| 627 | 652 | """Test that IndexFile.commit() supports adding trailers.""" | |
| Back | FazBrowse Home | New Git URL |
0 commit comments