diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-02-22 15:00:32 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-02-22 15:00:32 +0000 |
| commit | 35c78dc991bb17bf58211de756a46074ea44dba5 (patch) | |
| tree | d5708d82d5e1ade8e40f1bc709e188d4ebad83e8 /src | |
| parent | fcad6abb95b92c36fd766ff5987e954bfcb8af62 (diff) | |
refactor: simplifed ammendments and rebases
to align with changes done to pull
c5dfd1b7e509eedc33de75343de8659e3c9e0b2a
also improved copy
Diffstat (limited to 'src')
| -rw-r--r-- | src/sub_commands/list.rs | 207 |
1 files changed, 76 insertions, 131 deletions
diff --git a/src/sub_commands/list.rs b/src/sub_commands/list.rs index 6c620ad..c6af397 100644 --- a/src/sub_commands/list.rs +++ b/src/sub_commands/list.rs | |||
| @@ -477,154 +477,99 @@ pub async fn launch(_cli_args: &Cli, _args: &SubCommandArgs) -> Result<()> { | |||
| 477 | } | 477 | } |
| 478 | 478 | ||
| 479 | // TODO: write tests | 479 | // TODO: write tests |
| 480 | // user has probably has an unpublished rebase of the latest proposal version | 480 | |
| 481 | println!("you have an ammended/rebase version the proposal that is unpublished"); | ||
| 482 | // user probably has a unpublished ammended or rebase version of the latest | ||
| 483 | // proposal version | ||
| 481 | // if tip of proposal commits exist (were once part of branch but have been | 484 | // if tip of proposal commits exist (were once part of branch but have been |
| 482 | // ammended and git clean up job hasn't removed them) | 485 | // ammended and git clean up job hasn't removed them) |
| 483 | if git_repo.does_commit_exist(&proposal_tip.to_string())? { | 486 | if git_repo.does_commit_exist(&proposal_tip.to_string())? { |
| 484 | println!( | 487 | println!( |
| 485 | "you have previously applied the latest version of the proposal ({} ahead {} behind '{main_branch_name}') but your local proposal branch has other unpublished changes ({} ahead {} behind '{main_branch_name}')", | 488 | "you have previously applied the latest version of the proposal ({} ahead {} behind '{main_branch_name}') but your local proposal branch has ammended or rebased it ({} ahead {} behind '{main_branch_name}')", |
| 486 | most_recent_proposal_patch_chain.len(), | 489 | most_recent_proposal_patch_chain.len(), |
| 487 | proposal_behind_main.len(), | 490 | proposal_behind_main.len(), |
| 488 | local_ahead_of_main.len(), | 491 | local_ahead_of_main.len(), |
| 489 | local_beind_main.len(), | 492 | local_beind_main.len(), |
| 490 | ); | 493 | ); |
| 494 | } | ||
| 495 | // user probably has a unpublished ammended or rebase version of an older | ||
| 496 | // proposal version | ||
| 497 | else { | ||
| 491 | println!( | 498 | println!( |
| 492 | "if this sounds right then consider publishing your rebase `ngit push --force` or discarding your local branch" | 499 | "your local proposal branch ({} ahead {} behind '{main_branch_name}') has conflicting changes with the latest published proposal ({} ahead {} behind '{main_branch_name}')", |
| 500 | local_ahead_of_main.len(), | ||
| 501 | local_beind_main.len(), | ||
| 502 | most_recent_proposal_patch_chain.len(), | ||
| 503 | proposal_behind_main.len(), | ||
| 493 | ); | 504 | ); |
| 494 | return match Interactor::default().choice( | ||
| 495 | PromptChoiceParms::default().with_default(0) | ||
| 496 | .with_choices( | ||
| 497 | vec![ | ||
| 498 | format!( | ||
| 499 | "checkout local branch with unpublished changes ({} ahead {} behind '{main_branch_name}')", | ||
| 500 | local_ahead_of_main.len(), | ||
| 501 | local_beind_main.len(), | ||
| 502 | ), | ||
| 503 | format!( | ||
| 504 | "discard local branch with old version ({} ahead {} behind '{main_branch_name}') and checkout latest published version ({} ahead {} behind '{main_branch_name}')", | ||
| 505 | most_recent_proposal_patch_chain.len(), | ||
| 506 | proposal_behind_main.len(), | ||
| 507 | local_ahead_of_main.len(), | ||
| 508 | local_beind_main.len(), | ||
| 509 | ), | ||
| 510 | format!("apply to current branch with `git am`"), | ||
| 511 | format!("download to ./patches"), | ||
| 512 | "back".to_string(), | ||
| 513 | ], | ||
| 514 | ) | ||
| 515 | )? { | ||
| 516 | 0 => { | ||
| 517 | check_clean(&git_repo)?; | ||
| 518 | git_repo.checkout(&cover_letter.branch_name)?; | ||
| 519 | println!( | ||
| 520 | "checked out old proposal in existing branch ({} ahead {} behind '{main_branch_name}')", | ||
| 521 | local_ahead_of_main.len(), | ||
| 522 | local_beind_main.len(), | ||
| 523 | ); | ||
| 524 | Ok(()) | ||
| 525 | }, | ||
| 526 | 1 => { | ||
| 527 | check_clean(&git_repo)?; | ||
| 528 | git_repo.create_branch_at_commit(&cover_letter.branch_name, &proposal_base_commit.to_string())?; | ||
| 529 | git_repo.checkout(&cover_letter.branch_name)?; | ||
| 530 | let chain_length = most_recent_proposal_patch_chain.len(); | ||
| 531 | let _ = git_repo | ||
| 532 | .apply_patch_chain(&cover_letter.branch_name, most_recent_proposal_patch_chain) | ||
| 533 | .context("cannot apply patch chain")?; | ||
| 534 | println!( | ||
| 535 | "checked out new version of proposal ({} ahead {} behind '{main_branch_name}'), replacing old version ({} ahead {} behind '{main_branch_name}')", | ||
| 536 | chain_length, | ||
| 537 | proposal_behind_main.len(), | ||
| 538 | local_ahead_of_main.len(), | ||
| 539 | local_beind_main.len(), | ||
| 540 | ); | ||
| 541 | Ok(()) | ||
| 542 | }, | ||
| 543 | 2 => {launch_git_am_with_patches(most_recent_proposal_patch_chain)}, | ||
| 544 | 3 => {save_patches_to_dir(most_recent_proposal_patch_chain, &git_repo)}, | ||
| 545 | 4 => { continue }, | ||
| 546 | _ => { bail!("unexpected choice")} | ||
| 547 | }; | ||
| 548 | } | ||
| 549 | |||
| 550 | // TODO: write tests | ||
| 551 | // user has probaly has an unpublished rebase of an older version of the | ||
| 552 | // proposal | ||
| 553 | println!( | ||
| 554 | "your local proposal branch ({} ahead {} behind '{main_branch_name}') has conflicting changes with the latest published proposal ({} ahead {} behind '{main_branch_name}')", | ||
| 555 | local_ahead_of_main.len(), | ||
| 556 | local_beind_main.len(), | ||
| 557 | most_recent_proposal_patch_chain.len(), | ||
| 558 | proposal_behind_main.len(), | ||
| 559 | ); | ||
| 560 | println!( | ||
| 561 | "its likely that you are working off an old proposal version because git has no record of the latest proposal commit." | ||
| 562 | ); | ||
| 563 | println!( | ||
| 564 | "it is possible that you have ammended the latest version and git has delete this commit as part of a clean up" | ||
| 565 | ); | ||
| 566 | 505 | ||
| 506 | println!( | ||
| 507 | "its likely that you have rebased / ammended an old proposal version because git has no record of the latest proposal commit." | ||
| 508 | ); | ||
| 509 | println!( | ||
| 510 | "it is possible that you have been working off the latest version and git has delete this commit as part of a clean up" | ||
| 511 | ); | ||
| 512 | } | ||
| 567 | println!("to view the latest proposal but retain your changes:"); | 513 | println!("to view the latest proposal but retain your changes:"); |
| 568 | println!(" 1) checkout the local branch"); | 514 | println!(" 1) create a new branch off the tip commit of this one to store your changes"); |
| 569 | println!(" 2) create a new branch off the tip commit to store your changes"); | 515 | println!(" 2) run `ngit list` and checkout the latest published version of this proposal"); |
| 570 | println!(" 3) run `ngit list` and checkout the latest published version of this proposal"); | ||
| 571 | 516 | ||
| 572 | println!("if you are confident in your changes consider running `ngit push --force`"); | 517 | println!("if you are confident in your changes consider running `ngit push --force`"); |
| 573 | 518 | ||
| 574 | return match Interactor::default().choice( | 519 | return match Interactor::default().choice( |
| 575 | PromptChoiceParms::default().with_default(0) | 520 | PromptChoiceParms::default().with_default(0) |
| 576 | .with_choices( | 521 | .with_choices( |
| 577 | vec![ | 522 | vec![ |
| 578 | format!( | 523 | format!( |
| 579 | "checkout local branch with unpublished changes ({} ahead {} behind '{main_branch_name}')", | 524 | "checkout local branch with unpublished changes ({} ahead {} behind '{main_branch_name}')", |
| 580 | local_ahead_of_main.len(), | 525 | local_ahead_of_main.len(), |
| 581 | local_beind_main.len(), | 526 | local_beind_main.len(), |
| 582 | ), | 527 | ), |
| 583 | format!( | 528 | format!( |
| 584 | "discard local branch with unpublished version ({} ahead {} behind '{main_branch_name}') and checkout latest published version ({} ahead {} behind '{main_branch_name}'). consider creating a temporary branch with your existing unchanges first.", | 529 | "discard local branch with old version ({} ahead {} behind '{main_branch_name}') and checkout latest published version ({} ahead {} behind '{main_branch_name}')", |
| 585 | most_recent_proposal_patch_chain.len(), | 530 | most_recent_proposal_patch_chain.len(), |
| 586 | proposal_behind_main.len(), | 531 | proposal_behind_main.len(), |
| 587 | local_ahead_of_main.len(), | 532 | local_ahead_of_main.len(), |
| 588 | local_beind_main.len(), | 533 | local_beind_main.len(), |
| 589 | ), | 534 | ), |
| 590 | format!("apply to current branch with `git am`"), | 535 | format!("apply to current branch with `git am`"), |
| 591 | format!("download to ./patches"), | 536 | format!("download to ./patches"), |
| 592 | "back".to_string(), | 537 | "back".to_string(), |
| 593 | ], | 538 | ], |
| 594 | ) | 539 | ) |
| 595 | )? { | 540 | )? { |
| 596 | 0 => { | 541 | 0 => { |
| 597 | check_clean(&git_repo)?; | 542 | check_clean(&git_repo)?; |
| 598 | git_repo.checkout(&cover_letter.branch_name)?; | 543 | git_repo.checkout(&cover_letter.branch_name)?; |
| 599 | println!( | 544 | println!( |
| 600 | "checked out old proposal in existing branch ({} ahead {} behind '{main_branch_name}')", | 545 | "checked out old proposal in existing branch ({} ahead {} behind '{main_branch_name}')", |
| 601 | local_ahead_of_main.len(), | 546 | local_ahead_of_main.len(), |
| 602 | local_beind_main.len(), | 547 | local_beind_main.len(), |
| 603 | ); | 548 | ); |
| 604 | Ok(()) | 549 | Ok(()) |
| 605 | }, | 550 | }, |
| 606 | 1 => { | 551 | 1 => { |
| 607 | check_clean(&git_repo)?; | 552 | check_clean(&git_repo)?; |
| 608 | git_repo.create_branch_at_commit(&cover_letter.branch_name, &proposal_base_commit.to_string())?; | 553 | git_repo.create_branch_at_commit(&cover_letter.branch_name, &proposal_base_commit.to_string())?; |
| 609 | git_repo.checkout(&cover_letter.branch_name)?; | 554 | git_repo.checkout(&cover_letter.branch_name)?; |
| 610 | let chain_length = most_recent_proposal_patch_chain.len(); | 555 | let chain_length = most_recent_proposal_patch_chain.len(); |
| 611 | let _ = git_repo | 556 | let _ = git_repo |
| 612 | .apply_patch_chain(&cover_letter.branch_name, most_recent_proposal_patch_chain) | 557 | .apply_patch_chain(&cover_letter.branch_name, most_recent_proposal_patch_chain) |
| 613 | .context("cannot apply patch chain")?; | 558 | .context("cannot apply patch chain")?; |
| 614 | println!( | 559 | println!( |
| 615 | "checked out new version of proposal ({} ahead {} behind '{main_branch_name}'), replacing old version ({} ahead {} behind '{main_branch_name}'). consider creating a temporary branch with your existing unchanges first.", | 560 | "checked out new version of proposal ({} ahead {} behind '{main_branch_name}'), replacing old version ({} ahead {} behind '{main_branch_name}')", |
| 616 | chain_length, | 561 | chain_length, |
| 617 | proposal_behind_main.len(), | 562 | proposal_behind_main.len(), |
| 618 | local_ahead_of_main.len(), | 563 | local_ahead_of_main.len(), |
| 619 | local_beind_main.len(), | 564 | local_beind_main.len(), |
| 620 | ); | 565 | ); |
| 621 | Ok(()) | 566 | Ok(()) |
| 622 | }, | 567 | }, |
| 623 | 2 => {launch_git_am_with_patches(most_recent_proposal_patch_chain)}, | 568 | 2 => {launch_git_am_with_patches(most_recent_proposal_patch_chain)}, |
| 624 | 3 => {save_patches_to_dir(most_recent_proposal_patch_chain, &git_repo)}, | 569 | 3 => {save_patches_to_dir(most_recent_proposal_patch_chain, &git_repo)}, |
| 625 | 4 => { continue }, | 570 | 4 => { continue }, |
| 626 | _ => { bail!("unexpected choice")} | 571 | _ => { bail!("unexpected choice")} |
| 627 | }; | 572 | }; |
| 628 | } | 573 | } |
| 629 | } | 574 | } |
| 630 | 575 | ||