diff --git a/CHANGELOG.md b/CHANGELOG.md index 1187472047..4e535e5de0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -72,6 +72,9 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). * `jj diffedit` now accepts a `--restore-descendants` flag. When used, descendants of the edited commit will keep their original content. +* `jj abandon` now accepts a `--restore-descendants` flag. When used, + descendants of the abandoned commits will keep their original content. + ### Fixed bugs * Update working copy before reporting changes. This prevents errors during reporting diff --git a/cli/src/commands/abandon.rs b/cli/src/commands/abandon.rs index a0a8917385..3a697b069a 100644 --- a/cli/src/commands/abandon.rs +++ b/cli/src/commands/abandon.rs @@ -43,6 +43,9 @@ pub(crate) struct AbandonArgs { /// Ignored (but lets you pass `-r` for consistency with other commands) #[arg(short = 'r', hide = true, action = clap::ArgAction::Count)] unused_revision: u8, + /// Do not modify the content of the children of the abandoned commits + #[arg(long)] + restore_descendants: bool, } #[instrument(skip_all)] @@ -66,7 +69,14 @@ pub(crate) fn cmd_abandon( for commit in &to_abandon { tx.repo_mut().record_abandoned_commit(commit.id().clone()); } - let num_rebased = tx.repo_mut().rebase_descendants(command.settings())?; + let (num_rebased, extra_msg) = if args.restore_descendants { + ( + tx.repo_mut().reparent_descendants(command.settings())?, + " (no content change)", + ) + } else { + (tx.repo_mut().rebase_descendants(command.settings())?, "") + }; if let Some(mut formatter) = ui.status_formatter() { if to_abandon.len() == 1 { @@ -88,7 +98,8 @@ pub(crate) fn cmd_abandon( if num_rebased > 0 { writeln!( formatter, - "Rebased {num_rebased} descendant commits onto parents of abandoned commits" + "Rebased {num_rebased} descendant commits onto parents of abandoned \ + commits{extra_msg}", )?; } } diff --git a/cli/tests/cli-reference@.md.snap b/cli/tests/cli-reference@.md.snap index 395c88c739..c379572fe9 100644 --- a/cli/tests/cli-reference@.md.snap +++ b/cli/tests/cli-reference@.md.snap @@ -207,6 +207,7 @@ If a working-copy commit gets abandoned, it will be given a new, empty commit. T ###### **Options:** * `-s`, `--summary` — Do not print every abandoned commit on a separate line +* `--restore-descendants` — Do not modify the content of the children of the abandoned commits