diff options
Diffstat (limited to 'src')
| -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 |
4 files changed, 44 insertions, 21 deletions
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 | ||