Skip to content

Commit 69812e2

Browse files
committed
Add a test for 01c8fd8 (but it's not testing set_len())
Note that this test doesn't actually validate the newly added line as currently the file will be truncated when opening it. When that is disabled, the test will actually kick in, and validate the safeguard. Let's keep it for that purpose alone.
1 parent 082bd7d commit 69812e2

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

gix-worktree-state/tests/state/checkout.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,3 +710,38 @@ fn setup_filter_pipeline(opts: &mut gix_filter::pipeline::Options) {
710710
required: true,
711711
}];
712712
}
713+
714+
#[test]
715+
fn checkout_truncates_existing_longer_files() -> crate::Result {
716+
let mut opts = opts_from_probe();
717+
opts.overwrite_existing = false;
718+
opts.destination_is_initially_empty = false;
719+
720+
// Use existing fixture and modify one file to be longer
721+
let (_source_tree, destination, _index, _outcome) = checkout_index_in_tmp_dir_opts(
722+
opts.clone(),
723+
"make_mixed_without_submodules_and_symlinks",
724+
None,
725+
|_| true,
726+
|dest| {
727+
// Create a longer version of the "executable" file before checkout
728+
let file_path = dest.join("executable");
729+
std::fs::create_dir_all(dest)?;
730+
std::fs::write(
731+
&file_path,
732+
b"This is much longer content that should be truncated to match git's version",
733+
)?;
734+
Ok(())
735+
},
736+
)?;
737+
738+
let file_path = destination.path().join("executable");
739+
let final_content = std::fs::read(&file_path)?;
740+
assert_eq!(
741+
final_content[..].as_bstr(),
742+
"content",
743+
"File content should match git's version"
744+
);
745+
746+
Ok(())
747+
}

0 commit comments

Comments
 (0)