-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
141f3d1
commit e5459d1
Showing
1 changed file
with
68 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,84 @@ | ||
use std::process::Command; | ||
|
||
use colorful::Colorful; | ||
|
||
pub fn gitpush(message: &str) { | ||
// TODO: use git commit -pm "message" | ||
|
||
let has_commit = Command::new("git") | ||
.arg("diff") | ||
.arg("--quiet") | ||
.arg("--exit-code") | ||
.status() | ||
.expect("Failed to execute git diff command"); | ||
// TODO: use git commit -pm "message" | ||
let has_commit = Command::new("git") | ||
.arg("diff") | ||
.arg("--quiet") | ||
.arg("--exit-code") | ||
.status() | ||
.expect("Failed to execute git diff command"); | ||
|
||
match has_commit.success() { | ||
true => { | ||
println!("Nothing to commit"); | ||
std::process::exit(0); | ||
} | ||
false => (), | ||
} | ||
match has_commit.success() { | ||
true => { | ||
println!("Nothing to commit"); | ||
std::process::exit(0); | ||
} | ||
false => (), | ||
} | ||
|
||
let add_command = | ||
Command::new("git").arg("add").arg("-A").output().expect("Failed to execute git add command"); | ||
let add_command = Command::new("git") | ||
.arg("add") | ||
.arg("-A") | ||
.output() | ||
.expect("Failed to execute git add command"); | ||
|
||
match !add_command.status.success() { | ||
true => { | ||
eprintln!("{}", "π Error: Failed to add files git repository.".red().bold()); | ||
std::process::exit(1); | ||
} | ||
false => (), | ||
} | ||
match !add_command.status.success() { | ||
true => { | ||
eprintln!("{}", "π Error: Failed to add files to git repository.".red().bold()); | ||
std::process::exit(1); | ||
} | ||
false => (), | ||
} | ||
|
||
let commit_command = Command::new("git") | ||
.arg("commit") | ||
.arg("-m") | ||
.arg(message) | ||
.output() | ||
.expect("Failed to execute git commit command"); | ||
let commit_command = Command::new("git") | ||
.arg("commit") | ||
.arg("-m") | ||
.arg(message) | ||
.output() | ||
.expect("Failed to execute git commit command"); | ||
|
||
match !commit_command.status.success() { | ||
true => { | ||
eprintln!("{}", "π Error: Failed to commit changes to git repository.".red().bold()); | ||
std::process::exit(1); | ||
} | ||
false => (), | ||
} | ||
match !commit_command.status.success() { | ||
true => { | ||
eprintln!("{}", "π Error: Failed to commit changes to git repository.".red().bold()); | ||
std::process::exit(1); | ||
} | ||
false => (), | ||
} | ||
|
||
let branch = Command::new("git") | ||
.arg("rev-parse") | ||
.arg("--abbrev-ref") | ||
.arg("HEAD") | ||
.output() | ||
.expect("Failed to execute git rev-parse command"); | ||
let branch = Command::new("git") | ||
.arg("rev-parse") | ||
.arg("--abbrev-ref") | ||
.arg("HEAD") | ||
.output() | ||
.expect("Failed to execute git rev-parse command"); | ||
|
||
match !branch.status.success() { | ||
true => { | ||
eprintln!("Error: Failed to get current branch name."); | ||
std::process::exit(1); | ||
} | ||
false => (), | ||
} | ||
match !branch.status.success() { | ||
true => { | ||
eprintln!("Error: Failed to get current branch name."); | ||
std::process::exit(1); | ||
} | ||
false => (), | ||
} | ||
|
||
let branch_name = String::from_utf8_lossy(&branch.stdout).trim().to_string(); | ||
let branch_name = String::from_utf8_lossy(&branch.stdout).trim().to_string(); | ||
|
||
let push_command = Command::new("git") | ||
.arg("push") | ||
.arg("origin") | ||
.arg(branch_name) | ||
.output() | ||
.expect("Failed to execute git push command"); | ||
let push_command = Command::new("git") | ||
.arg("push") | ||
.arg("origin") | ||
.arg(branch_name) | ||
.output() | ||
.expect("Failed to execute git push command"); | ||
|
||
match !push_command.status.success() { | ||
true => { | ||
eprintln!("{}", "π Error: Failed to push changes to git repository.".red().bold()); | ||
std::process::exit(1); | ||
} | ||
false => (), | ||
} | ||
match !push_command.status.success() { | ||
true => { | ||
eprintln!("{}", "π Error: Failed to push changes to git repository.".red().bold()); | ||
std::process::exit(1); | ||
} | ||
false => (), | ||
} | ||
|
||
println!("{}", "π Successfully added, committed, and pushed changes!".yellow()); | ||
std::process::exit(0) | ||
println!("{}", "π Successfully added, committed, and pushed changes!".yellow()); | ||
std::process::exit(0) | ||
} |