test load repo
[?]
Jun 3, 2025, 11:26 AM
UF5NJKASGMZSZMBUKSUI67B2GIMQFX5SNNQEHHGUBNDBQ2QZZWSACDependencies
- [2]
6YZAVBWUInitial commit - [3]
KLR5FRIBadd fs state read/write of repos - [4]
SWWE2R6Mdisplay basic repo stuff - [5]
W7IUT3ZVstart recording impl - [6]
YBJRDOTCmake all repo actions async - [7]
A5YBC77Vrecord! - [8]
JE44NYHMdisplay log files diffs - [9]
ONRCENKTrm unnecessary state from repo's internal state - [10]
CALXOZXAflatten crates dir - [11]
VCNKFNUFapp init test - [12]
I56UGW7Umake record test, fix log update - [13]
YYKXNBFLtest: add untracked file - [14]
OQ6HSAWHshow record log - [15]
4WO3ZJM2show untracked files' contents - [16]
ESMM3FELtest selection reindexing - [17]
5CYU7UT7test: rm added file - [18]
KMB6FND3test view update fn rather than direct fn calls - [19]
TSFQFCB2test got repo change - [20]
EC3TVL4Xadd untracked files
Change contents
- edit in libflorescence/src/testing.rs at line 7
use std::path::{Path, PathBuf}; - edit in libflorescence/src/testing.rs at line 10
/// Get the path to the repopub fn repo_path(repo: &PijulRepo) -> PathBuf {let PijulRepo {rootdir: dir,subdir,} = repo;if let Some(subdir) = subdir {dir.path().join(subdir)} else {dir.path().to_path_buf()}} - replacement in libflorescence/src/testing.rs at line 58
let dir = tempdir().unwrap();setup_pijul_repo_in_subdir("")} - replacement in libflorescence/src/testing.rs at line 61
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(); - replacement in libflorescence/src/testing.rs at line 73
PijulRepo { dir }PijulRepo {rootdir,subdir: if subdir.as_ref().as_os_str().is_empty() {None} else {Some(subdir.as_ref().to_path_buf())},} - replacement in libflorescence/src/testing.rs at line 93
pub dir: TempDir,pub rootdir: TempDir,pub subdir: Option<PathBuf>, - edit in libflorescence/src/repo.rs at line 1
#[cfg(test)]mod test; - edit in libflorescence/src/repo.rs at line 179
#[derive(Debug)]pub enum LoadError {DoesntExist,NotPijulRepo,Inaccessible(std::io::Error),} - replacement in libflorescence/src/repo.rs at line 193
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)); - replacement in libflorescence/src/repo.rs at line 197
let _ = msg_out_tx.send(MsgOut::Init(state));let _ = msg_out_tx.send(MsgOut::Init(state)); - replacement in libflorescence/src/repo.rs at line 199
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}));} - replacement in libflorescence/src/repo.rs at line 276[4.663]→[9.1393:1444](∅→∅),[9.1444]→[5.151:217](∅→∅),[6.3101]→[5.151:217](∅→∅),[4.701]→[5.151:217](∅→∅)
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)?; - replacement in libflorescence/src/repo.rs at line 286
(internal_state, state)Ok((internal_state, state)) - edit in libflorescence/src/repo.rs at line 300
dbg!(&log); - file addition: repo[10.31]
- file addition: test.rs[0.1941]
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());} - edit in libflorescence/Cargo.toml at line 77
[dev-dependencies.assert_matches]workspace = true - replacement in inflorescence/src/test.rs at line 10
setup_pijul_id, setup_pijul_repo, PijulId, PijulRepo,repo_path, setup_pijul_id, setup_pijul_repo, PijulId, PijulRepo, - replacement in inflorescence/src/test.rs at line 27
let repo_path = repo.dir.path();let repo_path = repo_path(&repo); - replacement in inflorescence/src/test.rs at line 76
let repo_path = repo.dir.path();let repo_path = repo_path(&repo); - replacement in inflorescence/src/test.rs at line 278
let repo_path = repo.dir.path();let repo_path = repo_path(&repo); - replacement in inflorescence/src/test.rs at line 721
let repo_path = repo.dir.path();let repo_path = repo_path(&repo); - edit in Cargo.lock at line 3057
"assert_matches",