(&self)
| 474 | } |
| 475 | |
| 476 | fn output_patch_if_needed(&self) { |
| 477 | if let Some(ref output_target) = self.output_patch { |
| 478 | if let Some(patch) = self.get_git_diff() { |
| 479 | let status = if patch.trim().is_empty() { |
| 480 | "empty" |
| 481 | } else { |
| 482 | "generated" |
| 483 | }; |
| 484 | let patch_value = json!({ |
| 485 | "type": "patch", |
| 486 | "target": output_target, |
| 487 | "status": status, |
| 488 | "patch": if output_target == "-" { Some(patch.as_str()) } else { None }, |
| 489 | "bytes": patch.len(), |
| 490 | }); |
| 491 | |
| 492 | if self.emit(patch_value).is_err() { |
| 493 | eprintln!("Failed to emit patch event"); |
| 494 | } |
| 495 | |
| 496 | if self.output_format != ExecOutputFormat::Text { |
| 497 | if output_target != "-" && !patch.trim().is_empty() { |
| 498 | if let Err(e) = std::fs::write(output_target, &patch) { |
| 499 | eprintln!("Failed to save patch: {}", e); |
| 500 | } |
| 501 | } |
| 502 | return; |
| 503 | } |
| 504 | |
| 505 | println!("\n--- Generating Patch ---"); |
| 506 | if patch.trim().is_empty() { |
| 507 | println!("(No file modifications)"); |
| 508 | } else if output_target == "-" { |
| 509 | println!("---PATCH_START---"); |
| 510 | println!("{}", patch); |
| 511 | println!("---PATCH_END---"); |
| 512 | } else { |
| 513 | match std::fs::write(output_target, &patch) { |
| 514 | Ok(_) => { |
| 515 | println!("Patch saved to: {}", output_target); |
| 516 | println!("({} bytes)", patch.len()); |
| 517 | } |
| 518 | Err(e) => { |
| 519 | eprintln!("Failed to save patch: {}", e); |
| 520 | println!("---PATCH_START---"); |
| 521 | println!("{}", patch); |
| 522 | println!("---PATCH_END---"); |
| 523 | } |
| 524 | } |
| 525 | } |
| 526 | } else { |
| 527 | let value = json!({ |
| 528 | "type": "patch", |
| 529 | "target": output_target, |
| 530 | "status": "unavailable", |
| 531 | }); |
| 532 | if self.emit(value).is_err() { |
| 533 | eprintln!("Failed to emit patch event"); |
no test coverage detected