From 417938473875ee4208845da781309129e5ca42a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christina=20S=C3=B8rensen?= Date: Thu, 22 Jun 2023 14:29:32 +0200 Subject: [PATCH] feat(git)!: add push field MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding the push field to git repos, allowing to block gg attempting to push Signed-off-by: Christina Sørensen --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/git.rs | 17 +++++++++++------ src/main.rs | 5 +++++ src/test/config.yaml | 4 ++++ src/test/test.yaml | 4 ++++ 6 files changed, 26 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a4ce6d9..e1bacac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -190,7 +190,7 @@ dependencies = [ [[package]] name = "gg" -version = "0.0.2" +version = "0.0.3" dependencies = [ "clap", "clap_mangen", diff --git a/Cargo.toml b/Cargo.toml index 18ebf16..70847c1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "gg" -version = "0.0.3" +version = "0.0.4" edition = "2021" authors = ["Christina Sørensen "] repository = "https://github.com/cafkafk/gg" diff --git a/src/git.rs b/src/git.rs index 2569826..5bf9c6e 100644 --- a/src/git.rs +++ b/src/git.rs @@ -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> { diff --git a/src/main.rs b/src/main.rs index 99f3551..e725ce3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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"); diff --git a/src/test/config.yaml b/src/test/config.yaml index 9a216c0..cacfacc 100644 --- a/src/test/config.yaml +++ b/src/test/config.yaml @@ -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 diff --git a/src/test/test.yaml b/src/test/test.yaml index 529690e..427ed13 100644 --- a/src/test/test.yaml +++ b/src/test/test.yaml @@ -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