Skip to content

Commit

Permalink
feat: add -p flag for git push after commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rzmk committed Dec 2, 2023
1 parent 5cd3c35 commit 2b8d4b1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "commit-helper"
version = "0.1.3"
version = "0.1.4"
edition = "2021"

[[bin]]
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 19 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));

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

0 comments on commit 2b8d4b1

Please sign in to comment.