feat: add -p flag for git push after commit

This commit is contained in:
rzmk 2023-12-01 20:59:42 -05:00
parent 5cd3c35814
commit 2b8d4b103e
No known key found for this signature in database
4 changed files with 29 additions and 2 deletions

2
Cargo.lock generated
View file

@ -22,7 +22,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "commit-helper"
version = "0.1.3"
version = "0.1.4"
dependencies = [
"inquire",
]

View file

@ -1,6 +1,6 @@
[package]
name = "commit-helper"
version = "0.1.3"
version = "0.1.4"
edition = "2021"
[[bin]]

View file

@ -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.

View file

@ -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");