UF5NJKASGMZSZMBUKSUI67B2GIMQFX5SNNQEHHGUBNDBQ2QZZWSAC 6YZAVBWU6E5FYOI5JGEIPXGZLIKAW6LS2AOFIQWEE5DMOPPCD5PQC KLR5FRIBS6UOH3S3XAOE22TJACVSVOY7TOLW22DIWNGY27S6WZRAC SWWE2R6MVBX5CNM6X3WLXZTSRTU53PBJL7WJSFVF77XBPXDX4COAC W7IUT3ZVMFH77IGKLAL7WX7IVVTGTY3FKEJ3WHMP3KI37B6NENLQC YBJRDOTCX3ZRDB5EVXJBR55FX3CADCSIGMYWNYVC2PD5W3GXR3DQC A5YBC77VWH2LXCZJOPZORQJI5ZYABSCHJWVX5HVNWPM5RABXESLQC JE44NYHM4QORCRKOF33QM42EDT7SBCPTULWGT6IVDL3D5LUHQXLAC ONRCENKTUB4JJMPXNAQQYEWDYD54TAGOLWH742GF4EH3KTHV7YLQC CALXOZXANFZ64NBZBTR2KYTZ6ZLLCJXNFAEALBB2EYAVDVJJ6X6AC VCNKFNUF7OWVSWC6I5D25KUZ3XZZICZ3LHWVPF2N5ZSP7LQ2JOUQC I56UGW7UUKLSR4753EYRGNROZB5PD522REEOGHVAQOZZTSVRUEEQC YYKXNBFL44LLOBABLXBKOF7IFUIGIEL2SYIPLGDH6UOEY5EZZZSQC let repo =Repository::init(Some(dir.path().to_path_buf()), None, None).unwrap();
/// Setup an empty Pijul repo inside a given subdir in a temp dirpub fn setup_pijul_repo_in_subdir<P: AsRef<Path>>(subdir: P) -> PijulRepo {let rootdir = tempdir().unwrap();let repo = Repository::init(Some(rootdir.path().join(&subdir)), None, None).unwrap();
let (mut internal_state, state) =spawn_blocking(move || load(path)).await.unwrap();// dbg!(diff(&state.repo));
match spawn_blocking(move || load(path)).await.unwrap() {Ok((mut internal_state, state)) => {// dbg!(diff(&state.repo));
while let Some(msg) = msg_in_rx.recv().await {info!("Repo received msg {msg}");internal_state = update(internal_state, msg, &msg_out_tx).await;
while let Some(msg) = msg_in_rx.recv().await {info!("Repo received msg {msg}");internal_state = update(internal_state, msg, &msg_out_tx).await;}}Err(_err) => {// let _ = msg_out_tx.send(MsgOut::CannotLoad{err, msg_in_rx}));}
fn load(path: PathBuf) -> (InternalState, State) {let repo = pijul::Repository::find_root(Some(path)).unwrap();
fn load(path: PathBuf) -> Result<(InternalState, State), LoadError> {match std::fs::exists(&path) {Ok(true) => {}Ok(false) => return Err(LoadError::DoesntExist),Err(e) => return Err(LoadError::Inaccessible(e)),}let repo = pijul::Repository::find_root(Some(path)).map_err(|_e| LoadError::NotPijulRepo)?;
use crate::repo;use crate::testing::{repo_path, setup_pijul_repo, setup_pijul_repo_in_subdir};use assert_matches::assert_matches;use tempfile::tempdir;#[test]fn test_load_repo() {// Handle a non-existent path gracefullylet dir = tempdir().unwrap();let result =repo::load(dir.path().join("howdoyouopensomethingthatdoesntexist"));assert!(result.is_err());assert_matches!(result.unwrap_err(), repo::LoadError::DoesntExist);// Handle a path without a pijul repo gracefullylet dir = tempdir().unwrap();let result = repo::load(dir.path().to_path_buf());assert!(result.is_err());assert_matches!(result.unwrap_err(), repo::LoadError::NotPijulRepo);#[cfg(unix)]{// Handle an inaccessible path due to permissions gracefullylet subdir = "inaccessible";let repo = setup_pijul_repo_in_subdir(subdir);let repo_path = repo_path(&repo);// Make the dir inaccessiblestd::fs::set_permissions(repo.rootdir.path(), <std::fs::Permissions as std::os::unix::fs::PermissionsExt>::from_mode(0o000)).unwrap();assert!(std::fs::exists(&repo_path).is_err());let result = repo::load(repo.rootdir.path().join(subdir).to_path_buf());assert!(result.is_err());assert_matches!(result.unwrap_err(), repo::LoadError::Inaccessible(_));}// A valid path with a repolet repo = setup_pijul_repo();let repo_path = repo_path(&repo);let (_internal, state) = repo::load(repo_path.clone()).unwrap();let repo::State {dir_name,channel,untracked_files,changed_files,log,} = state;assert_eq!(&dir_name,&repo_path.components().last().unwrap().as_os_str().to_string_lossy());assert_eq!(&channel, libpijul::DEFAULT_CHANNEL);assert_eq!(untracked_files.len(), 1);assert!(untracked_files.contains(".ignore"));assert!(changed_files.is_empty());assert!(log.is_empty());}