use crate::scan_path;
use std::env;
use std::path::PathBuf;
pub fn find_upstream_git() -> anyhow::Result<PathBuf> {
let path = std::env::var("PATH")?;
let thisgit = env::current_exe()?;
let mut gits = scan_path("git")?.into_iter();
let mut upstream = gits
.next()
.ok_or_else(|| errormsg!("No `git` found at all on PATH: {:?}", path))?;
if upstream == thisgit {
upstream = gits
.next()
.ok_or_else(|| errormsg!("No upstream `git` found on PATH: {}", path))?;
}
Ok(upstream)
}