From d4ef8cad0b95baa67e0f2803a7ec8601754a82a7 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Wed, 28 Feb 2024 16:38:39 +0000 Subject: fix: branch-name specified as main or master branch-name should be ommitted or ignored if patches created on main or master instead it should be infered based on commit msg --- src/sub_commands/send.rs | 28 ++++++++++++++++++----- tests/send.rs | 59 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 80 insertions(+), 7 deletions(-) diff --git a/src/sub_commands/send.rs b/src/sub_commands/send.rs index 857bc60..5994f4f 100644 --- a/src/sub_commands/send.rs +++ b/src/sub_commands/send.rs @@ -441,10 +441,13 @@ pub fn generate_cover_letter_and_patch_events( // a change like this, or the removal of this tag will require the actual branch name to be tracked // so pulling and pushing still work if let Ok(branch_name) = git_repo.get_checked_out_branch_name() { - vec![Tag::Generic( - TagKind::Custom("branch-name".to_string()), - vec![branch_name], - )] + if !branch_name.eq("main") && !branch_name.eq("master") { + vec![Tag::Generic( + TagKind::Custom("branch-name".to_string()), + vec![branch_name], + )] + } + else { vec![] } } else { vec![] }, @@ -475,7 +478,11 @@ pub fn generate_cover_letter_and_patch_events( }, if events.is_empty() { if let Ok(branch_name) = git_repo.get_checked_out_branch_name() { - Some(branch_name) + if !branch_name.eq("main") && !branch_name.eq("master") { + Some(branch_name) + } else { + None + } } else { None } @@ -586,7 +593,16 @@ pub fn event_to_cover_letter(event: &nostr::Event) -> Result { title: title.clone(), description, // TODO should this be prefixed by format!("{}-"e.id.to_string()[..5]?) - branch_name: if let Ok(name) = tag_value(event, "branch-name") { + branch_name: if let Ok(name) = match tag_value(event, "branch-name") { + Ok(name) => { + if !name.eq("main") && !name.eq("master") { + Ok(name) + } else { + Err(()) + } + } + _ => Err(()), + } { name } else { let s = title diff --git a/tests/send.rs b/tests/send.rs index 06f1b86..2c86566 100644 --- a/tests/send.rs +++ b/tests/send.rs @@ -1088,6 +1088,30 @@ mod sends_2_patches_without_cover_letter { Ok(()) } + #[tokio::test] + #[serial] + async fn root_patch_tags_branch_name() -> Result<()> { + let (_, _, r53, r55, r56) = prep_run_create_proposal(false).await?; + for relay in [&r53, &r55, &r56] { + let patch_events = relay + .events + .iter() + .filter(|e| is_patch(e)) + .collect::>(); + + // branch-name tag + assert_eq!( + patch_events[0] + .iter_tags() + .find(|t| t.as_vec()[0].eq("branch-name")) + .unwrap() + .as_vec()[1], + "feature" + ); + } + Ok(()) + } + #[tokio::test] #[serial] async fn second_patch_lists_first_as_root() -> Result<()> { @@ -1113,8 +1137,20 @@ mod sends_2_patches_without_cover_letter { Ok(()) } } -mod specify_starting_commits { +mod specify_starting_commits_whist_on_main_branch { use super::*; + + fn prep_git_repo() -> Result { + let test_repo = GitTestRepo::default(); + test_repo.populate()?; + // dont checkout feature branch + std::fs::write(test_repo.dir.join("t3.md"), "some content")?; + test_repo.stage_and_commit("add t3.md")?; + std::fs::write(test_repo.dir.join("t4.md"), "some content")?; + test_repo.stage_and_commit("add t4.md")?; + Ok(test_repo) + } + fn cli_tester_create_proposal(git_repo: &GitTestRepo) -> CliTester { let args = vec![ "--nsec", @@ -1144,6 +1180,7 @@ mod specify_starting_commits { Relay<'static>, )> { let git_repo = prep_git_repo()?; + // fallback (51,52) user write (53, 55) repo (55, 56) let (mut r51, mut r52, mut r53, mut r55, mut r56) = ( Relay::new( @@ -1291,6 +1328,26 @@ mod specify_starting_commits { Ok(()) } + #[tokio::test] + #[serial] + async fn root_patch_doesnt_have_a_branch_name_tag() -> Result<()> { + let (_, _, r53, r55, r56) = prep_run_create_proposal().await?; + for relay in [&r53, &r55, &r56] { + let patch_events = relay + .events + .iter() + .filter(|e| is_patch(e)) + .collect::>(); + + assert!( + !patch_events[0] + .iter_tags() + .any(|t| t.as_vec()[0].eq("branch-name")) + ); + } + Ok(()) + } + #[tokio::test] #[serial] async fn first_patch_is_ancestor_and_root_others_in_correct_order() -> Result<()> { -- cgit v1.2.3