diff options
Diffstat (limited to 'src/test_helpers/with_temp_repository.rs')
-rw-r--r-- | src/test_helpers/with_temp_repository.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/test_helpers/with_temp_repository.rs b/src/test_helpers/with_temp_repository.rs new file mode 100644 index 0000000..4e5140d --- /dev/null +++ b/src/test_helpers/with_temp_repository.rs @@ -0,0 +1,20 @@ +use crate::{ + git::Repository, + test_helpers::shared::{create_repository, with_temporary_path}, +}; + +/// Provides a new repository instance in a temporary directory for testing that contains an initial +/// empty commit. +/// +/// # Panics +/// +/// If the repository cannot be created for any reason, this function will panic. +pub(crate) fn with_temp_repository<F>(callback: F) +where F: FnOnce(Repository) { + with_temporary_path(|path| { + let mut opts = git2::RepositoryInitOptions::new(); + _ = opts.initial_head("main"); + let repo = create_repository(git2::Repository::init_opts(path, &opts).unwrap()); + callback(repo); + }); +} |