From 55fd2693e314a87d32872cd74d3d563cd94201a2 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Fri, 19 Jul 2024 21:43:47 +0100 Subject: feat: integrate `fetch` into `pull` the last set of pull integration test fails: when_latest_event_rebases_branch we are planning on replacing pull so I'm not sure whether it is worth fixing --- src/sub_commands/pull.rs | 54 ++++++++++++++++++++++++++---------------------- tests/pull.rs | 37 +++++++++++++++------------------ 2 files changed, 46 insertions(+), 45 deletions(-) diff --git a/src/sub_commands/pull.rs b/src/sub_commands/pull.rs index 716e6c5..357782a 100644 --- a/src/sub_commands/pull.rs +++ b/src/sub_commands/pull.rs @@ -1,32 +1,32 @@ use anyhow::{bail, Context, Result}; -use super::list::{get_commit_id_from_patch, tag_value}; -#[cfg(not(test))] -use crate::client::Client; +use super::{ + list::{ + get_all_proposal_patch_events_from_cache, get_commit_id_from_patch, + get_proposals_and_revisions_from_cache, tag_value, + }, + send::event_to_cover_letter, +}; #[cfg(test)] use crate::client::MockConnect; +#[cfg(not(test))] +use crate::client::{Client, Connect}; use crate::{ - client::Connect, + client::{fetching_with_report, get_repo_ref_from_cache}, git::{str_to_sha1, Repo, RepoActions}, - repo_ref, - sub_commands::{ - list::get_most_recent_patch_with_ancestors, - push::fetch_proposal_root_and_most_recent_patch_chain, - }, + repo_ref::get_repo_coordinates, + sub_commands::list::get_most_recent_patch_with_ancestors, }; #[allow(clippy::too_many_lines)] pub async fn launch() -> Result<()> { let git_repo = Repo::discover().context("cannot find a git repository")?; + let git_repo_path = git_repo.get_path()?; let (main_or_master_branch_name, _) = git_repo .get_main_or_master_branch() .context("no main or master branch")?; - let root_commit = git_repo - .get_root_commit() - .context("failed to get root commit of the repository")?; - let branch_name = git_repo .get_checked_out_branch_name() .context("cannot get checked out branch name")?; @@ -39,20 +39,24 @@ pub async fn launch() -> Result<()> { #[cfg(test)] let client = ::default(); - let repo_ref = repo_ref::fetch( - &git_repo, - root_commit.to_string(), - &client, - client.get_fallback_relays().clone(), - true, - ) - .await?; + let repo_coordinates = get_repo_coordinates(&git_repo, &client).await?; + + fetching_with_report(git_repo_path, &client, &repo_coordinates).await?; + + let repo_ref = get_repo_ref_from_cache(git_repo_path, &repo_coordinates).await?; + + let proposal_root_event = + get_proposals_and_revisions_from_cache(git_repo_path, repo_ref.coordinates()) + .await? + .iter() + .find(|e| event_to_cover_letter(e).is_ok_and(|cl| cl.branch_name.eq(&branch_name))) + .context("cannot find proposal that matches the current branch name")? + .clone(); - let (_proposal_root_event, commit_events) = fetch_proposal_root_and_most_recent_patch_chain( - &client, + let commit_events = get_all_proposal_patch_events_from_cache( + git_repo_path, &repo_ref, - &root_commit, - &branch_name, + &proposal_root_event.id(), ) .await?; diff --git a/tests/pull.rs b/tests/pull.rs index bf132e7..ecd64ff 100644 --- a/tests/pull.rs +++ b/tests/pull.rs @@ -218,10 +218,9 @@ mod when_branch_doesnt_exist { test_repo.checkout("random-name")?; let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); - p.expect("finding proposal root event...\r\n")?; - p.expect( - "Error: cannot find a proposal root event associated with the checked out branch name\r\n", - )?; + p.expect("fetching updates...\r\n")?; + p.expect_eventually("\r\n")?; // some updates listed here + p.expect("Error: cannot find proposal that matches the current branch name\r\n")?; p.expect_end()?; @@ -281,8 +280,8 @@ mod when_branch_is_checked_out { create_and_populate_branch(&test_repo, FEATURE_BRANCH_NAME_1, "a", false)?; let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); - p.expect("finding proposal root event...\r\n")?; - p.expect("found proposal root event. finding commits...\r\n")?; + p.expect("fetching updates...\r\n")?; + p.expect_eventually("\r\n")?; // some updates listed here p.expect("branch already up-to-date\r\n")?; p.expect_end()?; @@ -391,8 +390,8 @@ mod when_branch_is_checked_out { create_and_populate_branch(&test_repo, FEATURE_BRANCH_NAME_1, "a", true)?; let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); - p.expect("finding proposal root event...\r\n")?; - p.expect("found proposal root event. finding commits...\r\n")?; + p.expect("fetching updates...\r\n")?; + p.expect_eventually("\r\n")?; // some updates listed here p.expect("applied 1 new commits\r\n")?; p.expect_end()?; @@ -469,8 +468,8 @@ mod when_branch_is_checked_out { )?; let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); - p.expect("finding proposal root event...\r\n")?; - p.expect("found proposal root event. finding commits...\r\n")?; + p.expect("fetching updates...\r\n")?; + p.expect_eventually("\r\n")?; // some updates listed here p.expect( "you have an amended/rebase version the proposal that is unpublished\r\n", )?; @@ -547,8 +546,8 @@ mod when_branch_is_checked_out { )?; let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); - p.expect("finding proposal root event...\r\n")?; - p.expect("found proposal root event. finding commits...\r\n")?; + p.expect("fetching updates...\r\n")?; + p.expect_eventually("\r\n")?; // some updates listed here p.expect( "you have an amended/rebase version the proposal that is unpublished\r\n", )?; @@ -613,8 +612,8 @@ mod when_branch_is_checked_out { test_repo.stage_and_commit("appended commit")?; let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); - p.expect("finding proposal root event...\r\n")?; - p.expect("found proposal root event. finding commits...\r\n")?; + p.expect("fetching updates...\r\n")?; + p.expect_eventually("\r\n")?; // some updates listed here p.expect("local proposal branch exists with 1 unpublished commits on top of the most up-to-date version of the proposal\r\n")?; p.expect_end()?; @@ -672,8 +671,8 @@ mod when_branch_is_checked_out { test_repo.stage_and_commit("appended commit")?; let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); - p.expect("finding proposal root event...\r\n")?; - p.expect("found proposal root event. finding commits...\r\n")?; + p.expect("fetching updates...\r\n")?; + p.expect_eventually("\r\n")?; // some updates listed here p.expect("local proposal branch exists with 1 unpublished commits on top of the most up-to-date version of the proposal\r\n")?; p.expect_end()?; @@ -708,7 +707,6 @@ mod when_branch_is_checked_out { Ok(()) } } - mod when_latest_event_rebases_branch { use std::time::Duration; @@ -895,10 +893,9 @@ mod when_branch_is_checked_out { test_repo.checkout(FEATURE_BRANCH_NAME_1)?; let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); - p.expect("finding proposal root event...\r\n")?; - p.expect("found proposal root event. finding commits...\r\n")?; + p.expect("fetching updates...\r\n")?; + p.expect_eventually("\r\n")?; // some updates listed here p.expect_end_with("pulled new version of proposal (2 ahead 0 behind 'main'), replacing old version (2 ahead 1 behind 'main')\r\n")?; - for p in [51, 52, 53, 55, 56] { relay::shutdown_relay(8000 + p)?; } -- cgit v1.2.3