diff --git a/Cargo.lock b/Cargo.lock index d0d2dc7..fc90d0e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -99,6 +99,17 @@ dependencies = [ "syn", ] +[[package]] +name = "colored" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3616f750b84d8f0de8a58bda93e08e2a81ad3f523089b05f1dffecab48c6cbd" +dependencies = [ + "atty", + "lazy_static", + "winapi", +] + [[package]] name = "commit" version = "0.4.0" @@ -106,6 +117,7 @@ dependencies = [ "anyhow", "assert_fs", "clap", + "colored", "dirs", "inquire", "serde", diff --git a/Cargo.toml b/Cargo.toml index efcb9c9..f13bf39 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,7 @@ serde_json = "1.0.79" clap = { version = "3.1.6", features = ["derive"] } dirs = "4.0.0" anyhow = "1.0.56" +colored = "2.0.0" [dev-dependencies] assert_fs = "1.0.7" diff --git a/src/main.rs b/src/main.rs index 7e36b95..f5466ff 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,11 +11,13 @@ mod commit; mod commit_message; mod config; +use anyhow::anyhow; use anyhow::Result; use clap::Parser; +use colored::Colorize; use std::io::Write; - use std::path::PathBuf; +use std::process::Command; use commit_message::make_message_commit; @@ -44,6 +46,19 @@ fn main() -> Result<()> { std::env::set_current_dir(current_dir)?; } + if Command::new("git") + .args(["diff", "--cached", "--quiet"]) + .output() + .expect("failed to execute process") + .status + .code() + == Some(0) + { + return Err(anyhow!( + "You have not added anything please do `git add`".red() + )); + } + let opt = Opt::parse(); if opt.init { let mut file = std::fs::File::create("commit.json")?;