Skip to content

Added Error message when nothing staged. #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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