imag/libimagstorestdhook/src/vcs/git/util.rs

29 lines
732 B
Rust
Raw Normal View History

2016-05-14 22:21:26 +00:00
//! Utility functionality for integrating git hooks in the store
//!
//! Contains primitives to create a repository within the store path
2016-05-14 22:35:09 +00:00
use git2::Repository;
2016-07-16 09:49:19 +00:00
use git2::RepositoryInitOptions;
use libimagstore::store::Store;
2016-05-14 22:35:09 +00:00
use vcs::git::error::GitHookErrorKind as GHEK;
use vcs::git::error::MapErrInto;
2016-07-16 09:49:19 +00:00
use vcs::git::result::Result;
2016-05-14 22:35:09 +00:00
2016-05-14 22:21:26 +00:00
pub fn mkrepo(store: &Store) -> Result<()> {
2016-05-14 22:35:09 +00:00
let mut opts = RepositoryInitOptions::new();
opts.bare(false);
opts.no_reinit(true);
opts.mkdir(false);
opts.external_template(false);
Repository::init_opts(store.path(), &opts)
.map(|_| ())
.map_err_into(GHEK::MkRepo)
2016-05-14 22:21:26 +00:00
}
pub fn hasrepo(store: &Store) -> bool {
Repository::open(store.path()).is_ok()
}