diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-07-19 21:43:47 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-07-19 21:49:51 +0100 |
| commit | 55fd2693e314a87d32872cd74d3d563cd94201a2 (patch) | |
| tree | 589135b4ca762a65043b5ea98215c4b80f8c29b2 /src | |
| parent | 8531328558c7f5870be3571f63a952743eb0b9e6 (diff) | |
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
Diffstat (limited to 'src')
| -rw-r--r-- | src/sub_commands/pull.rs | 54 |
1 files changed, 29 insertions, 25 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 @@ | |||
| 1 | use anyhow::{bail, Context, Result}; | 1 | use anyhow::{bail, Context, Result}; |
| 2 | 2 | ||
| 3 | use super::list::{get_commit_id_from_patch, tag_value}; | 3 | use super::{ |
| 4 | #[cfg(not(test))] | 4 | list::{ |
| 5 | use crate::client::Client; | 5 | get_all_proposal_patch_events_from_cache, get_commit_id_from_patch, |
| 6 | get_proposals_and_revisions_from_cache, tag_value, | ||
| 7 | }, | ||
| 8 | send::event_to_cover_letter, | ||
| 9 | }; | ||
| 6 | #[cfg(test)] | 10 | #[cfg(test)] |
| 7 | use crate::client::MockConnect; | 11 | use crate::client::MockConnect; |
| 12 | #[cfg(not(test))] | ||
| 13 | use crate::client::{Client, Connect}; | ||
| 8 | use crate::{ | 14 | use crate::{ |
| 9 | client::Connect, | 15 | client::{fetching_with_report, get_repo_ref_from_cache}, |
| 10 | git::{str_to_sha1, Repo, RepoActions}, | 16 | git::{str_to_sha1, Repo, RepoActions}, |
| 11 | repo_ref, | 17 | repo_ref::get_repo_coordinates, |
| 12 | sub_commands::{ | 18 | sub_commands::list::get_most_recent_patch_with_ancestors, |
| 13 | list::get_most_recent_patch_with_ancestors, | ||
| 14 | push::fetch_proposal_root_and_most_recent_patch_chain, | ||
| 15 | }, | ||
| 16 | }; | 19 | }; |
| 17 | 20 | ||
| 18 | #[allow(clippy::too_many_lines)] | 21 | #[allow(clippy::too_many_lines)] |
| 19 | pub async fn launch() -> Result<()> { | 22 | pub async fn launch() -> Result<()> { |
| 20 | let git_repo = Repo::discover().context("cannot find a git repository")?; | 23 | let git_repo = Repo::discover().context("cannot find a git repository")?; |
| 24 | let git_repo_path = git_repo.get_path()?; | ||
| 21 | 25 | ||
| 22 | let (main_or_master_branch_name, _) = git_repo | 26 | let (main_or_master_branch_name, _) = git_repo |
| 23 | .get_main_or_master_branch() | 27 | .get_main_or_master_branch() |
| 24 | .context("no main or master branch")?; | 28 | .context("no main or master branch")?; |
| 25 | 29 | ||
| 26 | let root_commit = git_repo | ||
| 27 | .get_root_commit() | ||
| 28 | .context("failed to get root commit of the repository")?; | ||
| 29 | |||
| 30 | let branch_name = git_repo | 30 | let branch_name = git_repo |
| 31 | .get_checked_out_branch_name() | 31 | .get_checked_out_branch_name() |
| 32 | .context("cannot get checked out branch name")?; | 32 | .context("cannot get checked out branch name")?; |
| @@ -39,20 +39,24 @@ pub async fn launch() -> Result<()> { | |||
| 39 | #[cfg(test)] | 39 | #[cfg(test)] |
| 40 | let client = <MockConnect as std::default::Default>::default(); | 40 | let client = <MockConnect as std::default::Default>::default(); |
| 41 | 41 | ||
| 42 | let repo_ref = repo_ref::fetch( | 42 | let repo_coordinates = get_repo_coordinates(&git_repo, &client).await?; |
| 43 | &git_repo, | 43 | |
| 44 | root_commit.to_string(), | 44 | fetching_with_report(git_repo_path, &client, &repo_coordinates).await?; |
| 45 | &client, | 45 | |
| 46 | client.get_fallback_relays().clone(), | 46 | let repo_ref = get_repo_ref_from_cache(git_repo_path, &repo_coordinates).await?; |
| 47 | true, | 47 | |
| 48 | ) | 48 | let proposal_root_event = |
| 49 | .await?; | 49 | get_proposals_and_revisions_from_cache(git_repo_path, repo_ref.coordinates()) |
| 50 | .await? | ||
| 51 | .iter() | ||
| 52 | .find(|e| event_to_cover_letter(e).is_ok_and(|cl| cl.branch_name.eq(&branch_name))) | ||
| 53 | .context("cannot find proposal that matches the current branch name")? | ||
| 54 | .clone(); | ||
| 50 | 55 | ||
| 51 | let (_proposal_root_event, commit_events) = fetch_proposal_root_and_most_recent_patch_chain( | 56 | let commit_events = get_all_proposal_patch_events_from_cache( |
| 52 | &client, | 57 | git_repo_path, |
| 53 | &repo_ref, | 58 | &repo_ref, |
| 54 | &root_commit, | 59 | &proposal_root_event.id(), |
| 55 | &branch_name, | ||
| 56 | ) | 60 | ) |
| 57 | .await?; | 61 | .await?; |
| 58 | 62 | ||