g-cli 0.1.0

Git that talks back. A human-friendly CLI wrapper for Git.
use colored::Colorize;

use crate::git;

pub fn run(message: &str) {
    // Check for changes
    let files_before = git::parse_status();
    if files_before.is_empty() {
        println!();
        println!("  {} Nothing to save — working directory is clean.", "".green());
        println!();
        return;
    }

    println!();
    println!("  Staging all changes...");

    let add_result = git::run(&["add", "-A"]);
    if !add_result.success {
        println!("  {} Failed to stage changes: {}", "".red(), add_result.stderr);
        return;
    }

    println!("  Creating commit...");
    println!();

    let commit_result = git::run(&["commit", "-m", message]);
    if !commit_result.success {
        println!("  {} Failed to commit: {}", "".red(), commit_result.stderr);
        return;
    }

    println!("  {} Commit created:", "".green().bold());
    println!("    \"{}\"", message.bold());
    println!();

    // Show what was committed
    let diff_result = git::run(&["diff", "--stat", "HEAD~1", "HEAD"]);
    if diff_result.success && !diff_result.stdout.is_empty() {
        println!("  {}:", "Files".dimmed());
        for line in diff_result.stdout.lines() {
            let trimmed = line.trim();
            if trimmed.contains('|') {
                // File stat line
                let parts: Vec<&str> = trimmed.splitn(2, '|').collect();
                let filename = parts[0].trim();
                let stat = parts.get(1).map(|s| s.trim()).unwrap_or("");
                if stat.contains('+') && stat.contains('-') {
                    println!("    {} {}", "~".yellow(), filename);
                } else if stat.contains('+') {
                    println!("    {} {}", "+".green(), filename);
                } else if stat.contains('-') {
                    println!("    {} {}", "-".red(), filename);
                } else {
                    println!("    {} {}", "~".yellow(), filename);
                }
            }
        }
        println!();
    }

    // Show ahead/behind
    let branch = git::current_branch();
    if let Some((ahead, _behind)) = git::ahead_behind() {
        if ahead > 0 {
            println!(
                "  You're now {} ahead of origin/{}",
                format!("{} commit(s)", ahead).bold(),
                branch
            );
            println!();
        }
    }
}