git-override 0.1.0

Enable overriding git subcommands
Documentation
use crate::scan_path;
use std::env;
use std::path::PathBuf;

/// Find the "upstream" `git` path after the `git-override` binary named `git`
///
/// `git-override` delegates to this upstream `git`.
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 {
        // Skip ourselves:
        upstream = gits
            .next()
            .ok_or_else(|| errormsg!("No upstream `git` found on PATH: {}", path))?;
    }

    Ok(upstream)
}