diff --git a/cli/src/commands/rebase.rs b/cli/src/commands/rebase.rs index 7ebfbb1075..9ef0dfb42e 100644 --- a/cli/src/commands/rebase.rs +++ b/cli/src/commands/rebase.rs @@ -409,12 +409,7 @@ fn rebase_descendants_transaction( ) }; - let MoveCommitsStats { - num_rebased_targets, - num_rebased_descendants, - num_skipped_rebases, - num_abandoned, - } = move_commits( + let stats = move_commits( settings, tx.repo_mut(), new_parent_ids, @@ -422,29 +417,7 @@ fn rebase_descendants_transaction( &MoveCommitsTarget::Roots(target_roots), rebase_options, )?; - - if num_skipped_rebases > 0 { - writeln!( - ui.status(), - "Skipped rebase of {num_skipped_rebases} commits that were already in place" - )?; - } - if num_rebased_targets > 0 { - writeln!(ui.status(), "Rebased {num_rebased_targets} commits")?; - } - if num_rebased_descendants > 0 { - writeln!( - ui.status(), - "Rebased {num_rebased_descendants} descendant commits" - )?; - } - if num_abandoned > 0 { - writeln!( - ui.status(), - "Abandoned {num_abandoned} newly emptied commits" - )?; - } - + print_move_commits_stats(ui, &stats)?; tx.finish(ui, tx_description) } @@ -541,12 +514,7 @@ fn rebase_revisions_transaction( ) }; - let MoveCommitsStats { - num_rebased_targets, - num_rebased_descendants, - num_skipped_rebases, - num_abandoned, - } = move_commits( + let stats = move_commits( settings, tx.repo_mut(), new_parent_ids, @@ -554,28 +522,7 @@ fn rebase_revisions_transaction( &MoveCommitsTarget::Commits(target_commits), rebase_options, )?; - - if let Some(mut fmt) = ui.status_formatter() { - if num_skipped_rebases > 0 { - writeln!( - fmt, - "Skipped rebase of {num_skipped_rebases} commits that were already in place" - )?; - } - if num_rebased_targets > 0 { - writeln!( - fmt, - "Rebased {num_rebased_targets} commits onto destination" - )?; - } - if num_rebased_descendants > 0 { - writeln!(fmt, "Rebased {num_rebased_descendants} descendant commits")?; - } - if num_abandoned > 0 { - writeln!(fmt, "Abandoned {num_abandoned} newly emptied commits")?; - } - } - + print_move_commits_stats(ui, &stats)?; tx.finish(ui, tx_description) } @@ -618,3 +565,38 @@ fn check_rebase_destinations( } Ok(()) } + +/// Print details about the provided [`MoveCommitsStats`]. +fn print_move_commits_stats(ui: &Ui, stats: &MoveCommitsStats) -> std::io::Result<()> { + let Some(mut formatter) = ui.status_formatter() else { + return Ok(()); + }; + let &MoveCommitsStats { + num_rebased_targets, + num_rebased_descendants, + num_skipped_rebases, + num_abandoned, + } = stats; + if num_skipped_rebases > 0 { + writeln!( + formatter, + "Skipped rebase of {num_skipped_rebases} commits that were already in place" + )?; + } + if num_rebased_targets > 0 { + writeln!( + formatter, + "Rebased {num_rebased_targets} commits onto destination" + )?; + } + if num_rebased_descendants > 0 { + writeln!( + formatter, + "Rebased {num_rebased_descendants} descendant commits" + )?; + } + if num_abandoned > 0 { + writeln!(formatter, "Abandoned {num_abandoned} newly emptied commits")?; + } + Ok(()) +} diff --git a/cli/tests/test_duplicate_command.rs b/cli/tests/test_duplicate_command.rs index 85d5197c2e..a9770eb2d7 100644 --- a/cli/tests/test_duplicate_command.rs +++ b/cli/tests/test_duplicate_command.rs @@ -329,12 +329,12 @@ fn test_rebase_duplicates() { let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["rebase", "-s", "b", "-d", "root()"]); insta::assert_snapshot!(stdout, @""); - insta::assert_snapshot!(stderr, @r###" - Rebased 4 commits + insta::assert_snapshot!(stderr, @r#" + Rebased 4 commits onto destination Working copy now at: royxmykx ed671a3c c | c Parent commit : zsuskuln 4c6f1569 b | b Added 0 files, modified 0 files, removed 1 files - "###); + "#); // Some of the duplicate commits' timestamps were changed a little to make them // have distinct commit ids. insta::assert_snapshot!(get_log_output_with_ts(&test_env, &repo_path), @r###" diff --git a/cli/tests/test_rebase_command.rs b/cli/tests/test_rebase_command.rs index 602486bb0d..4c1e1b97ed 100644 --- a/cli/tests/test_rebase_command.rs +++ b/cli/tests/test_rebase_command.rs @@ -156,9 +156,7 @@ fn test_rebase_bookmark() { let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["rebase", "-b", "c", "-d", "e"]); insta::assert_snapshot!(stdout, @""); - insta::assert_snapshot!(stderr, @r###" - Rebased 3 commits - "###); + insta::assert_snapshot!(stderr, @"Rebased 3 commits onto destination"); insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###" ○ d: b │ ○ c: b @@ -173,13 +171,13 @@ fn test_rebase_bookmark() { test_env.jj_cmd_ok(&repo_path, &["undo"]); let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["rebase", "-b=e", "-b=d", "-d=b"]); insta::assert_snapshot!(stdout, @""); - insta::assert_snapshot!(stderr, @r###" + insta::assert_snapshot!(stderr, @r#" Skipped rebase of 1 commits that were already in place - Rebased 1 commits + Rebased 1 commits onto destination Working copy now at: znkkpsqq 9ca2a154 e | e Parent commit : zsuskuln 1394f625 b | b Added 1 files, modified 0 files, removed 0 files - "###); + "#); insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###" @ e: b │ ○ d: b @@ -203,13 +201,13 @@ fn test_rebase_bookmark() { "###); let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["rebase", "-b=all:e|d", "-d=b"]); insta::assert_snapshot!(stdout, @""); - insta::assert_snapshot!(stderr, @r###" + insta::assert_snapshot!(stderr, @r#" Skipped rebase of 1 commits that were already in place - Rebased 1 commits + Rebased 1 commits onto destination Working copy now at: znkkpsqq 817e3fb0 e | e Parent commit : zsuskuln 1394f625 b | b Added 1 files, modified 0 files, removed 0 files - "###); + "#); insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###" @ e: b │ ○ d: b @@ -248,13 +246,13 @@ fn test_rebase_bookmark_with_merge() { let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["rebase", "-b", "d", "-d", "b"]); insta::assert_snapshot!(stdout, @""); - insta::assert_snapshot!(stderr, @r###" - Rebased 3 commits + insta::assert_snapshot!(stderr, @r#" + Rebased 3 commits onto destination Working copy now at: znkkpsqq 5f8a3db2 e | e Parent commit : rlvkpnrz 2443ea76 a | a Parent commit : vruxwmqv 1677f795 d | d Added 1 files, modified 0 files, removed 0 files - "###); + "#); insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###" @ e: a d ├─╮ @@ -269,13 +267,13 @@ fn test_rebase_bookmark_with_merge() { test_env.jj_cmd_ok(&repo_path, &["undo"]); let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["rebase", "-d", "b"]); insta::assert_snapshot!(stdout, @""); - insta::assert_snapshot!(stderr, @r###" - Rebased 3 commits + insta::assert_snapshot!(stderr, @r#" + Rebased 3 commits onto destination Working copy now at: znkkpsqq a331ac11 e | e Parent commit : rlvkpnrz 2443ea76 a | a Parent commit : vruxwmqv 3d0f3644 d | d Added 1 files, modified 0 files, removed 0 files - "###); + "#); insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###" @ e: a d ├─╮ @@ -798,11 +796,11 @@ fn test_rebase_with_descendants() { let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["rebase", "-s", "b", "-d", "a"]); insta::assert_snapshot!(stdout, @""); - insta::assert_snapshot!(stderr, @r###" - Rebased 3 commits + insta::assert_snapshot!(stderr, @r#" + Rebased 3 commits onto destination Working copy now at: vruxwmqv 705832bd d | d Parent commit : royxmykx 57c7246a c | c - "###); + "#); insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###" @ d: c ○ c: a b @@ -817,12 +815,12 @@ fn test_rebase_with_descendants() { test_env.jj_cmd_ok(&repo_path, &["undo"]); let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["rebase", "-s=c", "-s=d", "-d=a"]); insta::assert_snapshot!(stdout, @""); - insta::assert_snapshot!(stderr, @r###" - Rebased 2 commits + insta::assert_snapshot!(stderr, @r#" + Rebased 2 commits onto destination Working copy now at: vruxwmqv 92c2bc9a d | d Parent commit : rlvkpnrz 2443ea76 a | a Added 0 files, modified 0 files, removed 2 files - "###); + "#); insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###" @ d: a │ ○ c: a @@ -849,12 +847,12 @@ fn test_rebase_with_descendants() { // `a`. `c` remains a descendant of `b`. let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["rebase", "-s=b", "-s=d", "-d=a"]); insta::assert_snapshot!(stdout, @""); - insta::assert_snapshot!(stderr, @r###" - Rebased 3 commits + insta::assert_snapshot!(stderr, @r#" + Rebased 3 commits onto destination Working copy now at: vruxwmqv f1e71cb7 d | d Parent commit : rlvkpnrz 2443ea76 a | a Added 0 files, modified 0 files, removed 2 files - "###); + "#); insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###" @ d: a │ ○ c: a b @@ -877,12 +875,12 @@ fn test_rebase_with_descendants() { "###); let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["rebase", "-s=all:b|d", "-d=a"]); insta::assert_snapshot!(stdout, @""); - insta::assert_snapshot!(stderr, @r###" - Rebased 3 commits + insta::assert_snapshot!(stderr, @r#" + Rebased 3 commits onto destination Working copy now at: vruxwmqv d17539f7 d | d Parent commit : rlvkpnrz 2443ea76 a | a Added 0 files, modified 0 files, removed 2 files - "###); + "#); insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###" @ d: a │ ○ c: a b @@ -983,11 +981,11 @@ fn test_rebase_with_child_and_descendant_bug_2600() { test_env.jj_cmd_ok(&repo_path, &["op", "restore", &setup_opid]); let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["rebase", "-s", "a", "-d", "root()"]); insta::assert_snapshot!(stdout, @""); - insta::assert_snapshot!(stderr, @r###" - Rebased 3 commits + insta::assert_snapshot!(stderr, @r#" + Rebased 3 commits onto destination Working copy now at: znkkpsqq cf8ecff5 c | c Parent commit : vruxwmqv 24e1a270 b | b - "###); + "#); // Commit "a" should be rebased onto the root commit. Commit "b" should have // "base" and "a" as parents as before. insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###" @@ -1037,11 +1035,11 @@ fn test_rebase_with_child_and_descendant_bug_2600() { test_env.jj_cmd_ok(&repo_path, &["op", "restore", &setup_opid]); let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["rebase", "-b", "c", "-d", "a"]); insta::assert_snapshot!(stdout, @""); - insta::assert_snapshot!(stderr, @r###" - Rebased 2 commits + insta::assert_snapshot!(stderr, @r#" + Rebased 2 commits onto destination Working copy now at: znkkpsqq 76914dcc c | c Parent commit : vruxwmqv f73f03c7 b | b - "###); + "#); // The commits in roots(a..c), i.e. commit "b" should be rebased onto "a", // which means "b" loses its "base" parent insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###" @@ -1694,13 +1692,13 @@ fn test_rebase_after() { &["rebase", "-s", "c", "--after", "b1", "--after", "b3"], ); insta::assert_snapshot!(stdout, @""); - insta::assert_snapshot!(stderr, @r###" - Rebased 4 commits + insta::assert_snapshot!(stderr, @r#" + Rebased 4 commits onto destination Rebased 2 descendant commits Working copy now at: xznxytkn a4ace41c f | f Parent commit : nkmrtpmo c7744d08 e | e Added 0 files, modified 0 files, removed 2 files - "###); + "#); insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###" ○ b4: d f ├─╮ @@ -2201,13 +2199,13 @@ fn test_rebase_before() { &["rebase", "-s", "c", "--before", "b2", "--before", "b4"], ); insta::assert_snapshot!(stdout, @""); - insta::assert_snapshot!(stderr, @r###" - Rebased 4 commits + insta::assert_snapshot!(stderr, @r#" + Rebased 4 commits onto destination Rebased 2 descendant commits Working copy now at: xznxytkn 84704387 f | f Parent commit : nkmrtpmo cff61821 e | e Added 0 files, modified 0 files, removed 2 files - "###); + "#); insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###" ○ b4: d f ├─╮ @@ -2399,13 +2397,13 @@ fn test_rebase_after_before() { &["rebase", "-s", "c", "--before", "b1", "--after", "b2"], ); insta::assert_snapshot!(stdout, @""); - insta::assert_snapshot!(stderr, @r###" - Rebased 4 commits + insta::assert_snapshot!(stderr, @r#" + Rebased 4 commits onto destination Rebased 1 descendant commits Working copy now at: lylxulpl 108f0202 f | f Parent commit : kmkuslsw 52245d71 e | e Added 0 files, modified 0 files, removed 1 files - "###); + "#); insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###" ○ b1: a d f ├─┬─╮ @@ -2459,7 +2457,7 @@ fn test_rebase_skip_emptied() { let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["rebase", "-d=b", "--skip-emptied"]); insta::assert_snapshot!(stdout, @""); insta::assert_snapshot!(stderr, @r#" - Rebased 2 commits + Rebased 2 commits onto destination Abandoned 1 newly emptied commits Working copy now at: yostqsxw bc4222f2 (empty) also already empty Parent commit : vruxwmqv 6b41ecb2 (empty) already empty diff --git a/cli/tests/test_repo_change_report.rs b/cli/tests/test_repo_change_report.rs index 6bfd020b6a..18ed64734f 100644 --- a/cli/tests/test_repo_change_report.rs +++ b/cli/tests/test_repo_change_report.rs @@ -30,8 +30,8 @@ fn test_report_conflicts() { let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["rebase", "-s=description(B)", "-d=root()"]); insta::assert_snapshot!(stdout, @""); - insta::assert_snapshot!(stderr, @r###" - Rebased 3 commits + insta::assert_snapshot!(stderr, @r#" + Rebased 3 commits onto destination Working copy now at: zsuskuln aa73e2ae (conflict) (empty) (no description set) Parent commit : kkmpptxz 64bdec0c (conflict) C Added 0 files, modified 1 files, removed 0 files @@ -45,19 +45,19 @@ fn test_report_conflicts() { Then use `jj resolve`, or edit the conflict markers in the file directly. Once the conflicts are resolved, you may want to inspect the result with `jj diff`. Then run `jj squash` to move the resolution into the conflicted commit. - "###); + "#); let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["rebase", "-d=description(A)"]); insta::assert_snapshot!(stdout, @""); - insta::assert_snapshot!(stderr, @r###" - Rebased 3 commits + insta::assert_snapshot!(stderr, @r#" + Rebased 3 commits onto destination Working copy now at: zsuskuln d70c003d (empty) (no description set) Parent commit : kkmpptxz 43e94449 C Added 0 files, modified 1 files, removed 0 files Existing conflicts were resolved or abandoned from these commits: kkmpptxz hidden 64bdec0c (conflict) C rlvkpnrz hidden 10a5fd45 (conflict) B - "###); + "#); // Can get hint about multiple root commits let (stdout, stderr) = @@ -121,9 +121,9 @@ fn test_report_conflicts_with_divergent_commits() { let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["rebase", "-s=description(B)", "-d=root()"]); insta::assert_snapshot!(stdout, @""); - insta::assert_snapshot!(stderr, @r###" + insta::assert_snapshot!(stderr, @r#" Concurrent modification detected, resolving automatically. - Rebased 3 commits + Rebased 3 commits onto destination Working copy now at: zsuskuln?? 97ce1783 (conflict) C2 Parent commit : kkmpptxz eb93a73d (conflict) B Added 0 files, modified 1 files, removed 0 files @@ -138,12 +138,12 @@ fn test_report_conflicts_with_divergent_commits() { Then use `jj resolve`, or edit the conflict markers in the file directly. Once the conflicts are resolved, you may want to inspect the result with `jj diff`. Then run `jj squash` to move the resolution into the conflicted commit. - "###); + "#); let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["rebase", "-d=description(A)"]); insta::assert_snapshot!(stdout, @""); - insta::assert_snapshot!(stderr, @r###" - Rebased 3 commits + insta::assert_snapshot!(stderr, @r#" + Rebased 3 commits onto destination Working copy now at: zsuskuln?? f2d7a228 C2 Parent commit : kkmpptxz db069a22 B Added 0 files, modified 1 files, removed 0 files @@ -151,14 +151,14 @@ fn test_report_conflicts_with_divergent_commits() { zsuskuln hidden b535189c (conflict) C3 zsuskuln hidden 97ce1783 (conflict) C2 kkmpptxz hidden eb93a73d (conflict) B - "###); + "#); // Same thing when rebasing the divergent commits one at a time let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["rebase", "-s=description(C2)", "-d=root()"]); insta::assert_snapshot!(stdout, @""); - insta::assert_snapshot!(stderr, @r###" - Rebased 1 commits + insta::assert_snapshot!(stderr, @r#" + Rebased 1 commits onto destination Working copy now at: zsuskuln?? b15416ac (conflict) C2 Parent commit : zzzzzzzz 00000000 (empty) (no description set) Added 0 files, modified 1 files, removed 0 files @@ -171,13 +171,13 @@ fn test_report_conflicts_with_divergent_commits() { Then use `jj resolve`, or edit the conflict markers in the file directly. Once the conflicts are resolved, you may want to inspect the result with `jj diff`. Then run `jj squash` to move the resolution into the conflicted commit. - "###); + "#); let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["rebase", "-s=description(C3)", "-d=root()"]); insta::assert_snapshot!(stdout, @""); insta::assert_snapshot!(stderr, @r#" - Rebased 1 commits + Rebased 1 commits onto destination New conflicts appeared in these commits: zsuskuln?? 8cc7fde6 (conflict) C3 To resolve the conflicts, start by updating to it: @@ -192,23 +192,23 @@ fn test_report_conflicts_with_divergent_commits() { &["rebase", "-s=description(C2)", "-d=description(B)"], ); insta::assert_snapshot!(stdout, @""); - insta::assert_snapshot!(stderr, @r###" - Rebased 1 commits + insta::assert_snapshot!(stderr, @r#" + Rebased 1 commits onto destination Working copy now at: zsuskuln?? 1f9680bd C2 Parent commit : kkmpptxz db069a22 B Added 0 files, modified 1 files, removed 0 files Existing conflicts were resolved or abandoned from these commits: zsuskuln hidden b15416ac (conflict) C2 - "###); + "#); let (stdout, stderr) = test_env.jj_cmd_ok( &repo_path, &["rebase", "-s=description(C3)", "-d=description(B)"], ); insta::assert_snapshot!(stdout, @""); - insta::assert_snapshot!(stderr, @r###" - Rebased 1 commits + insta::assert_snapshot!(stderr, @r#" + Rebased 1 commits onto destination Existing conflicts were resolved or abandoned from these commits: zsuskuln hidden 8cc7fde6 (conflict) C3 - "###); + "#); }