Skip to content

Commit e6682a4

Browse files
committed
Add tests for checking out in non-empty folder
1 parent 592b69d commit e6682a4

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

gix/tests/gix/clone.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,33 @@ mod blocking_io {
550550
assure_index_entries_on_disk(&index, repo.workdir().expect("non-bare"));
551551
Ok(())
552552
}
553+
554+
#[test]
555+
fn fetch_and_checkout_into_non_empty_directory_is_allowed_by_default() -> crate::Result {
556+
let tmp = gix_testtools::tempfile::TempDir::new()?;
557+
let existing_path = tmp.path().join("existing.txt");
558+
let existing_content = b"I was here before you";
559+
std::fs::write(&existing_path, existing_content)?;
560+
561+
let mut prepare = gix::clone::PrepareFetch::new(
562+
remote::repo("base").path(),
563+
tmp.path(),
564+
gix::create::Kind::WithWorktree,
565+
Default::default(),
566+
restricted(),
567+
)?;
568+
let (mut checkout, _out) =
569+
prepare.fetch_then_checkout(gix::progress::Discard, &std::sync::atomic::AtomicBool::default())?;
570+
let (repo, _) = checkout.main_worktree(gix::progress::Discard, &std::sync::atomic::AtomicBool::default())?;
571+
572+
let index = repo.index()?;
573+
assert_eq!(index.entries().len(), 1, "All entries are known as per HEAD tree");
574+
assure_index_entries_on_disk(&index, repo.workdir().expect("non-bare"));
575+
576+
assert_eq!(std::fs::read(&existing_path)?, existing_content);
577+
Ok(())
578+
}
579+
553580
#[test]
554581
fn fetch_and_checkout_specific_ref() -> crate::Result {
555582
let tmp = gix_testtools::tempfile::TempDir::new()?;
@@ -800,6 +827,28 @@ fn clone_and_destination_must_be_empty() -> crate::Result {
800827
Ok(())
801828
}
802829

830+
#[test]
831+
fn clone_with_worktree_and_destination_must_be_empty() -> crate::Result {
832+
let tmp = gix_testtools::tempfile::TempDir::new()?;
833+
std::fs::write(tmp.path().join("file"), b"hello")?;
834+
match gix::clone::PrepareFetch::new(
835+
remote::repo("base").path(),
836+
tmp.path(),
837+
gix::create::Kind::WithWorktree,
838+
gix::create::Options {
839+
destination_must_be_empty: true,
840+
..Default::default()
841+
},
842+
restricted(),
843+
) {
844+
Ok(_) => unreachable!("this should fail as the directory isn't empty"),
845+
Err(err) => assert!(err
846+
.to_string()
847+
.starts_with("Refusing to initialize the non-empty directory as ")),
848+
}
849+
Ok(())
850+
}
851+
803852
#[test]
804853
fn clone_bare_into_empty_directory_and_early_drop() -> crate::Result {
805854
let tmp = gix_testtools::tempfile::TempDir::new()?;

0 commit comments

Comments
 (0)