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();
|
let mut net = MockNetwork::new();
|
||||||
//given
|
//given
|
||||||
given_forgejo_has_branches(&mut net, 1);
|
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 net = Network::from(net);
|
||||||
let (repo, _reality) = git::repository::mock();
|
let (repo, _reality) = git::repository::mock();
|
||||||
|
@ -35,6 +35,47 @@ mod branch {
|
||||||
assert_eq!(branches, vec![config::BranchName::new("string")]);
|
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) {
|
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);
|
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(
|
git::common::repo_details(
|
||||||
i,
|
i,
|
||||||
git::Generation::new(),
|
git::Generation::new(),
|
||||||
|
|
|
@ -133,6 +133,17 @@ impl OpenRepositoryLike for MockOpenRepository {
|
||||||
.map(|inner| inner.push(repo_details, branch_name, to_commit, force))
|
.map(|inner| inner.push(repo_details, branch_name, to_commit, force))
|
||||||
.unwrap()
|
.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 {
|
impl OpenRepositoryLike for InnerMockOpenRepository {
|
||||||
fn find_default_remote(&self, direction: Direction) -> Option<GitRemote> {
|
fn find_default_remote(&self, direction: Direction) -> Option<GitRemote> {
|
||||||
|
@ -155,4 +166,12 @@ impl OpenRepositoryLike for InnerMockOpenRepository {
|
||||||
) -> std::prelude::v1::Result<(), crate::push::Error> {
|
) -> std::prelude::v1::Result<(), crate::push::Error> {
|
||||||
todo!()
|
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 std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
use git_next_config::BranchName;
|
use crate as git;
|
||||||
|
use git::repository::open::oreal::RealOpenRepository;
|
||||||
use crate::{
|
use git::repository::Direction;
|
||||||
fetch, push,
|
use git_next_config as config;
|
||||||
repository::{mock::MockOpenRepository, open::oreal::RealOpenRepository, Direction},
|
|
||||||
GitRef, GitRemote, RepoDetails,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum OpenRepository {
|
pub enum OpenRepository {
|
||||||
Real(oreal::RealOpenRepository),
|
Real(RealOpenRepository),
|
||||||
Mock(MockOpenRepository), // TODO: (#38) contain a mock model of a repo
|
Mock(git::repository::mock::MockOpenRepository), // TODO: (#38) contain a mock model of a repo
|
||||||
}
|
}
|
||||||
impl OpenRepository {
|
impl OpenRepository {
|
||||||
pub fn real(gix_repo: gix::Repository) -> Self {
|
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
|
#[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)
|
Self::Mock(mock)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub trait OpenRepositoryLike {
|
pub trait OpenRepositoryLike {
|
||||||
fn find_default_remote(&self, direction: Direction) -> Option<GitRemote>;
|
fn find_default_remote(&self, direction: Direction) -> Option<git::GitRemote>;
|
||||||
fn fetch(&self) -> Result<(), fetch::Error>;
|
fn fetch(&self) -> Result<(), git::fetch::Error>;
|
||||||
fn push(
|
fn push(
|
||||||
&self,
|
&self,
|
||||||
repo_details: &RepoDetails,
|
repo_details: &git::RepoDetails,
|
||||||
branch_name: BranchName,
|
branch_name: config::BranchName,
|
||||||
to_commit: GitRef,
|
to_commit: git::GitRef,
|
||||||
force: push::Force,
|
force: git::push::Force,
|
||||||
) -> Result<(), push::Error>;
|
) -> 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 {
|
impl std::ops::Deref for OpenRepository {
|
||||||
type Target = dyn OpenRepositoryLike;
|
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 {
|
impl From<&gix::Url> for GitRemote {
|
||||||
|
|
Loading…
Reference in a new issue