0.0.2-alpha.3
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// file: crates/knowledge-git-api/src/lib.rs
|
||||
// version: 2
|
||||
// version: 3
|
||||
|
||||
//! Provider-neutral contracts for Git-backed Knowledge sources.
|
||||
//!
|
||||
@@ -38,6 +38,30 @@ impl crate::GitRevision {
|
||||
}
|
||||
}
|
||||
|
||||
/// Read-only local materialization of one authoritative Git revision.
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct GitSnapshot {
|
||||
path: std::path::PathBuf,
|
||||
revision: crate::GitRevision,
|
||||
}
|
||||
|
||||
impl crate::GitSnapshot {
|
||||
/// Build a snapshot contract from a resolved revision and its local read root.
|
||||
pub fn new(revision: crate::GitRevision, path: std::path::PathBuf) -> crate::GitSnapshot {
|
||||
return crate::GitSnapshot { path, revision };
|
||||
}
|
||||
|
||||
/// Return the local root containing the materialized repository content.
|
||||
pub fn path(&self) -> &std::path::Path {
|
||||
return self.path.as_path();
|
||||
}
|
||||
|
||||
/// Return the authoritative revision represented by the snapshot.
|
||||
pub fn revision(&self) -> &crate::GitRevision {
|
||||
return &self.revision;
|
||||
}
|
||||
}
|
||||
|
||||
/// Provider-neutral operations required from a Git repository backend.
|
||||
///
|
||||
/// Implementations may use a local Git executable, a Rust Git library or another generic Git
|
||||
@@ -51,6 +75,9 @@ pub trait GitRepository {
|
||||
|
||||
/// Resolve one opaque reference to the authoritative revision used by synchronization.
|
||||
fn resolve_revision(&self, source_id: &knowledge_domain_lib::SourceId, reference: &crate::GitReference) -> Result<crate::GitRevision, Self::Error>;
|
||||
|
||||
/// Prepare or validate a read-only local snapshot for one resolved revision.
|
||||
fn prepare_snapshot(&self, source_id: &knowledge_domain_lib::SourceId, revision: &crate::GitRevision) -> Result<crate::GitSnapshot, Self::Error>;
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// file: crates/knowledge-git-api/unit_tests/lib.rs
|
||||
// version: 1
|
||||
// version: 2
|
||||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
struct FakeGitError;
|
||||
@@ -16,6 +16,10 @@ impl crate::GitRepository for FakeGitRepository {
|
||||
fn resolve_revision(&self, source_id: &knowledge_domain_lib::SourceId, reference: &crate::GitReference) -> Result<crate::GitRevision, Self::Error> {
|
||||
return Ok(crate::GitRevision::new(&format!("{}:{}", source_id.as_str(), reference.as_str())));
|
||||
}
|
||||
|
||||
fn prepare_snapshot(&self, _source_id: &knowledge_domain_lib::SourceId, revision: &crate::GitRevision) -> Result<crate::GitSnapshot, Self::Error> {
|
||||
return Ok(crate::GitSnapshot::new(revision.clone(), std::path::PathBuf::from("/controlled/snapshot")));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -31,5 +35,14 @@ fn generic_repository_contract_does_not_require_a_forge() {
|
||||
assert!(crate::GitRepository::refresh(&mut repository, &source_id).is_ok());
|
||||
let revision_result = crate::GitRepository::resolve_revision(&repository, &source_id, &reference);
|
||||
assert_eq!(revision_result, Ok(crate::GitRevision::new("local-pgr:refs/heads/master")));
|
||||
let revision = match revision_result {
|
||||
Ok(value) => value,
|
||||
Err(_) => return,
|
||||
};
|
||||
let snapshot_result = crate::GitRepository::prepare_snapshot(&repository, &source_id, &revision);
|
||||
assert_eq!(
|
||||
snapshot_result,
|
||||
Ok(crate::GitSnapshot::new(revision, std::path::PathBuf::from("/controlled/snapshot")))
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user