git_management/
commands.rs

1use crate::{is_git_repo};
2use std::env::{set_current_dir};
3use std::process::{Command, exit};
4
5// Main git commands
6pub struct GitCommands;
7
8impl GitCommands {
9    pub fn clone(website: &str, author: &str, repo: &str) {
10        Command::new("git")
11            .arg("clone")
12            .arg(format_args!("{}{}{}{}", website, author, "/", repo).to_string().as_str())
13            .spawn();
14    }
15
16    pub fn checkout_b(repo: &str, branch: &str) {
17        if is_git_repo(repo) != true {
18            red_ln!("{} is not a git repository", repo);
19            exit(0);
20        }
21        Command::new("git")
22            .arg("checkout")
23            .arg(branch)
24            .spawn();
25    }
26
27    pub fn checkout_t(repo: &str, tag: &str) {
28        if is_git_repo(repo) != true {
29            red_ln!("{} is not a git repository", repo);
30            exit(0);
31        }
32        Command::new("git")
33            .arg("checkout")
34            .arg(tag)
35            .spawn();
36    }
37
38    pub fn checkout_nb(repo: &str, branch: &str) {
39        if is_git_repo(repo) != true {
40            red_ln!("{} is not a git repository", repo);
41            exit(0);
42        }
43        Command::new("git")
44            .arg("checkout")
45            .arg("-b")
46            .arg(repo)
47            .spawn();
48    }
49
50    pub fn add(&mut self) {
51        Command::new("git")
52            .arg("add")
53            .arg(".")
54            .spawn();
55    }
56
57    pub fn commit(&mut self, message: &str) {
58        Command::new("git")
59            .arg("commit")
60            .arg("-m")
61            .arg(message)
62            .spawn();
63    }
64
65    pub fn push(&mut self, message: &str) {
66        self.add();
67        self.commit(message);
68        Command::new("git")
69            .arg("push")
70            .spawn();
71    }
72}