diff options
author | jemstep-edward <42668885+jemstep-edward@users.noreply.github.com> | 2020-02-03 13:46:46 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-03 13:46:46 +0200 |
commit | e3ed5e6cc1d85ff03c427d8781801404bb098162 (patch) | |
tree | 0a516f8606dba329616b042fd7295aa62053f9e2 | |
parent | 7c198ca97edc24fe8373526ba4891430ce04b75f (diff) | |
parent | 9b0f0324aa57cf2f1d2d0185b37b9ce199caac9c (diff) |
Merge pull request #45 from jemstep/PYKE-11909-multiple-mainline-branches
Pyke 11909 multiple mainline branches
-rw-r--r-- | src/git.rs | 151 | ||||
-rw-r--r-- | src/policies.rs | 6 | ||||
-rw-r--r-- | tests/policies_test.rs | 25 |
3 files changed, 111 insertions, 71 deletions
@@ -570,95 +570,108 @@ mod test { assert_eq!(git.is_mainline("refs/heads/tagged-branch").unwrap(), true); } - #[test] - fn new_commits_off_master_with_default_config() { - let project_root = env!("CARGO_MANIFEST_DIR"); - let git = LiveGit::default(format!("{}/tests/test-repo.git", project_root)).unwrap(); - let commits = git - .find_new_commits( - &[Oid::from_str("eb5e0185546b0bb1a13feec6b9ee8b39985fea42").unwrap()], - &[Oid::from_str("6004dfdb071c71e5e76ad55b924b576487e1c485").unwrap()], - &None, + #[quickcheck] + fn new_commits_fuzz(mainlines: Vec<String>) { + if valid_mainlines(&mainlines) { + let project_root = env!("CARGO_MANIFEST_DIR"); + let git = LiveGit::new( + format!("{}/tests/test-repo.git", project_root), + GitConfig { mainlines }, ) .unwrap(); - assert_eq!(commits.len(), 2) - } - - #[test] - fn new_commits_off_master_with_configured_mainline_glob() { - let project_root = env!("CARGO_MANIFEST_DIR"); - let git = LiveGit::new( - format!("{}/tests/test-repo.git", project_root), - GitConfig { - mainlines: vec!["HEAD".into(), "valid-*".into()], - }, - ) - .unwrap(); - let commits = git - .find_new_commits( + git.find_new_commits( &[Oid::from_str("eb5e0185546b0bb1a13feec6b9ee8b39985fea42").unwrap()], &[Oid::from_str("6004dfdb071c71e5e76ad55b924b576487e1c485").unwrap()], &None, ) .unwrap(); - assert_eq!(commits.len(), 1) + } } - #[test] - fn new_commits_off_master_with_configured_mainline_literal_branch_name() { - let project_root = env!("CARGO_MANIFEST_DIR"); - let git = LiveGit::new( - format!("{}/tests/test-repo.git", project_root), - GitConfig { - mainlines: vec!["HEAD".into(), "valid-branch".into()], - }, - ) - .unwrap(); - let commits = git - .find_new_commits( - &[Oid::from_str("eb5e0185546b0bb1a13feec6b9ee8b39985fea42").unwrap()], - &[Oid::from_str("6004dfdb071c71e5e76ad55b924b576487e1c485").unwrap()], - &None, - ) - .unwrap(); - assert_eq!(commits.len(), 1) - } + mod find_new_commits { + use super::super::*; + use git2::Oid; - #[test] - fn new_commits_off_master_with_configured_mainline_literal_branch_doesnt_exist() { - let project_root = env!("CARGO_MANIFEST_DIR"); - let git = LiveGit::new( - format!("{}/tests/test-repo.git", project_root), - GitConfig { - mainlines: vec!["HEAD".into(), "this-branch-does-not-exist-asdfg".into()], - }, - ) - .unwrap(); - let commits = git - .find_new_commits( - &[Oid::from_str("eb5e0185546b0bb1a13feec6b9ee8b39985fea42").unwrap()], - &[Oid::from_str("6004dfdb071c71e5e76ad55b924b576487e1c485").unwrap()], - &None, + // These tests are running on these commits: + // + // * 6004dfd (same-author) Merge branch 'valid-branch' into same-author + // |\ + // | * 26b9047 (valid-branch) Valid commit on a branch + // |/ + // * eb5e018 (HEAD -> master) A second valid commit + + #[test] + fn finds_all_commits_ahead_of_head_with_default_config() { + let project_root = env!("CARGO_MANIFEST_DIR"); + let git = LiveGit::default(format!("{}/tests/test-repo.git", project_root)).unwrap(); + let commits = git + .find_new_commits( + &[Oid::from_str("eb5e0185546b0bb1a13feec6b9ee8b39985fea42").unwrap()], + &[Oid::from_str("6004dfdb071c71e5e76ad55b924b576487e1c485").unwrap()], + &None, + ) + .unwrap(); + assert_eq!(commits.len(), 2) + } + + #[test] + fn finds_only_commits_in_none_of_the_mainlines_with_glob_configuration() { + let project_root = env!("CARGO_MANIFEST_DIR"); + let git = LiveGit::new( + format!("{}/tests/test-repo.git", project_root), + GitConfig { + mainlines: vec!["HEAD".into(), "valid-*".into()], + }, ) .unwrap(); - assert_eq!(commits.len(), 2) - } + let commits = git + .find_new_commits( + &[Oid::from_str("eb5e0185546b0bb1a13feec6b9ee8b39985fea42").unwrap()], + &[Oid::from_str("6004dfdb071c71e5e76ad55b924b576487e1c485").unwrap()], + &None, + ) + .unwrap(); + assert_eq!(commits.len(), 1) + } - #[quickcheck] - fn new_commits_fuzz(mainlines: Vec<String>) { - if valid_mainlines(&mainlines) { + #[test] + fn finds_only_commits_in_none_of_the_mainlines_with_literal_branch_name_configuration() { let project_root = env!("CARGO_MANIFEST_DIR"); let git = LiveGit::new( format!("{}/tests/test-repo.git", project_root), - GitConfig { mainlines }, + GitConfig { + mainlines: vec!["HEAD".into(), "valid-branch".into()], + }, ) .unwrap(); - git.find_new_commits( - &[Oid::from_str("eb5e0185546b0bb1a13feec6b9ee8b39985fea42").unwrap()], - &[Oid::from_str("6004dfdb071c71e5e76ad55b924b576487e1c485").unwrap()], - &None, + let commits = git + .find_new_commits( + &[Oid::from_str("eb5e0185546b0bb1a13feec6b9ee8b39985fea42").unwrap()], + &[Oid::from_str("6004dfdb071c71e5e76ad55b924b576487e1c485").unwrap()], + &None, + ) + .unwrap(); + assert_eq!(commits.len(), 1) + } + + #[test] + fn finds_only_commits_in_none_of_the_mainlines_with_missing_branch_in_configuration() { + let project_root = env!("CARGO_MANIFEST_DIR"); + let git = LiveGit::new( + format!("{}/tests/test-repo.git", project_root), + GitConfig { + mainlines: vec!["HEAD".into(), "this-branch-does-not-exist-asdfg".into()], + }, ) .unwrap(); + let commits = git + .find_new_commits( + &[Oid::from_str("eb5e0185546b0bb1a13feec6b9ee8b39985fea42").unwrap()], + &[Oid::from_str("6004dfdb071c71e5e76ad55b924b576487e1c485").unwrap()], + &None, + ) + .unwrap(); + assert_eq!(commits.len(), 2) } } } diff --git a/src/policies.rs b/src/policies.rs index eb5dcee..b3a6fdb 100644 --- a/src/policies.rs +++ b/src/policies.rs @@ -323,6 +323,12 @@ fn verify_different_authors<G: Git>( } else if commits.len() == 0 { info!("Multiple author verification passed for {}: No new commits pushed, does not require multiple authors", new_commit_id); Ok(PolicyResult::Ok) + } else if commits.len() == 1 && commits[0].is_identical_tree_to_any_parent { + info!("Multiple author verification passed for {}: There is only one commit and it has an identical filetree to one of its parents", new_commit_id); + Ok(PolicyResult::Ok) + } else if commits.len() == 1 && git.is_trivial_merge_commit(&commits[0])? { + info!("Multiple author verification passed for {}: There is only one commit and it is a trivial merge between mainline branches", new_commit_id); + Ok(PolicyResult::Ok) } else { let authors: HashSet<_> = commits .iter() diff --git a/tests/policies_test.rs b/tests/policies_test.rs index b5708dd..bff0834 100644 --- a/tests/policies_test.rs +++ b/tests/policies_test.rs @@ -267,7 +267,7 @@ fn verify_git_commits_author_merged_own_code_on_configured_mainline() { &LiveGit::new( "./", GitConfig { - mainlines: vec!["valid-*".into()], + mainlines: vec!["m*".into()], }, ) .unwrap(), @@ -275,13 +275,34 @@ fn verify_git_commits_author_merged_own_code_on_configured_mainline() { &verify_commits_config(), "eb5e0185546b0bb1a13feec6b9ee8b39985fea42", "6004dfdb071c71e5e76ad55b924b576487e1c485", - "refs/heads/valid-branch", + "refs/heads/master", ) .unwrap(); assert!(result.is_err()); } #[test] +fn verify_git_commits_author_trivial_merge_between_mainlines() { + before_all(); + let result = policies::verify_git_commits::<LiveGit, MockGpg>( + &LiveGit::new( + "./", + GitConfig { + mainlines: vec!["master".into(), "valid-*".into()], + }, + ) + .unwrap(), + MockGpg, + &verify_commits_config(), + "eb5e0185546b0bb1a13feec6b9ee8b39985fea42", + "6004dfdb071c71e5e76ad55b924b576487e1c485", + "refs/heads/valid-branch", + ) + .unwrap(); + assert!(result.is_ok(), "Error: {:?}", result); +} + +#[test] fn verify_git_commits_author_merged_own_code_on_head() { before_all(); let result = policies::verify_git_commits::<LiveGit, MockGpg>( |