use std::fs::File;
use std::io::{BufRead, BufReader};
use std::path::Path;
pub fn get_git_remote_url<P: AsRef<Path>>(cwd: P) -> String {
let git_config = cwd.as_ref().join(".git").join("config");
let file = match File::open(&git_config) {
Ok(f) => f,
Err(_) => return String::new(),
};
let reader = BufReader::new(file);
let mut in_origin_section = false;
for line in reader.lines().map_while(Result::ok) {
let trimmed = line.trim();
if trimmed.starts_with('[') && trimmed.ends_with(']') {
in_origin_section = trimmed.starts_with("[remote \"origin\"");
continue;
}
if in_origin_section && trimmed.starts_with("url = ") {
return trimmed.trim_start_matches("url = ").trim().to_string();
}
}
String::new()
}