diff options
Diffstat (limited to 'src/sub_commands')
| -rw-r--r-- | src/sub_commands/send.rs | 72 |
1 files changed, 39 insertions, 33 deletions
diff --git a/src/sub_commands/send.rs b/src/sub_commands/send.rs index 23016e1..6417870 100644 --- a/src/sub_commands/send.rs +++ b/src/sub_commands/send.rs | |||
| @@ -50,43 +50,49 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 50 | if args.since_or_revision_range.is_empty() | 50 | if args.since_or_revision_range.is_empty() |
| 51 | || args.since_or_revision_range.eq("master..HEAD") | 51 | || args.since_or_revision_range.eq("master..HEAD") |
| 52 | { | 52 | { |
| 53 | let (from_branch, to_branch, ahead, behind) = | 53 | let (branch_name, tip) = git_repo.get_main_or_master_branch()?; |
| 54 | identify_ahead_behind(&git_repo, &None, &None)?; | 54 | if branch_name.eq("main") || branch_name.eq("master") { |
| 55 | println!("creating 1 patch from latest commit"); | ||
| 56 | vec![tip] | ||
| 57 | } else { | ||
| 58 | let (from_branch, to_branch, ahead, behind) = | ||
| 59 | identify_ahead_behind(&git_repo, &None, &None)?; | ||
| 55 | 60 | ||
| 56 | if ahead.is_empty() { | 61 | if ahead.is_empty() { |
| 57 | bail!(format!( | 62 | bail!(format!( |
| 58 | "'{from_branch}' is 0 commits ahead of '{to_branch}' so no patches were created" | 63 | "'{from_branch}' is 0 commits ahead of '{to_branch}' so no patches were created" |
| 59 | )); | 64 | )); |
| 60 | } | 65 | } |
| 61 | 66 | ||
| 62 | if behind.is_empty() { | 67 | if behind.is_empty() { |
| 63 | println!( | 68 | println!( |
| 64 | "creating patch for {} commits from '{from_branch}' that can be merged into '{to_branch}'", | 69 | "creating patch for {} commits from '{from_branch}' that can be merged into '{to_branch}'", |
| 65 | ahead.len(), | ||
| 66 | ); | ||
| 67 | } else { | ||
| 68 | if !Interactor::default().confirm( | ||
| 69 | PromptConfirmParms::default() | ||
| 70 | .with_prompt( | ||
| 71 | format!( | ||
| 72 | "'{from_branch}' is {} commits behind '{to_branch}' and {} ahead. Consider rebasing before sending patches. Proceed anyway?", | ||
| 73 | behind.len(), | ||
| 74 | ahead.len(), | 70 | ahead.len(), |
| 75 | ) | 71 | ); |
| 76 | ) | 72 | } else { |
| 77 | .with_default(false) | 73 | if !Interactor::default().confirm( |
| 78 | ).context("failed to get confirmation response from interactor confirm")? { | 74 | PromptConfirmParms::default() |
| 79 | bail!("aborting so branch can be rebased"); | 75 | .with_prompt( |
| 80 | } | 76 | format!( |
| 81 | println!( | 77 | "'{from_branch}' is {} commits behind '{to_branch}' and {} ahead. Consider rebasing before sending patches. Proceed anyway?", |
| 82 | "creating patch for {} commit{} from '{from_branch}' that {} {} behind '{to_branch}'", | 78 | behind.len(), |
| 83 | ahead.len(), | 79 | ahead.len(), |
| 84 | if ahead.len() > 1 { "s" } else { "" }, | 80 | ) |
| 85 | if ahead.len() > 1 { "are" } else { "is" }, | 81 | ) |
| 86 | behind.len(), | 82 | .with_default(false) |
| 87 | ); | 83 | ).context("failed to get confirmation response from interactor confirm")? { |
| 84 | bail!("aborting so branch can be rebased"); | ||
| 85 | } | ||
| 86 | println!( | ||
| 87 | "creating patch for {} commit{} from '{from_branch}' that {} {} behind '{to_branch}'", | ||
| 88 | ahead.len(), | ||
| 89 | if ahead.len() > 1 { "s" } else { "" }, | ||
| 90 | if ahead.len() > 1 { "are" } else { "is" }, | ||
| 91 | behind.len(), | ||
| 92 | ); | ||
| 93 | } | ||
| 94 | ahead | ||
| 88 | } | 95 | } |
| 89 | ahead | ||
| 90 | } else { | 96 | } else { |
| 91 | let ahead = git_repo | 97 | let ahead = git_repo |
| 92 | .parse_starting_commits(&args.since_or_revision_range) | 98 | .parse_starting_commits(&args.since_or_revision_range) |