diff options
| -rw-r--r-- | Cargo.lock | 3 | ||||
| -rw-r--r-- | src/sub_commands/list.rs | 39 | ||||
| -rw-r--r-- | src/sub_commands/pull.rs | 3 | ||||
| -rw-r--r-- | src/sub_commands/push.rs | 8 | ||||
| -rw-r--r-- | src/sub_commands/send.rs | 15 | ||||
| -rw-r--r-- | test_utils/Cargo.toml | 3 | ||||
| -rw-r--r-- | test_utils/src/lib.rs | 60 | ||||
| -rw-r--r-- | tests/list.rs | 539 | ||||
| -rw-r--r-- | tests/pull.rs | 406 | ||||
| -rw-r--r-- | tests/push.rs | 204 |
10 files changed, 1062 insertions, 218 deletions
| @@ -3054,9 +3054,12 @@ dependencies = [ | |||
| 3054 | "assert_cmd", | 3054 | "assert_cmd", |
| 3055 | "dialoguer", | 3055 | "dialoguer", |
| 3056 | "directories", | 3056 | "directories", |
| 3057 | "futures", | ||
| 3057 | "git2", | 3058 | "git2", |
| 3058 | "nostr", | 3059 | "nostr", |
| 3060 | "nostr-database", | ||
| 3059 | "nostr-sdk", | 3061 | "nostr-sdk", |
| 3062 | "nostr-sqlite", | ||
| 3060 | "once_cell", | 3063 | "once_cell", |
| 3061 | "rand", | 3064 | "rand", |
| 3062 | "rexpect 0.5.0 (git+https://github.com/rust-cli/rexpect.git?rev=9eb61dd)", | 3065 | "rexpect 0.5.0 (git+https://github.com/rust-cli/rexpect.git?rev=9eb61dd)", |
diff --git a/src/sub_commands/list.rs b/src/sub_commands/list.rs index 2ae4cfb..cc7ac6f 100644 --- a/src/sub_commands/list.rs +++ b/src/sub_commands/list.rs | |||
| @@ -263,11 +263,11 @@ pub async fn launch() -> Result<()> { | |||
| 263 | .get_local_branch_names() | 263 | .get_local_branch_names() |
| 264 | .context("gitlib2 will not show a list of local branch names")? | 264 | .context("gitlib2 will not show a list of local branch names")? |
| 265 | .iter() | 265 | .iter() |
| 266 | .any(|n| n.eq(&cover_letter.branch_name)); | 266 | .any(|n| n.eq(&cover_letter.get_branch_name().unwrap())); |
| 267 | 267 | ||
| 268 | let checked_out_proposal_branch = git_repo | 268 | let checked_out_proposal_branch = git_repo |
| 269 | .get_checked_out_branch_name()? | 269 | .get_checked_out_branch_name()? |
| 270 | .eq(&cover_letter.branch_name); | 270 | .eq(&cover_letter.get_branch_name()?); |
| 271 | 271 | ||
| 272 | let proposal_base_commit = str_to_sha1(&tag_value( | 272 | let proposal_base_commit = str_to_sha1(&tag_value( |
| 273 | most_recent_proposal_patch_chain.last().context( | 273 | most_recent_proposal_patch_chain.last().context( |
| @@ -329,14 +329,14 @@ pub async fn launch() -> Result<()> { | |||
| 329 | check_clean(&git_repo)?; | 329 | check_clean(&git_repo)?; |
| 330 | let _ = git_repo | 330 | let _ = git_repo |
| 331 | .apply_patch_chain( | 331 | .apply_patch_chain( |
| 332 | &cover_letter.branch_name, | 332 | &cover_letter.get_branch_name()?, |
| 333 | most_recent_proposal_patch_chain, | 333 | most_recent_proposal_patch_chain, |
| 334 | ) | 334 | ) |
| 335 | .context("cannot apply patch chain")?; | 335 | .context("cannot apply patch chain")?; |
| 336 | 336 | ||
| 337 | println!( | 337 | println!( |
| 338 | "checked out proposal as '{}' branch", | 338 | "checked out proposal as '{}' branch", |
| 339 | cover_letter.branch_name | 339 | cover_letter.get_branch_name()? |
| 340 | ); | 340 | ); |
| 341 | Ok(()) | 341 | Ok(()) |
| 342 | } | 342 | } |
| @@ -349,7 +349,7 @@ pub async fn launch() -> Result<()> { | |||
| 349 | }; | 349 | }; |
| 350 | } | 350 | } |
| 351 | 351 | ||
| 352 | let local_branch_tip = git_repo.get_tip_of_branch(&cover_letter.branch_name)?; | 352 | let local_branch_tip = git_repo.get_tip_of_branch(&cover_letter.get_branch_name()?)?; |
| 353 | 353 | ||
| 354 | // up-to-date | 354 | // up-to-date |
| 355 | if proposal_tip.eq(&local_branch_tip) { | 355 | if proposal_tip.eq(&local_branch_tip) { |
| @@ -384,10 +384,10 @@ pub async fn launch() -> Result<()> { | |||
| 384 | )? { | 384 | )? { |
| 385 | 0 => { | 385 | 0 => { |
| 386 | check_clean(&git_repo)?; | 386 | check_clean(&git_repo)?; |
| 387 | git_repo.checkout(&cover_letter.branch_name)?; | 387 | git_repo.checkout(&cover_letter.get_branch_name()?)?; |
| 388 | println!( | 388 | println!( |
| 389 | "checked out proposal as '{}' branch", | 389 | "checked out proposal as '{}' branch", |
| 390 | cover_letter.branch_name | 390 | cover_letter.get_branch_name()? |
| 391 | ); | 391 | ); |
| 392 | Ok(()) | 392 | Ok(()) |
| 393 | } | 393 | } |
| @@ -421,10 +421,10 @@ pub async fn launch() -> Result<()> { | |||
| 421 | )? { | 421 | )? { |
| 422 | 0 => { | 422 | 0 => { |
| 423 | check_clean(&git_repo)?; | 423 | check_clean(&git_repo)?; |
| 424 | git_repo.checkout(&cover_letter.branch_name)?; | 424 | git_repo.checkout(&cover_letter.get_branch_name()?)?; |
| 425 | let _ = git_repo | 425 | let _ = git_repo |
| 426 | .apply_patch_chain( | 426 | .apply_patch_chain( |
| 427 | &cover_letter.branch_name, | 427 | &cover_letter.get_branch_name()?, |
| 428 | most_recent_proposal_patch_chain, | 428 | most_recent_proposal_patch_chain, |
| 429 | ) | 429 | ) |
| 430 | .context("cannot apply patch chain")?; | 430 | .context("cannot apply patch chain")?; |
| @@ -474,14 +474,14 @@ pub async fn launch() -> Result<()> { | |||
| 474 | 0 => { | 474 | 0 => { |
| 475 | check_clean(&git_repo)?; | 475 | check_clean(&git_repo)?; |
| 476 | git_repo.create_branch_at_commit( | 476 | git_repo.create_branch_at_commit( |
| 477 | &cover_letter.branch_name, | 477 | &cover_letter.get_branch_name()?, |
| 478 | &proposal_base_commit.to_string(), | 478 | &proposal_base_commit.to_string(), |
| 479 | )?; | 479 | )?; |
| 480 | git_repo.checkout(&cover_letter.branch_name)?; | 480 | git_repo.checkout(&cover_letter.get_branch_name()?)?; |
| 481 | let chain_length = most_recent_proposal_patch_chain.len(); | 481 | let chain_length = most_recent_proposal_patch_chain.len(); |
| 482 | let _ = git_repo | 482 | let _ = git_repo |
| 483 | .apply_patch_chain( | 483 | .apply_patch_chain( |
| 484 | &cover_letter.branch_name, | 484 | &cover_letter.get_branch_name()?, |
| 485 | most_recent_proposal_patch_chain, | 485 | most_recent_proposal_patch_chain, |
| 486 | ) | 486 | ) |
| 487 | .context("cannot apply patch chain")?; | 487 | .context("cannot apply patch chain")?; |
| @@ -496,7 +496,7 @@ pub async fn launch() -> Result<()> { | |||
| 496 | } | 496 | } |
| 497 | 1 => { | 497 | 1 => { |
| 498 | check_clean(&git_repo)?; | 498 | check_clean(&git_repo)?; |
| 499 | git_repo.checkout(&cover_letter.branch_name)?; | 499 | git_repo.checkout(&cover_letter.get_branch_name()?)?; |
| 500 | println!( | 500 | println!( |
| 501 | "checked out old proposal in existing branch ({} ahead {} behind '{main_branch_name}')", | 501 | "checked out old proposal in existing branch ({} ahead {} behind '{main_branch_name}')", |
| 502 | local_ahead_of_main.len(), | 502 | local_ahead_of_main.len(), |
| @@ -537,7 +537,7 @@ pub async fn launch() -> Result<()> { | |||
| 537 | ]), | 537 | ]), |
| 538 | )? { | 538 | )? { |
| 539 | 0 => { | 539 | 0 => { |
| 540 | git_repo.checkout(&cover_letter.branch_name)?; | 540 | git_repo.checkout(&cover_letter.get_branch_name()?)?; |
| 541 | println!( | 541 | println!( |
| 542 | "checked out proposal branch with {} unpublished commits ({} ahead {} behind '{main_branch_name}')", | 542 | "checked out proposal branch with {} unpublished commits ({} ahead {} behind '{main_branch_name}')", |
| 543 | local_ahead_of_proposal.len(), | 543 | local_ahead_of_proposal.len(), |
| @@ -604,7 +604,7 @@ pub async fn launch() -> Result<()> { | |||
| 604 | )? { | 604 | )? { |
| 605 | 0 => { | 605 | 0 => { |
| 606 | check_clean(&git_repo)?; | 606 | check_clean(&git_repo)?; |
| 607 | git_repo.checkout(&cover_letter.branch_name)?; | 607 | git_repo.checkout(&cover_letter.get_branch_name()?)?; |
| 608 | println!( | 608 | println!( |
| 609 | "checked out old proposal in existing branch ({} ahead {} behind '{main_branch_name}')", | 609 | "checked out old proposal in existing branch ({} ahead {} behind '{main_branch_name}')", |
| 610 | local_ahead_of_main.len(), | 610 | local_ahead_of_main.len(), |
| @@ -615,15 +615,18 @@ pub async fn launch() -> Result<()> { | |||
| 615 | 1 => { | 615 | 1 => { |
| 616 | check_clean(&git_repo)?; | 616 | check_clean(&git_repo)?; |
| 617 | git_repo.create_branch_at_commit( | 617 | git_repo.create_branch_at_commit( |
| 618 | &cover_letter.branch_name, | 618 | &cover_letter.get_branch_name()?, |
| 619 | &proposal_base_commit.to_string(), | 619 | &proposal_base_commit.to_string(), |
| 620 | )?; | 620 | )?; |
| 621 | let chain_length = most_recent_proposal_patch_chain.len(); | 621 | let chain_length = most_recent_proposal_patch_chain.len(); |
| 622 | let _ = git_repo | 622 | let _ = git_repo |
| 623 | .apply_patch_chain(&cover_letter.branch_name, most_recent_proposal_patch_chain) | 623 | .apply_patch_chain( |
| 624 | &cover_letter.get_branch_name()?, | ||
| 625 | most_recent_proposal_patch_chain, | ||
| 626 | ) | ||
| 624 | .context("cannot apply patch chain")?; | 627 | .context("cannot apply patch chain")?; |
| 625 | 628 | ||
| 626 | git_repo.checkout(&cover_letter.branch_name)?; | 629 | git_repo.checkout(&cover_letter.get_branch_name()?)?; |
| 627 | println!( | 630 | println!( |
| 628 | "checked out latest version of proposal ({} ahead {} behind '{main_branch_name}'), replacing unpublished version ({} ahead {} behind '{main_branch_name}')", | 631 | "checked out latest version of proposal ({} ahead {} behind '{main_branch_name}'), replacing unpublished version ({} ahead {} behind '{main_branch_name}')", |
| 629 | chain_length, | 632 | chain_length, |
diff --git a/src/sub_commands/pull.rs b/src/sub_commands/pull.rs index dfa6f89..e33a744 100644 --- a/src/sub_commands/pull.rs +++ b/src/sub_commands/pull.rs | |||
| @@ -50,7 +50,8 @@ pub async fn launch() -> Result<()> { | |||
| 50 | .await? | 50 | .await? |
| 51 | .iter() | 51 | .iter() |
| 52 | .find(|e| { | 52 | .find(|e| { |
| 53 | event_to_cover_letter(e).is_ok_and(|cl| cl.branch_name.eq(&branch_name)) | 53 | event_to_cover_letter(e) |
| 54 | .is_ok_and(|cl| cl.get_branch_name().is_ok_and(|s| s.eq(&branch_name))) | ||
| 54 | && !event_is_revision_root(e) | 55 | && !event_is_revision_root(e) |
| 55 | }) | 56 | }) |
| 56 | .context("cannot find proposal that matches the current branch name")? | 57 | .context("cannot find proposal that matches the current branch name")? |
diff --git a/src/sub_commands/push.rs b/src/sub_commands/push.rs index d05158f..9af8b40 100644 --- a/src/sub_commands/push.rs +++ b/src/sub_commands/push.rs | |||
| @@ -16,7 +16,7 @@ use crate::{ | |||
| 16 | get_most_recent_patch_with_ancestors, get_proposals_and_revisions_from_cache, | 16 | get_most_recent_patch_with_ancestors, get_proposals_and_revisions_from_cache, |
| 17 | tag_value, | 17 | tag_value, |
| 18 | }, | 18 | }, |
| 19 | send::{event_to_cover_letter, generate_patch_event, send_events}, | 19 | send::{event_is_revision_root, event_to_cover_letter, generate_patch_event, send_events}, |
| 20 | }, | 20 | }, |
| 21 | Cli, | 21 | Cli, |
| 22 | }; | 22 | }; |
| @@ -66,7 +66,11 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 66 | get_proposals_and_revisions_from_cache(git_repo_path, repo_ref.coordinates()) | 66 | get_proposals_and_revisions_from_cache(git_repo_path, repo_ref.coordinates()) |
| 67 | .await? | 67 | .await? |
| 68 | .iter() | 68 | .iter() |
| 69 | .find(|e| event_to_cover_letter(e).is_ok_and(|cl| cl.branch_name.eq(&branch_name))) | 69 | .find(|e| { |
| 70 | event_to_cover_letter(e) | ||
| 71 | .is_ok_and(|cl| cl.get_branch_name().is_ok_and(|s| s.eq(&branch_name))) | ||
| 72 | && !event_is_revision_root(e) | ||
| 73 | }) | ||
| 70 | .context("cannot find proposal that matches the current branch name")? | 74 | .context("cannot find proposal that matches the current branch name")? |
| 71 | .clone(); | 75 | .clone(); |
| 72 | 76 | ||
diff --git a/src/sub_commands/send.rs b/src/sub_commands/send.rs index 33ce104..6b9dd58 100644 --- a/src/sub_commands/send.rs +++ b/src/sub_commands/send.rs | |||
| @@ -769,8 +769,22 @@ pub struct CoverLetter { | |||
| 769 | pub title: String, | 769 | pub title: String, |
| 770 | pub description: String, | 770 | pub description: String, |
| 771 | pub branch_name: String, | 771 | pub branch_name: String, |
| 772 | pub event_id: Option<nostr::EventId>, | ||
| 772 | } | 773 | } |
| 773 | 774 | ||
| 775 | impl CoverLetter { | ||
| 776 | pub fn get_branch_name(&self) -> Result<String> { | ||
| 777 | Ok(format!( | ||
| 778 | "prs/{}({})", | ||
| 779 | self.branch_name, | ||
| 780 | &self | ||
| 781 | .event_id | ||
| 782 | .context("proposal root event_id must be know to get it's branch name")? | ||
| 783 | .to_hex() | ||
| 784 | .as_str()[..8], | ||
| 785 | )) | ||
| 786 | } | ||
| 787 | } | ||
| 774 | pub fn event_is_cover_letter(event: &nostr::Event) -> bool { | 788 | pub fn event_is_cover_letter(event: &nostr::Event) -> bool { |
| 775 | // TODO: look for Subject:[ PATCH 0/n ] but watch out for: | 789 | // TODO: look for Subject:[ PATCH 0/n ] but watch out for: |
| 776 | // [PATCH v1 0/n ] or | 790 | // [PATCH v1 0/n ] or |
| @@ -841,6 +855,7 @@ pub fn event_to_cover_letter(event: &nostr::Event) -> Result<CoverLetter> { | |||
| 841 | .collect(); | 855 | .collect(); |
| 842 | s | 856 | s |
| 843 | }, | 857 | }, |
| 858 | event_id: Some(event.id()), | ||
| 844 | }) | 859 | }) |
| 845 | } | 860 | } |
| 846 | 861 | ||
diff --git a/test_utils/Cargo.toml b/test_utils/Cargo.toml index b7010c9..2e4c012 100644 --- a/test_utils/Cargo.toml +++ b/test_utils/Cargo.toml | |||
| @@ -8,9 +8,12 @@ anyhow = "1.0.75" | |||
| 8 | assert_cmd = "2.0.12" | 8 | assert_cmd = "2.0.12" |
| 9 | dialoguer = "0.10.4" | 9 | dialoguer = "0.10.4" |
| 10 | directories = "5.0.1" | 10 | directories = "5.0.1" |
| 11 | futures = "0.3.28" | ||
| 11 | git2 = "0.18.1" | 12 | git2 = "0.18.1" |
| 12 | nostr = "0.33.0" | 13 | nostr = "0.33.0" |
| 14 | nostr-database = "0.33.0" | ||
| 13 | nostr-sdk = "0.33.0" | 15 | nostr-sdk = "0.33.0" |
| 16 | nostr-sqlite = "0.33.0" | ||
| 14 | once_cell = "1.18.0" | 17 | once_cell = "1.18.0" |
| 15 | rand = "0.8" | 18 | rand = "0.8" |
| 16 | rexpect = { git = "https://github.com/rust-cli/rexpect.git", rev = "9eb61dd" } | 19 | rexpect = { git = "https://github.com/rust-cli/rexpect.git", rev = "9eb61dd" } |
diff --git a/test_utils/src/lib.rs b/test_utils/src/lib.rs index a2ed5f2..de7aee5 100644 --- a/test_utils/src/lib.rs +++ b/test_utils/src/lib.rs | |||
| @@ -1,9 +1,17 @@ | |||
| 1 | use std::{ffi::OsStr, path::PathBuf, str::FromStr}; | 1 | use std::{ |
| 2 | ffi::OsStr, | ||
| 3 | path::{Path, PathBuf}, | ||
| 4 | str::FromStr, | ||
| 5 | }; | ||
| 2 | 6 | ||
| 3 | use anyhow::{bail, ensure, Context, Result}; | 7 | use anyhow::{bail, ensure, Context, Result}; |
| 4 | use dialoguer::theme::{ColorfulTheme, Theme}; | 8 | use dialoguer::theme::{ColorfulTheme, Theme}; |
| 9 | use futures::executor::block_on; | ||
| 10 | use git::GitTestRepo; | ||
| 5 | use nostr::{self, nips::nip65::RelayMetadata, Kind, Tag}; | 11 | use nostr::{self, nips::nip65::RelayMetadata, Kind, Tag}; |
| 12 | use nostr_database::{NostrDatabase, Order}; | ||
| 6 | use nostr_sdk::{serde_json, NostrSigner, TagStandard}; | 13 | use nostr_sdk::{serde_json, NostrSigner, TagStandard}; |
| 14 | use nostr_sqlite::SQLiteDatabase; | ||
| 7 | use once_cell::sync::Lazy; | 15 | use once_cell::sync::Lazy; |
| 8 | use rexpect::session::{Options, PtySession}; | 16 | use rexpect::session::{Options, PtySession}; |
| 9 | use strip_ansi_escapes::strip_str; | 17 | use strip_ansi_escapes::strip_str; |
| @@ -935,3 +943,53 @@ where | |||
| 935 | }, | 943 | }, |
| 936 | ) | 944 | ) |
| 937 | } | 945 | } |
| 946 | |||
| 947 | /** copied from client.rs */ | ||
| 948 | async fn get_local_cache_database(git_repo_path: &Path) -> Result<SQLiteDatabase> { | ||
| 949 | SQLiteDatabase::open(git_repo_path.join(".git/nostr-cache.sqlite")) | ||
| 950 | .await | ||
| 951 | .context("cannot open or create nostr cache database at .git/nostr-cache.sqlite") | ||
| 952 | } | ||
| 953 | |||
| 954 | /** copied from client.rs */ | ||
| 955 | pub async fn get_events_from_cache( | ||
| 956 | git_repo_path: &Path, | ||
| 957 | filters: Vec<nostr::Filter>, | ||
| 958 | ) -> Result<Vec<nostr::Event>> { | ||
| 959 | get_local_cache_database(git_repo_path) | ||
| 960 | .await? | ||
| 961 | .query(filters.clone(), Order::Asc) | ||
| 962 | .await | ||
| 963 | .context( | ||
| 964 | "cannot execute query on opened git repo nostr cache database .git/nostr-cache.sqlite", | ||
| 965 | ) | ||
| 966 | } | ||
| 967 | |||
| 968 | pub fn get_proposal_branch_name( | ||
| 969 | test_repo: &GitTestRepo, | ||
| 970 | branch_name_in_event: &str, | ||
| 971 | ) -> Result<String> { | ||
| 972 | let events = block_on(get_events_from_cache( | ||
| 973 | &test_repo.dir, | ||
| 974 | vec![ | ||
| 975 | nostr::Filter::default() | ||
| 976 | .kind(nostr_sdk::Kind::GitPatch) | ||
| 977 | .hashtag("root"), | ||
| 978 | ], | ||
| 979 | ))?; | ||
| 980 | for event in events { | ||
| 981 | if event.iter_tags().any(|t| { | ||
| 982 | !t.as_vec()[1].eq("revision-root") | ||
| 983 | && event.iter_tags().any(|t| { | ||
| 984 | t.as_vec()[0].eq("branch-name") && t.as_vec()[1].eq(branch_name_in_event) | ||
| 985 | }) | ||
| 986 | }) { | ||
| 987 | return Ok(format!( | ||
| 988 | "prs/{}({})", | ||
| 989 | branch_name_in_event, | ||
| 990 | &event.id.to_hex().as_str()[..8], | ||
| 991 | )); | ||
| 992 | } | ||
| 993 | } | ||
| 994 | bail!("cannot find proposal root with branch-name tag matching title") | ||
| 995 | } | ||
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(), |