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(new_message: &str) {
    // Make sure there's a commit to amend
    let last = git::last_commit_message();
    if last.is_none() {
        println!();
        println!("  {} No commits to fix.", "".yellow());
        println!();
        return;
    }

    let old_msg = last.unwrap();

    println!();
    println!("  Fixing last commit message...");
    println!();
    println!("  Before: \"{}\"", old_msg.dimmed());
    println!("  After:  \"{}\"", new_message.bold());
    println!();

    let result = git::run(&["commit", "--amend", "-m", new_message]);
    if result.success {
        println!("  {} Commit message updated.", "".green().bold());
    } else {
        println!("  {} Failed: {}", "".red(), result.stderr);
    }
    println!();
}