jj abandon: Report what commit or how many commits were abandoned

There are not tests for `jj abandon`, and I haven't written any yet.
This commit is contained in:
Ilya Grigoriev 2023-01-07 16:17:36 -08:00
parent c43f0a580a
commit 6765850c7d
2 changed files with 27 additions and 5 deletions

View file

@ -2085,10 +2085,29 @@ fn cmd_abandon(
) )
}; };
let mut tx = workspace_command.start_transaction(&transaction_description); let mut tx = workspace_command.start_transaction(&transaction_description);
for commit in to_abandon { for commit in &to_abandon {
tx.mut_repo().record_abandoned_commit(commit.id().clone()); tx.mut_repo().record_abandoned_commit(commit.id().clone());
} }
let num_rebased = tx.mut_repo().rebase_descendants(command.settings())?; let num_rebased = tx.mut_repo().rebase_descendants(command.settings())?;
if to_abandon.len() == 1 {
ui.write("Abandoned commit ")?;
let workspace_id = command.workspace_helper(ui)?.workspace_id();
write_commit_summary(
ui.stdout_formatter().as_mut(),
tx.repo().as_repo_ref(),
&workspace_id,
&to_abandon[0],
command.settings(),
)?;
ui.write("\n")?;
} else {
writeln!(
ui,
"Abandoned {} commits. This can be undone with `jj undo` or `jj op restore`.",
&to_abandon.len()
)?;
}
if num_rebased > 0 { if num_rebased > 0 {
writeln!( writeln!(
ui, ui,

View file

@ -56,6 +56,7 @@ fn test_rebase_branch_with_merge() {
let stdout = test_env.jj_cmd_success(&repo_path, &["abandon", "d"]); let stdout = test_env.jj_cmd_success(&repo_path, &["abandon", "d"]);
insta::assert_snapshot!(stdout, @r###" insta::assert_snapshot!(stdout, @r###"
Abandoned commit b7c62f28ed10 d
Rebased 1 descendant commits onto parents of abandoned commits Rebased 1 descendant commits onto parents of abandoned commits
Working copy now at: 11a2e10edf4e e Working copy now at: 11a2e10edf4e e
Added 0 files, modified 0 files, removed 1 files Added 0 files, modified 0 files, removed 1 files
@ -74,17 +75,18 @@ fn test_rebase_branch_with_merge() {
test_env.jj_cmd_success(&repo_path, &["undo"]); test_env.jj_cmd_success(&repo_path, &["undo"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["abandon"] /* abandons `e` */); let stdout = test_env.jj_cmd_success(&repo_path, &["abandon"] /* abandons `e` */);
insta::assert_snapshot!(stdout, @r###" insta::assert_snapshot!(stdout, @r###"
Abandoned commit 5557ece3e631 e
Working copy now at: 6b5275139632 (no description set) Working copy now at: 6b5275139632 (no description set)
Added 0 files, modified 0 files, removed 3 files Added 0 files, modified 0 files, removed 3 files
"###); "###);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###" insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ @
| o d e? | o d e??
| o c | o c
| | o b | | o b
| |/ | |/
|/| |/|
o | a e? o | a e??
|/ |/
o o
"###); "###);
@ -92,6 +94,7 @@ fn test_rebase_branch_with_merge() {
test_env.jj_cmd_success(&repo_path, &["undo"]); test_env.jj_cmd_success(&repo_path, &["undo"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["abandon", "descendants(c)"]); let stdout = test_env.jj_cmd_success(&repo_path, &["abandon", "descendants(c)"]);
insta::assert_snapshot!(stdout, @r###" insta::assert_snapshot!(stdout, @r###"
Abandoned 3 commits. This can be undone with `jj undo` or `jj op restore`.
Working copy now at: e7bb061217d5 (no description set) Working copy now at: e7bb061217d5 (no description set)
Added 0 files, modified 0 files, removed 3 files Added 0 files, modified 0 files, removed 3 files
"###); "###);
@ -99,8 +102,8 @@ fn test_rebase_branch_with_merge() {
@ @
| o b | o b
|/ |/
o a e? o a e??
o c d e? o c d e??
"###); "###);
} }