liboxen 0.53.0

Oxen is a fast data version control system, built with machine learning training data in mind. Designed to handle terabytes of data with ease, using a workflow similar to git. Version both structured and unstructured data of any modality: text, images, video, audio, CSV, Parquet, JSONL, model checkpoints, and more. liboxen is the embeddable core library behind the oxen CLI and server, which power fine tuning and inference pipelines for multimodal LLMs, image models, and video models on Oxen.ai.
//! # oxen init
//!
//! Initialize a local oxen repository
//!

use std::path::Path;

use crate::core;
use crate::core::db::merkle_node::MerkleNodeBackend;
use crate::error::OxenError;
use crate::model::LocalRepository;
use crate::storage::StorageConfig;

/// # Initialize an Empty Oxen Repository
/// ```ignore
/// use liboxen::repositories;
/// use std::path::Path;
///
/// let base_dir = Path::new("repo_dir_init");
/// let repo = repositories::init(base_dir)?;
/// assert!(base_dir.join(".oxen").exists());
/// ```
pub fn init(path: impl AsRef<Path>) -> Result<LocalRepository, OxenError> {
    init_with_version(path)
}

pub fn init_with_version(path: impl AsRef<Path>) -> Result<LocalRepository, OxenError> {
    let path = path.as_ref();
    core::v_latest::init_with_version_default(path)
}

pub async fn init_with_storage_config(
    path: impl AsRef<Path>,
    storage_config: Option<StorageConfig>,
) -> Result<LocalRepository, OxenError> {
    init_with_version_and_storage_config(path, storage_config, None).await
}

pub async fn init_with_version_and_storage_config(
    path: impl AsRef<Path>,
    storage_config: Option<StorageConfig>,
    merkle_backend: Option<MerkleNodeBackend>,
) -> Result<LocalRepository, OxenError> {
    let path = path.as_ref();
    core::v_latest::init_with_version_and_storage_config(path, storage_config, merkle_backend).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| {
            // Init repo
            repositories::init(repo_dir)?;

            // Init should create the .oxen directory
            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| {
            // Init repo
            let repo = repositories::init(repo_dir)?;
            assert!(!repo.is_remote_mode());

            Ok(())
        })
    }
}