From e6f597e08bd6feec8c5461eb6ffab6ff46030307 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christina=20S=C3=B8rensen?= Date: Sun, 2 Jul 2023 10:52:23 +0200 Subject: [PATCH] feat(git): add Commit, Add flags MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This also fixes behaviour of all flags. Signed-off-by: Christina Sørensen --- doc/roadmap.org | 2 +- src/git.rs | 14 +++++++++----- src/test/test.yaml | 40 ++++++++++++++++++++-------------------- 3 files changed, 30 insertions(+), 26 deletions(-) diff --git a/doc/roadmap.org b/doc/roadmap.org index 8b6665a..8126d17 100644 --- a/doc/roadmap.org +++ b/doc/roadmap.org @@ -9,7 +9,7 @@ - [X] No functionality regressions - [X] commit works in quick, fast - [X] commit with edit works -- [ ] Repo Flags Finished +- [-] Repo Flags Finished - [ ] Category Flags Finished - [ ] Optional Fields - [ ] Subcommands diff --git a/src/git.rs b/src/git.rs index 4bb0e65..ae3c35f 100644 --- a/src/git.rs +++ b/src/git.rs @@ -28,12 +28,16 @@ use std::{fs, process::Command}; /// An enum containing flags that change behaviour of repos and categories #[derive(PartialOrd, Ord, PartialEq, Eq, Serialize, Deserialize, Debug)] pub enum RepoFlags { - /// If push is set, the repository should respond to the push subcommand - Push, /// If clone is set, the repository should respond to the clone subcommand Clone, /// If pull is set, the repository should respond to the pull subcommand Pull, + /// If add is set, the repository should respond to the add subcommand + Add, + /// If commit is set, the repository should respond to the commit subcommand + Commit, + /// If push is set, the repository should respond to the push subcommand + Push, } /// Represents the config.toml file. @@ -174,7 +178,7 @@ impl GitRepo { } /// Adds all files in the repository. fn add_all(&self) -> bool { - if self.flags.contains(&RepoFlags::Push) { + if self.flags.contains(&RepoFlags::Add) { let output = Command::new("git") .current_dir(format!("{}{}", &self.path, &self.name)) .arg("add") @@ -196,7 +200,7 @@ impl GitRepo { /// easy #[allow(dead_code)] fn commit(&self) -> bool { - if self.flags.contains(&RepoFlags::Push) { + if self.flags.contains(&RepoFlags::Commit) { let status = Command::new("git") .current_dir(format!("{}{}", &self.path, &self.name)) .arg("commit") @@ -210,7 +214,7 @@ impl GitRepo { } /// Tries to commit changes with a message argument. fn commit_with_msg(&self, msg: &str) -> bool { - if self.flags.contains(&RepoFlags::Push) { + if self.flags.contains(&RepoFlags::Commit) { let output = Command::new("git") .current_dir(format!("{}{}", &self.path, &self.name)) .arg("commit") diff --git a/src/test/test.yaml b/src/test/test.yaml index ca79c57..47a5899 100644 --- a/src/test/test.yaml +++ b/src/test/test.yaml @@ -1,24 +1,14 @@ categories: - utils: - flags: [] - repos: - li: - name: li - path: /home/ces/org/src/git/ - url: git@github.com:cafkafk/li.git - flags: - - Clone - - Push - gg: - name: gg - path: /home/ces/.dots/ - url: git@github.com:cafkafk/gg.git - flags: - - Clone - - Push config: flags: [] repos: + starship: + name: starship + path: /home/ces/org/src/git/ + url: https://github.com/starship/starship.git + flags: + - Clone + - Push qmk_firmware: name: qmk_firmware path: /home/ces/org/src/git/ @@ -26,10 +16,20 @@ categories: flags: - Clone - Push - starship: - name: starship + utils: + flags: [] + repos: + gg: + name: gg + path: /home/ces/.dots/ + url: git@github.com:cafkafk/gg.git + flags: + - Clone + - Push + li: + name: li path: /home/ces/org/src/git/ - url: https://github.com/starship/starship.git + url: git@github.com:cafkafk/li.git flags: - Clone - Push