WIP: refactor: get commit log from local repo
Avoid using a forge-specific API to get a commit log when the information is already available locally in the cloned repo through a generic git command.
This commit is contained in:
parent
7818b25a5c
commit
22a0b401c0
4 changed files with 94 additions and 20 deletions
|
@ -20,7 +20,7 @@ mod branch {
|
|||
let mut net = MockNetwork::new();
|
||||
//given
|
||||
given_forgejo_has_branches(&mut net, 1);
|
||||
let repo_details = given_a_repo(fs.base(), 1);
|
||||
let repo_details = given_repo_details(fs.base(), 1);
|
||||
|
||||
let net = Network::from(net);
|
||||
let (repo, _reality) = git::repository::mock();
|
||||
|
@ -35,6 +35,47 @@ mod branch {
|
|||
assert_eq!(branches, vec![config::BranchName::new("string")]);
|
||||
}
|
||||
}
|
||||
// mod validate_positions {
|
||||
//
|
||||
// use git::ForgeLike;
|
||||
//
|
||||
// use super::*;
|
||||
//
|
||||
// #[test]
|
||||
// fn should_ok_all_branches_on_same_commit() {
|
||||
// let_assert!(Ok(fs) = kxio::fs::temp());
|
||||
// let mut net = MockNetwork::new();
|
||||
// //given
|
||||
// let repo_details = given_repo_details(fs.base(), 1);
|
||||
// let net = Network::from(net);
|
||||
// let (repo, _reality) = git::repository::mock();
|
||||
// let forge = given_a_forge(repo_details, &net, repo);
|
||||
// let open_repository = given_an_open_repository();
|
||||
// let repo_config = given_a_repo_config();
|
||||
//
|
||||
// let forge = forgejo::ForgeJo::new(repo_details, net.clone(), repo);
|
||||
//
|
||||
// let_assert!(
|
||||
// Ok(positions) = forge
|
||||
// .branches_validate_positions(open_repository, repo_config)
|
||||
// .await
|
||||
// );
|
||||
// }
|
||||
//
|
||||
// fn given_a_forge(
|
||||
// repo_details: git::RepoDetails,
|
||||
// net: &Network,
|
||||
// repo: git::Repository,
|
||||
// ) -> forgejo::ForgeJo {
|
||||
// forgejo::ForgeJo::new(repo_details, net.clone(), repo)
|
||||
// }
|
||||
// fn given_an_open_repository() -> git::OpenRepository {
|
||||
// todo!()
|
||||
// }
|
||||
// fn given_a_repo_config() -> config::RepoConfig {
|
||||
// todo!()
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
fn given_forgejo_has_branches(net: &mut MockNetwork, i: u32) {
|
||||
|
@ -48,7 +89,7 @@ fn given_forgejo_has_branches(net: &mut MockNetwork, i: u32) {
|
|||
net.add_get_response(&url, StatusCode::OK, body);
|
||||
}
|
||||
|
||||
fn given_a_repo(path: &Path, i: u32) -> git::RepoDetails {
|
||||
fn given_repo_details(path: &Path, i: u32) -> git::RepoDetails {
|
||||
git::common::repo_details(
|
||||
i,
|
||||
git::Generation::new(),
|
||||
|
|
|
@ -133,6 +133,17 @@ impl OpenRepositoryLike for MockOpenRepository {
|
|||
.map(|inner| inner.push(repo_details, branch_name, to_commit, force))
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
fn commit_log(
|
||||
&self,
|
||||
branch_name: git_next_config::BranchName,
|
||||
find_commits: Vec<crate::Commit>,
|
||||
) -> Vec<crate::Commit> {
|
||||
self.inner
|
||||
.lock()
|
||||
.map(|inner| inner.commit_log(branch_name, find_commits))
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
impl OpenRepositoryLike for InnerMockOpenRepository {
|
||||
fn find_default_remote(&self, direction: Direction) -> Option<GitRemote> {
|
||||
|
@ -155,4 +166,12 @@ impl OpenRepositoryLike for InnerMockOpenRepository {
|
|||
) -> std::prelude::v1::Result<(), crate::push::Error> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn commit_log(
|
||||
&self,
|
||||
branch_name: git_next_config::BranchName,
|
||||
find_commits: Vec<crate::Commit>,
|
||||
) -> Vec<crate::Commit> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,38 +6,44 @@ pub mod oreal;
|
|||
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use git_next_config::BranchName;
|
||||
|
||||
use crate::{
|
||||
fetch, push,
|
||||
repository::{mock::MockOpenRepository, open::oreal::RealOpenRepository, Direction},
|
||||
GitRef, GitRemote, RepoDetails,
|
||||
};
|
||||
use crate as git;
|
||||
use git::repository::open::oreal::RealOpenRepository;
|
||||
use git::repository::Direction;
|
||||
use git_next_config as config;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum OpenRepository {
|
||||
Real(oreal::RealOpenRepository),
|
||||
Mock(MockOpenRepository), // TODO: (#38) contain a mock model of a repo
|
||||
Real(RealOpenRepository),
|
||||
Mock(git::repository::mock::MockOpenRepository), // TODO: (#38) contain a mock model of a repo
|
||||
}
|
||||
impl OpenRepository {
|
||||
pub fn real(gix_repo: gix::Repository) -> Self {
|
||||
Self::Real(RealOpenRepository::new(Arc::new(Mutex::new(gix_repo))))
|
||||
Self::Real(oreal::RealOpenRepository::new(Arc::new(Mutex::new(
|
||||
gix_repo,
|
||||
))))
|
||||
}
|
||||
#[cfg(not(tarpaulin_include))] // don't test mocks
|
||||
pub const fn mock(mock: MockOpenRepository) -> Self {
|
||||
pub const fn mock(mock: git::repository::mock::MockOpenRepository) -> Self {
|
||||
Self::Mock(mock)
|
||||
}
|
||||
}
|
||||
pub trait OpenRepositoryLike {
|
||||
fn find_default_remote(&self, direction: Direction) -> Option<GitRemote>;
|
||||
fn fetch(&self) -> Result<(), fetch::Error>;
|
||||
fn find_default_remote(&self, direction: Direction) -> Option<git::GitRemote>;
|
||||
fn fetch(&self) -> Result<(), git::fetch::Error>;
|
||||
fn push(
|
||||
&self,
|
||||
repo_details: &RepoDetails,
|
||||
branch_name: BranchName,
|
||||
to_commit: GitRef,
|
||||
force: push::Force,
|
||||
) -> Result<(), push::Error>;
|
||||
repo_details: &git::RepoDetails,
|
||||
branch_name: config::BranchName,
|
||||
to_commit: git::GitRef,
|
||||
force: git::push::Force,
|
||||
) -> Result<(), git::push::Error>;
|
||||
|
||||
/// List of commits in a branch, optionally up-to any specified commit.
|
||||
fn commit_log(
|
||||
&self,
|
||||
branch_name: config::BranchName,
|
||||
find_commits: Vec<git::Commit>,
|
||||
) -> Vec<git::Commit>;
|
||||
}
|
||||
impl std::ops::Deref for OpenRepository {
|
||||
type Target = dyn OpenRepositoryLike;
|
||||
|
|
|
@ -100,6 +100,14 @@ impl super::OpenRepositoryLike for RealOpenRepository {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn commit_log(
|
||||
&self,
|
||||
branch_name: git_next_config::BranchName,
|
||||
find_commits: Vec<crate::Commit>,
|
||||
) -> Vec<crate::Commit> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&gix::Url> for GitRemote {
|
||||
|
|
Loading…
Reference in a new issue