git_next_core/config/
server_repo_config.rs1use std::path::PathBuf;
3
4use crate::{
5 config::{
6 git_dir::StoragePathType, BranchName, GitDir, RepoBranches, RepoConfig, RepoConfigSource,
7 RepoPath,
8 },
9 s,
10};
11
12#[derive(
15 Clone,
16 Debug,
17 derive_more::From,
18 PartialEq,
19 Eq,
20 PartialOrd,
21 Ord,
22 serde::Deserialize,
23 derive_more::Display,
24 derive_more::Constructor,
25)]
26#[display("{}@{}", repo, branch)]
27pub struct ServerRepoConfig {
28 repo: String,
29 branch: String,
30 gitdir: Option<PathBuf>,
31 main: Option<String>,
32 next: Option<String>,
33 dev: Option<String>,
34}
35impl ServerRepoConfig {
36 pub(crate) fn repo(&self) -> RepoPath {
37 RepoPath::new(self.repo.clone())
38 }
39
40 pub(crate) fn branch(&self) -> BranchName {
41 BranchName::new(&self.branch)
42 }
43
44 #[must_use]
45 pub fn gitdir(&self) -> Option<GitDir> {
46 self.gitdir
47 .clone()
48 .map(|dir| GitDir::new(dir, StoragePathType::External))
50 }
51
52 #[must_use]
54 pub fn repo_config(&self) -> Option<RepoConfig> {
55 match (&self.main, &self.next, &self.dev) {
56 (Some(main), Some(next), Some(dev)) => Some(RepoConfig::new(
57 RepoBranches::new(s!(main), s!(next), s!(dev)),
58 RepoConfigSource::Server,
59 )),
60 _ => None,
61 }
62 }
63}