From a2f86770d1bcb64c9c35b69fae427879293956c4 Mon Sep 17 00:00:00 2001 From: Thom Dickson Date: Thu, 16 Dec 2021 21:12:30 -0500 Subject: [PATCH] Don't add repo if it's already tracked --- src/config.rs | 2 +- src/lib.rs | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/config.rs b/src/config.rs index fc8a4e9..527c0d4 100644 --- a/src/config.rs +++ b/src/config.rs @@ -13,7 +13,7 @@ pub struct Config { pub repositories: Vec, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Eq, PartialEq, Serialize, Deserialize)] /// The internal representation of a single repository pub struct Repository { name: String, diff --git a/src/lib.rs b/src/lib.rs index bc0d0ae..3349ec0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -116,11 +116,17 @@ pub fn run(state: State, mut config: Config) -> Result<(), Box> { println!("{}", config.to_string().unwrap()); } Some(Cmd::Add) => { - config.repositories.push(Repository::new(match state.url { + let repo = Repository::new(match state.url { Some(x) => x, None => String::new(), - })); - config.save_config()?; + }); + if let None = config.repositories.iter().find(|x| **x == repo) { + config.repositories.push(repo); + config.save_config()?; + println!("Repository has been added"); + } else { + println!("Repository is already being tracked"); + } } Some(x) => { println!("{:?} hasn't been implemented yet!", x)