Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: print operation summary on "op restore" #4531

Merged
merged 2 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cli/src/commands/operation/restore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ pub fn cmd_op_restore(
&args.what,
);
tx.repo_mut().set_view(new_view);
if let Some(mut formatter) = ui.status_formatter() {
write!(formatter, "Restored to operation ")?;
let template = tx.base_workspace_helper().operation_summary_template();
template.format(&target_op, formatter.as_mut())?;
writeln!(formatter)?;
}
tx.finish(ui, format!("restore to operation {}", target_op.id().hex()))?;

Ok(())
Expand Down
7 changes: 3 additions & 4 deletions cli/src/commands/operation/undo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,13 @@ pub fn cmd_op_undo(
&args.what,
);
tx.repo_mut().set_view(new_view);
tx.finish(ui, format!("undo operation {}", bad_op.id().hex()))?;

if let Some(mut formatter) = ui.status_formatter() {
write!(formatter, "Undid operation ")?;
let template = workspace_command.operation_summary_template();
template.format(&bad_op, &mut *formatter)?;
let template = tx.base_workspace_helper().operation_summary_template();
template.format(&bad_op, formatter.as_mut())?;
writeln!(formatter)?;
}
tx.finish(ui, format!("undo operation {}", bad_op.id().hex()))?;

Ok(())
}
2 changes: 1 addition & 1 deletion cli/tests/test_git_colocated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -757,9 +757,9 @@ fn test_git_colocated_undo_head_move() {
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["undo"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r#"
Undid operation 951a1c249028 2001-02-03 04:05:13.000 +07:00 - 2001-02-03 04:05:13.000 +07:00 new empty commit
Working copy now at: royxmykx eb08b363 (empty) (no description set)
Parent commit : qpvuntsm 230dd059 (empty) (no description set)
Undid operation 951a1c249028 2001-02-03 04:05:13.000 +07:00 - 2001-02-03 04:05:13.000 +07:00 new empty commit
"#);
insta::assert_snapshot!(
git_repo.head().unwrap().target().unwrap().to_string(),
Expand Down
8 changes: 6 additions & 2 deletions cli/tests/test_git_fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,9 @@ fn test_fetch_undo_what() {
&["op", "restore", "--what", "repo", &base_operation_id],
);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(stderr, @r#"
Restored to operation b51416386f26 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00 add workspace 'default'
"#);
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @r###"
b (deleted)
@origin: vpupmnsl hidden c7d4bdcb descr_for_b
Expand All @@ -1044,7 +1046,9 @@ fn test_fetch_undo_what() {
],
);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(stderr, @r#"
Restored to operation b51416386f26 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00 add workspace 'default'
"#);
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @r###"
newbookmark: qpvuntsm 230dd059 (empty) (no description set)
"###);
Expand Down
9 changes: 6 additions & 3 deletions cli/tests/test_git_import_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ fn test_git_import_undo() {
// "git import" can be undone by default.
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["op", "restore", &base_operation_id]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(stderr, @r#"
Restored to operation b51416386f26 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00 add workspace 'default'
"#);
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @"");
// Try "git import" again, which should re-import the bookmark "a".
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["git", "import"]);
Expand Down Expand Up @@ -225,10 +227,11 @@ fn test_git_import_move_export_with_default_undo() {
// repo stay where they were.
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["op", "restore", &base_operation_id]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r###"
insta::assert_snapshot!(stderr, @r#"
Restored to operation b51416386f26 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00 add workspace 'default'
Working copy now at: qpvuntsm 230dd059 (empty) (no description set)
Parent commit : zzzzzzzz 00000000 (empty) (no description set)
"###);
"#);
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @"");
insta::assert_debug_snapshot!(get_git_repo_refs(&git_repo), @r###"
[
Expand Down
5 changes: 3 additions & 2 deletions cli/tests/test_rebase_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,12 +680,13 @@ fn test_rebase_revision_onto_descendant() {
// Now, let's rebase onto the descendant merge
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["op", "restore", &setup_opid]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r###"
insta::assert_snapshot!(stderr, @r#"
Restored to operation 0957966a18b4 2001-02-03 04:05:15.000 +07:00 - 2001-02-03 04:05:15.000 +07:00 create bookmark merge pointing to commit b05964d109522cd06e48f1a2661e1a0f58be0984
Working copy now at: vruxwmqv b05964d1 merge | merge
Parent commit : royxmykx cea87a87 b | b
Parent commit : zsuskuln 2c5b7858 a | a
Added 1 files, modified 0 files, removed 0 files
"###);
"#);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["rebase", "-r", "base", "-d", "merge"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r###"
Expand Down