use std::path::PathBuf;
use crate::config::{
git_dir::StoragePathType, BranchName, GitDir, RepoBranches, RepoConfig, RepoConfigSource,
RepoPath,
};
#[derive(
Clone,
Debug,
derive_more::From,
PartialEq,
Eq,
PartialOrd,
Ord,
serde::Deserialize,
derive_more::Display,
derive_more::Constructor,
)]
#[display("{}@{}", repo, branch)]
pub struct ServerRepoConfig {
repo: String,
branch: String,
gitdir: Option<PathBuf>,
main: Option<String>,
next: Option<String>,
dev: Option<String>,
}
impl ServerRepoConfig {
pub(crate) fn repo(&self) -> RepoPath {
RepoPath::new(self.repo.clone())
}
pub(crate) fn branch(&self) -> BranchName {
BranchName::new(&self.branch)
}
#[must_use]
pub fn gitdir(&self) -> Option<GitDir> {
self.gitdir
.clone()
.map(|dir| GitDir::new(dir, StoragePathType::External))
}
pub(crate) fn repo_config(&self) -> Option<RepoConfig> {
match (&self.main, &self.next, &self.dev) {
(Some(main), Some(next), Some(dev)) => Some(RepoConfig::new(
RepoBranches::new(main.to_string(), next.to_string(), dev.to_string()),
RepoConfigSource::Server,
)),
_ => None,
}
}
}