Skip to content

Commit e6727f1

Browse files
committed
Make destination_must_be_empty default to true
1 parent e6682a4 commit e6727f1

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

gix/src/create.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ fn create_dir(p: &Path) -> Result<(), Error> {
108108
}
109109

110110
/// Options for use in [`into()`];
111-
#[derive(Copy, Clone, Default)]
111+
#[derive(Copy, Clone)]
112112
pub struct Options {
113113
/// If true, and the kind of repository to create has a worktree, then the destination directory must be empty.
114114
///
@@ -119,6 +119,15 @@ pub struct Options {
119119
pub fs_capabilities: Option<gix_fs::Capabilities>,
120120
}
121121

122+
impl Default for Options {
123+
fn default() -> Self {
124+
Options {
125+
destination_must_be_empty: true,
126+
fs_capabilities: None,
127+
}
128+
}
129+
}
130+
122131
/// Create a new `.git` repository of `kind` within the possibly non-existing `directory`
123132
/// and return its path.
124133
/// Note that this is a simple template-based initialization routine which should be accompanied with additional corrections

gix/src/lib.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,15 @@ pub fn open_with_environment_overrides(directory: impl Into<std::path::PathBuf>)
293293
/// ```
294294
#[allow(clippy::result_large_err)]
295295
pub fn init(directory: impl AsRef<std::path::Path>) -> Result<Repository, init::Error> {
296-
ThreadSafeRepository::init(directory, create::Kind::WithWorktree, create::Options::default()).map(Into::into)
296+
ThreadSafeRepository::init(
297+
directory,
298+
create::Kind::WithWorktree,
299+
create::Options {
300+
destination_must_be_empty: false,
301+
..Default::default()
302+
},
303+
)
304+
.map(Into::into)
297305
}
298306

299307
/// See [`ThreadSafeRepository::init()`], but returns a [`Repository`] instead.

gix/tests/gix/clone.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ mod blocking_io {
552552
}
553553

554554
#[test]
555-
fn fetch_and_checkout_into_non_empty_directory_is_allowed_by_default() -> crate::Result {
555+
fn fetch_and_checkout_into_non_empty_directory() -> crate::Result {
556556
let tmp = gix_testtools::tempfile::TempDir::new()?;
557557
let existing_path = tmp.path().join("existing.txt");
558558
let existing_content = b"I was here before you";
@@ -562,7 +562,10 @@ mod blocking_io {
562562
remote::repo("base").path(),
563563
tmp.path(),
564564
gix::create::Kind::WithWorktree,
565-
Default::default(),
565+
gix::create::Options {
566+
destination_must_be_empty: false,
567+
..Default::default()
568+
},
566569
restricted(),
567570
)?;
568571
let (mut checkout, _out) =
@@ -835,10 +838,7 @@ fn clone_with_worktree_and_destination_must_be_empty() -> crate::Result {
835838
remote::repo("base").path(),
836839
tmp.path(),
837840
gix::create::Kind::WithWorktree,
838-
gix::create::Options {
839-
destination_must_be_empty: true,
840-
..Default::default()
841-
},
841+
Default::default(),
842842
restricted(),
843843
) {
844844
Ok(_) => unreachable!("this should fail as the directory isn't empty"),

0 commit comments

Comments
 (0)