upleb.uk

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

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/sub_commands/pull.rs54
-rw-r--r--tests/pull.rs37
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 @@
1use anyhow::{bail, Context, Result}; 1use anyhow::{bail, Context, Result};
2 2
3use super::list::{get_commit_id_from_patch, tag_value}; 3use super::{
4#[cfg(not(test))] 4 list::{
5use 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)]
7use crate::client::MockConnect; 11use crate::client::MockConnect;
12#[cfg(not(test))]
13use crate::client::{Client, Connect};
8use crate::{ 14use 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)]
19pub async fn launch() -> Result<()> { 22pub 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
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 {
218 test_repo.checkout("random-name")?; 218 test_repo.checkout("random-name")?;
219 219
220 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); 220 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]);
221 p.expect("finding proposal root event...\r\n")?; 221 p.expect("fetching updates...\r\n")?;
222 p.expect( 222 p.expect_eventually("\r\n")?; // some updates listed here
223 "Error: cannot find a proposal root event associated with the checked out branch name\r\n", 223 p.expect("Error: cannot find proposal that matches the current branch name\r\n")?;
224 )?;
225 224
226 p.expect_end()?; 225 p.expect_end()?;
227 226
@@ -281,8 +280,8 @@ mod when_branch_is_checked_out {
281 create_and_populate_branch(&test_repo, FEATURE_BRANCH_NAME_1, "a", false)?; 280 create_and_populate_branch(&test_repo, FEATURE_BRANCH_NAME_1, "a", false)?;
282 281
283 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); 282 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]);
284 p.expect("finding proposal root event...\r\n")?; 283 p.expect("fetching updates...\r\n")?;
285 p.expect("found proposal root event. finding commits...\r\n")?; 284 p.expect_eventually("\r\n")?; // some updates listed here
286 p.expect("branch already up-to-date\r\n")?; 285 p.expect("branch already up-to-date\r\n")?;
287 p.expect_end()?; 286 p.expect_end()?;
288 287
@@ -391,8 +390,8 @@ mod when_branch_is_checked_out {
391 create_and_populate_branch(&test_repo, FEATURE_BRANCH_NAME_1, "a", true)?; 390 create_and_populate_branch(&test_repo, FEATURE_BRANCH_NAME_1, "a", true)?;
392 391
393 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); 392 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]);
394 p.expect("finding proposal root event...\r\n")?; 393 p.expect("fetching updates...\r\n")?;
395 p.expect("found proposal root event. finding commits...\r\n")?; 394 p.expect_eventually("\r\n")?; // some updates listed here
396 p.expect("applied 1 new commits\r\n")?; 395 p.expect("applied 1 new commits\r\n")?;
397 p.expect_end()?; 396 p.expect_end()?;
398 397
@@ -469,8 +468,8 @@ mod when_branch_is_checked_out {
469 )?; 468 )?;
470 469
471 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); 470 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]);
472 p.expect("finding proposal root event...\r\n")?; 471 p.expect("fetching updates...\r\n")?;
473 p.expect("found proposal root event. finding commits...\r\n")?; 472 p.expect_eventually("\r\n")?; // some updates listed here
474 p.expect( 473 p.expect(
475 "you have an amended/rebase version the proposal that is unpublished\r\n", 474 "you have an amended/rebase version the proposal that is unpublished\r\n",
476 )?; 475 )?;
@@ -547,8 +546,8 @@ mod when_branch_is_checked_out {
547 )?; 546 )?;
548 547
549 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); 548 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]);
550 p.expect("finding proposal root event...\r\n")?; 549 p.expect("fetching updates...\r\n")?;
551 p.expect("found proposal root event. finding commits...\r\n")?; 550 p.expect_eventually("\r\n")?; // some updates listed here
552 p.expect( 551 p.expect(
553 "you have an amended/rebase version the proposal that is unpublished\r\n", 552 "you have an amended/rebase version the proposal that is unpublished\r\n",
554 )?; 553 )?;
@@ -613,8 +612,8 @@ mod when_branch_is_checked_out {
613 test_repo.stage_and_commit("appended commit")?; 612 test_repo.stage_and_commit("appended commit")?;
614 613
615 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); 614 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]);
616 p.expect("finding proposal root event...\r\n")?; 615 p.expect("fetching updates...\r\n")?;
617 p.expect("found proposal root event. finding commits...\r\n")?; 616 p.expect_eventually("\r\n")?; // some updates listed here
618 p.expect("local proposal branch exists with 1 unpublished commits on top of the most up-to-date version of the proposal\r\n")?; 617 p.expect("local proposal branch exists with 1 unpublished commits on top of the most up-to-date version of the proposal\r\n")?;
619 p.expect_end()?; 618 p.expect_end()?;
620 619
@@ -672,8 +671,8 @@ mod when_branch_is_checked_out {
672 test_repo.stage_and_commit("appended commit")?; 671 test_repo.stage_and_commit("appended commit")?;
673 672
674 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); 673 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]);
675 p.expect("finding proposal root event...\r\n")?; 674 p.expect("fetching updates...\r\n")?;
676 p.expect("found proposal root event. finding commits...\r\n")?; 675 p.expect_eventually("\r\n")?; // some updates listed here
677 p.expect("local proposal branch exists with 1 unpublished commits on top of the most up-to-date version of the proposal\r\n")?; 676 p.expect("local proposal branch exists with 1 unpublished commits on top of the most up-to-date version of the proposal\r\n")?;
678 p.expect_end()?; 677 p.expect_end()?;
679 678
@@ -708,7 +707,6 @@ mod when_branch_is_checked_out {
708 Ok(()) 707 Ok(())
709 } 708 }
710 } 709 }
711
712 mod when_latest_event_rebases_branch { 710 mod when_latest_event_rebases_branch {
713 use std::time::Duration; 711 use std::time::Duration;
714 712
@@ -895,10 +893,9 @@ mod when_branch_is_checked_out {
895 test_repo.checkout(FEATURE_BRANCH_NAME_1)?; 893 test_repo.checkout(FEATURE_BRANCH_NAME_1)?;
896 894
897 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); 895 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]);
898 p.expect("finding proposal root event...\r\n")?; 896 p.expect("fetching updates...\r\n")?;
899 p.expect("found proposal root event. finding commits...\r\n")?; 897 p.expect_eventually("\r\n")?; // some updates listed here
900 p.expect_end_with("pulled new version of proposal (2 ahead 0 behind 'main'), replacing old version (2 ahead 1 behind 'main')\r\n")?; 898 p.expect_end_with("pulled new version of proposal (2 ahead 0 behind 'main'), replacing old version (2 ahead 1 behind 'main')\r\n")?;
901
902 for p in [51, 52, 53, 55, 56] { 899 for p in [51, 52, 53, 55, 56] {
903 relay::shutdown_relay(8000 + p)?; 900 relay::shutdown_relay(8000 + p)?;
904 } 901 }