Skip to content
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
17 changes: 16 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -44,6 +46,19 @@ fn main() -> Result<()> {
std::env::set_current_dir(current_dir)?;
}

if let Some(0) = Command::new("git")
.args(["diff", "--cached", "--quiet"])
.output()
.expect("failed to execute process")
.status
.code()
{
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")?;
Expand Down