From 720b9b0de1485bc56171780e364ac8cd7b510f0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christina=20S=C3=B8rensen?= Date: Thu, 22 Jun 2023 14:58:13 +0200 Subject: [PATCH] fix: remove potentially destructive operaton MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commented out code that could potentially be destructive, right now it's only a sketch, and if the unimplemented macro was removed one might be mistaken thinking the associated function was intended for use. Signed-off-by: Christina Sørensen --- src/git.rs | 56 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/src/git.rs b/src/git.rs index 5bf9c6e..37e222d 100644 --- a/src/git.rs +++ b/src/git.rs @@ -117,34 +117,46 @@ impl GitRepo { } /// Adds all files in the repository. fn add_all(&self) { - let out = Command::new("git") - .current_dir(format!("{}{}", &self.path, &self.name)) - .arg("add") - .arg(".") - .status() - .unwrap_or_else(|_| panic!("git repo failed to add: {:?}", &self,)); - info!("{out}"); + if self.push { + let out = Command::new("git") + .current_dir(format!("{}{}", &self.path, &self.name)) + .arg("add") + .arg(".") + .status() + .unwrap_or_else(|_| panic!("git repo failed to add: {:?}", &self,)); + info!("{out}"); + } else { + info!("{} has clone set to false, not cloned", &self.name); + } } /// Tries to commit changes in the repository. #[allow(dead_code)] fn commit(&self) { - let out = Command::new("git") - .current_dir(format!("{}{}", &self.path, &self.name)) - .arg("commit") - .status() - .unwrap_or_else(|_| panic!("git repo failed to commit: {:?}", &self,)); - info!("{out}"); + if self.push { + let out = Command::new("git") + .current_dir(format!("{}{}", &self.path, &self.name)) + .arg("commit") + .status() + .unwrap_or_else(|_| panic!("git repo failed to commit: {:?}", &self,)); + info!("{out}"); + } else { + info!("{} has clone set to false, not cloned", &self.name); + } } /// Tries to commit changes with a message argument. fn commit_with_msg(&self, msg: &String) { - let out = Command::new("git") - .current_dir(format!("{}{}", &self.path, &self.name)) - .arg("commit") - .arg("-m") - .arg(msg) - .status() - .unwrap_or_else(|_| panic!("git repo failed to commit: {:?}", &self,)); - info!("{out}"); + if self.push { + let out = Command::new("git") + .current_dir(format!("{}{}", &self.path, &self.name)) + .arg("commit") + .arg("-m") + .arg(msg) + .status() + .unwrap_or_else(|_| panic!("git repo failed to commit: {:?}", &self,)); + info!("{out}"); + } else { + info!("{} has clone set to false, not cloned", &self.name); + } } /// Attempts to push the repository. fn push(&self) { @@ -163,7 +175,7 @@ impl GitRepo { fn remove(&self) -> Result<(), std::io::Error> { // https://doc.rust-lang.org/std/fs/fn.remove_dir_all.html unimplemented!("This seems to easy to missuse/exploit"); - fs::remove_dir_all(format!("{}{}", &self.path, &self.name)) + // fs::remove_dir_all(format!("{}{}", &self.path, &self.name)) } }