From 5187afd28901151493eb437361d4328435375b0c Mon Sep 17 00:00:00 2001 From: n0m1s Date: Fri, 28 Sep 2018 15:01:30 +0200 Subject: [PATCH] :recycle: clone only if cannot open repository --- src/main.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index d89cb71..7a8899d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,10 +21,10 @@ fn gitmoji_path() -> PathBuf { fn main() { let url = "https://github.com/carloscuesta/gitmoji/"; - let mut gitmoji_dir = gitmoji_path(); - - let repo = match Repository::clone(url, gitmoji_dir) { - Ok(repo) => repo, - Err(e) => panic!("failed to clone: {}", e), + let repo_dir = gitmoji_path(); + let repo = match Repository::open(&repo_dir) { + Ok(r) => Ok(r), + Err(_) => Repository::clone(url, &repo_dir), //TODO check error kind }; + repo.expect(&format!("error opening repository {}", repo_dir.to_str().expect("path error"))); }