From 0d197791a099176808f5864cfcb0663d10094337 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Sat, 16 Mar 2024 06:16:37 -0700 Subject: [PATCH] tests: add unsnapshotted changes in secondary workspace in recovery test This adds modifed, removed, and added files in the secondary working copy. --- cli/tests/test_workspaces.rs | 54 ++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/cli/tests/test_workspaces.rs b/cli/tests/test_workspaces.rs index 547d5584e..42c941bf5 100644 --- a/cli/tests/test_workspaces.rs +++ b/cli/tests/test_workspaces.rs @@ -417,10 +417,17 @@ fn test_workspaces_current_op_discarded_by_other() { let main_path = test_env.env_root().join("main"); let secondary_path = test_env.env_root().join("secondary"); - std::fs::write(main_path.join("file"), "contents\n").unwrap(); + std::fs::write(main_path.join("modified"), "base\n").unwrap(); + std::fs::write(main_path.join("deleted"), "base\n").unwrap(); + test_env.jj_cmd_ok(&main_path, &["new"]); + std::fs::write(main_path.join("modified"), "main\n").unwrap(); test_env.jj_cmd_ok(&main_path, &["new"]); test_env.jj_cmd_ok(&main_path, &["workspace", "add", "../secondary"]); + // Make unsnapshotted writes in the secondary working copy + std::fs::write(secondary_path.join("modified"), "secondary\n").unwrap(); + std::fs::remove_file(secondary_path.join("deleted")).unwrap(); + std::fs::write(secondary_path.join("added"), "secondary\n").unwrap(); // Create an op by abandoning the parent commit. Importantly, that commit also // changes the target tree in the secondary workspace. @@ -436,11 +443,13 @@ fn test_workspaces_current_op_discarded_by_other() { ], ); insta::assert_snapshot!(stdout, @r###" - @ f1dc1bf396 abandon commit acb4b92517b20aa4ee2f3dc58d7c2373754d0b29a3df310dbabda5813f13c3730d28d6a1b6dd37f3b0c8c5c9adaead5dab242ffe7ecc2e5a6a534fe4c6639f89 - ◉ 47f1ad5e1a Create initial working-copy commit in workspace secondary - ◉ fd918ce207 add workspace 'secondary' - ◉ 5927500c4b new empty commit - ◉ c86cb4fdf4 snapshot working copy + @ ca4014fc13 abandon commit 9e69961a6cb8dc42410fa11421c5ce14c9ba4dba3d85c99b3f5d7214e01c09211d3f6abf0a5502038bc9531d4d7828a4b3e978ca4f64f6cb5b00f4181c1710cc + ◉ b7e3c248b3 Create initial working-copy commit in workspace secondary + ◉ 3a464a164b add workspace 'secondary' + ◉ 1a8a57ad06 new empty commit + ◉ 34dce00889 snapshot working copy + ◉ 64b8644c69 new empty commit + ◉ 983fc29dc3 snapshot working copy ◉ 17dbb2fe40 add workspace 'default' ◉ cecfee9647 initialize repo ◉ 0000000000 @@ -451,9 +460,10 @@ fn test_workspaces_current_op_discarded_by_other() { test_env.jj_cmd_ok(&main_path, &["util", "gc", "--expire=now"]); insta::assert_snapshot!(get_log_output(&test_env, &main_path), @r###" - @ 6dc8f254cd3c default@ - │ ◉ 4278b78fb503 secondary@ + @ b026dbb4ded8 default@ + │ ◉ 11b31a7bf02c secondary@ ├─╯ + ◉ cab81fe8ecb0 ◉ 000000000000 "###); @@ -466,16 +476,17 @@ fn test_workspaces_current_op_discarded_by_other() { let (stdout, stderr) = test_env.jj_cmd_ok(&secondary_path, &["workspace", "update-stale"]); insta::assert_snapshot!(stderr, @r###" - Failed to read working copy's current operation; attempting recovery. Error message from read attempt: Object 47f1ad5e1adfaa1e9863181e6e45ae12b9db553e82bde82e278c0c6288053c833b4039a5baf2415871964bcdcd4b7875692979e66f2ec18bfc3896355091cf53 of type operation not found - Created and checked out recovery commit df3e46148439 + Failed to read working copy's current operation; attempting recovery. Error message from read attempt: Object b7e3c248b31b30b9ebe9bc0960bb5138a9832745f0e02d76e7dc9e65a44fcfd092cdf9e22e6ca84498dc496dd08c22027ecc3ba8fc45ab54bf565b9cda13eca6 of type operation not found + Created and checked out recovery commit 1e90e5d2ab94 "###); insta::assert_snapshot!(stdout, @""); insta::assert_snapshot!(get_log_output(&test_env, &main_path), @r###" - ◉ 54400d0c58b7 secondary@ - ◉ 4278b78fb503 - │ @ 6dc8f254cd3c default@ + ◉ bffc5782a10d secondary@ + ◉ 11b31a7bf02c + │ @ b026dbb4ded8 default@ ├─╯ + ◉ cab81fe8ecb0 ◉ 000000000000 "###); @@ -483,17 +494,24 @@ fn test_workspaces_current_op_discarded_by_other() { insta::assert_snapshot!(stderr, @""); insta::assert_snapshot!(stdout, @r###" Working copy changes: - A file - Working copy : znkkpsqq 54400d0c (no description set) - Parent commit: pmmvwywv 4278b78f (empty) (no description set) + A added + D deleted + M modified + Working copy : kpqxywon bffc5782 (no description set) + Parent commit: rzvqmyuk 11b31a7b (empty) (no description set) + "###); + // The modified file should have the same contents it had before (not reset to + // the base contents) + insta::assert_snapshot!(std::fs::read_to_string(secondary_path.join("modified")).unwrap(), @r###" + secondary "###); let (stdout, stderr) = test_env.jj_cmd_ok(&secondary_path, &["obslog"]); insta::assert_snapshot!(stderr, @""); insta::assert_snapshot!(stdout, @r###" - @ znkkpsqq test.user@example.com 2001-02-03 04:05:16.000 +07:00 secondary@ 54400d0c + @ kpqxywon test.user@example.com 2001-02-03 04:05:17.000 +07:00 secondary@ bffc5782 │ (no description set) - ◉ znkkpsqq hidden test.user@example.com 2001-02-03 04:05:16.000 +07:00 df3e4614 + ◉ kpqxywon hidden test.user@example.com 2001-02-03 04:05:17.000 +07:00 1e90e5d2 (empty) (no description set) "###); }