diff --git a/Cargo.lock b/Cargo.lock index 4c204ec..edbd684 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -22,7 +22,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "commit-helper" -version = "0.1.3" +version = "0.1.4" dependencies = [ "inquire", ] diff --git a/Cargo.toml b/Cargo.toml index f6235f3..7520859 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "commit-helper" -version = "0.1.3" +version = "0.1.4" edition = "2021" [[bin]] diff --git a/README.md b/README.md index 3abdae3..978b1d1 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,14 @@ If you want to run `git add -A` before committing, use the `-a` flag ch -a ``` +### `-p` + +If you want to run `git push` after committing, use the `-p` flag + +```bash +ch -p +``` + ### `--dry-run` or `-d` If you want to do a dry run without actually adding or committing, use the `-d` or `--dry-run` flag. diff --git a/src/main.rs b/src/main.rs index 396cd3e..212b592 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,6 +11,8 @@ fn main() { if dry_run { println!("Running in dry run mode\n"); } + // Check if -p flag is passed to run git push after commit + let run_git_push = args.len() > 1 && args.contains(&String::from("-p")); // Check if --debug flag is passed to run in debug mode let debug = args.len() > 1 && args.contains(&String::from("--debug")); @@ -89,6 +91,23 @@ fn main() { println!("Exit status:\n{}", output.status); } } + + if run_git_push { + println!("Running git push"); + if !dry_run { + let output = Command::new("git") + .args(["push"]) + .output() + .expect("failed to execute process"); + + if debug { + println!("Debug info:"); + println!("stdout:\n{}", String::from_utf8_lossy(&output.stdout)); + println!("stderr:\n{}", String::from_utf8_lossy(&output.stderr)); + println!("Exit status:\n{}", output.status); + } + } + } } _ => { println!("Exiting");