cli: rebase descendants earlier for jj diffedit and jj restore

Makes sure that, at the point the commit summary for the new commit is written,
the original commit that is being rewritten is already abandoned. Otherwise,
once we show divergent change ids (in a subsequent commit) in the short commit
template, the commits would be shown as divergent.

This also has an effect on whether branches are displayed next to the commit;
the changes in test_resotre_command happen because, now, the branch is properly
propagated to the restored commit before its summary is displayed.
This commit is contained in:
Ilya Grigoriev 2023-10-25 21:03:29 -07:00
parent 2874a69faf
commit 6a128f56ed
2 changed files with 14 additions and 2 deletions

View file

@ -3191,9 +3191,15 @@ fn cmd_restore(
.rewrite_commit(command.settings(), &to_commit)
.set_tree_id(new_tree_id)
.write()?;
// rebase_descendants early; otherwise `new_commit` would always have
// a conflicted change id at this point.
let num_rebased = tx.mut_repo().rebase_descendants(command.settings())?;
write!(ui.stderr(), "Created ")?;
tx.write_commit_summary(ui.stderr_formatter().as_mut(), &new_commit)?;
writeln!(ui.stderr())?;
if num_rebased > 0 {
writeln!(ui.stderr(), "Rebased {num_rebased} descendant commits")?;
}
tx.finish(ui)?;
}
Ok(())
@ -3248,9 +3254,15 @@ don't make any changes, then the operation will be aborted.",
.rewrite_commit(command.settings(), &target_commit)
.set_tree_id(tree_id)
.write()?;
// rebase_descendants early; otherwise `new_commit` would always have
// a conflicted change id at this point.
let num_rebased = tx.mut_repo().rebase_descendants(command.settings())?;
write!(ui.stderr(), "Created ")?;
tx.write_commit_summary(ui.stderr_formatter().as_mut(), &new_commit)?;
writeln!(ui.stderr())?;
if num_rebased > 0 {
writeln!(ui.stderr(), "Rebased {num_rebased} descendant commits")?;
}
tx.finish(ui)?;
}
Ok(())

View file

@ -192,7 +192,7 @@ fn test_restore_conflicted_merge() {
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["restore", "file"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r###"
Created vruxwmqv b2c9c888 (conflict) (empty) conflict
Created vruxwmqv b2c9c888 conflict | (conflict) (empty) conflict
Working copy now at: vruxwmqv b2c9c888 conflict | (conflict) (empty) conflict
Parent commit : zsuskuln aa493daf a | a
Parent commit : royxmykx db6a4daf b | b
@ -231,7 +231,7 @@ fn test_restore_conflicted_merge() {
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["restore"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r###"
Created vruxwmqv 4fc10820 (conflict) (empty) conflict
Created vruxwmqv 4fc10820 conflict | (conflict) (empty) conflict
Working copy now at: vruxwmqv 4fc10820 conflict | (conflict) (empty) conflict
Parent commit : zsuskuln aa493daf a | a
Parent commit : royxmykx db6a4daf b | b