git-file-history 0.1.0

TUI for browsing the Git history of a single file
use std::{env, path::Path};

use crate::{
    app::App,
    error::{AppError, Result},
    git::{load_commits, resolve_target_file},
};

/// Loads the initial application state for the requested file history.
pub(crate) fn load_app(file_path: &Path) -> Result<App> {
    let invocation_dir =
        env::current_dir().map_err(|err| AppError::io("failed to get current directory", err))?;
    let target = resolve_target_file(&invocation_dir, file_path)
        .map_err(|err| AppError::message(format!("failed to resolve target file: {err}")))?;
    let commits = load_commits(&target.repo_root, &target.repo_path)
        .map_err(|err| AppError::message(format!("failed to load commits: {err}")))?;

    Ok(App::new(target.repo_root, target.repo_path, commits))
}