upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2024-07-23 16:36:06 +0100
committerDanConwayDev <DanConwayDev@protonmail.com>2024-07-23 16:36:06 +0100
commitb67376ff54abeab31422921ba5f4883d5d3dccdb (patch)
treed4f4194fdf2d285332dd7aacea31678042389b00 /tests
parent643fa17fde858c2d6f934dcc435eb84843cc172e (diff)
feat(list): unique proposal branch names
to prevent accidental name conflicts. also moved to prs/* namespace `pull` and `push` integration tests are intermitantly failing to end at least for `push` they work when run individually but not when run together
Diffstat (limited to 'tests')
-rw-r--r--tests/list.rs539
-rw-r--r--tests/pull.rs406
-rw-r--r--tests/push.rs204
3 files changed, 953 insertions, 196 deletions
diff --git a/tests/list.rs b/tests/list.rs
index 22d82fd..60c9423 100644
--- a/tests/list.rs
+++ b/tests/list.rs
@@ -277,10 +277,8 @@ mod when_main_branch_is_uptodate {
277 ], 277 ],
278 )?; 278 )?;
279 c.succeeds_with(0, false, Some(0))?; 279 c.succeeds_with(0, false, Some(0))?;
280 p.expect(format!( 280 p.expect_end_eventually_and_print()?;
281 "checked out proposal as '{FEATURE_BRANCH_NAME_1}' branch\r\n" 281
282 ))?;
283 p.expect_end()?;
284 for p in [51, 52, 53, 55, 56] { 282 for p in [51, 52, 53, 55, 56] {
285 relay::shutdown_relay(8000 + p)?; 283 relay::shutdown_relay(8000 + p)?;
286 } 284 }
@@ -351,10 +349,11 @@ mod when_main_branch_is_uptodate {
351 ], 349 ],
352 )?; 350 )?;
353 c.succeeds_with(0, false, None)?; 351 c.succeeds_with(0, false, None)?;
354 p.expect(format!( 352 p.expect(&format!(
355 "checked out proposal as '{FEATURE_BRANCH_NAME_1}' branch\r\n" 353 "checked out proposal as 'prs/{}(",
354 FEATURE_BRANCH_NAME_1,
356 ))?; 355 ))?;
357 p.expect_end()?; 356 p.expect_end_eventually_with(")' branch\r\n")?;
358 357
359 for p in [51, 52, 53, 55, 56] { 358 for p in [51, 52, 53, 55, 56] {
360 relay::shutdown_relay(8000 + p)?; 359 relay::shutdown_relay(8000 + p)?;
@@ -381,7 +380,10 @@ mod when_main_branch_is_uptodate {
381 async fn proposal_branch_created_with_correct_name() -> Result<()> { 380 async fn proposal_branch_created_with_correct_name() -> Result<()> {
382 let (_, test_repo) = prep_and_run().await?; 381 let (_, test_repo) = prep_and_run().await?;
383 assert_eq!( 382 assert_eq!(
384 vec![FEATURE_BRANCH_NAME_1, "main"], 383 vec![
384 "main",
385 &get_proposal_branch_name(&test_repo, FEATURE_BRANCH_NAME_1)?,
386 ],
385 test_repo.get_local_branch_names()? 387 test_repo.get_local_branch_names()?
386 ); 388 );
387 Ok(()) 389 Ok(())
@@ -392,7 +394,7 @@ mod when_main_branch_is_uptodate {
392 async fn proposal_branch_checked_out() -> Result<()> { 394 async fn proposal_branch_checked_out() -> Result<()> {
393 let (_, test_repo) = prep_and_run().await?; 395 let (_, test_repo) = prep_and_run().await?;
394 assert_eq!( 396 assert_eq!(
395 FEATURE_BRANCH_NAME_1, 397 get_proposal_branch_name(&test_repo, FEATURE_BRANCH_NAME_1)?,
396 test_repo.get_checked_out_branch_name()?, 398 test_repo.get_checked_out_branch_name()?,
397 ); 399 );
398 Ok(()) 400 Ok(())
@@ -404,7 +406,10 @@ mod when_main_branch_is_uptodate {
404 let (originating_repo, test_repo) = prep_and_run().await?; 406 let (originating_repo, test_repo) = prep_and_run().await?;
405 assert_eq!( 407 assert_eq!(
406 originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, 408 originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?,
407 test_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, 409 test_repo.get_tip_of_local_branch(&get_proposal_branch_name(
410 &test_repo,
411 FEATURE_BRANCH_NAME_1
412 )?)?,
408 ); 413 );
409 Ok(()) 414 Ok(())
410 } 415 }
@@ -461,11 +466,8 @@ mod when_main_branch_is_uptodate {
461 ], 466 ],
462 )?; 467 )?;
463 c.succeeds_with(0, false, Some(0))?; 468 c.succeeds_with(0, false, Some(0))?;
464 p.expect(format!( 469 p.expect_end_eventually_and_print()?;
465 "checked out proposal as '{FEATURE_BRANCH_NAME_3}' branch\r\n" 470
466 ))?;
467 p.expect_end()?;
468 println!("blablagothere");
469 for p in [51, 52, 53, 55, 56] { 471 for p in [51, 52, 53, 55, 56] {
470 relay::shutdown_relay(8000 + p)?; 472 relay::shutdown_relay(8000 + p)?;
471 } 473 }
@@ -537,10 +539,11 @@ mod when_main_branch_is_uptodate {
537 ], 539 ],
538 )?; 540 )?;
539 c.succeeds_with(0, false, Some(0))?; 541 c.succeeds_with(0, false, Some(0))?;
540 p.expect(format!( 542 p.expect(&format!(
541 "checked out proposal as '{FEATURE_BRANCH_NAME_3}' branch\r\n" 543 "checked out proposal as 'prs/{}(",
544 FEATURE_BRANCH_NAME_3,
542 ))?; 545 ))?;
543 p.expect_end()?; 546 p.expect_end_eventually_with(")' branch\r\n")?;
544 547
545 for p in [51, 52, 53, 55, 56] { 548 for p in [51, 52, 53, 55, 56] {
546 relay::shutdown_relay(8000 + p)?; 549 relay::shutdown_relay(8000 + p)?;
@@ -567,7 +570,10 @@ mod when_main_branch_is_uptodate {
567 async fn proposal_branch_created_with_correct_name() -> Result<()> { 570 async fn proposal_branch_created_with_correct_name() -> Result<()> {
568 let (_, test_repo) = prep_and_run().await?; 571 let (_, test_repo) = prep_and_run().await?;
569 assert_eq!( 572 assert_eq!(
570 vec![FEATURE_BRANCH_NAME_3, "main"], 573 vec![
574 "main",
575 &get_proposal_branch_name(&test_repo, FEATURE_BRANCH_NAME_3)?,
576 ],
571 test_repo.get_local_branch_names()? 577 test_repo.get_local_branch_names()?
572 ); 578 );
573 Ok(()) 579 Ok(())
@@ -578,7 +584,7 @@ mod when_main_branch_is_uptodate {
578 async fn proposal_branch_checked_out() -> Result<()> { 584 async fn proposal_branch_checked_out() -> Result<()> {
579 let (_, test_repo) = prep_and_run().await?; 585 let (_, test_repo) = prep_and_run().await?;
580 assert_eq!( 586 assert_eq!(
581 FEATURE_BRANCH_NAME_3, 587 get_proposal_branch_name(&test_repo, FEATURE_BRANCH_NAME_3)?,
582 test_repo.get_checked_out_branch_name()?, 588 test_repo.get_checked_out_branch_name()?,
583 ); 589 );
584 Ok(()) 590 Ok(())
@@ -590,7 +596,10 @@ mod when_main_branch_is_uptodate {
590 let (originating_repo, test_repo) = prep_and_run().await?; 596 let (originating_repo, test_repo) = prep_and_run().await?;
591 assert_eq!( 597 assert_eq!(
592 originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_3)?, 598 originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_3)?,
593 test_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_3)?, 599 test_repo.get_tip_of_local_branch(&get_proposal_branch_name(
600 &test_repo,
601 FEATURE_BRANCH_NAME_3
602 )?)?,
594 ); 603 );
595 Ok(()) 604 Ok(())
596 } 605 }
@@ -653,10 +662,7 @@ mod when_main_branch_is_uptodate {
653 ], 662 ],
654 )?; 663 )?;
655 c.succeeds_with(0, false, Some(0))?; 664 c.succeeds_with(0, false, Some(0))?;
656 p.expect(format!( 665 p.expect_end_eventually_and_print()?;
657 "checked out proposal as '{FEATURE_BRANCH_NAME_4}' branch\r\n"
658 ))?;
659 p.expect_end()?;
660 666
661 for p in [51, 52, 53, 55, 56] { 667 for p in [51, 52, 53, 55, 56] {
662 relay::shutdown_relay(8000 + p)?; 668 relay::shutdown_relay(8000 + p)?;
@@ -737,10 +743,11 @@ mod when_main_branch_is_uptodate {
737 ], 743 ],
738 )?; 744 )?;
739 c.succeeds_with(0, false, Some(0))?; 745 c.succeeds_with(0, false, Some(0))?;
740 p.expect(format!( 746 p.expect(&format!(
741 "checked out proposal as '{FEATURE_BRANCH_NAME_4}' branch\r\n" 747 "checked out proposal as 'prs/{}(",
748 FEATURE_BRANCH_NAME_4,
742 ))?; 749 ))?;
743 p.expect_end()?; 750 p.expect_end_eventually_with(")' branch\r\n")?;
744 751
745 for p in [51, 52, 53, 55, 56] { 752 for p in [51, 52, 53, 55, 56] {
746 relay::shutdown_relay(8000 + p)?; 753 relay::shutdown_relay(8000 + p)?;
@@ -767,7 +774,10 @@ mod when_main_branch_is_uptodate {
767 async fn proposal_branch_created_with_correct_name() -> Result<()> { 774 async fn proposal_branch_created_with_correct_name() -> Result<()> {
768 let (_, test_repo) = prep_and_run().await?; 775 let (_, test_repo) = prep_and_run().await?;
769 assert_eq!( 776 assert_eq!(
770 vec![FEATURE_BRANCH_NAME_4, "main"], 777 vec![
778 "main",
779 &get_proposal_branch_name(&test_repo, FEATURE_BRANCH_NAME_4)?,
780 ],
771 test_repo.get_local_branch_names()? 781 test_repo.get_local_branch_names()?
772 ); 782 );
773 Ok(()) 783 Ok(())
@@ -778,7 +788,7 @@ mod when_main_branch_is_uptodate {
778 async fn proposal_branch_checked_out() -> Result<()> { 788 async fn proposal_branch_checked_out() -> Result<()> {
779 let (_, test_repo) = prep_and_run().await?; 789 let (_, test_repo) = prep_and_run().await?;
780 assert_eq!( 790 assert_eq!(
781 FEATURE_BRANCH_NAME_4, 791 get_proposal_branch_name(&test_repo, FEATURE_BRANCH_NAME_4)?,
782 test_repo.get_checked_out_branch_name()?, 792 test_repo.get_checked_out_branch_name()?,
783 ); 793 );
784 Ok(()) 794 Ok(())
@@ -790,7 +800,10 @@ mod when_main_branch_is_uptodate {
790 let (originating_repo, test_repo) = prep_and_run().await?; 800 let (originating_repo, test_repo) = prep_and_run().await?;
791 assert_eq!( 801 assert_eq!(
792 originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_4)?, 802 originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_4)?,
793 test_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_4)?, 803 test_repo.get_tip_of_local_branch(&get_proposal_branch_name(
804 &test_repo,
805 FEATURE_BRANCH_NAME_4
806 )?)?,
794 ); 807 );
795 Ok(()) 808 Ok(())
796 } 809 }
@@ -824,21 +837,40 @@ mod when_main_branch_is_uptodate {
824 r55.events.push(generate_test_key_1_metadata_event("fred")); 837 r55.events.push(generate_test_key_1_metadata_event("fred"));
825 r55.events.push(generate_test_key_1_relay_list_event()); 838 r55.events.push(generate_test_key_1_relay_list_event());
826 839
827 let cli_tester_handle = 840 let cli_tester_handle = std::thread::spawn(
828 std::thread::spawn(move || -> Result<(GitTestRepo, GitTestRepo)> { 841 move || -> Result<(GitTestRepo, GitTestRepo)> {
829 let originating_repo = cli_tester_create_proposals()?; 842 let originating_repo = cli_tester_create_proposals()?;
830 843
831 let test_repo = GitTestRepo::default(); 844 let test_repo = GitTestRepo::default();
832 test_repo.populate()?; 845 test_repo.populate()?;
846 // create proposal branch
833 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); 847 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
834 848 p.expect("fetching updates...\r\n")?;
835 create_and_populate_branch( 849 p.expect_eventually("\r\n")?; // some updates listed here
836 &test_repo, 850 let mut c = p.expect_choice(
837 FEATURE_BRANCH_NAME_1, 851 "all proposals",
838 "a", 852 vec![
839 false, 853 format!("\"{PROPOSAL_TITLE_3}\""),
854 format!("\"{PROPOSAL_TITLE_2}\""),
855 format!("\"{PROPOSAL_TITLE_1}\""),
856 ],
840 )?; 857 )?;
858 c.succeeds_with(2, true, None)?;
859 let mut c = p.expect_choice(
860 "",
861 vec![
862 format!("create and checkout proposal branch (2 ahead 0 behind 'main')"),
863 format!("apply to current branch with `git am`"),
864 format!("download to ./patches"),
865 format!("back"),
866 ],
867 )?;
868 c.succeeds_with(0, false, Some(0))?;
869 p.expect_end_eventually()?;
870
841 test_repo.checkout("main")?; 871 test_repo.checkout("main")?;
872 // run test
873 p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
842 p.expect("fetching updates...\r\n")?; 874 p.expect("fetching updates...\r\n")?;
843 p.expect_eventually("\r\n")?; // some updates listed here 875 p.expect_eventually("\r\n")?; // some updates listed here
844 let mut c = p.expect_choice( 876 let mut c = p.expect_choice(
@@ -860,16 +892,14 @@ mod when_main_branch_is_uptodate {
860 ], 892 ],
861 )?; 893 )?;
862 c.succeeds_with(0, false, Some(0))?; 894 c.succeeds_with(0, false, Some(0))?;
863 p.expect(format!( 895 p.expect_end_eventually_and_print()?;
864 "checked out proposal as '{FEATURE_BRANCH_NAME_1}' branch\r\n"
865 ))?;
866 p.expect_end()?;
867 896
868 for p in [51, 52, 53, 55, 56] { 897 for p in [51, 52, 53, 55, 56] {
869 relay::shutdown_relay(8000 + p)?; 898 relay::shutdown_relay(8000 + p)?;
870 } 899 }
871 Ok((originating_repo, test_repo)) 900 Ok((originating_repo, test_repo))
872 }); 901 },
902 );
873 903
874 // launch relay 904 // launch relay
875 let _ = join!( 905 let _ = join!(
@@ -911,16 +941,34 @@ mod when_main_branch_is_uptodate {
911 941
912 let test_repo = GitTestRepo::default(); 942 let test_repo = GitTestRepo::default();
913 test_repo.populate()?; 943 test_repo.populate()?;
944 // create proposal branch
914 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); 945 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
915 946 p.expect("fetching updates...\r\n")?;
916 create_and_populate_branch( 947 p.expect_eventually("\r\n")?; // some updates listed here
917 &test_repo, 948 let mut c = p.expect_choice(
918 FEATURE_BRANCH_NAME_1, 949 "all proposals",
919 "a", 950 vec![
920 false, 951 format!("\"{PROPOSAL_TITLE_3}\""),
952 format!("\"{PROPOSAL_TITLE_2}\""),
953 format!("\"{PROPOSAL_TITLE_1}\""),
954 ],
921 )?; 955 )?;
922 test_repo.checkout("main")?; 956 c.succeeds_with(2, true, None)?;
957 let mut c = p.expect_choice(
958 "",
959 vec![
960 format!("create and checkout proposal branch (2 ahead 0 behind 'main')"),
961 format!("apply to current branch with `git am`"),
962 format!("download to ./patches"),
963 format!("back"),
964 ],
965 )?;
966 c.succeeds_with(0, false, Some(0))?;
967 p.expect_end_eventually()?;
923 968
969 test_repo.checkout("main")?;
970 // run test
971 p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
924 p.expect("fetching updates...\r\n")?; 972 p.expect("fetching updates...\r\n")?;
925 p.expect_eventually("\r\n")?; // some updates listed here 973 p.expect_eventually("\r\n")?; // some updates listed here
926 let mut c = p.expect_choice( 974 let mut c = p.expect_choice(
@@ -942,10 +990,11 @@ mod when_main_branch_is_uptodate {
942 ], 990 ],
943 )?; 991 )?;
944 c.succeeds_with(0, false, Some(0))?; 992 c.succeeds_with(0, false, Some(0))?;
945 p.expect(format!( 993 p.expect(&format!(
946 "checked out proposal as '{FEATURE_BRANCH_NAME_1}' branch\r\n" 994 "checked out proposal as 'prs/{}(",
995 FEATURE_BRANCH_NAME_1,
947 ))?; 996 ))?;
948 p.expect_end()?; 997 p.expect_end_eventually_with(")' branch\r\n")?;
949 998
950 for p in [51, 52, 53, 55, 56] { 999 for p in [51, 52, 53, 55, 56] {
951 relay::shutdown_relay(8000 + p)?; 1000 relay::shutdown_relay(8000 + p)?;
@@ -972,7 +1021,7 @@ mod when_main_branch_is_uptodate {
972 async fn proposal_branch_checked_out() -> Result<()> { 1021 async fn proposal_branch_checked_out() -> Result<()> {
973 let (_, test_repo) = prep_and_run().await?; 1022 let (_, test_repo) = prep_and_run().await?;
974 assert_eq!( 1023 assert_eq!(
975 FEATURE_BRANCH_NAME_1, 1024 get_proposal_branch_name(&test_repo, FEATURE_BRANCH_NAME_1)?,
976 test_repo.get_checked_out_branch_name()?, 1025 test_repo.get_checked_out_branch_name()?,
977 ); 1026 );
978 Ok(()) 1027 Ok(())
@@ -1003,19 +1052,46 @@ mod when_main_branch_is_uptodate {
1003 let cli_tester_handle = std::thread::spawn( 1052 let cli_tester_handle = std::thread::spawn(
1004 move || -> Result<(GitTestRepo, GitTestRepo)> { 1053 move || -> Result<(GitTestRepo, GitTestRepo)> {
1005 let originating_repo = cli_tester_create_proposals()?; 1054 let originating_repo = cli_tester_create_proposals()?;
1006
1007 let test_repo = GitTestRepo::default(); 1055 let test_repo = GitTestRepo::default();
1008 test_repo.populate()?; 1056 test_repo.populate()?;
1057 // create proposal branch
1009 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); 1058 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1059 p.expect("fetching updates...\r\n")?;
1060 p.expect_eventually("\r\n")?; // some updates listed here
1061 let mut c = p.expect_choice(
1062 "all proposals",
1063 vec![
1064 format!("\"{PROPOSAL_TITLE_3}\""),
1065 format!("\"{PROPOSAL_TITLE_2}\""),
1066 format!("\"{PROPOSAL_TITLE_1}\""),
1067 ],
1068 )?;
1069 c.succeeds_with(2, true, None)?;
1070 let mut c = p.expect_choice(
1071 "",
1072 vec![
1073 format!("create and checkout proposal branch (2 ahead 0 behind 'main')"),
1074 format!("apply to current branch with `git am`"),
1075 format!("download to ./patches"),
1076 format!("back"),
1077 ],
1078 )?;
1079 c.succeeds_with(0, false, Some(0))?;
1080 p.expect_end_eventually()?;
1010 1081
1011 create_and_populate_branch( 1082 // remove latest commit so it is behind
1012 &test_repo, 1083 let branch_name = test_repo.get_checked_out_branch_name()?;
1013 FEATURE_BRANCH_NAME_1, 1084 test_repo.checkout("main")?;
1014 "a", 1085 test_repo.git_repo.branch(
1086 &branch_name,
1087 &test_repo
1088 .git_repo
1089 .find_commit(test_repo.get_tip_of_local_branch(&branch_name)?)?
1090 .parent(0)?,
1015 true, 1091 true,
1016 )?; 1092 )?;
1017 test_repo.checkout("main")?; 1093 // run test
1018 1094 p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1019 p.expect("fetching updates...\r\n")?; 1095 p.expect("fetching updates...\r\n")?;
1020 p.expect_eventually("\r\n")?; // some updates listed here 1096 p.expect_eventually("\r\n")?; // some updates listed here
1021 let mut c = p.expect_choice( 1097 let mut c = p.expect_choice(
@@ -1087,16 +1163,44 @@ mod when_main_branch_is_uptodate {
1087 1163
1088 let test_repo = GitTestRepo::default(); 1164 let test_repo = GitTestRepo::default();
1089 test_repo.populate()?; 1165 test_repo.populate()?;
1166 // create proposal branch
1090 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); 1167 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1168 p.expect("fetching updates...\r\n")?;
1169 p.expect_eventually("\r\n")?; // some updates listed here
1170 let mut c = p.expect_choice(
1171 "all proposals",
1172 vec![
1173 format!("\"{PROPOSAL_TITLE_3}\""),
1174 format!("\"{PROPOSAL_TITLE_2}\""),
1175 format!("\"{PROPOSAL_TITLE_1}\""),
1176 ],
1177 )?;
1178 c.succeeds_with(2, true, None)?;
1179 let mut c = p.expect_choice(
1180 "",
1181 vec![
1182 format!("create and checkout proposal branch (2 ahead 0 behind 'main')"),
1183 format!("apply to current branch with `git am`"),
1184 format!("download to ./patches"),
1185 format!("back"),
1186 ],
1187 )?;
1188 c.succeeds_with(0, false, Some(0))?;
1189 p.expect_end_eventually()?;
1091 1190
1092 create_and_populate_branch( 1191 // remove latest commit so it is behind
1093 &test_repo, 1192 let branch_name = test_repo.get_checked_out_branch_name()?;
1094 FEATURE_BRANCH_NAME_1, 1193 test_repo.checkout("main")?;
1095 "a", 1194 test_repo.git_repo.branch(
1195 &branch_name,
1196 &test_repo
1197 .git_repo
1198 .find_commit(test_repo.get_tip_of_local_branch(&branch_name)?)?
1199 .parent(0)?,
1096 true, 1200 true,
1097 )?; 1201 )?;
1098 test_repo.checkout("main")?; 1202 // run test
1099 1203 p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1100 p.expect("fetching updates...\r\n")?; 1204 p.expect("fetching updates...\r\n")?;
1101 p.expect_eventually("\r\n")?; // some updates listed here 1205 p.expect_eventually("\r\n")?; // some updates listed here
1102 let mut c = p.expect_choice( 1206 let mut c = p.expect_choice(
@@ -1146,7 +1250,7 @@ mod when_main_branch_is_uptodate {
1146 async fn proposal_branch_checked_out() -> Result<()> { 1250 async fn proposal_branch_checked_out() -> Result<()> {
1147 let (_, test_repo) = prep_and_run().await?; 1251 let (_, test_repo) = prep_and_run().await?;
1148 assert_eq!( 1252 assert_eq!(
1149 FEATURE_BRANCH_NAME_1, 1253 get_proposal_branch_name(&test_repo, FEATURE_BRANCH_NAME_1)?,
1150 test_repo.get_checked_out_branch_name()?, 1254 test_repo.get_checked_out_branch_name()?,
1151 ); 1255 );
1152 Ok(()) 1256 Ok(())
@@ -1158,7 +1262,10 @@ mod when_main_branch_is_uptodate {
1158 let (originating_repo, test_repo) = prep_and_run().await?; 1262 let (originating_repo, test_repo) = prep_and_run().await?;
1159 assert_eq!( 1263 assert_eq!(
1160 originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, 1264 originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?,
1161 test_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, 1265 test_repo.get_tip_of_local_branch(&get_proposal_branch_name(
1266 &test_repo,
1267 FEATURE_BRANCH_NAME_1
1268 )?)?,
1162 ); 1269 );
1163 Ok(()) 1270 Ok(())
1164 } 1271 }
@@ -1185,30 +1292,59 @@ mod when_main_branch_is_uptodate {
1185 r55.events.push(generate_test_key_1_metadata_event("fred")); 1292 r55.events.push(generate_test_key_1_metadata_event("fred"));
1186 r55.events.push(generate_test_key_1_relay_list_event()); 1293 r55.events.push(generate_test_key_1_relay_list_event());
1187 1294
1188 let cli_tester_handle = 1295 let cli_tester_handle = std::thread::spawn(
1189 std::thread::spawn(move || -> Result<(GitTestRepo, GitTestRepo)> { 1296 move || -> Result<(GitTestRepo, GitTestRepo)> {
1190 let originating_repo = cli_tester_create_proposals()?; 1297 let originating_repo = cli_tester_create_proposals()?;
1191 1298
1192 let test_repo = GitTestRepo::default(); 1299 let test_repo = GitTestRepo::default();
1193 test_repo.populate()?; 1300 test_repo.populate()?;
1301 // create proposal branch
1194 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); 1302 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1195 1303 p.expect("fetching updates...\r\n")?;
1196 // simulating checking out the proposal (the commits_ids will match) 1304 p.expect_eventually("\r\n")?; // some updates listed here
1197 create_and_populate_branch( 1305 let mut c = p.expect_choice(
1198 &test_repo, 1306 "all proposals",
1199 "different-branch-name", 1307 vec![
1200 "a", 1308 format!("\"{PROPOSAL_TITLE_3}\""),
1201 false, 1309 format!("\"{PROPOSAL_TITLE_2}\""),
1310 format!("\"{PROPOSAL_TITLE_1}\""),
1311 ],
1202 )?; 1312 )?;
1203 // simulating amending the proposal 1313 c.succeeds_with(2, true, None)?;
1204 create_and_populate_branch( 1314 let mut c = p.expect_choice(
1205 &test_repo, 1315 "",
1206 FEATURE_BRANCH_NAME_1, 1316 vec![
1207 "a-changed", 1317 format!("create and checkout proposal branch (2 ahead 0 behind 'main')"),
1208 false, 1318 format!("apply to current branch with `git am`"),
1319 format!("download to ./patches"),
1320 format!("back"),
1321 ],
1209 )?; 1322 )?;
1323 c.succeeds_with(0, false, Some(0))?;
1324 p.expect_end_eventually()?;
1210 1325
1326 // remove latest commit so it is behind
1327 let branch_name = test_repo.get_checked_out_branch_name()?;
1328 test_repo.checkout("main")?;
1329 test_repo.git_repo.branch(
1330 &branch_name,
1331 &test_repo
1332 .git_repo
1333 .find_commit(test_repo.get_tip_of_local_branch(&branch_name)?)?
1334 .parent(0)?,
1335 true,
1336 )?;
1337 // add another commit (so we have an ammened local branch)
1338 test_repo.checkout(&branch_name)?;
1339 std::fs::write(
1340 test_repo.dir.join("ammended-commit.md"),
1341 "some content",
1342 )?;
1343 test_repo.stage_and_commit("add ammended-commit.md")?;
1211 test_repo.checkout("main")?; 1344 test_repo.checkout("main")?;
1345
1346 // run test
1347 p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1212 p.expect("fetching updates...\r\n")?; 1348 p.expect("fetching updates...\r\n")?;
1213 p.expect_eventually("\r\n")?; // some updates listed here 1349 p.expect_eventually("\r\n")?; // some updates listed here
1214 let mut c = p.expect_choice( 1350 let mut c = p.expect_choice(
@@ -1242,7 +1378,8 @@ mod when_main_branch_is_uptodate {
1242 relay::shutdown_relay(8000 + p)?; 1378 relay::shutdown_relay(8000 + p)?;
1243 } 1379 }
1244 Ok((originating_repo, test_repo)) 1380 Ok((originating_repo, test_repo))
1245 }); 1381 },
1382 );
1246 // launch relay 1383 // launch relay
1247 let _ = join!( 1384 let _ = join!(
1248 r51.listen_until_close(), 1385 r51.listen_until_close(),
@@ -1284,24 +1421,53 @@ mod when_main_branch_is_uptodate {
1284 1421
1285 let test_repo = GitTestRepo::default(); 1422 let test_repo = GitTestRepo::default();
1286 test_repo.populate()?; 1423 test_repo.populate()?;
1424 // create proposal branch
1287 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); 1425 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1288 1426 p.expect("fetching updates...\r\n")?;
1289 // simulating checking out the proposal (the commits_ids will match) 1427 p.expect_eventually("\r\n")?; // some updates listed here
1290 create_and_populate_branch( 1428 let mut c = p.expect_choice(
1291 &test_repo, 1429 "all proposals",
1292 "different-branch-name", 1430 vec![
1293 "a", 1431 format!("\"{PROPOSAL_TITLE_3}\""),
1294 false, 1432 format!("\"{PROPOSAL_TITLE_2}\""),
1433 format!("\"{PROPOSAL_TITLE_1}\""),
1434 ],
1295 )?; 1435 )?;
1296 // simulating amending the proposal 1436 c.succeeds_with(2, true, None)?;
1297 create_and_populate_branch( 1437 let mut c = p.expect_choice(
1298 &test_repo, 1438 "",
1299 FEATURE_BRANCH_NAME_1, 1439 vec![
1300 "a-changed", 1440 format!("create and checkout proposal branch (2 ahead 0 behind 'main')"),
1301 false, 1441 format!("apply to current branch with `git am`"),
1442 format!("download to ./patches"),
1443 format!("back"),
1444 ],
1302 )?; 1445 )?;
1446 c.succeeds_with(0, false, Some(0))?;
1447 p.expect_end_eventually()?;
1303 1448
1449 // remove latest commit so it is behind
1450 let branch_name = test_repo.get_checked_out_branch_name()?;
1304 test_repo.checkout("main")?; 1451 test_repo.checkout("main")?;
1452 test_repo.git_repo.branch(
1453 &branch_name,
1454 &test_repo
1455 .git_repo
1456 .find_commit(test_repo.get_tip_of_local_branch(&branch_name)?)?
1457 .parent(0)?,
1458 true,
1459 )?;
1460 // add another commit (so we have an ammened local branch)
1461 test_repo.checkout(&branch_name)?;
1462 std::fs::write(
1463 test_repo.dir.join("ammended-commit.md"),
1464 "some content",
1465 )?;
1466 test_repo.stage_and_commit("add ammended-commit.md")?;
1467 test_repo.checkout("main")?;
1468
1469 // run test
1470 p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1305 p.expect("fetching updates...\r\n")?; 1471 p.expect("fetching updates...\r\n")?;
1306 p.expect_eventually("\r\n")?; // some updates listed here 1472 p.expect_eventually("\r\n")?; // some updates listed here
1307 let mut c = p.expect_choice( 1473 let mut c = p.expect_choice(
@@ -1362,7 +1528,10 @@ mod when_main_branch_is_uptodate {
1362 let (originating_repo, test_repo) = prep_and_run().await?; 1528 let (originating_repo, test_repo) = prep_and_run().await?;
1363 println!("test_dir: {:?}", test_repo.dir); 1529 println!("test_dir: {:?}", test_repo.dir);
1364 assert_eq!( 1530 assert_eq!(
1365 test_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, 1531 test_repo.get_tip_of_local_branch(&get_proposal_branch_name(
1532 &test_repo,
1533 FEATURE_BRANCH_NAME_1
1534 )?)?,
1366 originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, 1535 originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?,
1367 ); 1536 );
1368 Ok(()) 1537 Ok(())
@@ -1395,19 +1564,41 @@ mod when_main_branch_is_uptodate {
1395 1564
1396 let test_repo = GitTestRepo::default(); 1565 let test_repo = GitTestRepo::default();
1397 test_repo.populate()?; 1566 test_repo.populate()?;
1567 // create proposal branch
1398 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); 1568 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1399 1569 p.expect("fetching updates...\r\n")?;
1400 create_and_populate_branch( 1570 p.expect_eventually("\r\n")?; // some updates listed here
1401 &test_repo, 1571 let mut c = p.expect_choice(
1402 FEATURE_BRANCH_NAME_1, 1572 "all proposals",
1403 "a", 1573 vec![
1404 false, 1574 format!("\"{PROPOSAL_TITLE_3}\""),
1575 format!("\"{PROPOSAL_TITLE_2}\""),
1576 format!("\"{PROPOSAL_TITLE_1}\""),
1577 ],
1578 )?;
1579 c.succeeds_with(2, true, None)?;
1580 let mut c = p.expect_choice(
1581 "",
1582 vec![
1583 format!("create and checkout proposal branch (2 ahead 0 behind 'main')"),
1584 format!("apply to current branch with `git am`"),
1585 format!("download to ./patches"),
1586 format!("back"),
1587 ],
1405 )?; 1588 )?;
1406 // add appended commit to local branch 1589 c.succeeds_with(0, false, Some(0))?;
1407 std::fs::write(test_repo.dir.join("appended.md"), "some content")?; 1590 p.expect_end_eventually()?;
1408 test_repo.stage_and_commit("appended commit")?;
1409 1591
1592 // add another commit (so we have a local branch 1 ahead)
1593 std::fs::write(
1594 test_repo.dir.join("ammended-commit.md"),
1595 "some content",
1596 )?;
1597 test_repo.stage_and_commit("add ammended-commit.md")?;
1410 test_repo.checkout("main")?; 1598 test_repo.checkout("main")?;
1599
1600 // run test
1601 p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1411 p.expect("fetching updates...\r\n")?; 1602 p.expect("fetching updates...\r\n")?;
1412 p.expect_eventually("\r\n")?; // some updates listed here 1603 p.expect_eventually("\r\n")?; // some updates listed here
1413 let mut c = p.expect_choice( 1604 let mut c = p.expect_choice(
@@ -1481,19 +1672,41 @@ mod when_main_branch_is_uptodate {
1481 1672
1482 let test_repo = GitTestRepo::default(); 1673 let test_repo = GitTestRepo::default();
1483 test_repo.populate()?; 1674 test_repo.populate()?;
1675 // create proposal branch
1484 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); 1676 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1485 1677 p.expect("fetching updates...\r\n")?;
1486 create_and_populate_branch( 1678 p.expect_eventually("\r\n")?; // some updates listed here
1487 &test_repo, 1679 let mut c = p.expect_choice(
1488 FEATURE_BRANCH_NAME_1, 1680 "all proposals",
1489 "a", 1681 vec![
1490 false, 1682 format!("\"{PROPOSAL_TITLE_3}\""),
1683 format!("\"{PROPOSAL_TITLE_2}\""),
1684 format!("\"{PROPOSAL_TITLE_1}\""),
1685 ],
1491 )?; 1686 )?;
1492 // add appended commit to local branch 1687 c.succeeds_with(2, true, None)?;
1493 std::fs::write(test_repo.dir.join("appended.md"), "some content")?; 1688 let mut c = p.expect_choice(
1494 test_repo.stage_and_commit("appended commit")?; 1689 "",
1690 vec![
1691 format!("create and checkout proposal branch (2 ahead 0 behind 'main')"),
1692 format!("apply to current branch with `git am`"),
1693 format!("download to ./patches"),
1694 format!("back"),
1695 ],
1696 )?;
1697 c.succeeds_with(0, false, Some(0))?;
1698 p.expect_end_eventually()?;
1495 1699
1700 // add another commit (so we have a local branch 1 ahead)
1701 std::fs::write(
1702 test_repo.dir.join("ammended-commit.md"),
1703 "some content",
1704 )?;
1705 test_repo.stage_and_commit("add ammended-commit.md")?;
1496 test_repo.checkout("main")?; 1706 test_repo.checkout("main")?;
1707
1708 // run test
1709 p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1497 p.expect("fetching updates...\r\n")?; 1710 p.expect("fetching updates...\r\n")?;
1498 p.expect_eventually("\r\n")?; // some updates listed here 1711 p.expect_eventually("\r\n")?; // some updates listed here
1499 let mut c = p.expect_choice( 1712 let mut c = p.expect_choice(
@@ -1545,7 +1758,7 @@ mod when_main_branch_is_uptodate {
1545 async fn proposal_branch_checked_out() -> Result<()> { 1758 async fn proposal_branch_checked_out() -> Result<()> {
1546 let (_, test_repo) = prep_and_run().await?; 1759 let (_, test_repo) = prep_and_run().await?;
1547 assert_eq!( 1760 assert_eq!(
1548 FEATURE_BRANCH_NAME_1, 1761 get_proposal_branch_name(&test_repo, FEATURE_BRANCH_NAME_1)?,
1549 test_repo.get_checked_out_branch_name()?, 1762 test_repo.get_checked_out_branch_name()?,
1550 ); 1763 );
1551 Ok(()) 1764 Ok(())
@@ -1556,7 +1769,10 @@ mod when_main_branch_is_uptodate {
1556 async fn didnt_overwrite_local_appendments() -> Result<()> { 1769 async fn didnt_overwrite_local_appendments() -> Result<()> {
1557 let (originating_repo, test_repo) = prep_and_run().await?; 1770 let (originating_repo, test_repo) = prep_and_run().await?;
1558 assert_ne!( 1771 assert_ne!(
1559 test_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, 1772 test_repo.get_tip_of_local_branch(&get_proposal_branch_name(
1773 &test_repo,
1774 FEATURE_BRANCH_NAME_1
1775 )?)?,
1560 originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, 1776 originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?,
1561 ); 1777 );
1562 Ok(()) 1778 Ok(())
@@ -1592,7 +1808,34 @@ mod when_main_branch_is_uptodate {
1592 tokio::task::spawn_blocking(move || { 1808 tokio::task::spawn_blocking(move || {
1593 // create 3 proposals 1809 // create 3 proposals
1594 let _ = cli_tester_create_proposals()?; 1810 let _ = cli_tester_create_proposals()?;
1595 // get proposal id of first 1811 // download the origianl version of the first proposal
1812 let test_repo = GitTestRepo::default();
1813 test_repo.populate()?;
1814
1815 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1816 p.expect("fetching updates...\r\n")?;
1817 p.expect_eventually("\r\n")?; // some updates listed here
1818 let mut c = p.expect_choice(
1819 "all proposals",
1820 vec![
1821 format!("\"{PROPOSAL_TITLE_3}\""),
1822 format!("\"{PROPOSAL_TITLE_2}\""),
1823 format!("\"{PROPOSAL_TITLE_1}\""),
1824 ],
1825 )?;
1826 c.succeeds_with(2, true, None)?;
1827 let mut c = p.expect_choice(
1828 "",
1829 vec![
1830 format!("create and checkout proposal branch (2 ahead 0 behind 'main')"),
1831 format!("apply to current branch with `git am`"),
1832 format!("download to ./patches"),
1833 format!("back"),
1834 ],
1835 )?;
1836 c.succeeds_with(0, false, Some(0))?;
1837 p.expect_end_eventually()?;
1838
1596 // get proposal id of first 1839 // get proposal id of first
1597 let client = Client::default(); 1840 let client = Client::default();
1598 Handle::current().block_on(client.add_relay("ws://localhost:8055"))?; 1841 Handle::current().block_on(client.add_relay("ws://localhost:8055"))?;
@@ -1638,15 +1881,6 @@ mod when_main_branch_is_uptodate {
1638 Some(proposal_1_id.to_string()), 1881 Some(proposal_1_id.to_string()),
1639 )?; 1882 )?;
1640 1883
1641 // pretend we have downloaded the origianl version of the first proposal
1642 let test_repo = GitTestRepo::default();
1643 test_repo.populate()?;
1644 create_and_populate_branch(
1645 &test_repo,
1646 FEATURE_BRANCH_NAME_1,
1647 "a",
1648 false,
1649 )?;
1650 // pretend we have pulled the updated main branch 1884 // pretend we have pulled the updated main branch
1651 test_repo.checkout("main")?; 1885 test_repo.checkout("main")?;
1652 std::fs::write(test_repo.dir.join("amazing.md"), "some content")?; 1886 std::fs::write(test_repo.dir.join("amazing.md"), "some content")?;
@@ -1724,6 +1958,34 @@ mod when_main_branch_is_uptodate {
1724 move || { 1958 move || {
1725 // create 3 proposals 1959 // create 3 proposals
1726 let _ = cli_tester_create_proposals()?; 1960 let _ = cli_tester_create_proposals()?;
1961 // download the origianl version of the first proposal
1962 let test_repo = GitTestRepo::default();
1963 test_repo.populate()?;
1964
1965 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1966 p.expect("fetching updates...\r\n")?;
1967 p.expect_eventually("\r\n")?; // some updates listed here
1968 let mut c = p.expect_choice(
1969 "all proposals",
1970 vec![
1971 format!("\"{PROPOSAL_TITLE_3}\""),
1972 format!("\"{PROPOSAL_TITLE_2}\""),
1973 format!("\"{PROPOSAL_TITLE_1}\""),
1974 ],
1975 )?;
1976 c.succeeds_with(2, true, None)?;
1977 let mut c = p.expect_choice(
1978 "",
1979 vec![
1980 format!("create and checkout proposal branch (2 ahead 0 behind 'main')"),
1981 format!("apply to current branch with `git am`"),
1982 format!("download to ./patches"),
1983 format!("back"),
1984 ],
1985 )?;
1986 c.succeeds_with(0, false, Some(0))?;
1987 p.expect_end_eventually()?;
1988
1727 // get proposal id of first 1989 // get proposal id of first
1728 let client = Client::default(); 1990 let client = Client::default();
1729 Handle::current() 1991 Handle::current()
@@ -1771,16 +2033,6 @@ mod when_main_branch_is_uptodate {
1771 Some(proposal_1_id.to_string()), 2033 Some(proposal_1_id.to_string()),
1772 )?; 2034 )?;
1773 2035
1774 // pretend we have downloaded the origianl version of the first
1775 // proposal
1776 let test_repo = GitTestRepo::default();
1777 test_repo.populate()?;
1778 create_and_populate_branch(
1779 &test_repo,
1780 FEATURE_BRANCH_NAME_1,
1781 "a",
1782 false,
1783 )?;
1784 // pretend we have pulled the updated main branch 2036 // pretend we have pulled the updated main branch
1785 test_repo.checkout("main")?; 2037 test_repo.checkout("main")?;
1786 std::fs::write(test_repo.dir.join("amazing.md"), "some content")?; 2038 std::fs::write(test_repo.dir.join("amazing.md"), "some content")?;
@@ -1839,7 +2091,7 @@ mod when_main_branch_is_uptodate {
1839 async fn proposal_branch_checked_out() -> Result<()> { 2091 async fn proposal_branch_checked_out() -> Result<()> {
1840 let (_, test_repo) = prep_and_run().await?; 2092 let (_, test_repo) = prep_and_run().await?;
1841 assert_eq!( 2093 assert_eq!(
1842 FEATURE_BRANCH_NAME_1, 2094 get_proposal_branch_name(&test_repo, FEATURE_BRANCH_NAME_1)?,
1843 test_repo.get_checked_out_branch_name()?, 2095 test_repo.get_checked_out_branch_name()?,
1844 ); 2096 );
1845 Ok(()) 2097 Ok(())
@@ -1851,7 +2103,10 @@ mod when_main_branch_is_uptodate {
1851 let (originating_repo, test_repo) = prep_and_run().await?; 2103 let (originating_repo, test_repo) = prep_and_run().await?;
1852 assert_eq!( 2104 assert_eq!(
1853 originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, 2105 originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?,
1854 test_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, 2106 test_repo.get_tip_of_local_branch(&get_proposal_branch_name(
2107 &test_repo,
2108 FEATURE_BRANCH_NAME_1
2109 )?)?,
1855 ); 2110 );
1856 Ok(()) 2111 Ok(())
1857 } 2112 }
diff --git a/tests/pull.rs b/tests/pull.rs
index ecd64ff..0febd5c 100644
--- a/tests/pull.rs
+++ b/tests/pull.rs
@@ -156,7 +156,30 @@ mod when_main_is_checked_out {
156 let test_repo = GitTestRepo::default(); 156 let test_repo = GitTestRepo::default();
157 test_repo.populate()?; 157 test_repo.populate()?;
158 158
159 create_and_populate_branch(&test_repo, FEATURE_BRANCH_NAME_1, "a", false)?; 159 // create proposal branch
160 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
161 p.expect("fetching updates...\r\n")?;
162 p.expect_eventually("\r\n")?; // some updates listed here
163 let mut c = p.expect_choice(
164 "all proposals",
165 vec![
166 format!("\"{PROPOSAL_TITLE_3}\""),
167 format!("\"{PROPOSAL_TITLE_2}\""),
168 format!("\"{PROPOSAL_TITLE_1}\""),
169 ],
170 )?;
171 c.succeeds_with(2, true, None)?;
172 let mut c = p.expect_choice(
173 "",
174 vec![
175 format!("create and checkout proposal branch (2 ahead 0 behind 'main')"),
176 format!("apply to current branch with `git am`"),
177 format!("download to ./patches"),
178 format!("back"),
179 ],
180 )?;
181 c.succeeds_with(0, false, Some(0))?;
182 p.expect_end_eventually()?;
160 test_repo.checkout("main")?; 183 test_repo.checkout("main")?;
161 184
162 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); 185 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]);
@@ -277,7 +300,32 @@ mod when_branch_is_checked_out {
277 let test_repo = GitTestRepo::default(); 300 let test_repo = GitTestRepo::default();
278 test_repo.populate()?; 301 test_repo.populate()?;
279 302
280 create_and_populate_branch(&test_repo, FEATURE_BRANCH_NAME_1, "a", false)?; 303 // create proposal branch
304 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
305 p.expect("fetching updates...\r\n")?;
306 p.expect_eventually("\r\n")?; // some updates listed here
307 let mut c = p.expect_choice(
308 "all proposals",
309 vec![
310 format!("\"{PROPOSAL_TITLE_3}\""),
311 format!("\"{PROPOSAL_TITLE_2}\""),
312 format!("\"{PROPOSAL_TITLE_1}\""),
313 ],
314 )?;
315 c.succeeds_with(2, true, None)?;
316 let mut c = p.expect_choice(
317 "",
318 vec![
319 format!(
320 "create and checkout proposal branch (2 ahead 0 behind 'main')"
321 ),
322 format!("apply to current branch with `git am`"),
323 format!("download to ./patches"),
324 format!("back"),
325 ],
326 )?;
327 c.succeeds_with(0, false, Some(0))?;
328 p.expect_end_eventually()?;
281 329
282 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); 330 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]);
283 p.expect("fetching updates...\r\n")?; 331 p.expect("fetching updates...\r\n")?;
@@ -333,7 +381,44 @@ mod when_branch_is_checked_out {
333 let test_repo = GitTestRepo::default(); 381 let test_repo = GitTestRepo::default();
334 test_repo.populate()?; 382 test_repo.populate()?;
335 383
336 create_and_populate_branch(&test_repo, FEATURE_BRANCH_NAME_1, "a", true)?; 384 // create proposal branch
385 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
386 p.expect("fetching updates...\r\n")?;
387 p.expect_eventually("\r\n")?; // some updates listed here
388 let mut c = p.expect_choice(
389 "all proposals",
390 vec![
391 format!("\"{PROPOSAL_TITLE_3}\""),
392 format!("\"{PROPOSAL_TITLE_2}\""),
393 format!("\"{PROPOSAL_TITLE_1}\""),
394 ],
395 )?;
396 c.succeeds_with(2, true, None)?;
397 let mut c = p.expect_choice(
398 "",
399 vec![
400 format!(
401 "create and checkout proposal branch (2 ahead 0 behind 'main')"
402 ),
403 format!("apply to current branch with `git am`"),
404 format!("download to ./patches"),
405 format!("back"),
406 ],
407 )?;
408 c.succeeds_with(0, false, Some(0))?;
409 p.expect_end_eventually()?;
410
411 // remove latest commit so it is behind
412 let branch_name = test_repo.get_checked_out_branch_name()?;
413 test_repo.checkout("main")?;
414 test_repo.git_repo.branch(
415 &branch_name,
416 &test_repo
417 .git_repo
418 .find_commit(test_repo.get_tip_of_local_branch(&branch_name)?)?
419 .parent(0)?,
420 true,
421 )?;
337 422
338 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); 423 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]);
339 p.expect_end_eventually()?; 424 p.expect_end_eventually()?;
@@ -387,13 +472,49 @@ mod when_branch_is_checked_out {
387 let test_repo = GitTestRepo::default(); 472 let test_repo = GitTestRepo::default();
388 test_repo.populate()?; 473 test_repo.populate()?;
389 474
390 create_and_populate_branch(&test_repo, FEATURE_BRANCH_NAME_1, "a", true)?; 475 // create proposal branch
476 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
477 p.expect("fetching updates...\r\n")?;
478 p.expect_eventually("\r\n")?; // some updates listed here
479 let mut c = p.expect_choice(
480 "all proposals",
481 vec![
482 format!("\"{PROPOSAL_TITLE_3}\""),
483 format!("\"{PROPOSAL_TITLE_2}\""),
484 format!("\"{PROPOSAL_TITLE_1}\""),
485 ],
486 )?;
487 c.succeeds_with(2, true, None)?;
488 let mut c = p.expect_choice(
489 "",
490 vec![
491 format!(
492 "create and checkout proposal branch (2 ahead 0 behind 'main')"
493 ),
494 format!("apply to current branch with `git am`"),
495 format!("download to ./patches"),
496 format!("back"),
497 ],
498 )?;
499 c.succeeds_with(0, false, Some(0))?;
500 p.expect_end_eventually()?;
501
502 // remove latest commit so it is behind
503 let branch_name = test_repo.get_checked_out_branch_name()?;
504 test_repo.checkout("main")?;
505 test_repo.git_repo.branch(
506 &branch_name,
507 &test_repo
508 .git_repo
509 .find_commit(test_repo.get_tip_of_local_branch(&branch_name)?)?
510 .parent(0)?,
511 true,
512 )?;
391 513
392 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); 514 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]);
393 p.expect("fetching updates...\r\n")?; 515 p.expect("fetching updates...\r\n")?;
394 p.expect_eventually("\r\n")?; // some updates listed here 516 p.expect_eventually("\r\n")?; // some updates listed here
395 p.expect("applied 1 new commits\r\n")?; 517 p.expect_end_with("applied 1 new commits\r\n")?;
396 p.expect_end()?;
397 518
398 for p in [51, 52, 53, 55, 56] { 519 for p in [51, 52, 53, 55, 56] {
399 relay::shutdown_relay(8000 + p)?; 520 relay::shutdown_relay(8000 + p)?;
@@ -421,7 +542,10 @@ mod when_branch_is_checked_out {
421 let (originating_repo, test_repo) = prep_and_run().await?; 542 let (originating_repo, test_repo) = prep_and_run().await?;
422 assert_eq!( 543 assert_eq!(
423 originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, 544 originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?,
424 test_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, 545 test_repo.get_tip_of_local_branch(&get_proposal_branch_name(
546 &test_repo,
547 FEATURE_BRANCH_NAME_1
548 )?)?,
425 ); 549 );
426 Ok(()) 550 Ok(())
427 } 551 }
@@ -453,20 +577,72 @@ mod when_branch_is_checked_out {
453 r55.events.push(generate_test_key_1_relay_list_event()); 577 r55.events.push(generate_test_key_1_relay_list_event());
454 578
455 let cli_tester_handle = std::thread::spawn(move || -> Result<()> { 579 let cli_tester_handle = std::thread::spawn(move || -> Result<()> {
456 cli_tester_create_proposals()?; 580 let originating_repo = cli_tester_create_proposals()?;
457 581
458 let test_repo = GitTestRepo::default(); 582 let test_repo = GitTestRepo::default();
459 test_repo.populate()?; 583 test_repo.populate()?;
460 584
461 // simulating amending an older version of the proposal commits on the current 585 // create proposal branch
462 // branch 586 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
463 create_and_populate_branch( 587 p.expect("fetching updates...\r\n")?;
464 &test_repo, 588 p.expect_eventually("\r\n")?; // some updates listed here
465 FEATURE_BRANCH_NAME_1, 589 let mut c = p.expect_choice(
466 "a-changed", 590 "all proposals",
467 false, 591 vec![
592 format!("\"{PROPOSAL_TITLE_3}\""),
593 format!("\"{PROPOSAL_TITLE_2}\""),
594 format!("\"{PROPOSAL_TITLE_1}\""),
595 ],
596 )?;
597 c.succeeds_with(2, true, None)?;
598 let mut c = p.expect_choice(
599 "",
600 vec![
601 format!(
602 "create and checkout proposal branch (2 ahead 0 behind 'main')"
603 ),
604 format!("apply to current branch with `git am`"),
605 format!("download to ./patches"),
606 format!("back"),
607 ],
468 )?; 608 )?;
609 c.succeeds_with(0, false, Some(0))?;
610 p.expect_end_eventually()?;
611
612 // remove latest commit so it is behind
613 let branch_name = test_repo.get_checked_out_branch_name()?;
614 test_repo.checkout("main")?;
615 test_repo.git_repo.branch(
616 &branch_name,
617 &test_repo
618 .git_repo
619 .find_commit(test_repo.get_tip_of_local_branch(&branch_name)?)?
620 .parent(0)?,
621 true,
622 )?;
623 // add another commit (so we have an ammened local branch)
624 test_repo.checkout(&branch_name)?;
625 std::fs::write(test_repo.dir.join("ammended-commit.md"), "some content")?;
626 test_repo.stage_and_commit("add ammended-commit.md")?;
627 test_repo.checkout("main")?;
469 628
629 // create and send a revision from another repository
630 originating_repo.checkout("main")?;
631 test_repo.git_repo.branch(
632 &branch_name,
633 &test_repo
634 .git_repo
635 .find_commit(test_repo.get_tip_of_local_branch(&branch_name)?)?
636 .parent(0)?,
637 true,
638 )?;
639 originating_repo.checkout(&branch_name)?;
640 test_repo.checkout(&branch_name)?;
641 std::fs::write(test_repo.dir.join("ammended-commit.md"), "some content")?;
642 test_repo.stage_and_commit("add ammended-commit.md")?;
643 let mut p = CliTester::new_from_dir(&test_repo.dir, ["push", "--force"]);
644 p.expect_end_eventually()?;
645 // test when branch is ammended an older version of the proposal
470 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); 646 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]);
471 p.expect("fetching updates...\r\n")?; 647 p.expect("fetching updates...\r\n")?;
472 p.expect_eventually("\r\n")?; // some updates listed here 648 p.expect_eventually("\r\n")?; // some updates listed here
@@ -534,17 +710,51 @@ mod when_branch_is_checked_out {
534 let test_repo = GitTestRepo::default(); 710 let test_repo = GitTestRepo::default();
535 test_repo.populate()?; 711 test_repo.populate()?;
536 712
537 // simulating checking out the proposal (the commits_ids will match) 713 // create proposal branch
538 create_and_populate_branch(&test_repo, "different-branch-name", "a", false)?; 714 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
715 p.expect("fetching updates...\r\n")?;
716 p.expect_eventually("\r\n")?; // some updates listed here
717 let mut c = p.expect_choice(
718 "all proposals",
719 vec![
720 format!("\"{PROPOSAL_TITLE_3}\""),
721 format!("\"{PROPOSAL_TITLE_2}\""),
722 format!("\"{PROPOSAL_TITLE_1}\""),
723 ],
724 )?;
725 c.succeeds_with(2, true, None)?;
726 let mut c = p.expect_choice(
727 "",
728 vec![
729 format!(
730 "create and checkout proposal branch (2 ahead 0 behind 'main')"
731 ),
732 format!("apply to current branch with `git am`"),
733 format!("download to ./patches"),
734 format!("back"),
735 ],
736 )?;
737 c.succeeds_with(0, false, Some(0))?;
738 p.expect_end_eventually()?;
739
740 // remove latest commit so it is behind
741 let branch_name = test_repo.get_checked_out_branch_name()?;
539 test_repo.checkout("main")?; 742 test_repo.checkout("main")?;
540 // simulating amending the proposal 743 test_repo.git_repo.branch(
541 create_and_populate_branch( 744 &branch_name,
542 &test_repo, 745 &test_repo
543 FEATURE_BRANCH_NAME_1, 746 .git_repo
544 "a-changed", 747 .find_commit(test_repo.get_tip_of_local_branch(&branch_name)?)?
545 false, 748 .parent(0)?,
749 true,
546 )?; 750 )?;
751 // add another commit (so we have an ammened local branch)
752 test_repo.checkout(&branch_name)?;
753 std::fs::write(test_repo.dir.join("ammended-commit.md"), "some content")?;
754 test_repo.stage_and_commit("add ammended-commit.md")?;
755 test_repo.checkout("main")?;
547 756
757 // run test
548 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); 758 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]);
549 p.expect("fetching updates...\r\n")?; 759 p.expect("fetching updates...\r\n")?;
550 p.expect_eventually("\r\n")?; // some updates listed here 760 p.expect_eventually("\r\n")?; // some updates listed here
@@ -606,11 +816,39 @@ mod when_branch_is_checked_out {
606 let test_repo = GitTestRepo::default(); 816 let test_repo = GitTestRepo::default();
607 test_repo.populate()?; 817 test_repo.populate()?;
608 818
609 create_and_populate_branch(&test_repo, FEATURE_BRANCH_NAME_1, "a", false)?; 819 // create proposal branch
610 // add appended commit to local branch 820 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
611 std::fs::write(test_repo.dir.join("appended.md"), "some content")?; 821 p.expect("fetching updates...\r\n")?;
612 test_repo.stage_and_commit("appended commit")?; 822 p.expect_eventually("\r\n")?; // some updates listed here
823 let mut c = p.expect_choice(
824 "all proposals",
825 vec![
826 format!("\"{PROPOSAL_TITLE_3}\""),
827 format!("\"{PROPOSAL_TITLE_2}\""),
828 format!("\"{PROPOSAL_TITLE_1}\""),
829 ],
830 )?;
831 c.succeeds_with(2, true, None)?;
832 let mut c = p.expect_choice(
833 "",
834 vec![
835 format!(
836 "create and checkout proposal branch (2 ahead 0 behind 'main')"
837 ),
838 format!("apply to current branch with `git am`"),
839 format!("download to ./patches"),
840 format!("back"),
841 ],
842 )?;
843 c.succeeds_with(0, false, Some(0))?;
844 p.expect_end_eventually()?;
613 845
846 // add another commit (so we have a local branch 1 ahead)
847 std::fs::write(test_repo.dir.join("ammended-commit.md"), "some content")?;
848 test_repo.stage_and_commit("add ammended-commit.md")?;
849 test_repo.checkout("main")?;
850
851 // run test
614 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); 852 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]);
615 p.expect("fetching updates...\r\n")?; 853 p.expect("fetching updates...\r\n")?;
616 p.expect_eventually("\r\n")?; // some updates listed here 854 p.expect_eventually("\r\n")?; // some updates listed here
@@ -665,11 +903,39 @@ mod when_branch_is_checked_out {
665 let test_repo = GitTestRepo::default(); 903 let test_repo = GitTestRepo::default();
666 test_repo.populate()?; 904 test_repo.populate()?;
667 905
668 create_and_populate_branch(&test_repo, FEATURE_BRANCH_NAME_1, "a", false)?; 906 // create proposal branch
669 // add appended commit to local branch 907 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
670 std::fs::write(test_repo.dir.join("appended.md"), "some content")?; 908 p.expect("fetching updates...\r\n")?;
671 test_repo.stage_and_commit("appended commit")?; 909 p.expect_eventually("\r\n")?; // some updates listed here
910 let mut c = p.expect_choice(
911 "all proposals",
912 vec![
913 format!("\"{PROPOSAL_TITLE_3}\""),
914 format!("\"{PROPOSAL_TITLE_2}\""),
915 format!("\"{PROPOSAL_TITLE_1}\""),
916 ],
917 )?;
918 c.succeeds_with(2, true, None)?;
919 let mut c = p.expect_choice(
920 "",
921 vec![
922 format!(
923 "create and checkout proposal branch (2 ahead 0 behind 'main')"
924 ),
925 format!("apply to current branch with `git am`"),
926 format!("download to ./patches"),
927 format!("back"),
928 ],
929 )?;
930 c.succeeds_with(0, false, Some(0))?;
931 p.expect_end_eventually()?;
932
933 // add another commit (so we have a local branch 1 ahead)
934 std::fs::write(test_repo.dir.join("ammended-commit.md"), "some content")?;
935 test_repo.stage_and_commit("add ammended-commit.md")?;
936 test_repo.checkout("main")?;
672 937
938 // run test
673 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); 939 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]);
674 p.expect("fetching updates...\r\n")?; 940 p.expect("fetching updates...\r\n")?;
675 p.expect_eventually("\r\n")?; // some updates listed here 941 p.expect_eventually("\r\n")?; // some updates listed here
@@ -701,7 +967,10 @@ mod when_branch_is_checked_out {
701 async fn didnt_overwrite_local_appendments() -> Result<()> { 967 async fn didnt_overwrite_local_appendments() -> Result<()> {
702 let (originating_repo, test_repo) = prep_and_run().await?; 968 let (originating_repo, test_repo) = prep_and_run().await?;
703 assert_ne!( 969 assert_ne!(
704 test_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, 970 test_repo.get_tip_of_local_branch(&get_proposal_branch_name(
971 &test_repo,
972 FEATURE_BRANCH_NAME_1
973 )?)?,
705 originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, 974 originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?,
706 ); 975 );
707 Ok(()) 976 Ok(())
@@ -737,6 +1006,36 @@ mod when_branch_is_checked_out {
737 tokio::task::spawn_blocking(move || { 1006 tokio::task::spawn_blocking(move || {
738 // create 3 proposals 1007 // create 3 proposals
739 let _ = cli_tester_create_proposals()?; 1008 let _ = cli_tester_create_proposals()?;
1009 // download the origianl version of the first proposal
1010 let test_repo = GitTestRepo::default();
1011 test_repo.populate()?;
1012
1013 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1014 p.expect("fetching updates...\r\n")?;
1015 p.expect_eventually("\r\n")?; // some updates listed here
1016 let mut c = p.expect_choice(
1017 "all proposals",
1018 vec![
1019 format!("\"{PROPOSAL_TITLE_3}\""),
1020 format!("\"{PROPOSAL_TITLE_2}\""),
1021 format!("\"{PROPOSAL_TITLE_1}\""),
1022 ],
1023 )?;
1024 c.succeeds_with(2, true, None)?;
1025 let mut c = p.expect_choice(
1026 "",
1027 vec![
1028 format!(
1029 "create and checkout proposal branch (2 ahead 0 behind 'main')"
1030 ),
1031 format!("apply to current branch with `git am`"),
1032 format!("download to ./patches"),
1033 format!("back"),
1034 ],
1035 )?;
1036 c.succeeds_with(0, false, Some(0))?;
1037 p.expect_end_eventually()?;
1038
740 // get proposal id of first 1039 // get proposal id of first
741 let client = Client::default(); 1040 let client = Client::default();
742 Handle::current().block_on(client.add_relay("ws://localhost:8055"))?; 1041 Handle::current().block_on(client.add_relay("ws://localhost:8055"))?;
@@ -780,10 +1079,6 @@ mod when_branch_is_checked_out {
780 Some(proposal_1_id.to_string()), 1079 Some(proposal_1_id.to_string()),
781 )?; 1080 )?;
782 1081
783 // pretend we have downloaded the origianl version of the first proposal
784 let test_repo = GitTestRepo::default();
785 test_repo.populate()?;
786 create_and_populate_branch(&test_repo, FEATURE_BRANCH_NAME_1, "a", false)?;
787 // pretend we have pulled the updated main branch 1082 // pretend we have pulled the updated main branch
788 test_repo.checkout("main")?; 1083 test_repo.checkout("main")?;
789 std::fs::write(test_repo.dir.join("amazing.md"), "some content")?; 1084 std::fs::write(test_repo.dir.join("amazing.md"), "some content")?;
@@ -838,6 +1133,36 @@ mod when_branch_is_checked_out {
838 move || { 1133 move || {
839 // create 3 proposals 1134 // create 3 proposals
840 let _ = cli_tester_create_proposals()?; 1135 let _ = cli_tester_create_proposals()?;
1136 // download the origianl version of the first proposal
1137 let test_repo = GitTestRepo::default();
1138 test_repo.populate()?;
1139
1140 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1141 p.expect("fetching updates...\r\n")?;
1142 p.expect_eventually("\r\n")?; // some updates listed here
1143 let mut c = p.expect_choice(
1144 "all proposals",
1145 vec![
1146 format!("\"{PROPOSAL_TITLE_3}\""),
1147 format!("\"{PROPOSAL_TITLE_2}\""),
1148 format!("\"{PROPOSAL_TITLE_1}\""),
1149 ],
1150 )?;
1151 c.succeeds_with(2, true, None)?;
1152 let mut c = p.expect_choice(
1153 "",
1154 vec![
1155 format!(
1156 "create and checkout proposal branch (2 ahead 0 behind 'main')"
1157 ),
1158 format!("apply to current branch with `git am`"),
1159 format!("download to ./patches"),
1160 format!("back"),
1161 ],
1162 )?;
1163 c.succeeds_with(0, false, Some(0))?;
1164 p.expect_end_eventually()?;
1165
841 // get proposal id of first 1166 // get proposal id of first
842 let client = Client::default(); 1167 let client = Client::default();
843 Handle::current().block_on(client.add_relay("ws://localhost:8055"))?; 1168 Handle::current().block_on(client.add_relay("ws://localhost:8055"))?;
@@ -882,10 +1207,6 @@ mod when_branch_is_checked_out {
882 Some(proposal_1_id.to_string()), 1207 Some(proposal_1_id.to_string()),
883 )?; 1208 )?;
884 1209
885 // pretend we have downloaded the origianl version of the first proposal
886 let test_repo = GitTestRepo::default();
887 test_repo.populate()?;
888 create_and_populate_branch(&test_repo, FEATURE_BRANCH_NAME_1, "a", false)?;
889 // pretend we have pulled the updated main branch 1210 // pretend we have pulled the updated main branch
890 test_repo.checkout("main")?; 1211 test_repo.checkout("main")?;
891 std::fs::write(test_repo.dir.join("amazing.md"), "some content")?; 1212 std::fs::write(test_repo.dir.join("amazing.md"), "some content")?;
@@ -923,7 +1244,10 @@ mod when_branch_is_checked_out {
923 let (originating_repo, test_repo) = prep_and_run().await?; 1244 let (originating_repo, test_repo) = prep_and_run().await?;
924 assert_eq!( 1245 assert_eq!(
925 originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, 1246 originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?,
926 test_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, 1247 test_repo.get_tip_of_local_branch(&get_proposal_branch_name(
1248 &test_repo,
1249 FEATURE_BRANCH_NAME_1
1250 )?)?,
927 ); 1251 );
928 Ok(()) 1252 Ok(())
929 } 1253 }
diff --git a/tests/push.rs b/tests/push.rs
index 1f09d28..b771d4b 100644
--- a/tests/push.rs
+++ b/tests/push.rs
@@ -201,7 +201,32 @@ mod when_branch_is_checked_out {
201 let test_repo = GitTestRepo::default(); 201 let test_repo = GitTestRepo::default();
202 test_repo.populate()?; 202 test_repo.populate()?;
203 203
204 create_and_populate_branch(&test_repo, FEATURE_BRANCH_NAME_1, "a", false)?; 204 // create proposal branch
205 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
206 p.expect("fetching updates...\r\n")?;
207 p.expect_eventually("\r\n")?; // some updates listed here
208 let mut c = p.expect_choice(
209 "all proposals",
210 vec![
211 format!("\"{PROPOSAL_TITLE_3}\""),
212 format!("\"{PROPOSAL_TITLE_2}\""),
213 format!("\"{PROPOSAL_TITLE_1}\""),
214 ],
215 )?;
216 c.succeeds_with(2, true, None)?;
217 let mut c = p.expect_choice(
218 "",
219 vec![
220 format!(
221 "create and checkout proposal branch (2 ahead 0 behind 'main')"
222 ),
223 format!("apply to current branch with `git am`"),
224 format!("download to ./patches"),
225 format!("back"),
226 ],
227 )?;
228 c.succeeds_with(0, false, Some(0))?;
229 p.expect_end_eventually()?;
205 230
206 let mut p = CliTester::new_from_dir(&test_repo.dir, ["push"]); 231 let mut p = CliTester::new_from_dir(&test_repo.dir, ["push"]);
207 p.expect("fetching updates...\r\n")?; 232 p.expect("fetching updates...\r\n")?;
@@ -259,8 +284,46 @@ mod when_branch_is_checked_out {
259 let test_repo = GitTestRepo::default(); 284 let test_repo = GitTestRepo::default();
260 test_repo.populate()?; 285 test_repo.populate()?;
261 286
262 create_and_populate_branch(&test_repo, FEATURE_BRANCH_NAME_1, "a", true)?; 287 // create proposal branch
263 288 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
289 p.expect("fetching updates...\r\n")?;
290 p.expect_eventually("\r\n")?; // some updates listed here
291 let mut c = p.expect_choice(
292 "all proposals",
293 vec![
294 format!("\"{PROPOSAL_TITLE_3}\""),
295 format!("\"{PROPOSAL_TITLE_2}\""),
296 format!("\"{PROPOSAL_TITLE_1}\""),
297 ],
298 )?;
299 c.succeeds_with(2, true, None)?;
300 let mut c = p.expect_choice(
301 "",
302 vec![
303 format!(
304 "create and checkout proposal branch (2 ahead 0 behind 'main')"
305 ),
306 format!("apply to current branch with `git am`"),
307 format!("download to ./patches"),
308 format!("back"),
309 ],
310 )?;
311 c.succeeds_with(0, false, Some(0))?;
312 p.expect_end_eventually()?;
313
314 // remove latest commit so it is behind
315 let branch_name = test_repo.get_checked_out_branch_name()?;
316 test_repo.checkout("main")?;
317 test_repo.git_repo.branch(
318 &branch_name,
319 &test_repo
320 .git_repo
321 .find_commit(test_repo.get_tip_of_local_branch(&branch_name)?)?
322 .parent(0)?,
323 true,
324 )?;
325 test_repo.checkout(&branch_name)?;
326 // run test
264 let mut p = CliTester::new_from_dir(&test_repo.dir, ["push"]); 327 let mut p = CliTester::new_from_dir(&test_repo.dir, ["push"]);
265 p.expect("fetching updates...\r\n")?; 328 p.expect("fetching updates...\r\n")?;
266 p.expect_eventually("\r\n")?; // some updates listed here 329 p.expect_eventually("\r\n")?; // some updates listed here
@@ -322,11 +385,37 @@ mod when_branch_is_checked_out {
322 let test_repo = GitTestRepo::default(); 385 let test_repo = GitTestRepo::default();
323 test_repo.populate()?; 386 test_repo.populate()?;
324 387
325 create_and_populate_branch(&test_repo, FEATURE_BRANCH_NAME_1, "a", false)?; 388 // create proposal branch
326 389 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
327 std::fs::write(test_repo.dir.join("a5.md"), "some content")?; 390 p.expect("fetching updates...\r\n")?;
328 test_repo.stage_and_commit("add a5.md".to_string().as_str())?; 391 p.expect_eventually("\r\n")?; // some updates listed here
392 let mut c = p.expect_choice(
393 "all proposals",
394 vec![
395 format!("\"{PROPOSAL_TITLE_3}\""),
396 format!("\"{PROPOSAL_TITLE_2}\""),
397 format!("\"{PROPOSAL_TITLE_1}\""),
398 ],
399 )?;
400 c.succeeds_with(2, true, None)?;
401 let mut c = p.expect_choice(
402 "",
403 vec![
404 format!(
405 "create and checkout proposal branch (2 ahead 0 behind 'main')"
406 ),
407 format!("apply to current branch with `git am`"),
408 format!("download to ./patches"),
409 format!("back"),
410 ],
411 )?;
412 c.succeeds_with(0, false, Some(0))?;
413 p.expect_end_eventually()?;
414 // add another commit (so we have an ammened local branch)
415 std::fs::write(test_repo.dir.join("ammended-commit.md"), "some content")?;
416 test_repo.stage_and_commit("add ammended-commit.md")?;
329 417
418 // run test
330 let mut p = CliTester::new_from_dir( 419 let mut p = CliTester::new_from_dir(
331 &test_repo.dir, 420 &test_repo.dir,
332 [ 421 [
@@ -404,7 +493,35 @@ mod when_branch_is_checked_out {
404 let test_repo = GitTestRepo::default(); 493 let test_repo = GitTestRepo::default();
405 test_repo.populate()?; 494 test_repo.populate()?;
406 495
407 create_and_populate_branch(&test_repo, FEATURE_BRANCH_NAME_1, "a", false)?; 496 // create proposal branch
497 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
498 p.expect("fetching updates...\r\n")?;
499 p.expect_eventually("\r\n")?; // some updates listed here
500 let mut c = p.expect_choice(
501 "all proposals",
502 vec![
503 format!("\"{PROPOSAL_TITLE_3}\""),
504 format!("\"{PROPOSAL_TITLE_2}\""),
505 format!("\"{PROPOSAL_TITLE_1}\""),
506 ],
507 )?;
508 c.succeeds_with(2, true, None)?;
509 let mut c = p.expect_choice(
510 "",
511 vec![
512 format!("create and checkout proposal branch (2 ahead 0 behind 'main')"),
513 format!("apply to current branch with `git am`"),
514 format!("download to ./patches"),
515 format!("back"),
516 ],
517 )?;
518 c.succeeds_with(0, false, Some(0))?;
519 p.expect_end_eventually()?;
520 // add another commit (so we have an ammened local branch)
521 std::fs::write(test_repo.dir.join("ammended-commit.md"), "some content")?;
522 test_repo.stage_and_commit("add ammended-commit.md")?;
523
524 // run test
408 525
409 let mut p = CliTester::new_from_dir( 526 let mut p = CliTester::new_from_dir(
410 &test_repo.dir, 527 &test_repo.dir,
@@ -443,7 +560,7 @@ mod when_branch_is_checked_out {
443 let (test_repo, r55_events) = prep_and_run().await?; 560 let (test_repo, r55_events) = prep_and_run().await?;
444 561
445 let commit_id = test_repo 562 let commit_id = test_repo
446 .get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)? 563 .get_tip_of_local_branch(&test_repo.get_checked_out_branch_name()?)?
447 .to_string(); 564 .to_string();
448 assert!(r55_events.iter().any(|e| { 565 assert!(r55_events.iter().any(|e| {
449 e.tags 566 e.tags
@@ -482,20 +599,52 @@ mod when_branch_is_checked_out {
482 let cli_tester_handle = std::thread::spawn(move || -> Result<()> { 599 let cli_tester_handle = std::thread::spawn(move || -> Result<()> {
483 cli_tester_create_proposals()?; 600 cli_tester_create_proposals()?;
484 601
602 // discover proposal branch name
603 let tmp_repo = GitTestRepo::default();
604 tmp_repo.populate()?;
605 let mut p = CliTester::new_from_dir(&tmp_repo.dir, ["list"]);
606 p.expect("fetching updates...\r\n")?;
607 p.expect_eventually("\r\n")?; // some updates listed here
608 let mut c = p.expect_choice(
609 "all proposals",
610 vec![
611 format!("\"{PROPOSAL_TITLE_3}\""),
612 format!("\"{PROPOSAL_TITLE_2}\""),
613 format!("\"{PROPOSAL_TITLE_1}\""),
614 ],
615 )?;
616 c.succeeds_with(2, true, None)?;
617 let mut c = p.expect_choice(
618 "",
619 vec![
620 format!(
621 "create and checkout proposal branch (2 ahead 0 behind 'main')"
622 ),
623 format!("apply to current branch with `git am`"),
624 format!("download to ./patches"),
625 format!("back"),
626 ],
627 )?;
628 c.succeeds_with(0, false, Some(0))?;
629 p.expect_end_eventually()?;
630 let branch_name = tmp_repo.get_checked_out_branch_name()?;
631
485 let test_repo = GitTestRepo::default(); 632 let test_repo = GitTestRepo::default();
486 test_repo.populate()?; 633 test_repo.populate()?;
487 634
488 // simulate rebase 635 // simulate rebase
489 std::fs::write(test_repo.dir.join("amazing.md"), "some content")?; 636 std::fs::write(test_repo.dir.join("amazing.md"), "some content")?;
490 test_repo.stage_and_commit("commit for rebasing on top of")?; 637 test_repo.stage_and_commit("commit for rebasing on top of")?;
491 create_and_populate_branch(&test_repo, FEATURE_BRANCH_NAME_1, "a", true)?; 638 create_and_populate_branch(&test_repo, &branch_name, "a", true)?;
492 639
493 let mut p = CliTester::new_from_dir(&test_repo.dir, ["push"]); 640 let mut p = CliTester::new_from_dir(&test_repo.dir, ["push"]);
494 // p.expect_end_eventually_and_print()?; 641 // p.expect_end_eventually_and_print()?;
495 642
496 p.expect("fetching updates...\r\n")?; 643 p.expect("fetching updates...\r\n")?;
497 p.expect_eventually("\r\n")?; // some updates listed here 644 p.expect_eventually("\r\n")?; // some updates listed here
498 p.expect("Error: local unpublished proposal has been rebased. consider force pushing\r\n")?; 645 p.expect(
646 "Error: local unpublished proposal has been rebased. consider force pushing\r\n",
647 )?;
499 p.expect_end()?; 648 p.expect_end()?;
500 649
501 for p in [51, 52, 53, 55, 56] { 650 for p in [51, 52, 53, 55, 56] {
@@ -543,6 +692,35 @@ mod when_branch_is_checked_out {
543 692
544 let cli_tester_handle = std::thread::spawn(move || -> Result<()> { 693 let cli_tester_handle = std::thread::spawn(move || -> Result<()> {
545 cli_tester_create_proposals()?; 694 cli_tester_create_proposals()?;
695 // discover proposal branch name
696 let tmp_repo = GitTestRepo::default();
697 tmp_repo.populate()?;
698 let mut p = CliTester::new_from_dir(&tmp_repo.dir, ["list"]);
699 p.expect("fetching updates...\r\n")?;
700 p.expect_eventually("\r\n")?; // some updates listed here
701 let mut c = p.expect_choice(
702 "all proposals",
703 vec![
704 format!("\"{PROPOSAL_TITLE_3}\""),
705 format!("\"{PROPOSAL_TITLE_2}\""),
706 format!("\"{PROPOSAL_TITLE_1}\""),
707 ],
708 )?;
709 c.succeeds_with(2, true, None)?;
710 let mut c = p.expect_choice(
711 "",
712 vec![
713 format!(
714 "create and checkout proposal branch (2 ahead 0 behind 'main')"
715 ),
716 format!("apply to current branch with `git am`"),
717 format!("download to ./patches"),
718 format!("back"),
719 ],
720 )?;
721 c.succeeds_with(0, false, Some(0))?;
722 p.expect_end_eventually()?;
723 let branch_name = tmp_repo.get_checked_out_branch_name()?;
546 724
547 let test_repo = GitTestRepo::default(); 725 let test_repo = GitTestRepo::default();
548 test_repo.populate()?; 726 test_repo.populate()?;
@@ -550,7 +728,7 @@ mod when_branch_is_checked_out {
550 // simulate rebase 728 // simulate rebase
551 std::fs::write(test_repo.dir.join("amazing.md"), "some content")?; 729 std::fs::write(test_repo.dir.join("amazing.md"), "some content")?;
552 test_repo.stage_and_commit("commit for rebasing on top of")?; 730 test_repo.stage_and_commit("commit for rebasing on top of")?;
553 create_and_populate_branch(&test_repo, FEATURE_BRANCH_NAME_1, "a", false)?; 731 create_and_populate_branch(&test_repo, &branch_name, "a", false)?;
554 let mut p = CliTester::new_from_dir( 732 let mut p = CliTester::new_from_dir(
555 &test_repo.dir, 733 &test_repo.dir,
556 [ 734 [
@@ -574,7 +752,7 @@ mod when_branch_is_checked_out {
574 let mut selector = p.expect_multi_select( 752 let mut selector = p.expect_multi_select(
575 "select commits for proposal", 753 "select commits for proposal",
576 vec![ 754 vec![
577 "(Joe Bloggs) add a4.md [feature-example-t] 355bdf1".to_string(), 755 format!("(Joe Bloggs) add a4.md [{branch_name}] 355bdf1"),
578 "(Joe Bloggs) add a3.md dbd1115".to_string(), 756 "(Joe Bloggs) add a3.md dbd1115".to_string(),
579 "(Joe Bloggs) commit for rebasing on top of [main] 1aa2cfe" 757 "(Joe Bloggs) commit for rebasing on top of [main] 1aa2cfe"
580 .to_string(), 758 .to_string(),