diff --git a/cli/src/commands/absorb.rs b/cli/src/commands/absorb.rs index e843b5d17..20383ce35 100644 --- a/cli/src/commands/absorb.rs +++ b/cli/src/commands/absorb.rs @@ -16,6 +16,7 @@ use clap_complete::ArgValueCandidates; use jj_lib::absorb::absorb_hunks; use jj_lib::absorb::split_hunks_to_trees; use jj_lib::absorb::AbsorbSource; +use jj_lib::matchers::EverythingMatcher; use pollster::FutureExt as _; use tracing::instrument; @@ -23,6 +24,7 @@ use crate::cli_util::CommandHelper; use crate::cli_util::RevisionArg; use crate::command_error::CommandError; use crate::complete; +use crate::diff_util::DiffFormat; use crate::ui::Ui; /// Move changes from a revision into the stack of mutable revisions @@ -119,5 +121,18 @@ pub(crate) fn cmd_absorb( stats.rewritten_destinations.len() ), )?; + + if let Some(mut formatter) = ui.status_formatter() { + if let Some(commit) = &stats.rewritten_source { + let repo = workspace_command.repo().as_ref(); + if !commit.is_empty(repo)? { + writeln!(formatter, "Remaining changes:")?; + let diff_renderer = workspace_command.diff_renderer(vec![DiffFormat::Summary]); + let matcher = &EverythingMatcher; // also print excluded paths + let width = ui.term_width(); + diff_renderer.show_patch(ui, formatter.as_mut(), commit, matcher, width)?; + } + } + } Ok(()) } diff --git a/cli/tests/test_absorb_command.rs b/cli/tests/test_absorb_command.rs index eb6ec390b..23443fe0c 100644 --- a/cli/tests/test_absorb_command.rs +++ b/cli/tests/test_absorb_command.rs @@ -480,6 +480,8 @@ fn test_absorb_file_mode() { Rebased 1 descendant commits. Working copy now at: zsuskuln 77de368e (no description set) Parent commit : qpvuntsm 991365da 1 + Remaining changes: + M file1 "); insta::assert_snapshot!(get_diffs(&test_env, &repo_path, "mutable()"), @r" @@ -521,6 +523,8 @@ fn test_absorb_from_into() { Rebased 1 descendant commits. Working copy now at: zsuskuln d5424357 (no description set) Parent commit : kkmpptxz 91df4543 2 + Remaining changes: + M file1 "); insta::assert_snapshot!(get_diffs(&test_env, &repo_path, "@-::"), @r" @@ -623,6 +627,8 @@ fn test_absorb_paths() { Rebased 1 descendant commits. Working copy now at: kkmpptxz c6f31836 (no description set) Parent commit : qpvuntsm ae044adb 1 + Remaining changes: + M file2 "); insta::assert_snapshot!(get_diffs(&test_env, &repo_path, "mutable()"), @r" @@ -677,6 +683,8 @@ fn test_absorb_immutable() { Rebased 1 descendant commits. Working copy now at: mzvwutvl 3021153d (no description set) Parent commit : kkmpptxz d80e3c2a 2 + Remaining changes: + M file1 "); // Immutable revisions shouldn't be rewritten diff --git a/lib/src/absorb.rs b/lib/src/absorb.rs index cb15a49b7..fc71de1db 100644 --- a/lib/src/absorb.rs +++ b/lib/src/absorb.rs @@ -271,6 +271,9 @@ fn combine_texts(text1: &[u8], text2: &[u8], selected_ranges: &[SelectedRange]) /// Describes changes made by [`absorb_hunks()`]. #[derive(Clone, Debug)] pub struct AbsorbStats { + /// Rewritten source commit which the absorbed hunks were removed, or `None` + /// if the source commit was abandoned or no hunks were moved. + pub rewritten_source: Option, /// Rewritten commits which the source hunks were absorbed into, in forward /// topological order. pub rewritten_destinations: Vec, @@ -287,6 +290,7 @@ pub fn absorb_hunks( mut selected_trees: HashMap, ) -> BackendResult { let store = repo.store().clone(); + let mut rewritten_source = None; let mut rewritten_destinations = Vec::new(); let mut num_rebased = 0; // Rewrite commits in topological order so that descendant commits wouldn't @@ -298,7 +302,7 @@ pub fn absorb_hunks( if commit_builder.is_discardable()? { commit_builder.abandon(); } else { - commit_builder.write()?; + rewritten_source = Some(commit_builder.write()?); num_rebased += 1; } return Ok(()); @@ -324,6 +328,7 @@ pub fn absorb_hunks( Ok(()) })?; Ok(AbsorbStats { + rewritten_source, rewritten_destinations, num_rebased, })