0.0.2-alpha.2.fix.1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// file: crates/knowledge-git-lib/src/backend.rs
|
||||
// version: 1
|
||||
// version: 2
|
||||
|
||||
//! Physical source configuration, generated-state layout and controlled Git process runner.
|
||||
|
||||
@@ -17,10 +17,7 @@ impl crate::GitBackendConfig {
|
||||
}
|
||||
|
||||
/// Build a backend configuration with an explicit Git executable path.
|
||||
pub fn with_git_executable(
|
||||
state_root: std::path::PathBuf,
|
||||
git_executable: std::path::PathBuf,
|
||||
) -> Result<crate::GitBackendConfig, crate::GitBackendError> {
|
||||
pub fn with_git_executable(state_root: std::path::PathBuf, git_executable: std::path::PathBuf) -> Result<crate::GitBackendConfig, crate::GitBackendError> {
|
||||
if state_root.as_os_str().is_empty() {
|
||||
return Err(crate::GitBackendError::EmptyStateRoot);
|
||||
}
|
||||
@@ -75,18 +72,11 @@ pub struct GitSourceConfig {
|
||||
|
||||
impl crate::GitSourceConfig {
|
||||
/// Build a local Git source configuration.
|
||||
pub fn local(
|
||||
source_id: knowledge_domain_lib::SourceId,
|
||||
path: std::path::PathBuf,
|
||||
) -> Result<crate::GitSourceConfig, crate::GitBackendError> {
|
||||
pub fn local(source_id: knowledge_domain_lib::SourceId, path: std::path::PathBuf) -> Result<crate::GitSourceConfig, crate::GitBackendError> {
|
||||
if path.as_os_str().is_empty() {
|
||||
return Err(crate::GitBackendError::EmptySourceLocation);
|
||||
}
|
||||
return Ok(crate::GitSourceConfig {
|
||||
location: path.into_os_string(),
|
||||
source_id,
|
||||
source_kind: crate::GitSourceKind::Local,
|
||||
});
|
||||
return Ok(crate::GitSourceConfig { location: path.into_os_string(), source_id, source_kind: crate::GitSourceKind::Local });
|
||||
}
|
||||
|
||||
/// Build a remote Git source configuration without interpreting provider-specific syntax.
|
||||
@@ -94,11 +84,7 @@ impl crate::GitSourceConfig {
|
||||
if location.trim().is_empty() {
|
||||
return Err(crate::GitBackendError::EmptySourceLocation);
|
||||
}
|
||||
return Ok(crate::GitSourceConfig {
|
||||
location: std::ffi::OsString::from(location),
|
||||
source_id,
|
||||
source_kind: crate::GitSourceKind::Remote,
|
||||
});
|
||||
return Ok(crate::GitSourceConfig { location: std::ffi::OsString::from(location), source_id, source_kind: crate::GitSourceKind::Remote });
|
||||
}
|
||||
|
||||
/// Return the logical source identifier associated with this physical source.
|
||||
@@ -123,7 +109,7 @@ impl crate::GitSourceKey {
|
||||
for byte in source_id.as_str().as_bytes() {
|
||||
value.push_str(format!("{:02x}", *byte).as_str());
|
||||
}
|
||||
return crate::GitSourceKey(value);
|
||||
return Self(value);
|
||||
}
|
||||
|
||||
/// Return the path-safe key text.
|
||||
@@ -204,16 +190,11 @@ impl GitCommandRunner for SystemGitRunner {
|
||||
let output = match output_result {
|
||||
Ok(value) => value,
|
||||
Err(_) => {
|
||||
return Err(crate::GitBackendError::GitUnavailable {
|
||||
operation: specification.operation,
|
||||
});
|
||||
}
|
||||
return Err(crate::GitBackendError::GitUnavailable { operation: specification.operation });
|
||||
},
|
||||
};
|
||||
if !output.status.success() {
|
||||
return Err(crate::GitBackendError::GitCommandFailed {
|
||||
operation: specification.operation,
|
||||
exit_code: output.status.code(),
|
||||
});
|
||||
return Err(crate::GitBackendError::GitCommandFailed { operation: specification.operation, exit_code: output.status.code() });
|
||||
}
|
||||
return Ok(GitCommandOutput { stdout: output.stdout });
|
||||
}
|
||||
@@ -228,10 +209,7 @@ pub struct GitBackend {
|
||||
impl crate::GitBackend {
|
||||
/// Create a backend using the configured real Git executable.
|
||||
pub fn new(config: crate::GitBackendConfig) -> crate::GitBackend {
|
||||
return crate::GitBackend {
|
||||
config,
|
||||
runner: Box::new(SystemGitRunner),
|
||||
};
|
||||
return crate::GitBackend { config, runner: Box::new(SystemGitRunner) };
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -260,12 +238,8 @@ impl crate::GitBackend {
|
||||
let inspection_result = self.inspect_bare_repository(&repository_path);
|
||||
match inspection_result {
|
||||
Ok(()) => {
|
||||
return Ok(Some(crate::GitMirror {
|
||||
repository_path,
|
||||
source_key,
|
||||
status: crate::GitMirrorStatus::Existing,
|
||||
}));
|
||||
}
|
||||
return Ok(Some(crate::GitMirror { repository_path, source_key, status: crate::GitMirrorStatus::Existing }));
|
||||
},
|
||||
Err(error) => return Err(error),
|
||||
}
|
||||
}
|
||||
@@ -283,12 +257,8 @@ impl crate::GitBackend {
|
||||
let inspection_result = self.inspect_bare_repository(&repository_path);
|
||||
match inspection_result {
|
||||
Ok(()) => {
|
||||
return Ok(crate::GitMirror {
|
||||
repository_path,
|
||||
source_key,
|
||||
status: crate::GitMirrorStatus::Existing,
|
||||
});
|
||||
}
|
||||
return Ok(crate::GitMirror { repository_path, source_key, status: crate::GitMirrorStatus::Existing });
|
||||
},
|
||||
Err(error) => return Err(error),
|
||||
}
|
||||
}
|
||||
@@ -300,12 +270,8 @@ impl crate::GitBackend {
|
||||
let inspection_result = self.inspect_bare_repository(&repository_path);
|
||||
match inspection_result {
|
||||
Ok(()) => {
|
||||
return Ok(crate::GitMirror {
|
||||
repository_path,
|
||||
source_key,
|
||||
status: crate::GitMirrorStatus::Created,
|
||||
});
|
||||
}
|
||||
return Ok(crate::GitMirror { repository_path, source_key, status: crate::GitMirrorStatus::Created });
|
||||
},
|
||||
Err(error) => return Err(error),
|
||||
}
|
||||
}
|
||||
@@ -362,10 +328,8 @@ impl crate::GitBackend {
|
||||
let stdout = match stdout_result {
|
||||
Ok(value) => value.trim(),
|
||||
Err(_) => {
|
||||
return Err(crate::GitBackendError::UnexpectedGitOutput {
|
||||
operation: crate::GitOperation::InspectMirror,
|
||||
});
|
||||
}
|
||||
return Err(crate::GitBackendError::UnexpectedGitOutput { operation: crate::GitOperation::InspectMirror });
|
||||
},
|
||||
};
|
||||
if stdout != "true" {
|
||||
return Err(crate::GitBackendError::InvalidMirror);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// file: crates/knowledge-git-lib/src/error.rs
|
||||
// version: 1
|
||||
// version: 2
|
||||
|
||||
//! Recoverable errors for controlled Git process execution.
|
||||
|
||||
@@ -66,11 +66,11 @@ impl std::fmt::Display for crate::GitBackendError {
|
||||
crate::GitBackendError::GitUnavailable { operation } => return write!(formatter, "git is unavailable while attempting to {operation}"),
|
||||
crate::GitBackendError::GitCommandFailed { operation, exit_code } => {
|
||||
return write!(formatter, "git failed while attempting to {operation}; exit code {exit_code:?}");
|
||||
}
|
||||
},
|
||||
crate::GitBackendError::InvalidMirror => return formatter.write_str("controlled git repository is not a valid bare mirror"),
|
||||
crate::GitBackendError::UnexpectedGitOutput { operation } => {
|
||||
return write!(formatter, "git returned unexpected output while attempting to {operation}");
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// file: crates/knowledge-git-lib/src/lib.rs
|
||||
// version: 1
|
||||
// version: 2
|
||||
|
||||
//! Controlled Git process backend for Knowledge content sources.
|
||||
//!
|
||||
@@ -17,10 +17,10 @@ pub use self::backend::GitBackendConfig;
|
||||
pub use self::backend::GitMirror;
|
||||
/// Result of ensuring that a controlled mirror exists.
|
||||
pub use self::backend::GitMirrorStatus;
|
||||
/// Path-safe storage key derived from a logical Knowledge source identifier.
|
||||
pub use self::backend::GitSourceKey;
|
||||
/// Physical Git source configuration associated with one logical source identifier.
|
||||
pub use self::backend::GitSourceConfig;
|
||||
/// Path-safe storage key derived from a logical Knowledge source identifier.
|
||||
pub use self::backend::GitSourceKey;
|
||||
/// Coarse physical source kind used by the backend.
|
||||
pub use self::backend::GitSourceKind;
|
||||
/// Recoverable error returned by the controlled Git backend.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// file: crates/knowledge-git-lib/unit_tests/backend.rs
|
||||
// version: 1
|
||||
// version: 2
|
||||
|
||||
#[derive(Clone)]
|
||||
struct RecordingRunner {
|
||||
@@ -41,9 +41,7 @@ impl super::GitCommandRunner for RecordingRunner {
|
||||
return Err(error);
|
||||
}
|
||||
if specification.operation == crate::GitOperation::InspectMirror {
|
||||
return Ok(super::GitCommandOutput {
|
||||
stdout: self.inspection_stdout.clone(),
|
||||
});
|
||||
return Ok(super::GitCommandOutput { stdout: self.inspection_stdout.clone() });
|
||||
}
|
||||
return Ok(super::GitCommandOutput { stdout: Vec::new() });
|
||||
}
|
||||
@@ -180,10 +178,7 @@ fn process_errors_do_not_expose_remote_location_or_credentials() {
|
||||
Ok(value) => value,
|
||||
Err(_) => return,
|
||||
};
|
||||
let runner = RecordingRunner::failing(crate::GitBackendError::GitCommandFailed {
|
||||
operation: crate::GitOperation::CloneMirror,
|
||||
exit_code: Some(128),
|
||||
});
|
||||
let runner = RecordingRunner::failing(crate::GitBackendError::GitCommandFailed { operation: crate::GitOperation::CloneMirror, exit_code: Some(128) });
|
||||
let backend = crate::GitBackend::with_runner(config, Box::new(runner));
|
||||
let source_id_result = source_id("snippets");
|
||||
assert!(source_id_result.is_some());
|
||||
@@ -206,13 +201,7 @@ fn process_errors_do_not_expose_remote_location_or_credentials() {
|
||||
let display = error.to_string();
|
||||
assert!(!display.contains("secret"));
|
||||
assert!(!display.contains("example.invalid"));
|
||||
assert_eq!(
|
||||
error,
|
||||
crate::GitBackendError::GitCommandFailed {
|
||||
operation: crate::GitOperation::CloneMirror,
|
||||
exit_code: Some(128),
|
||||
}
|
||||
);
|
||||
assert_eq!(error, crate::GitBackendError::GitCommandFailed { operation: crate::GitOperation::CloneMirror, exit_code: Some(128) });
|
||||
let _ = std::fs::remove_dir_all(root);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user