feat(git)!: add push field

Adding the push field to git repos, allowing to block gg attempting to push

Signed-off-by: Christina Sørensen <christina@cafkafk.com>
This commit is contained in:
Christina Sørensen 2023-06-22 14:29:32 +02:00
parent 90dfeb985a
commit 4179384738
Signed by: cafkafk
GPG key ID: CDDC792F655251ED
6 changed files with 26 additions and 8 deletions

2
Cargo.lock generated
View file

@ -190,7 +190,7 @@ dependencies = [
[[package]]
name = "gg"
version = "0.0.2"
version = "0.0.3"
dependencies = [
"clap",
"clap_mangen",

View file

@ -1,6 +1,6 @@
[package]
name = "gg"
version = "0.0.3"
version = "0.0.4"
edition = "2021"
authors = ["Christina Sørensen <christina@cafkafk.com>"]
repository = "https://github.com/cafkafk/gg"

View file

@ -43,6 +43,7 @@ pub struct GitRepo {
pub path: String,
pub url: String,
pub clone: bool,
pub push: bool,
}
fn handle_file_exists(selff: &Links, tx_path: &Path, rx_path: &Path) {
@ -147,12 +148,16 @@ impl GitRepo {
}
/// Attempts to push the repository.
fn push(&self) {
let out = Command::new("git")
.current_dir(format!("{}{}", &self.path, &self.name))
.arg("push")
.status()
.unwrap_or_else(|_| panic!("git repo failed to push: {:?}", &self,));
info!("{out}");
if self.push {
let out = Command::new("git")
.current_dir(format!("{}{}", &self.path, &self.name))
.arg("push")
.status()
.unwrap_or_else(|_| panic!("git repo failed to push: {:?}", &self,));
info!("{out}");
} else {
info!("{} has clone set to false, not cloned", &self.name);
}
}
/// Removes repository
fn remove(&self) -> Result<(), std::io::Error> {

View file

@ -95,6 +95,7 @@ mod config {
path: "/tmp".to_string(),
url: "https://github.com/cafkafk/gg".to_string(),
clone: false,
push: false,
};
config.repos.push(repo);
}
@ -147,10 +148,12 @@ mod config {
assert_eq!(config.repos[0].path, "/home/ces/.dots/");
assert_eq!(config.repos[0].url, "git@github.com:cafkafk/gg.git");
assert_eq!(config.repos[0].clone, true);
assert_eq!(config.repos[0].push, true);
assert_eq!(config.repos[1].name, "li");
assert_eq!(config.repos[1].path, "/home/ces/org/src/git/");
assert_eq!(config.repos[1].url, "git@github.com:cafkafk/li.git");
assert_eq!(config.repos[1].clone, true);
assert_eq!(config.repos[1].push, true);
assert_eq!(config.repos[2].name, "qmk_firmware");
assert_eq!(config.repos[2].path, "/home/ces/org/src/git/");
assert_eq!(
@ -158,6 +161,7 @@ mod config {
"git@github.com:cafkafk/qmk_firmware.git"
);
assert_eq!(config.repos[2].clone, true);
assert_eq!(config.repos[2].push, true);
assert_eq!(config.repos[3].name, "starship");
assert_eq!(config.repos[3].path, "/home/ces/org/src/git/");
assert_eq!(
@ -165,6 +169,7 @@ mod config {
"https://github.com/starship/starship.git"
);
assert_eq!(config.repos[3].clone, true);
assert_eq!(config.repos[3].push, true);
}
{
assert_eq!(config.links[0].name, "gg");

View file

@ -3,18 +3,22 @@ repos:
path: /home/ces/.dots/
url: git@github.com:cafkafk/gg.git
clone: true
push: true
- name: li
path: /home/ces/org/src/git/
url: git@github.com:cafkafk/li.git
clone: true
push: true
- name: qmk_firmware
path: /home/ces/org/src/git/
url: git@github.com:cafkafk/qmk_firmware.git
clone: true
push: true
- name: starship
path: /home/ces/org/src/git/
url: https://github.com/starship/starship.git
clone: true
push: true
links:
- name: gg
rx: /home/ces/.config/gg

View file

@ -3,18 +3,22 @@ repos:
path: /home/ces/.dots/
url: git@github.com:cafkafk/gg.git
clone: true
push: true
- name: li
path: /home/ces/org/src/git/
url: git@github.com:cafkafk/li.git
clone: true
push: true
- name: qmk_firmware
path: /home/ces/org/src/git/
url: git@github.com:cafkafk/qmk_firmware.git
clone: true
push: true
- name: starship
path: /home/ces/org/src/git/
url: https://github.com/starship/starship.git
clone: true
push: true
links:
- name: gg
rx: /home/ces/.config/gg