Skip to content

Commit f034664

Browse files
authored
fix: add context lines to generated patch (#390)
Apparently, `git apply` uses context lines in the patch to find a match for changed lines. Previously, we weren't adding context lines to keep the patch size minimal. As a bonus, `git apply` does not require being used in a git repository. This means I can `git apply` any generated patch in the integration tests about thread comments. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved the generated patch output so it may include more surrounding context when applied. * The test workflow now verifies that generated patches can be applied successfully, helping catch issues earlier. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 339337a commit f034664

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

cpp-linter/src/common_fs.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,7 @@ impl FileObj {
192192
repo_root: &Path,
193193
) -> Result<(), FileObjError> {
194194
let printer = BasicLineDiffPrinter(&input.interner);
195-
let mut diff_config = UnifiedDiffConfig::default();
196-
diff_config.context_len(0);
195+
let diff_config = UnifiedDiffConfig::default();
197196
let unified_diff = diff.unified_diff(&printer, diff_config, input).to_string();
198197
if !unified_diff.is_empty() {
199198
let patch_path_parent = repo_root.join(ClangParams::CACHE_DIR);

cpp-linter/tests/comments.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,14 @@ async fn setup(lib_root: &Path, tmp_dir: &TempDir, test_params: &TestParams) {
322322
};
323323
println!("{style}{l}{style:#}");
324324
}
325+
326+
let apply_patch_status = std::process::Command::new("git")
327+
.arg("apply")
328+
.arg(patch_path)
329+
.current_dir(tmp_dir.path())
330+
.status()
331+
.expect("Failed to execute `git apply` command.");
332+
assert!(apply_patch_status.success());
325333
}
326334

327335
let summary_out_file_abs_path = if test_params.relative_summary_out_file {

0 commit comments

Comments
 (0)