From af089952c8cc4c0eb8c873a92fe654a11d0da043 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 16 Jul 2016 16:26:16 +0200 Subject: [PATCH] Add Repository instantiation --- libimagstorestdhook/src/vcs/git/create.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libimagstorestdhook/src/vcs/git/create.rs b/libimagstorestdhook/src/vcs/git/create.rs index 88817434..887c2f0c 100644 --- a/libimagstorestdhook/src/vcs/git/create.rs +++ b/libimagstorestdhook/src/vcs/git/create.rs @@ -2,6 +2,7 @@ use std::path::PathBuf; use std::fmt::{Debug, Formatter, Error as FmtError}; use toml::Value; +use git2::{Repository, Error as Git2Error}; use libimagstore::storeid::StoreId; use libimagstore::hook::Hook; @@ -9,10 +10,13 @@ use libimagstore::hook::result::HookResult; use libimagstore::hook::position::HookPosition; use libimagstore::hook::accessor::{HookDataAccessor, HookDataAccessorProvider}; use libimagstore::hook::accessor::StoreIdAccessor; +use libimagerror::trace::trace_error; pub struct CreateHook<'a> { storepath: &'a PathBuf, + repository: Option, + position: HookPosition, config: Option, } @@ -20,8 +24,16 @@ pub struct CreateHook<'a> { impl<'a> CreateHook<'a> { pub fn new(storepath: &'a PathBuf, p: HookPosition) -> CreateHook<'a> { + let r = match Repository::open(storepath) { + Ok(r) => Some(r), + Err(e) => { + trace_error(&e); + None + }, + }; CreateHook { storepath: storepath, + repository: r, position: p, config: None, }