✨ feat(commands):为所有命令添加config_path参数支持,实现自定义配置文件路径
♻️ refactor(config):重构ConfigManager,添加with_path_fresh方法用于初始化新配置 🔧 fix(git):改进跨平台路径处理,增强git仓库检测的鲁棒性 ✅ test(tests):添加全面的集成测试,覆盖所有命令和跨平台场景
This commit is contained in:
@@ -19,7 +19,11 @@ impl ConfigManager {
|
||||
|
||||
/// Create config manager with specific path
|
||||
pub fn with_path(path: &Path) -> Result<Self> {
|
||||
let config = AppConfig::load(path)?;
|
||||
let config = if path.exists() {
|
||||
AppConfig::load(path)?
|
||||
} else {
|
||||
AppConfig::default()
|
||||
};
|
||||
Ok(Self {
|
||||
config,
|
||||
config_path: path.to_path_buf(),
|
||||
@@ -27,6 +31,15 @@ impl ConfigManager {
|
||||
})
|
||||
}
|
||||
|
||||
/// Create config manager with fresh config (ignoring existing)
|
||||
pub fn with_path_fresh(path: &Path) -> Result<Self> {
|
||||
Ok(Self {
|
||||
config: AppConfig::default(),
|
||||
config_path: path.to_path_buf(),
|
||||
modified: true,
|
||||
})
|
||||
}
|
||||
|
||||
/// Get configuration reference
|
||||
pub fn config(&self) -> &AppConfig {
|
||||
&self.config
|
||||
|
||||
@@ -177,8 +177,17 @@ impl GitProfile {
|
||||
|
||||
if let Some(ref ssh) = self.ssh {
|
||||
if let Some(ref key_path) = ssh.private_key_path {
|
||||
config.set_str("core.sshCommand",
|
||||
&format!("ssh -i {}", key_path.display()))?;
|
||||
let path_str = key_path.display().to_string();
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
config.set_str("core.sshCommand",
|
||||
&format!("ssh -i \"{}\"", path_str.replace('\\', "/")))?;
|
||||
}
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
{
|
||||
config.set_str("core.sshCommand",
|
||||
&format!("ssh -i '{}'", path_str))?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,8 +215,17 @@ impl GitProfile {
|
||||
|
||||
if let Some(ref ssh) = self.ssh {
|
||||
if let Some(ref key_path) = ssh.private_key_path {
|
||||
config.set_str("core.sshCommand",
|
||||
&format!("ssh -i {}", key_path.display()))?;
|
||||
let path_str = key_path.display().to_string();
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
config.set_str("core.sshCommand",
|
||||
&format!("ssh -i \"{}\"", path_str.replace('\\', "/")))?;
|
||||
}
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
{
|
||||
config.set_str("core.sshCommand",
|
||||
&format!("ssh -i '{}'", path_str))?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -351,7 +369,15 @@ impl SshConfig {
|
||||
if let Some(ref cmd) = self.ssh_command {
|
||||
Some(cmd.clone())
|
||||
} else if let Some(ref key_path) = self.private_key_path {
|
||||
Some(format!("ssh -i '{}'", key_path.display()))
|
||||
let path_str = key_path.display().to_string();
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
Some(format!("ssh -i \"{}\"", path_str.replace('\\', "/")))
|
||||
}
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
{
|
||||
Some(format!("ssh -i '{}'", path_str))
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -511,7 +537,11 @@ pub struct ConfigDifference {
|
||||
}
|
||||
|
||||
fn default_gpg_program() -> String {
|
||||
"gpg".to_string()
|
||||
if cfg!(target_os = "windows") {
|
||||
"gpg.exe".to_string()
|
||||
} else {
|
||||
"gpg".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
fn default_true() -> bool {
|
||||
|
||||
Reference in New Issue
Block a user