absorb: print status if source commit still contains diffs
Some checks are pending
binaries / Build binary artifacts (push) Waiting to run
website / prerelease-docs-build-deploy (ubuntu-24.04) (push) Waiting to run
Scorecards supply-chain security / Scorecards analysis (push) Waiting to run

Closes #5362
This commit is contained in:
Yuya Nishihara 2025-01-15 14:28:01 +09:00
parent e910ac4040
commit 646bdabe62
3 changed files with 29 additions and 1 deletions

View file

@ -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(())
}

View file

@ -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

View file

@ -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<Commit>,
/// Rewritten commits which the source hunks were absorbed into, in forward
/// topological order.
pub rewritten_destinations: Vec<Commit>,
@ -287,6 +290,7 @@ pub fn absorb_hunks(
mut selected_trees: HashMap<CommitId, MergedTreeBuilder>,
) -> BackendResult<AbsorbStats> {
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,
})