Skip to content

Commit

Permalink
abandon: add --restore-descendants flag
Browse files Browse the repository at this point in the history
  • Loading branch information
samueltardieu committed Sep 23, 2024
1 parent 8c81d9f commit 70c785a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 13 additions & 2 deletions cli/src/commands/abandon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand 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 {
Expand All @@ -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}",
)?;
}
}
Expand Down
1 change: 1 addition & 0 deletions cli/tests/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 70c785a

Please sign in to comment.