use git2::{Error, ErrorClass, ErrorCode};
use std::path::Path;
use std::process::{Command, Stdio};
use super::agent::SshAgentManager;
pub struct WindowsSshAgentManager;
impl SshAgentManager for WindowsSshAgentManager {
fn ensure_agent_ready() -> Result<(), Error> {
if std::env::var("SSH_AUTH_SOCK").is_err() {
Self::start_agent_detached(None)?;
}
Ok(())
}
fn start_agent_detached(_socket_path: Option<&Path>) -> Result<(), Error> {
let _child = Command::new("ssh-agent")
.stdin(Stdio::null())
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn()
.map_err(|e| {
Error::new(
ErrorCode::Auth,
ErrorClass::Net,
format!("Failed to spawn ssh-agent: {e}"),
)
})?;
Ok(())
}
}
pub fn ensure_agent_ready() -> Result<(), Error> {
WindowsSshAgentManager::ensure_agent_ready()
}