diff --git a/src/commands/reword.rs b/src/commands/reword.rs index 06c7521ec..18e2bee14 100644 --- a/src/commands/reword.rs +++ b/src/commands/reword.rs @@ -18,13 +18,8 @@ use crate::core::eventlog::{EventLogDb, EventReplayer}; use crate::core::formatting::{printable_styled_string, Glyphs}; use crate::core::node_descriptors::{render_node_descriptors, CommitOidDescriptor, NodeObject}; use crate::core::rewrite::{ - execute_rebase_plan, - BuildRebasePlanOptions, - ExecuteRebasePlanOptions, - // BuildRebasePlanError, - ExecuteRebasePlanResult, - RebasePlanBuilder, - RepoResource, + execute_rebase_plan, BuildRebasePlanOptions, ExecuteRebasePlanOptions, ExecuteRebasePlanResult, + RebasePlanBuilder, RepoResource, }; use crate::git::{CheckOutCommitOptions, Commit, GitRunInfo, MaybeZeroOid, NonZeroOid, Repo}; @@ -119,7 +114,7 @@ pub fn reword( writeln!( effects.get_output_stream(), "### - BUG: rebase plan indicates nothing to do, but rewording should always so something. + BUG: rebase plan indicates nothing to do, but rewording should always do something. Stopping; nothing reworded. ###" )?; @@ -150,49 +145,7 @@ pub fn reword( let exit_code = match result { ExecuteRebasePlanResult::Succeeded { rewritten_oids } => { - let glyphs = Glyphs::detect(); - let num_commits = commits.len(); - for original_commit in commits { - let replacement_oid = match rewritten_oids.get(&original_commit.get_oid()).unwrap() - { - MaybeZeroOid::NonZero(new_oid) => new_oid, - MaybeZeroOid::Zero => { - warn!( - "Encountered ZeroOid after success rewriting commit {}", - original_commit.get_oid() - ); - continue; - } - }; - let replacement_commit = repo.find_commit(*replacement_oid)?.unwrap(); - writeln!( - effects.get_output_stream(), - "Reworded commit {} as {}", - printable_styled_string( - &glyphs, - // Commit doesn't offer `friendly_describe_oid`, so we'll do it ourselves - render_node_descriptors( - &glyphs, - &NodeObject::Commit { - commit: original_commit.clone(), - }, - &mut [&mut CommitOidDescriptor::new(true)?], - )? - )?, - printable_styled_string( - &glyphs, - replacement_commit.friendly_describe(&glyphs)? - )? - )?; - } - - if num_commits != 1 { - writeln!( - effects.get_output_stream(), - "Reworded {} commits with same message. If this was unintentional, run: git undo", - num_commits, - )?; - } + render_status_report(&repo, effects, &commits, &rewritten_oids)?; 0 } @@ -275,7 +228,8 @@ fn build_messages( _ => { // TODO(bulk edit) build a bulk edit message for multiple commits format!( - "Enter a commit message to apply to {} commits", + "{} Enter a commit message to apply to {} commits", + comment_char.unwrap(), commits.len() ) } @@ -352,3 +306,53 @@ fn find_subtree_roots<'repo>( Ok(root_commits) } + +/// Print a basic status report of what commits were reworded. +fn render_status_report( + repo: &Repo, + effects: &Effects, + commits: &[Commit], + rewritten_oids: &HashMap, +) -> eyre::Result<()> { + let glyphs = Glyphs::detect(); + let num_commits = commits.len(); + for original_commit in commits { + let replacement_oid = match rewritten_oids.get(&original_commit.get_oid()).unwrap() { + MaybeZeroOid::NonZero(new_oid) => new_oid, + MaybeZeroOid::Zero => { + warn!( + "Encountered ZeroOid after success rewriting commit {}", + original_commit.get_oid() + ); + continue; + } + }; + let replacement_commit = repo.find_commit(*replacement_oid)?.unwrap(); + writeln!( + effects.get_output_stream(), + "Reworded commit {} as {}", + printable_styled_string( + &glyphs, + // Commit doesn't offer `friendly_describe_oid`, so we'll do it ourselves + render_node_descriptors( + &glyphs, + &NodeObject::Commit { + commit: original_commit.clone(), + }, + &mut [&mut CommitOidDescriptor::new(true)?], + )? + )?, + printable_styled_string(&glyphs, replacement_commit.friendly_describe(&glyphs)?)? + )?; + } + + if num_commits != 1 { + writeln!( + effects.get_output_stream(), + "Reworded {} commits with same message. If this was unintentional, run: git undo", + num_commits, + )?; + } + + Ok(()) +}