Debian Codegraph @

cli/tests/test_op_integrate_command.rs

raw
1 // Copyright 2025 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 std::path::PathBuf;
16
17 use testutils::TestResult;
18
19 use crate::common::TestEnvironment;
20
21 /// Integrating an already integrated operation is a no-op
22 #[test]
23 fn test_integrate_integrated_operation() {
24 let test_env = TestEnvironment::default();
25 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
26 let work_dir = test_env.work_dir("repo");
27
28 let output = work_dir.run_jj(["op", "integrate", "@"]);
29 insta::assert_snapshot!(output, @"");
30 let output = work_dir.run_jj(["op", "log"]);
31 insta::assert_snapshot!(output, @"
32 @ f63ee16f9553 [email protected] 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00
33 │ add workspace 'default'
34 ○ 000000000000 root()
35 [EOF]
36 ");
37 }
38
39 #[test]
40 fn test_integrate_sibling_operation() -> TestResult {
41 let test_env = TestEnvironment::default();
42 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
43 let work_dir = test_env.work_dir("repo");
44
45 let base_op_id = work_dir.current_operation_id();
46 work_dir.run_jj(["new", "-m=first"]).success();
47 let unintegrated_id = work_dir.current_operation_id();
48 assert_ne!(unintegrated_id, base_op_id);
49 // Manually remove the last operation from the operation log
50 let heads_dir = work_dir
51 .root()
52 .join(PathBuf::from_iter([".jj", "repo", "op_heads", "heads"]));
53 std::fs::rename(
54 heads_dir.join(&unintegrated_id),
55 heads_dir.join(&base_op_id),
56 )?;
57 // We use --ignore-working-copy to prevent the automatic reloading of the repo
58 // at the unintegrated operation that's mentioned in
59 // `.jj/working_copy/checkout`.
60 let output = work_dir.run_jj(["new", "-m=second", "--ignore-working-copy"]);
61 insta::assert_snapshot!(output, @"");
62
63 // The working copy should now be at the old unintegrated sibling operation
64 let output = work_dir.run_jj(["op", "log"]);
65 insta::assert_snapshot!(output, @"
66 ------- stderr -------
67 Internal error: The repo was loaded at operation 63a847e21093, which seems to be a sibling of the working copy's operation 4bffc36765bd
68 Hint: Run `jj op integrate 4bffc36765bd` to add the working copy's operation to the operation log.
69 [EOF]
70 [exit status: 255]
71 ");
72
73 // Integrate the operation
74 let output = work_dir.run_jj(["op", "integrate", &unintegrated_id]);
75 insta::assert_snapshot!(output, @"
76 ------- stderr -------
77 The specified operation has been integrated with other existing operations.
78 [EOF]
79 ");
80 let output = work_dir.run_jj(["op", "log"]);
81 insta::assert_snapshot!(output, @"
82 @ f28c8b5750f5 [email protected] default@ 2001-02-03 04:05:11.000 +07:00 - 2001-02-03 04:05:11.000 +07:00
83 ├─╮ reconcile divergent operations
84 │ │ args: jj op integrate 4bffc36765bd9b796cc8bd631a09e92c60b686ef98c316a9baa7164c4f6f9d0071871d5678b014fec33b920d1177776b748af2a6395fc28031f92ab75a1d31ec
85 ○ │ 4bffc36765bd [email protected] default@ 2001-02-03 04:05:08.000 +07:00 - 2001-02-03 04:05:08.000 +07:00
86 │ │ new empty commit
87 │ │ args: jj new '-m=first'
88 │ ○ 63a847e21093 [email protected] default@ 2001-02-03 04:05:09.000 +07:00 - 2001-02-03 04:05:09.000 +07:00
89 ├─╯ new empty commit
90 │ args: jj new '-m=second' --ignore-working-copy
91 ○ f63ee16f9553 [email protected] 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00
92 │ add workspace 'default'
93 ○ 000000000000 root()
94 [EOF]
95 ");
96 Ok(())
97 }
98
99 #[test]
100 fn test_integrate_rebase_descendants() -> TestResult {
101 let test_env = TestEnvironment::default();
102 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
103 let work_dir = test_env.work_dir("repo");
104 work_dir
105 .run_jj(["new", "--no-edit", "-m=child 1"])
106 .success();
107
108 let base_op_id = work_dir.current_operation_id();
109 work_dir.run_jj(["new", "-m=child 2"]).success();
110 let unintegrated_id = work_dir.current_operation_id();
111 assert_ne!(unintegrated_id, base_op_id);
112 // Manually remove the last operation from the operation log
113 let heads_dir = work_dir
114 .root()
115 .join(PathBuf::from_iter([".jj", "repo", "op_heads", "heads"]));
116 std::fs::rename(
117 heads_dir.join(&unintegrated_id),
118 heads_dir.join(&base_op_id),
119 )?;
120
121 // We use --ignore-working-copy to prevent the automatic reloading of the repo
122 // at the unintegrated operation that's mentioned in
123 // `.jj/working_copy/checkout`.
124 let output = work_dir.run_jj(["describe", "-m=parent", "--ignore-working-copy"]);
125 insta::assert_snapshot!(output, @r"
126 ------- stderr -------
127 Rebased 1 descendant commits.
128 [EOF]
129 ");
130
131 // The working copy should now be at the old unintegrated sibling operation
132 let output = work_dir.run_jj(["op", "log"]);
133 insta::assert_snapshot!(output, @"
134 ------- stderr -------
135 Internal error: The repo was loaded at operation 02d52b605abd, which seems to be a sibling of the working copy's operation ec162faff901
136 Hint: Run `jj op integrate ec162faff901` to add the working copy's operation to the operation log.
137 [EOF]
138 [exit status: 255]
139 ");
140
141 // Integrate the operation
142 let output = work_dir.run_jj(["op", "integrate", &unintegrated_id]);
143 insta::assert_snapshot!(output, @r"
144 ------- stderr -------
145 Rebased 1 descendant commits onto commits rewritten by other operation.
146 The specified operation has been integrated with other existing operations.
147 [EOF]
148 ");
149 let output = work_dir.run_jj(["op", "log"]);
150 insta::assert_snapshot!(output, @"
151 @ 000180467209 [email protected] default@ 2001-02-03 04:05:12.000 +07:00 - 2001-02-03 04:05:12.000 +07:00
152 ├─╮ reconcile divergent operations
153 │ │ args: jj op integrate ec162faff90142f42a8fe4e514c61c06c10756a11b3ee0d645500b6f4280225e20c0b21b18759c23c37f144c6643492f170b8b809ae5f932f5d73dcf651941d1
154 ○ │ ec162faff901 [email protected] default@ 2001-02-03 04:05:09.000 +07:00 - 2001-02-03 04:05:09.000 +07:00
155 │ │ new empty commit
156 │ │ args: jj new '-m=child 2'
157 │ ○ 02d52b605abd [email protected] default@ 2001-02-03 04:05:10.000 +07:00 - 2001-02-03 04:05:10.000 +07:00
158 ├─╯ describe commit e8849ae12c709f2321908879bc724fdb2ab8a781
159 │ args: jj describe '-m=parent' --ignore-working-copy
160 ○ 10ad95d988d6 [email protected] default@ 2001-02-03 04:05:08.000 +07:00 - 2001-02-03 04:05:08.000 +07:00
161 │ new empty commit
162 │ args: jj new --no-edit '-m=child 1'
163 ○ f63ee16f9553 [email protected] 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00
164 │ add workspace 'default'
165 ○ 000000000000 root()
166 [EOF]
167 ");
168
169 // Child 2 was successfully rebased
170 let output = work_dir.run_jj(["log"]);
171 insta::assert_snapshot!(output, @"
172 @ kkmpptxz [email protected] 2001-02-03 08:05:12 9780be6d
173 │ (empty) child 2
174 │ ○ rlvkpnrz [email protected] 2001-02-03 08:05:10 ce1fb6c9
175 ├─╯ (empty) child 1
176 ○ qpvuntsm [email protected] 2001-02-03 08:05:10 5f8729eb
177 │ (empty) parent
178 ◆ zzzzzzzz root() 00000000
179 [EOF]
180 ");
181 Ok(())
182 }
183
184 #[test]
185 fn test_integrate_concurrent_operations() -> TestResult {
186 let test_env = TestEnvironment::default();
187 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
188 let work_dir = test_env.work_dir("repo");
189
190 let base_op_id = work_dir.current_operation_id();
191 work_dir.run_jj(["describe", "-m=left"]).success();
192 let unintegrated_id = work_dir.current_operation_id();
193 assert_ne!(unintegrated_id, base_op_id);
194 // Manually remove the last operation from the operation log
195 let heads_dir = work_dir
196 .root()
197 .join(PathBuf::from_iter([".jj", "repo", "op_heads", "heads"]));
198 std::fs::rename(
199 heads_dir.join(&unintegrated_id),
200 heads_dir.join(&base_op_id),
201 )?;
202
203 // We use --ignore-working-copy to prevent the automatic reloading of the repo
204 // at the unintegrated operation that's mentioned in
205 // `.jj/working_copy/checkout`.
206 let output = work_dir.run_jj(["describe", "-m=right", "--ignore-working-copy"]);
207 insta::assert_snapshot!(output, @"");
208
209 // The working copy should now be at the old unintegrated sibling operation
210 let output = work_dir.run_jj(["op", "log"]);
211 insta::assert_snapshot!(output, @"
212 ------- stderr -------
213 Internal error: The repo was loaded at operation 383be968e923, which seems to be a sibling of the working copy's operation 49428a30d110
214 Hint: Run `jj op integrate 49428a30d110` to add the working copy's operation to the operation log.
215 [EOF]
216 [exit status: 255]
217 ");
218
219 // Integrate the operation
220 let output = work_dir.run_jj(["op", "integrate", &unintegrated_id]);
221 insta::assert_snapshot!(output, @"
222 ------- stderr -------
223 The specified operation has been integrated with other existing operations.
224 [EOF]
225 ");
226 let output = work_dir.run_jj(["op", "log"]);
227 insta::assert_snapshot!(output, @"
228 @ ddbaedf9ee34 [email protected] default@ 2001-02-03 04:05:11.000 +07:00 - 2001-02-03 04:05:11.000 +07:00
229 ├─╮ reconcile divergent operations
230 │ │ args: jj op integrate 49428a30d110a365178cdca38a32661982fb260d18df5c19f2b76df283c9cd2fd367dce1b124a7a75cfe9487eeee3b5031bd1b2a851261a3fc3f1d9dba41d768
231 ○ │ 49428a30d110 [email protected] default@ 2001-02-03 04:05:08.000 +07:00 - 2001-02-03 04:05:08.000 +07:00
232 │ │ describe commit e8849ae12c709f2321908879bc724fdb2ab8a781
233 │ │ args: jj describe '-m=left'
234 │ ○ 383be968e923 [email protected] default@ 2001-02-03 04:05:09.000 +07:00 - 2001-02-03 04:05:09.000 +07:00
235 ├─╯ describe commit e8849ae12c709f2321908879bc724fdb2ab8a781
236 │ args: jj describe '-m=right' --ignore-working-copy
237 ○ f63ee16f9553 [email protected] 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00
238 │ add workspace 'default'
239 ○ 000000000000 root()
240 [EOF]
241 ");
242
243 // Produces divergence equivalent to concurrent `jj describe`
244 let output = work_dir.run_jj(["log"]);
245 insta::assert_snapshot!(output, @"
246 @ qpvuntsm/1 [email protected] 2001-02-03 08:05:08 3c52528f (divergent)
247 │ (empty) left
248 │ ○ qpvuntsm/0 [email protected] 2001-02-03 08:05:09 fc350e9c (divergent)
249 ├─╯ (empty) right
250 ◆ zzzzzzzz root() 00000000
251 [EOF]
252 ");
253 Ok(())
254 }