mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-31 08:21:58 +00:00
absorb: print status if source commit still contains diffs
Closes #5362
This commit is contained in:
parent
e910ac4040
commit
646bdabe62
3 changed files with 29 additions and 1 deletions
|
@ -16,6 +16,7 @@ use clap_complete::ArgValueCandidates;
|
||||||
use jj_lib::absorb::absorb_hunks;
|
use jj_lib::absorb::absorb_hunks;
|
||||||
use jj_lib::absorb::split_hunks_to_trees;
|
use jj_lib::absorb::split_hunks_to_trees;
|
||||||
use jj_lib::absorb::AbsorbSource;
|
use jj_lib::absorb::AbsorbSource;
|
||||||
|
use jj_lib::matchers::EverythingMatcher;
|
||||||
use pollster::FutureExt as _;
|
use pollster::FutureExt as _;
|
||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
|
|
||||||
|
@ -23,6 +24,7 @@ use crate::cli_util::CommandHelper;
|
||||||
use crate::cli_util::RevisionArg;
|
use crate::cli_util::RevisionArg;
|
||||||
use crate::command_error::CommandError;
|
use crate::command_error::CommandError;
|
||||||
use crate::complete;
|
use crate::complete;
|
||||||
|
use crate::diff_util::DiffFormat;
|
||||||
use crate::ui::Ui;
|
use crate::ui::Ui;
|
||||||
|
|
||||||
/// Move changes from a revision into the stack of mutable revisions
|
/// Move changes from a revision into the stack of mutable revisions
|
||||||
|
@ -119,5 +121,18 @@ pub(crate) fn cmd_absorb(
|
||||||
stats.rewritten_destinations.len()
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -480,6 +480,8 @@ fn test_absorb_file_mode() {
|
||||||
Rebased 1 descendant commits.
|
Rebased 1 descendant commits.
|
||||||
Working copy now at: zsuskuln 77de368e (no description set)
|
Working copy now at: zsuskuln 77de368e (no description set)
|
||||||
Parent commit : qpvuntsm 991365da 1
|
Parent commit : qpvuntsm 991365da 1
|
||||||
|
Remaining changes:
|
||||||
|
M file1
|
||||||
");
|
");
|
||||||
|
|
||||||
insta::assert_snapshot!(get_diffs(&test_env, &repo_path, "mutable()"), @r"
|
insta::assert_snapshot!(get_diffs(&test_env, &repo_path, "mutable()"), @r"
|
||||||
|
@ -521,6 +523,8 @@ fn test_absorb_from_into() {
|
||||||
Rebased 1 descendant commits.
|
Rebased 1 descendant commits.
|
||||||
Working copy now at: zsuskuln d5424357 (no description set)
|
Working copy now at: zsuskuln d5424357 (no description set)
|
||||||
Parent commit : kkmpptxz 91df4543 2
|
Parent commit : kkmpptxz 91df4543 2
|
||||||
|
Remaining changes:
|
||||||
|
M file1
|
||||||
");
|
");
|
||||||
|
|
||||||
insta::assert_snapshot!(get_diffs(&test_env, &repo_path, "@-::"), @r"
|
insta::assert_snapshot!(get_diffs(&test_env, &repo_path, "@-::"), @r"
|
||||||
|
@ -623,6 +627,8 @@ fn test_absorb_paths() {
|
||||||
Rebased 1 descendant commits.
|
Rebased 1 descendant commits.
|
||||||
Working copy now at: kkmpptxz c6f31836 (no description set)
|
Working copy now at: kkmpptxz c6f31836 (no description set)
|
||||||
Parent commit : qpvuntsm ae044adb 1
|
Parent commit : qpvuntsm ae044adb 1
|
||||||
|
Remaining changes:
|
||||||
|
M file2
|
||||||
");
|
");
|
||||||
|
|
||||||
insta::assert_snapshot!(get_diffs(&test_env, &repo_path, "mutable()"), @r"
|
insta::assert_snapshot!(get_diffs(&test_env, &repo_path, "mutable()"), @r"
|
||||||
|
@ -677,6 +683,8 @@ fn test_absorb_immutable() {
|
||||||
Rebased 1 descendant commits.
|
Rebased 1 descendant commits.
|
||||||
Working copy now at: mzvwutvl 3021153d (no description set)
|
Working copy now at: mzvwutvl 3021153d (no description set)
|
||||||
Parent commit : kkmpptxz d80e3c2a 2
|
Parent commit : kkmpptxz d80e3c2a 2
|
||||||
|
Remaining changes:
|
||||||
|
M file1
|
||||||
");
|
");
|
||||||
|
|
||||||
// Immutable revisions shouldn't be rewritten
|
// Immutable revisions shouldn't be rewritten
|
||||||
|
|
|
@ -271,6 +271,9 @@ fn combine_texts(text1: &[u8], text2: &[u8], selected_ranges: &[SelectedRange])
|
||||||
/// Describes changes made by [`absorb_hunks()`].
|
/// Describes changes made by [`absorb_hunks()`].
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct AbsorbStats {
|
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
|
/// Rewritten commits which the source hunks were absorbed into, in forward
|
||||||
/// topological order.
|
/// topological order.
|
||||||
pub rewritten_destinations: Vec<Commit>,
|
pub rewritten_destinations: Vec<Commit>,
|
||||||
|
@ -287,6 +290,7 @@ pub fn absorb_hunks(
|
||||||
mut selected_trees: HashMap<CommitId, MergedTreeBuilder>,
|
mut selected_trees: HashMap<CommitId, MergedTreeBuilder>,
|
||||||
) -> BackendResult<AbsorbStats> {
|
) -> BackendResult<AbsorbStats> {
|
||||||
let store = repo.store().clone();
|
let store = repo.store().clone();
|
||||||
|
let mut rewritten_source = None;
|
||||||
let mut rewritten_destinations = Vec::new();
|
let mut rewritten_destinations = Vec::new();
|
||||||
let mut num_rebased = 0;
|
let mut num_rebased = 0;
|
||||||
// Rewrite commits in topological order so that descendant commits wouldn't
|
// Rewrite commits in topological order so that descendant commits wouldn't
|
||||||
|
@ -298,7 +302,7 @@ pub fn absorb_hunks(
|
||||||
if commit_builder.is_discardable()? {
|
if commit_builder.is_discardable()? {
|
||||||
commit_builder.abandon();
|
commit_builder.abandon();
|
||||||
} else {
|
} else {
|
||||||
commit_builder.write()?;
|
rewritten_source = Some(commit_builder.write()?);
|
||||||
num_rebased += 1;
|
num_rebased += 1;
|
||||||
}
|
}
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
@ -324,6 +328,7 @@ pub fn absorb_hunks(
|
||||||
Ok(())
|
Ok(())
|
||||||
})?;
|
})?;
|
||||||
Ok(AbsorbStats {
|
Ok(AbsorbStats {
|
||||||
|
rewritten_source,
|
||||||
rewritten_destinations,
|
rewritten_destinations,
|
||||||
num_rebased,
|
num_rebased,
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue