()
| 367 | /// This test verifies that attempting to record an empty file fails as expected. |
| 368 | #[test] |
| 369 | fn test_empty_file() { |
| 370 | let (repo, _temp, repo_path) = create_test_repo(); |
| 371 | |
| 372 | // Create an empty file and add it to tracking |
| 373 | let file_path = repo_path.join("empty.txt"); |
| 374 | fs::write(&file_path, "").expect("Failed to write empty file"); |
| 375 | repo.add("empty.txt", Default::default()) |
| 376 | .expect("Failed to add empty file"); |
| 377 | |
| 378 | // With the default options (record_empty_files: true), recording an |
| 379 | // empty file should succeed — the change captures the file's existence |
| 380 | // even though it has no content bytes. |
| 381 | let header = ChangeHeader::builder() |
| 382 | .message("Add empty file") |
| 383 | .author(Author::new("Test", Some("test@example.com"))) |
| 384 | .build(); |
| 385 | |
| 386 | let result = repo.record(header, RecordOptions::default()); |
| 387 | assert!( |
| 388 | result.is_ok(), |
| 389 | "Recording empty file should succeed with record_empty_files=true (default)" |
| 390 | ); |
| 391 | |
| 392 | // With record_empty_files explicitly disabled, recording an empty file |
| 393 | // should fail with NothingToRecord because there are no content changes. |
| 394 | let file_path2 = repo_path.join("empty2.txt"); |
| 395 | fs::write(&file_path2, "").expect("Failed to write empty file"); |
| 396 | repo.add("empty2.txt", Default::default()) |
| 397 | .expect("Failed to add empty file"); |
| 398 | |
| 399 | let header2 = ChangeHeader::builder() |
| 400 | .message("Add another empty file") |
| 401 | .author(Author::new("Test", Some("test@example.com"))) |
| 402 | .build(); |
| 403 | |
| 404 | let result2 = repo.record(header2, RecordOptions::default().record_empty_files(false)); |
| 405 | assert!( |
| 406 | result2.is_err(), |
| 407 | "Recording empty file should fail with record_empty_files=false" |
| 408 | ); |
| 409 | } |
| 410 | |
| 411 | #[test] |
| 412 | fn test_binary_content() { |
nothing calls this directly
no test coverage detected