repo: Ignore external commit diff helpers
3cbeb21c2d4c6f3ca05a7d7ce12f6e6e6d302acc
Commit diffs feed the brain's unified-diff parser, so configured external helpers must not replace Git's built-in patch output. Assisted-by: Codex:gpt-5.6-sol
1 parent
c6058237
crates/repo/src/git.rs
+48 -2
| 598 | 598 | fn diff(&self, from: Oid, to: Oid) -> Result<String, RepoError> { |
|
| 599 | 599 | let from = from.to_string(); |
|
| 600 | 600 | let to = to.to_string(); |
|
| 601 | 601 | let bytes = self.git( |
|
| 602 | 602 | "diff", |
|
| 603 | - | &["--no-ext-diff", "--no-color", "--full-index", &from, &to], |
|
| 603 | + | &[ |
|
| 604 | + | "--no-ext-diff", |
|
| 605 | + | "--no-textconv", |
|
| 606 | + | "--no-color", |
|
| 607 | + | "--full-index", |
|
| 608 | + | &from, |
|
| 609 | + | &to, |
|
| 610 | + | ], |
|
| 604 | 611 | )?; |
|
| 605 | 612 | utf8(bytes) |
|
| 606 | 613 | } |
|
| 607 | 614 | ||
| 608 | 615 | /// Computes a stable Git patch id for `patch` text. |
| 728 | 735 | ||
| 729 | 736 | /// Returns the unified diff for `commit` against its parent. |
|
| 730 | 737 | fn commit_diff(&self, commit: Oid) -> Result<Vec<u8>, RepoError> { |
|
| 731 | 738 | let commit = commit.to_string(); |
|
| 732 | 739 | let parent = format!("{commit}^"); |
|
| 733 | - | self.git("diff", &["--full-index", &parent, &commit]) |
|
| 740 | + | self.git( |
|
| 741 | + | "diff", |
|
| 742 | + | &[ |
|
| 743 | + | "--no-ext-diff", |
|
| 744 | + | "--no-textconv", |
|
| 745 | + | "--full-index", |
|
| 746 | + | &parent, |
|
| 747 | + | &commit, |
|
| 748 | + | ], |
|
| 749 | + | ) |
|
| 734 | 750 | } |
|
| 735 | 751 | } |
|
| 736 | 752 | ||
| 737 | 753 | impl WriteRepository for Repository { |
|
| 738 | 754 | /// Writes `bytes` as a blob object and returns its id. |
| 887 | 903 | fn diff(&self, context_lines: usize, paths: &[&Path]) -> Result<Vec<u8>, RepoError> { |
|
| 888 | 904 | let context = OsString::from(format!("-U{context_lines}")); |
|
| 889 | 905 | let output = self |
|
| 890 | 906 | .command("diff") |
|
| 891 | 907 | .args(&self.selector_args) |
|
| 908 | + | .arg("--no-ext-diff") |
|
| 909 | + | .arg("--no-textconv") |
|
| 892 | 910 | .arg("--full-index") |
|
| 893 | 911 | .arg(context) |
|
| 894 | 912 | .arg("--") |
|
| 895 | 913 | .args(paths) |
|
| 896 | 914 | .output()?; |
| 1092 | 1110 | deletions: 0, |
|
| 1093 | 1111 | }] |
|
| 1094 | 1112 | ); |
|
| 1095 | 1113 | } |
|
| 1096 | 1114 | ||
| 1115 | + | #[test] |
|
| 1116 | + | fn commit_diff_uses_builtin_diff_with_external_helper_configured() { |
|
| 1117 | + | let directory = TempIndex::new().unwrap(); |
|
| 1118 | + | let repository_path = directory.path().parent().unwrap(); |
|
| 1119 | + | let status = Command::new("git") |
|
| 1120 | + | .args(["init", "-q"]) |
|
| 1121 | + | .arg(repository_path) |
|
| 1122 | + | .status() |
|
| 1123 | + | .unwrap(); |
|
| 1124 | + | assert!(status.success()); |
|
| 1125 | + | let repository = Repository::discover(repository_path.to_owned()).unwrap(); |
|
| 1126 | + | fs::write(repository_path.join("file"), "old\n").unwrap(); |
|
| 1127 | + | git(&repository, "add", &["file"]); |
|
| 1128 | + | git(&repository, "commit", &["-q", "-m", "base"]); |
|
| 1129 | + | fs::write(repository_path.join("file"), "new\n").unwrap(); |
|
| 1130 | + | git(&repository, "commit", &["-q", "-am", "change"]); |
|
| 1131 | + | git( |
|
| 1132 | + | &repository, |
|
| 1133 | + | "config", |
|
| 1134 | + | &["diff.external", "printf 'external diff output\n'"], |
|
| 1135 | + | ); |
|
| 1136 | + | let head = repository |
|
| 1137 | + | .commit_id(&Rev::try_from("HEAD").unwrap()) |
|
| 1138 | + | .unwrap(); |
|
| 1139 | + | ||
| 1140 | + | let diff = utf8(repository.commit_diff(head).unwrap()).unwrap(); |
|
| 1141 | + | ||
| 1142 | + | assert!(diff.starts_with(" |
file\n"));
+0 -0
file\n"),
+0 -0
file\n"),
+0 -0
a\n--- a/a\n+++ b/a\n@@ -1 +1 @@\n-old\n+new\n".to_owned(),
+0 -0
b\n--- a/b\n+++ b/b\n@@ -0,0 +1 @@\n+line\n".to_owned(),
+0 -0