upleb.uk

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

summaryrefslogtreecommitdiff
path: root/tests/push.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/push.rs')
-rw-r--r--tests/push.rs204
1 files changed, 191 insertions, 13 deletions
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(),