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

25 lines
636 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;
use vcs::git::error::GitHookErrorKind as GHEK;
use vcs::git::error::MapErrInto;
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()
}