diff options
| -rw-r--r-- | src/sub_commands/send.rs | 28 | ||||
| -rw-r--r-- | 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( | |||
| 441 | // a change like this, or the removal of this tag will require the actual branch name to be tracked | 441 | // a change like this, or the removal of this tag will require the actual branch name to be tracked |
| 442 | // so pulling and pushing still work | 442 | // so pulling and pushing still work |
| 443 | if let Ok(branch_name) = git_repo.get_checked_out_branch_name() { | 443 | if let Ok(branch_name) = git_repo.get_checked_out_branch_name() { |
| 444 | vec![Tag::Generic( | 444 | if !branch_name.eq("main") && !branch_name.eq("master") { |
| 445 | TagKind::Custom("branch-name".to_string()), | 445 | vec![Tag::Generic( |
| 446 | vec![branch_name], | 446 | TagKind::Custom("branch-name".to_string()), |
| 447 | )] | 447 | vec![branch_name], |
| 448 | )] | ||
| 449 | } | ||
| 450 | else { vec![] } | ||
| 448 | } else { | 451 | } else { |
| 449 | vec![] | 452 | vec![] |
| 450 | }, | 453 | }, |
| @@ -475,7 +478,11 @@ pub fn generate_cover_letter_and_patch_events( | |||
| 475 | }, | 478 | }, |
| 476 | if events.is_empty() { | 479 | if events.is_empty() { |
| 477 | if let Ok(branch_name) = git_repo.get_checked_out_branch_name() { | 480 | if let Ok(branch_name) = git_repo.get_checked_out_branch_name() { |
| 478 | Some(branch_name) | 481 | if !branch_name.eq("main") && !branch_name.eq("master") { |
| 482 | Some(branch_name) | ||
| 483 | } else { | ||
| 484 | None | ||
| 485 | } | ||
| 479 | } else { | 486 | } else { |
| 480 | None | 487 | None |
| 481 | } | 488 | } |
| @@ -586,7 +593,16 @@ pub fn event_to_cover_letter(event: &nostr::Event) -> Result<CoverLetter> { | |||
| 586 | title: title.clone(), | 593 | title: title.clone(), |
| 587 | description, | 594 | description, |
| 588 | // TODO should this be prefixed by format!("{}-"e.id.to_string()[..5]?) | 595 | // TODO should this be prefixed by format!("{}-"e.id.to_string()[..5]?) |
| 589 | branch_name: if let Ok(name) = tag_value(event, "branch-name") { | 596 | branch_name: if let Ok(name) = match tag_value(event, "branch-name") { |
| 597 | Ok(name) => { | ||
| 598 | if !name.eq("main") && !name.eq("master") { | ||
| 599 | Ok(name) | ||
| 600 | } else { | ||
| 601 | Err(()) | ||
| 602 | } | ||
| 603 | } | ||
| 604 | _ => Err(()), | ||
| 605 | } { | ||
| 590 | name | 606 | name |
| 591 | } else { | 607 | } else { |
| 592 | let s = title | 608 | 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 | |||
| @@ -1090,6 +1090,30 @@ mod sends_2_patches_without_cover_letter { | |||
| 1090 | 1090 | ||
| 1091 | #[tokio::test] | 1091 | #[tokio::test] |
| 1092 | #[serial] | 1092 | #[serial] |
| 1093 | async fn root_patch_tags_branch_name() -> Result<()> { | ||
| 1094 | let (_, _, r53, r55, r56) = prep_run_create_proposal(false).await?; | ||
| 1095 | for relay in [&r53, &r55, &r56] { | ||
| 1096 | let patch_events = relay | ||
| 1097 | .events | ||
| 1098 | .iter() | ||
| 1099 | .filter(|e| is_patch(e)) | ||
| 1100 | .collect::<Vec<&nostr::Event>>(); | ||
| 1101 | |||
| 1102 | // branch-name tag | ||
| 1103 | assert_eq!( | ||
| 1104 | patch_events[0] | ||
| 1105 | .iter_tags() | ||
| 1106 | .find(|t| t.as_vec()[0].eq("branch-name")) | ||
| 1107 | .unwrap() | ||
| 1108 | .as_vec()[1], | ||
| 1109 | "feature" | ||
| 1110 | ); | ||
| 1111 | } | ||
| 1112 | Ok(()) | ||
| 1113 | } | ||
| 1114 | |||
| 1115 | #[tokio::test] | ||
| 1116 | #[serial] | ||
| 1093 | async fn second_patch_lists_first_as_root() -> Result<()> { | 1117 | async fn second_patch_lists_first_as_root() -> Result<()> { |
| 1094 | let (_, _, r53, r55, r56) = prep_run_create_proposal(false).await?; | 1118 | let (_, _, r53, r55, r56) = prep_run_create_proposal(false).await?; |
| 1095 | for relay in [&r53, &r55, &r56] { | 1119 | for relay in [&r53, &r55, &r56] { |
| @@ -1113,8 +1137,20 @@ mod sends_2_patches_without_cover_letter { | |||
| 1113 | Ok(()) | 1137 | Ok(()) |
| 1114 | } | 1138 | } |
| 1115 | } | 1139 | } |
| 1116 | mod specify_starting_commits { | 1140 | mod specify_starting_commits_whist_on_main_branch { |
| 1117 | use super::*; | 1141 | use super::*; |
| 1142 | |||
| 1143 | fn prep_git_repo() -> Result<GitTestRepo> { | ||
| 1144 | let test_repo = GitTestRepo::default(); | ||
| 1145 | test_repo.populate()?; | ||
| 1146 | // dont checkout feature branch | ||
| 1147 | std::fs::write(test_repo.dir.join("t3.md"), "some content")?; | ||
| 1148 | test_repo.stage_and_commit("add t3.md")?; | ||
| 1149 | std::fs::write(test_repo.dir.join("t4.md"), "some content")?; | ||
| 1150 | test_repo.stage_and_commit("add t4.md")?; | ||
| 1151 | Ok(test_repo) | ||
| 1152 | } | ||
| 1153 | |||
| 1118 | fn cli_tester_create_proposal(git_repo: &GitTestRepo) -> CliTester { | 1154 | fn cli_tester_create_proposal(git_repo: &GitTestRepo) -> CliTester { |
| 1119 | let args = vec![ | 1155 | let args = vec![ |
| 1120 | "--nsec", | 1156 | "--nsec", |
| @@ -1144,6 +1180,7 @@ mod specify_starting_commits { | |||
| 1144 | Relay<'static>, | 1180 | Relay<'static>, |
| 1145 | )> { | 1181 | )> { |
| 1146 | let git_repo = prep_git_repo()?; | 1182 | let git_repo = prep_git_repo()?; |
| 1183 | |||
| 1147 | // fallback (51,52) user write (53, 55) repo (55, 56) | 1184 | // fallback (51,52) user write (53, 55) repo (55, 56) |
| 1148 | let (mut r51, mut r52, mut r53, mut r55, mut r56) = ( | 1185 | let (mut r51, mut r52, mut r53, mut r55, mut r56) = ( |
| 1149 | Relay::new( | 1186 | Relay::new( |
| @@ -1293,6 +1330,26 @@ mod specify_starting_commits { | |||
| 1293 | 1330 | ||
| 1294 | #[tokio::test] | 1331 | #[tokio::test] |
| 1295 | #[serial] | 1332 | #[serial] |
| 1333 | async fn root_patch_doesnt_have_a_branch_name_tag() -> Result<()> { | ||
| 1334 | let (_, _, r53, r55, r56) = prep_run_create_proposal().await?; | ||
| 1335 | for relay in [&r53, &r55, &r56] { | ||
| 1336 | let patch_events = relay | ||
| 1337 | .events | ||
| 1338 | .iter() | ||
| 1339 | .filter(|e| is_patch(e)) | ||
| 1340 | .collect::<Vec<&nostr::Event>>(); | ||
| 1341 | |||
| 1342 | assert!( | ||
| 1343 | !patch_events[0] | ||
| 1344 | .iter_tags() | ||
| 1345 | .any(|t| t.as_vec()[0].eq("branch-name")) | ||
| 1346 | ); | ||
| 1347 | } | ||
| 1348 | Ok(()) | ||
| 1349 | } | ||
| 1350 | |||
| 1351 | #[tokio::test] | ||
| 1352 | #[serial] | ||
| 1296 | async fn first_patch_is_ancestor_and_root_others_in_correct_order() -> Result<()> { | 1353 | async fn first_patch_is_ancestor_and_root_others_in_correct_order() -> Result<()> { |
| 1297 | let (_, _, r53, r55, r56) = prep_run_create_proposal().await?; | 1354 | let (_, _, r53, r55, r56) = prep_run_create_proposal().await?; |
| 1298 | for relay in [&r53, &r55, &r56] { | 1355 | for relay in [&r53, &r55, &r56] { |