diff --git a/crates/gitbutler-git/Cargo.toml b/crates/gitbutler-git/Cargo.toml index b089da2e4..c7da41ce3 100644 --- a/crates/gitbutler-git/Cargo.toml +++ b/crates/gitbutler-git/Cargo.toml @@ -2,17 +2,21 @@ name = "gitbutler-git" version = "0.0.0" edition = "2021" +publish = false [lib] path = "src/lib.rs" +doctest = false [[bin]] name = "gitbutler-git-askpass" path = "src/bin/askpass.rs" +test = false [[bin]] name = "gitbutler-git-setsid" path = "src/bin/setsid.rs" +test = false [features] default = ["serde", "tokio"] @@ -22,7 +26,7 @@ tokio = ["dep:tokio"] [dependencies] thiserror.workspace = true serde = { workspace = true, optional = true } -tokio = { workspace = true, optional = true, features = ["process", "rt", "process", "time", "io-util", "net", "fs", "sync"]} +tokio = { workspace = true, optional = true, features = ["process", "rt", "process", "time", "io-util", "net", "fs", "sync"] } rand = "0.8.5" futures = "0.3.30" sysinfo = "0.30.5" diff --git a/crates/gitbutler-git/src/refspec.rs b/crates/gitbutler-git/src/refspec.rs index 16364186e..3b41ea6a1 100644 --- a/crates/gitbutler-git/src/refspec.rs +++ b/crates/gitbutler-git/src/refspec.rs @@ -120,283 +120,11 @@ mod tests { use super::*; #[test] - fn test_parse_source_dest() { - assert_eq!( - RefSpec::parse("refs/heads/*:refs/remotes/origin/*").unwrap(), - RefSpec { - update_non_fastforward: false, - source: Some("refs/heads/*".to_owned()), - destination: Some("refs/remotes/origin/*".to_owned()), - } - ); - } - - #[test] - fn test_parse_source_dest_force() { - assert_eq!( - RefSpec::parse("+refs/heads/*:refs/remotes/origin/*").unwrap(), - RefSpec { - update_non_fastforward: true, - source: Some("refs/heads/*".to_owned()), - destination: Some("refs/remotes/origin/*".to_owned()), - } - ); - } - - #[test] - fn test_parse_invalid_third_refspec() { + fn parse_invalid_third_refspec() { assert_eq!( RefSpec::parse("refs/heads/*:refs/remotes/origin/*:refs/remotes/upstream/*") .unwrap_err(), Error::UnexpectedChar(':', 34) ); } - - #[test] - fn test_parse_single_colon() { - assert_eq!( - RefSpec::parse(":").unwrap(), - RefSpec { - update_non_fastforward: false, - source: None, - destination: None, - } - ); - } - - #[test] - fn test_parse_single_colon_force() { - assert_eq!( - RefSpec::parse("+:").unwrap(), - RefSpec { - update_non_fastforward: true, - source: None, - destination: None, - } - ); - } - - #[test] - fn test_parse_empty() { - assert_eq!( - RefSpec::parse("").unwrap(), - RefSpec { - update_non_fastforward: false, - source: None, - destination: None, - } - ); - } - - #[test] - fn test_parse_empty_force() { - assert_eq!( - RefSpec::parse("+").unwrap(), - RefSpec { - update_non_fastforward: true, - source: None, - destination: None, - } - ); - } - - #[test] - fn test_parse_single() { - assert_eq!( - RefSpec::parse("refs/heads/*").unwrap(), - RefSpec { - update_non_fastforward: false, - source: Some("refs/heads/*".to_owned()), - destination: Some("refs/heads/*".to_owned()), - } - ); - } - - #[test] - fn test_parse_delete() { - assert_eq!( - RefSpec::parse(":refs/heads/experimental").unwrap(), - RefSpec { - update_non_fastforward: false, - source: None, - destination: Some("refs/heads/experimental".to_owned()), - } - ); - } - - #[test] - fn test_parse_single_force() { - assert_eq!( - RefSpec::parse("+refs/heads/*").unwrap(), - RefSpec { - update_non_fastforward: true, - source: Some("refs/heads/*".to_owned()), - destination: Some("refs/heads/*".to_owned()), - } - ); - } - - #[test] - fn test_parse_delete_force() { - assert_eq!( - RefSpec::parse("+:refs/heads/experimental").unwrap(), - RefSpec { - update_non_fastforward: true, - source: None, - destination: Some("refs/heads/experimental".to_owned()), - } - ); - } - - #[test] - fn test_parse_name() { - assert_eq!( - RefSpec::parse("master").unwrap(), - RefSpec { - update_non_fastforward: false, - source: Some("master".to_owned()), - destination: Some("master".to_owned()), - } - ); - } - - #[test] - fn test_parse_name_force() { - assert_eq!( - RefSpec::parse("+master").unwrap(), - RefSpec { - update_non_fastforward: true, - source: Some("master".to_owned()), - destination: Some("master".to_owned()), - } - ); - } - - #[test] - fn test_parse_source_only() { - assert_eq!( - RefSpec::parse("refs/heads/*:").unwrap(), - RefSpec { - update_non_fastforward: false, - source: Some("refs/heads/*".to_owned()), - destination: None, - } - ); - } - - #[test] - fn format_empty() { - assert_eq!( - RefSpec { - update_non_fastforward: false, - source: None, - destination: None, - } - .to_string(), - ":".to_owned() - ); - } - - #[test] - fn format_empty_force() { - assert_eq!( - RefSpec { - update_non_fastforward: true, - source: None, - destination: None, - } - .to_string(), - "+:".to_owned() - ); - } - - #[test] - fn format_source_only() { - assert_eq!( - RefSpec { - update_non_fastforward: false, - source: Some("refs/heads/*".to_owned()), - destination: None, - } - .to_string(), - "refs/heads/*:".to_owned() - ); - } - - #[test] - fn format_source_only_force() { - assert_eq!( - RefSpec { - update_non_fastforward: true, - source: Some("refs/heads/*".to_owned()), - destination: None, - } - .to_string(), - "+refs/heads/*:".to_owned() - ); - } - - #[test] - fn format_source_dest() { - assert_eq!( - RefSpec { - update_non_fastforward: false, - source: Some("refs/heads/*".to_owned()), - destination: Some("refs/remotes/origin/*".to_owned()), - } - .to_string(), - "refs/heads/*:refs/remotes/origin/*".to_owned() - ); - } - - #[test] - fn format_source_dest_force() { - assert_eq!( - RefSpec { - update_non_fastforward: true, - source: Some("refs/heads/*".to_owned()), - destination: Some("refs/remotes/origin/*".to_owned()), - } - .to_string(), - "+refs/heads/*:refs/remotes/origin/*".to_owned() - ); - } - - #[test] - fn format_dest_only() { - assert_eq!( - RefSpec { - update_non_fastforward: false, - source: None, - destination: Some("refs/heads/*".to_owned()), - } - .to_string(), - ":refs/heads/*".to_owned() - ); - } - - #[test] - fn format_dest_only_force() { - assert_eq!( - RefSpec { - update_non_fastforward: true, - source: None, - destination: Some("refs/heads/*".to_owned()), - } - .to_string(), - "+:refs/heads/*".to_owned() - ); - } - - #[test] - fn test_tuple() { - assert_eq!( - RefSpec::from(("refs/heads/*", "refs/remotes/origin/*")), - RefSpec { - update_non_fastforward: false, - source: Some("refs/heads/*".to_owned()), - destination: Some("refs/remotes/origin/*".to_owned()), - } - ); - } } diff --git a/crates/gitbutler-git/tests/git.rs b/crates/gitbutler-git/tests/git.rs new file mode 100644 index 000000000..864a70ff4 --- /dev/null +++ b/crates/gitbutler-git/tests/git.rs @@ -0,0 +1 @@ +mod refspec; diff --git a/crates/gitbutler-git/tests/refspec/mod.rs b/crates/gitbutler-git/tests/refspec/mod.rs new file mode 100644 index 000000000..7b9f21de2 --- /dev/null +++ b/crates/gitbutler-git/tests/refspec/mod.rs @@ -0,0 +1,273 @@ +use gitbutler_git::RefSpec; + +#[test] +fn parse_source_dest() { + assert_eq!( + RefSpec::parse("refs/heads/*:refs/remotes/origin/*").unwrap(), + RefSpec { + update_non_fastforward: false, + source: Some("refs/heads/*".to_owned()), + destination: Some("refs/remotes/origin/*".to_owned()), + } + ); +} + +#[test] +fn parse_source_dest_force() { + assert_eq!( + RefSpec::parse("+refs/heads/*:refs/remotes/origin/*").unwrap(), + RefSpec { + update_non_fastforward: true, + source: Some("refs/heads/*".to_owned()), + destination: Some("refs/remotes/origin/*".to_owned()), + } + ); +} + +#[test] +fn parse_single_colon() { + assert_eq!( + RefSpec::parse(":").unwrap(), + RefSpec { + update_non_fastforward: false, + source: None, + destination: None, + } + ); +} + +#[test] +fn parse_single_colon_force() { + assert_eq!( + RefSpec::parse("+:").unwrap(), + RefSpec { + update_non_fastforward: true, + source: None, + destination: None, + } + ); +} + +#[test] +fn parse_empty() { + assert_eq!( + RefSpec::parse("").unwrap(), + RefSpec { + update_non_fastforward: false, + source: None, + destination: None, + } + ); +} + +#[test] +fn parse_empty_force() { + assert_eq!( + RefSpec::parse("+").unwrap(), + RefSpec { + update_non_fastforward: true, + source: None, + destination: None, + } + ); +} + +#[test] +fn parse_single() { + assert_eq!( + RefSpec::parse("refs/heads/*").unwrap(), + RefSpec { + update_non_fastforward: false, + source: Some("refs/heads/*".to_owned()), + destination: Some("refs/heads/*".to_owned()), + } + ); +} + +#[test] +fn parse_delete() { + assert_eq!( + RefSpec::parse(":refs/heads/experimental").unwrap(), + RefSpec { + update_non_fastforward: false, + source: None, + destination: Some("refs/heads/experimental".to_owned()), + } + ); +} + +#[test] +fn parse_single_force() { + assert_eq!( + RefSpec::parse("+refs/heads/*").unwrap(), + RefSpec { + update_non_fastforward: true, + source: Some("refs/heads/*".to_owned()), + destination: Some("refs/heads/*".to_owned()), + } + ); +} + +#[test] +fn parse_delete_force() { + assert_eq!( + RefSpec::parse("+:refs/heads/experimental").unwrap(), + RefSpec { + update_non_fastforward: true, + source: None, + destination: Some("refs/heads/experimental".to_owned()), + } + ); +} + +#[test] +fn parse_name() { + assert_eq!( + RefSpec::parse("master").unwrap(), + RefSpec { + update_non_fastforward: false, + source: Some("master".to_owned()), + destination: Some("master".to_owned()), + } + ); +} + +#[test] +fn parse_name_force() { + assert_eq!( + RefSpec::parse("+master").unwrap(), + RefSpec { + update_non_fastforward: true, + source: Some("master".to_owned()), + destination: Some("master".to_owned()), + } + ); +} + +#[test] +fn parse_source_only() { + assert_eq!( + RefSpec::parse("refs/heads/*:").unwrap(), + RefSpec { + update_non_fastforward: false, + source: Some("refs/heads/*".to_owned()), + destination: None, + } + ); +} + +#[test] +fn format_empty() { + assert_eq!( + RefSpec { + update_non_fastforward: false, + source: None, + destination: None, + } + .to_string(), + ":".to_owned() + ); +} + +#[test] +fn format_empty_force() { + assert_eq!( + RefSpec { + update_non_fastforward: true, + source: None, + destination: None, + } + .to_string(), + "+:".to_owned() + ); +} + +#[test] +fn format_source_only() { + assert_eq!( + RefSpec { + update_non_fastforward: false, + source: Some("refs/heads/*".to_owned()), + destination: None, + } + .to_string(), + "refs/heads/*:".to_owned() + ); +} + +#[test] +fn format_source_only_force() { + assert_eq!( + RefSpec { + update_non_fastforward: true, + source: Some("refs/heads/*".to_owned()), + destination: None, + } + .to_string(), + "+refs/heads/*:".to_owned() + ); +} + +#[test] +fn format_source_dest() { + assert_eq!( + RefSpec { + update_non_fastforward: false, + source: Some("refs/heads/*".to_owned()), + destination: Some("refs/remotes/origin/*".to_owned()), + } + .to_string(), + "refs/heads/*:refs/remotes/origin/*".to_owned() + ); +} + +#[test] +fn format_source_dest_force() { + assert_eq!( + RefSpec { + update_non_fastforward: true, + source: Some("refs/heads/*".to_owned()), + destination: Some("refs/remotes/origin/*".to_owned()), + } + .to_string(), + "+refs/heads/*:refs/remotes/origin/*".to_owned() + ); +} + +#[test] +fn format_dest_only() { + assert_eq!( + RefSpec { + update_non_fastforward: false, + source: None, + destination: Some("refs/heads/*".to_owned()), + } + .to_string(), + ":refs/heads/*".to_owned() + ); +} + +#[test] +fn format_dest_only_force() { + assert_eq!( + RefSpec { + update_non_fastforward: true, + source: None, + destination: Some("refs/heads/*".to_owned()), + } + .to_string(), + "+:refs/heads/*".to_owned() + ); +} + +#[test] +fn tuple() { + assert_eq!( + RefSpec::from(("refs/heads/*", "refs/remotes/origin/*")), + RefSpec { + update_non_fastforward: false, + source: Some("refs/heads/*".to_owned()), + destination: Some("refs/remotes/origin/*".to_owned()), + } + ); +}