use crate::config_error::ConfigError;
use crate::config_file::{LoadedConfig, ignored_legacy_notice, load_repository_config};
use crate::config_schema::CliGitConfig;
use crate::diagnostics::{
EngineFailureCode, LEGACY_CONFIG_IGNORED_CODE, render_configuration_warning,
render_engine_failure,
};
use crate::worktree_identity::{WorktreeIdentity, worktree_root};
use std::path::PathBuf;
pub fn load_identity_config(identity: &WorktreeIdentity) -> Result<LoadedConfig, ConfigError> {
let Some(root) = worktree_root(identity) else {
return Ok(LoadedConfig {
config: CliGitConfig::defaults(),
source: None,
ignored_legacy: Vec::<PathBuf>::new(),
});
};
return load_repository_config(root);
}
pub fn config_invalid_event(error: &ConfigError) -> String {
return render_engine_failure(0, EngineFailureCode::ConfigInvalid, error.message.as_str());
}
pub fn legacy_warning_events(loaded: &LoadedConfig) -> String {
let mut events: String = String::new();
if let Some(source) = &loaded.source {
for (index, legacy) in loaded.ignored_legacy.iter().enumerate() {
events.push_str(
render_configuration_warning(
index as u64,
LEGACY_CONFIG_IGNORED_CODE,
ignored_legacy_notice(legacy.as_path(), source.as_path()).as_str(),
legacy.to_string_lossy().as_ref(),
)
.as_str(),
);
}
}
return events;
}
#[cfg(test)]
#[path = "invocation_config_tests.rs"]
mod tests;