Compare commits
2 commits
8ce4528c88
...
2cdaf39c0f
Author | SHA1 | Date | |
---|---|---|---|
2cdaf39c0f | |||
b9940cd205 |
11 changed files with 46 additions and 38 deletions
|
@ -777,7 +777,7 @@ mod forgejo {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn repo_details(fs: &kxio::fs::FileSystem) -> git::RepoDetails {
|
pub fn repo_details(fs: &kxio::fs::FileSystem) -> git::RepoDetails {
|
||||||
let generation = git::Generation::new();
|
let generation = git::Generation::default();
|
||||||
let repo_alias = a_repo_alias();
|
let repo_alias = a_repo_alias();
|
||||||
let server_repo_config = a_server_repo_config();
|
let server_repo_config = a_server_repo_config();
|
||||||
let forge_alias = a_forge_alias();
|
let forge_alias = a_forge_alias();
|
||||||
|
|
|
@ -636,7 +636,7 @@ mod github {
|
||||||
}
|
}
|
||||||
pub fn repo_details() -> git::RepoDetails {
|
pub fn repo_details() -> git::RepoDetails {
|
||||||
git::RepoDetails::new(
|
git::RepoDetails::new(
|
||||||
git::Generation::new(),
|
git::Generation::default(),
|
||||||
&a_repo_alias(),
|
&a_repo_alias(),
|
||||||
&ServerRepoConfig::new(
|
&ServerRepoConfig::new(
|
||||||
format!("{}/{}", a_name(), a_name()), // repo path: owner/repo
|
format!("{}/{}", a_name(), a_name()), // repo path: owner/repo
|
||||||
|
|
|
@ -30,7 +30,7 @@ fn test_github_name() {
|
||||||
|
|
||||||
fn given_fs() -> kxio::fs::FileSystem {
|
fn given_fs() -> kxio::fs::FileSystem {
|
||||||
kxio::fs::temp().unwrap_or_else(|e| {
|
kxio::fs::temp().unwrap_or_else(|e| {
|
||||||
eprintln!("{e}");
|
println!("{e}");
|
||||||
panic!("fs")
|
panic!("fs")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ fn given_repo_details(forge_type: config::ForgeType) -> RepoDetails {
|
||||||
let fs = given_fs();
|
let fs = given_fs();
|
||||||
git::common::repo_details(
|
git::common::repo_details(
|
||||||
1,
|
1,
|
||||||
git::Generation::new(),
|
git::Generation::default(),
|
||||||
config::common::forge_details(1, forge_type),
|
config::common::forge_details(1, forge_type),
|
||||||
Some(config::common::repo_config(
|
Some(config::common::repo_config(
|
||||||
1,
|
1,
|
||||||
|
|
|
@ -1,7 +1,19 @@
|
||||||
|
use config::newtype;
|
||||||
|
use derive_more::Display;
|
||||||
//
|
//
|
||||||
use git_next_config as config;
|
use git_next_config as config;
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, derive_more::Constructor, derive_more::Display)]
|
#[derive(
|
||||||
|
Clone,
|
||||||
|
Debug,
|
||||||
|
Hash,
|
||||||
|
PartialEq,
|
||||||
|
Eq,
|
||||||
|
PartialOrd,
|
||||||
|
Ord,
|
||||||
|
derive_more::Constructor,
|
||||||
|
derive_more::Display,
|
||||||
|
)]
|
||||||
#[display("{}", sha)]
|
#[display("{}", sha)]
|
||||||
pub struct Commit {
|
pub struct Commit {
|
||||||
sha: Sha,
|
sha: Sha,
|
||||||
|
@ -25,11 +37,8 @@ impl From<config::webhook::Push> for Commit {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, derive_more::Constructor, derive_more::Display)]
|
newtype!(Sha is a String, Display);
|
||||||
pub struct Sha(String);
|
newtype!(Message is a String);
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, derive_more::Constructor, derive_more::Display)]
|
|
||||||
pub struct Message(String);
|
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Histories {
|
pub struct Histories {
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
#[derive(Copy, Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord, derive_more::Display)]
|
use derive_more::Display;
|
||||||
pub struct Generation(u32);
|
use git_next_config::newtype;
|
||||||
|
|
||||||
|
newtype!(Generation is a u32, Display, Default, Copy);
|
||||||
impl Generation {
|
impl Generation {
|
||||||
pub fn new() -> Self {
|
|
||||||
Self::default()
|
|
||||||
}
|
|
||||||
pub fn inc(&mut self) {
|
pub fn inc(&mut self) {
|
||||||
self.0 += 1
|
self.0 += 1
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
//
|
//
|
||||||
use crate as git;
|
use crate as git;
|
||||||
use derive_more::Constructor;
|
use derive_more::Display;
|
||||||
|
use git_next_config::newtype;
|
||||||
|
|
||||||
use crate::Commit;
|
use crate::Commit;
|
||||||
|
|
||||||
#[derive(Clone, Constructor, Debug, Hash, PartialEq, Eq, derive_more::Display)]
|
newtype!(GitRef is a String, Display);
|
||||||
pub struct GitRef(String);
|
|
||||||
impl From<Commit> for GitRef {
|
impl From<Commit> for GitRef {
|
||||||
fn from(value: Commit) -> Self {
|
fn from(value: Commit) -> Self {
|
||||||
Self(value.sha().to_string())
|
Self(value.sha().to_string())
|
||||||
|
|
|
@ -82,7 +82,7 @@ impl git::repository::OpenRepositoryLike for TestOpenRepository {
|
||||||
.read()
|
.read()
|
||||||
.map_err(|_| git::fetch::Error::Lock)?
|
.map_err(|_| git::fetch::Error::Lock)?
|
||||||
.deref();
|
.deref();
|
||||||
eprintln!("Fetch: {i}");
|
println!("Fetch: {i}");
|
||||||
self.fetch_counter
|
self.fetch_counter
|
||||||
.write()
|
.write()
|
||||||
.map_err(|_| git::fetch::Error::Lock)
|
.map_err(|_| git::fetch::Error::Lock)
|
||||||
|
@ -104,7 +104,7 @@ impl git::repository::OpenRepositoryLike for TestOpenRepository {
|
||||||
.read()
|
.read()
|
||||||
.map_err(|_| git::fetch::Error::Lock)?
|
.map_err(|_| git::fetch::Error::Lock)?
|
||||||
.deref();
|
.deref();
|
||||||
eprintln!("Push: {i}");
|
println!("Push: {i}");
|
||||||
self.push_counter
|
self.push_counter
|
||||||
.write()
|
.write()
|
||||||
.map_err(|_| git::fetch::Error::Lock)
|
.map_err(|_| git::fetch::Error::Lock)
|
||||||
|
|
|
@ -40,7 +40,7 @@ mod generation {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn should_increment() {
|
fn should_increment() {
|
||||||
let mut g = Generation::new();
|
let mut g = Generation::default();
|
||||||
assert_eq!(g.to_string(), "0");
|
assert_eq!(g.to_string(), "0");
|
||||||
|
|
||||||
g.inc();
|
g.inc();
|
||||||
|
@ -153,7 +153,7 @@ mod repo_details {
|
||||||
#[test]
|
#[test]
|
||||||
fn should_return_origin() {
|
fn should_return_origin() {
|
||||||
let rd = RepoDetails::new(
|
let rd = RepoDetails::new(
|
||||||
Generation::new(),
|
Generation::default(),
|
||||||
&RepoAlias::new("foo"),
|
&RepoAlias::new("foo"),
|
||||||
&ServerRepoConfig::new(
|
&ServerRepoConfig::new(
|
||||||
"repo".to_string(),
|
"repo".to_string(),
|
||||||
|
@ -182,7 +182,7 @@ mod repo_details {
|
||||||
#[test]
|
#[test]
|
||||||
fn should_return_git_remote() {
|
fn should_return_git_remote() {
|
||||||
let rd = RepoDetails::new(
|
let rd = RepoDetails::new(
|
||||||
Generation::new(),
|
Generation::default(),
|
||||||
&RepoAlias::new("foo"),
|
&RepoAlias::new("foo"),
|
||||||
&ServerRepoConfig::new(
|
&ServerRepoConfig::new(
|
||||||
"user/repo".to_string(),
|
"user/repo".to_string(),
|
||||||
|
@ -327,7 +327,7 @@ pub mod given {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn repo_details(fs: &kxio::fs::FileSystem) -> git::RepoDetails {
|
pub fn repo_details(fs: &kxio::fs::FileSystem) -> git::RepoDetails {
|
||||||
let generation = git::Generation::new();
|
let generation = git::Generation::default();
|
||||||
let repo_alias = a_repo_alias();
|
let repo_alias = a_repo_alias();
|
||||||
let server_repo_config = a_server_repo_config();
|
let server_repo_config = a_server_repo_config();
|
||||||
let forge_alias = a_forge_alias();
|
let forge_alias = a_forge_alias();
|
||||||
|
@ -450,22 +450,22 @@ pub mod then {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exec(label: String, output: Result<std::process::Output, std::io::Error>) -> TestResult {
|
fn exec(label: String, output: Result<std::process::Output, std::io::Error>) -> TestResult {
|
||||||
eprintln!("== {label}");
|
println!("== {label}");
|
||||||
match output {
|
match output {
|
||||||
Ok(output) => {
|
Ok(output) => {
|
||||||
eprintln!(
|
println!(
|
||||||
"\nstdout:\n{}",
|
"\nstdout:\n{}",
|
||||||
String::from_utf8_lossy(output.stdout.as_slice())
|
String::from_utf8_lossy(output.stdout.as_slice())
|
||||||
);
|
);
|
||||||
eprintln!(
|
println!(
|
||||||
"\nstderr:\n{}",
|
"\nstderr:\n{}",
|
||||||
String::from_utf8_lossy(output.stderr.as_slice())
|
String::from_utf8_lossy(output.stderr.as_slice())
|
||||||
);
|
);
|
||||||
eprintln!("=============================");
|
println!("=============================");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("ERROR: {err:#?}");
|
println!("ERROR: {err:#?}");
|
||||||
Ok(Err(err)?)
|
Ok(Err(err)?)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -343,7 +343,7 @@ mod positions {
|
||||||
);
|
);
|
||||||
|
|
||||||
//then
|
//then
|
||||||
eprintln!("Got: {err:?}");
|
println!("Got: {err:?}");
|
||||||
// NOTE: assertions for correct push are in on_push above
|
// NOTE: assertions for correct push are in on_push above
|
||||||
assert!(matches!(
|
assert!(matches!(
|
||||||
err,
|
err,
|
||||||
|
@ -414,7 +414,7 @@ mod positions {
|
||||||
);
|
);
|
||||||
|
|
||||||
//then
|
//then
|
||||||
eprintln!("Got: {err:?}");
|
println!("Got: {err:?}");
|
||||||
let_assert!(
|
let_assert!(
|
||||||
Ok(sha_next) =
|
Ok(sha_next) =
|
||||||
then::get_sha_for_branch(&fs, &gitdir, &repo_config.branches().next()),
|
then::get_sha_for_branch(&fs, &gitdir, &repo_config.branches().next()),
|
||||||
|
@ -504,7 +504,7 @@ mod positions {
|
||||||
);
|
);
|
||||||
|
|
||||||
//then
|
//then
|
||||||
eprintln!("Got: {err:?}");
|
println!("Got: {err:?}");
|
||||||
// NOTE: assertions for correct push are in on_push above
|
// NOTE: assertions for correct push are in on_push above
|
||||||
assert!(matches!(
|
assert!(matches!(
|
||||||
err,
|
err,
|
||||||
|
@ -573,7 +573,7 @@ mod positions {
|
||||||
);
|
);
|
||||||
|
|
||||||
//then
|
//then
|
||||||
eprintln!("Got: {err:?}");
|
println!("Got: {err:?}");
|
||||||
let_assert!(
|
let_assert!(
|
||||||
Ok(sha_next) =
|
Ok(sha_next) =
|
||||||
then::get_sha_for_branch(&fs, &gitdir, &repo_config.branches().next()),
|
then::get_sha_for_branch(&fs, &gitdir, &repo_config.branches().next()),
|
||||||
|
@ -626,7 +626,7 @@ mod positions {
|
||||||
);
|
);
|
||||||
|
|
||||||
//then
|
//then
|
||||||
eprintln!("positions: {positions:#?}");
|
println!("positions: {positions:#?}");
|
||||||
|
|
||||||
let_assert!(
|
let_assert!(
|
||||||
Ok(main_sha) =
|
Ok(main_sha) =
|
||||||
|
|
|
@ -115,7 +115,7 @@ impl Handler<ServerConfig> for Server {
|
||||||
}
|
}
|
||||||
impl Server {
|
impl Server {
|
||||||
pub fn new(fs: FileSystem, net: Network, repo: Box<dyn RepositoryFactory>) -> Self {
|
pub fn new(fs: FileSystem, net: Network, repo: Box<dyn RepositoryFactory>) -> Self {
|
||||||
let generation = Generation::new();
|
let generation = Generation::default();
|
||||||
Self {
|
Self {
|
||||||
generation,
|
generation,
|
||||||
webhook: None,
|
webhook: None,
|
||||||
|
|
|
@ -50,7 +50,7 @@ fn repo_details_find_default_push_remote_finds_correct_remote() -> Result<()> {
|
||||||
let_assert!(Some(Some(root)) = cli_crate_dir.parent().map(|p| p.parent()));
|
let_assert!(Some(Some(root)) = cli_crate_dir.parent().map(|p| p.parent()));
|
||||||
let mut repo_details = git::common::repo_details(
|
let mut repo_details = git::common::repo_details(
|
||||||
1,
|
1,
|
||||||
git::Generation::new(),
|
git::Generation::default(),
|
||||||
config::common::forge_details(1, ForgeType::MockForge),
|
config::common::forge_details(1, ForgeType::MockForge),
|
||||||
None,
|
None,
|
||||||
GitDir::new(root), // Server GitDir - should be ignored
|
GitDir::new(root), // Server GitDir - should be ignored
|
||||||
|
@ -81,7 +81,7 @@ fn gitdir_validate_should_pass_a_valid_git_repo() -> Result<()> {
|
||||||
let_assert!(Some(Some(root)) = cli_crate_dir.parent().map(|p| p.parent()));
|
let_assert!(Some(Some(root)) = cli_crate_dir.parent().map(|p| p.parent()));
|
||||||
let mut repo_details = git::common::repo_details(
|
let mut repo_details = git::common::repo_details(
|
||||||
1,
|
1,
|
||||||
git::Generation::new(),
|
git::Generation::default(),
|
||||||
config::common::forge_details(1, ForgeType::MockForge),
|
config::common::forge_details(1, ForgeType::MockForge),
|
||||||
None,
|
None,
|
||||||
GitDir::new(root), // Server GitDir - should be ignored
|
GitDir::new(root), // Server GitDir - should be ignored
|
||||||
|
@ -105,7 +105,7 @@ fn gitdir_validate_should_fail_a_git_repo_with_wrong_remote() -> Result<()> {
|
||||||
let_assert!(Some(Some(root)) = cli_crate_dir.parent().map(|p| p.parent()));
|
let_assert!(Some(Some(root)) = cli_crate_dir.parent().map(|p| p.parent()));
|
||||||
let repo_details = git::common::repo_details(
|
let repo_details = git::common::repo_details(
|
||||||
1,
|
1,
|
||||||
git::Generation::new(),
|
git::Generation::default(),
|
||||||
config::common::forge_details(1, ForgeType::MockForge),
|
config::common::forge_details(1, ForgeType::MockForge),
|
||||||
None,
|
None,
|
||||||
GitDir::new(root), // Server GitDir - should be ignored
|
GitDir::new(root), // Server GitDir - should be ignored
|
||||||
|
|
Loading…
Reference in a new issue