use chrono::prelude::*;
use color_eyre::eyre::Report;
use git2::Repository;
use hex::ToHex;
#[doc(hidden)]
pub mod clone;
#[doc(hidden)]
pub mod info;
#[doc(hidden)]
pub mod types;
#[doc(hidden)]
pub mod repo;
#[doc(inline)]
pub use crate::types::*;
impl GitCommitMeta {
pub fn new<I: ToHex + AsRef<[u8]>>(id: I) -> GitCommitMeta {
GitCommitMeta {
id: hex::encode(id),
message: None,
timestamp: None,
}
}
pub fn with_timestamp(mut self, time: i64) -> Self {
let naive_datetime = NaiveDateTime::from_timestamp(time, 0);
let datetime: DateTime<Utc> = DateTime::from_utc(naive_datetime, Utc);
self.timestamp = Some(datetime);
self
}
pub fn with_message(mut self, msg: Option<String>) -> Self {
self.message = msg;
self
}
}
impl TryFrom<Repository> for GitRepo {
type Error = Report;
fn try_from(repo: Repository) -> Result<Self, Self::Error> {
GitRepo::open(repo.path().to_path_buf(), None, None)
}
}
impl From<&GitRepoInfo> for GitRepo {
fn from(repo: &GitRepoInfo) -> Self {
Self {
url: repo.url.clone(),
head: repo.head.clone(),
credentials: repo.credentials.clone(),
branch: repo.branch.clone(),
path: repo.path.clone(),
}
}
}
impl From<&GitRepoCloneRequest> for GitRepo {
fn from(repo: &GitRepoCloneRequest) -> Self {
Self {
url: repo.url.clone(),
head: repo.head.clone(),
credentials: repo.credentials.clone(),
branch: repo.branch.clone(),
path: repo.path.clone(),
}
}
}
impl From<GitRepo> for GitRepoCloneRequest {
fn from(repo: GitRepo) -> Self {
Self {
url: repo.url.clone(),
head: repo.head.clone(),
credentials: repo.credentials.clone(),
branch: repo.branch.clone(),
path: repo.path,
}
}
}
impl From<&GitRepo> for GitRepoCloneRequest {
fn from(repo: &GitRepo) -> Self {
Self {
url: repo.url.clone(),
head: repo.head.clone(),
credentials: repo.credentials.clone(),
branch: repo.branch.clone(),
path: repo.path.clone(),
}
}
}
impl From<&GitRepo> for GitRepoInfo {
fn from(repo: &GitRepo) -> Self {
Self {
url: repo.url.clone(),
head: repo.head.clone(),
credentials: repo.credentials.clone(),
branch: repo.branch.clone(),
path: repo.path.clone(),
}
}
}
impl From<&GitRepoInfo> for GitRepoCloneRequest {
fn from(repo: &GitRepoInfo) -> Self {
Self {
url: repo.url.clone(),
head: repo.head.clone(),
credentials: repo.credentials.clone(),
branch: repo.branch.clone(),
path: repo.path.clone(),
}
}
}
impl From<&GitRepoCloneRequest> for GitRepoInfo {
fn from(repo: &GitRepoCloneRequest) -> Self {
Self {
url: repo.url.clone(),
head: repo.head.clone(),
credentials: repo.credentials.clone(),
branch: repo.branch.clone(),
path: repo.path.clone(),
}
}
}