Skip to content

Commit

Permalink
Update git.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
waldirborbajr committed Mar 5, 2024
1 parent 141f3d1 commit e5459d1
Showing 1 changed file with 68 additions and 67 deletions.
135 changes: 68 additions & 67 deletions src/git.rs
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)
}

0 comments on commit e5459d1

Please sign in to comment.