use std::path::Path;
use crate::constants::MIN_OXEN_VERSION;
use crate::core;
use crate::core::versions::MinOxenVersion;
use crate::error::OxenError;
use crate::model::LocalRepository;
use crate::opts::StorageOpts;
pub fn init(path: impl AsRef<Path>) -> Result<LocalRepository, OxenError> {
init_with_version(path, MIN_OXEN_VERSION)
}
pub fn init_with_version(
path: impl AsRef<Path>,
version: MinOxenVersion,
) -> Result<LocalRepository, OxenError> {
let path = path.as_ref();
match version {
MinOxenVersion::V0_10_0 => panic!("v0.10.0 no longer supported"),
_ => core::v_latest::init_with_version_default(path, version),
}
}
pub async fn init_with_storage_opts(
path: impl AsRef<Path>,
storage_opts: Option<StorageOpts>,
) -> Result<LocalRepository, OxenError> {
init_with_version_and_storage_opts(path, MIN_OXEN_VERSION, storage_opts).await
}
pub async fn init_with_version_and_storage_opts(
path: impl AsRef<Path>,
version: MinOxenVersion,
storage_opts: Option<StorageOpts>,
) -> Result<LocalRepository, OxenError> {
let path = path.as_ref();
match version {
MinOxenVersion::V0_10_0 => panic!("v0.10.0 no longer supported"),
_ => core::v_latest::init_with_version_and_storage_opts(path, version, storage_opts).await,
}
}
#[cfg(test)]
mod tests {
use crate::error::OxenError;
use crate::repositories;
use crate::test;
use crate::util;
#[tokio::test]
async fn test_command_init() -> Result<(), OxenError> {
test::run_empty_dir_test(|repo_dir| {
repositories::init(repo_dir)?;
let hidden_dir = util::fs::oxen_hidden_dir(repo_dir);
let config_file = util::fs::config_filepath(repo_dir);
assert!(hidden_dir.exists());
assert!(config_file.exists());
Ok(())
})
}
#[test]
fn test_repositories_not_set_as_remote_mode_by_default() -> Result<(), OxenError> {
test::run_empty_dir_test(|repo_dir| {
let repo = repositories::init(repo_dir)?;
assert!(!repo.is_remote_mode());
Ok(())
})
}
}