use knotra_vcs::{ProjectConflictDetail, ProjectId, model::operation::ProjectOperationResult};
use std::collections::HashMap;
#[derive(Debug, Clone, Default)]
pub enum ConflictPhase {
#[default]
Idle,
Loading(ProjectId),
Browsing {
project_id: ProjectId,
detail: ProjectConflictDetail,
},
ConfirmStop {
project_id: ProjectId,
detail: ProjectConflictDetail,
},
Operating {
project_id: ProjectId,
action: String,
},
Done {
project_id: ProjectId,
success: bool,
message: String,
result: Option<ProjectOperationResult>,
},
}
#[derive(Debug, Default)]
pub struct ConflictOpsState {
pub phase: ConflictPhase,
pub cached: HashMap<ProjectId, ProjectConflictDetail>,
}
#[cfg(test)]
mod tests {
use knotra_vcs::{ConflictMarker, ConflictedFile, ProjectConflictDetail, ProjectId};
#[test]
fn conflict_detail_resolved_when_no_files() {
let detail = ProjectConflictDetail {
project_id: ProjectId::new(),
project_name: "svc".to_owned(),
conflicted_files: vec![],
read_error: None,
};
assert!(detail.is_resolved());
}
#[test]
fn conflict_detail_not_resolved_with_files() {
let detail = ProjectConflictDetail {
project_id: ProjectId::new(),
project_name: "svc".to_owned(),
conflicted_files: vec![ConflictedFile {
path: "src/lib.rs".to_owned(),
marker: ConflictMarker::BothModified,
}],
read_error: None,
};
assert!(!detail.is_resolved());
assert_eq!(detail.file_count(), 1);
}
}