Debian Codegraph @

cli/tests/test_op_restore_command.rs

raw
1 // Copyright 2026 The Jujutsu Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 use crate::common::TestEnvironment;
16
17 #[test]
18 fn test_op_restore_warns_when_workspace_missing() {
19 let test_env = TestEnvironment::default();
20 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
21 let work_dir = test_env.work_dir("repo");
22
23 let output = work_dir.run_jj(["op", "restore", "000000000000"]);
24 insta::assert_snapshot!(output, @"
25 ------- stderr -------
26 Restored to operation: 000000000000 root()
27 Warning: The current workspace 'default' no longer exists after this operation. The working copy was left untouched.
28 Hint: Restore to an operation that contains the workspace (e.g. `jj undo` or `jj redo`).
29 [EOF]
30 ");
31 }
32
33 #[test]
34 fn test_op_restore_to_valid_op_no_warning() {
35 let test_env = TestEnvironment::default();
36 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
37 let work_dir = test_env.work_dir("repo");
38
39 // Restore to the current operation (@). This should not emit the
40 // missing-workspace warning.
41 let output = work_dir.run_jj(["op", "restore", "@"]);
42 insta::assert_snapshot!(output, @r"
43 ------- stderr -------
44 Restored to operation: f63ee16f9553 (2001-02-03 08:05:07) add workspace 'default'
45 Nothing changed.
46 [EOF]
47 ");
48 }