Skip to content

Commit 2b8d4b1

Browse files
author
rzmk
committed
feat: add -p flag for git push after commit
1 parent 5cd3c35 commit 2b8d4b1

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "commit-helper"
3-
version = "0.1.3"
3+
version = "0.1.4"
44
edition = "2021"
55

66
[[bin]]

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ If you want to run `git add -A` before committing, use the `-a` flag
2828
ch -a
2929
```
3030

31+
### `-p`
32+
33+
If you want to run `git push` after committing, use the `-p` flag
34+
35+
```bash
36+
ch -p
37+
```
38+
3139
### `--dry-run` or `-d`
3240

3341
If you want to do a dry run without actually adding or committing, use the `-d` or `--dry-run` flag.

src/main.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ fn main() {
1111
if dry_run {
1212
println!("Running in dry run mode\n");
1313
}
14+
// Check if -p flag is passed to run git push after commit
15+
let run_git_push = args.len() > 1 && args.contains(&String::from("-p"));
1416
// Check if --debug flag is passed to run in debug mode
1517
let debug = args.len() > 1 && args.contains(&String::from("--debug"));
1618

@@ -89,6 +91,23 @@ fn main() {
8991
println!("Exit status:\n{}", output.status);
9092
}
9193
}
94+
95+
if run_git_push {
96+
println!("Running git push");
97+
if !dry_run {
98+
let output = Command::new("git")
99+
.args(["push"])
100+
.output()
101+
.expect("failed to execute process");
102+
103+
if debug {
104+
println!("Debug info:");
105+
println!("stdout:\n{}", String::from_utf8_lossy(&output.stdout));
106+
println!("stderr:\n{}", String::from_utf8_lossy(&output.stderr));
107+
println!("Exit status:\n{}", output.status);
108+
}
109+
}
110+
}
92111
}
93112
_ => {
94113
println!("Exiting");

0 commit comments

Comments
 (0)