Debian Codegraph @

cli/tests/test_immutable_commits.rs

raw
1 // Copyright 2023 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_rewrite_immutable_generic() {
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 work_dir.write_file("file", "a");
23 work_dir.run_jj(["describe", "-m=a"]).success();
24 work_dir.run_jj(["new", "-m=b"]).success();
25 work_dir.write_file("file", "b");
26 work_dir
27 .run_jj(["bookmark", "create", "-r@", "main"])
28 .success();
29 work_dir.run_jj(["new", "main-", "-m=c"]).success();
30 work_dir.write_file("file", "c");
31 let output = work_dir.run_jj(["log"]);
32 insta::assert_snapshot!(output, @"
33 @ mzvwutvl [email protected] 2001-02-03 08:05:12 a6923629
34 │ c
35 │ ○ kkmpptxz [email protected] 2001-02-03 08:05:10 main 9d190342
36 ├─╯ b
37 ○ qpvuntsm [email protected] 2001-02-03 08:05:08 c8c8515a
38 │ a
39 ◆ zzzzzzzz root() 00000000
40 [EOF]
41 ");
42
43 // Cannot rewrite a commit in the configured set
44 test_env.add_config(r#"revset-aliases."immutable_heads()" = "main""#);
45 let output = work_dir.run_jj(["edit", "main"]);
46 insta::assert_snapshot!(output, @r#"
47 ------- stderr -------
48 Error: Commit 9d190342454d is immutable
49 Hint: Could not modify commit: kkmpptxz 9d190342 main | b
50 Hint: Immutable commits are used to protect shared history.
51 Hint: For more information, see:
52 - https://docs.jj-vcs.dev/latest/config/#set-of-immutable-commits
53 - `jj help -k config`, "Set of immutable commits"
54 Hint: This operation would rewrite 1 immutable commits.
55 [EOF]
56 [exit status: 1]
57 "#);
58 // Cannot rewrite an ancestor of the configured set
59 let output = work_dir.run_jj(["edit", "main-"]);
60 insta::assert_snapshot!(output, @r#"
61 ------- stderr -------
62 Error: Commit c8c8515af455 is immutable
63 Hint: Could not modify commit: qpvuntsm c8c8515a a
64 Hint: Immutable commits are used to protect shared history.
65 Hint: For more information, see:
66 - https://docs.jj-vcs.dev/latest/config/#set-of-immutable-commits
67 - `jj help -k config`, "Set of immutable commits"
68 Hint: This operation would rewrite 2 immutable commits.
69 [EOF]
70 [exit status: 1]
71 "#);
72 // Cannot rewrite the root commit even with an empty set of immutable commits
73 test_env.add_config(r#"revset-aliases."immutable_heads()" = "none()""#);
74 let output = work_dir.run_jj(["edit", "root()"]);
75 insta::assert_snapshot!(output, @"
76 ------- stderr -------
77 Error: The root commit 000000000000 is immutable
78 [EOF]
79 [exit status: 1]
80 ");
81
82 // Unresolvable immutable_heads()
83 test_env.add_config(r#"revset-aliases."immutable_heads()" = "bookmark_that_does_not_exist""#);
84 // Suppress warning in the commit summary template
85 test_env.add_config("template-aliases.'format_short_id(id)' = 'id.short(8)'");
86 let output = work_dir.run_jj(["edit", "main"]);
87 insta::assert_snapshot!(output, @"
88 ------- stderr -------
89 Config error: Invalid `revset-aliases.immutable_heads()`
90 Caused by: Revision `bookmark_that_does_not_exist` doesn't exist
91 For help, see https://docs.jj-vcs.dev/latest/config/ or use `jj help -k config`.
92 [EOF]
93 [exit status: 1]
94 ");
95
96 // Can use --ignore-immutable to override
97 test_env.add_config(r#"revset-aliases."immutable_heads()" = "main""#);
98 let output = work_dir.run_jj(["--ignore-immutable", "edit", "main"]);
99 insta::assert_snapshot!(output, @"
100 ------- stderr -------
101 Working copy (@) now at: kkmpptxz 9d190342 main | b
102 Parent commit (@-) : qpvuntsm c8c8515a a
103 Added 0 files, modified 1 files, removed 0 files
104 [EOF]
105 ");
106 // ... but not the root commit
107 let output = work_dir.run_jj(["--ignore-immutable", "edit", "root()"]);
108 insta::assert_snapshot!(output, @"
109 ------- stderr -------
110 Error: The root commit 000000000000 is immutable
111 [EOF]
112 [exit status: 1]
113 ");
114
115 // Mutating the repo works if ref is wrapped in present()
116 test_env.add_config(
117 r#"revset-aliases."immutable_heads()" = "present(bookmark_that_does_not_exist)""#,
118 );
119 let output = work_dir.run_jj(["new", "main"]);
120 insta::assert_snapshot!(output, @"
121 ------- stderr -------
122 Working copy (@) now at: wqnwkozp 8fc35e6e (empty) (no description set)
123 Parent commit (@-) : kkmpptxz 9d190342 main | b
124 [EOF]
125 ");
126
127 // immutable_heads() of different arity doesn't shadow the 0-ary one
128 test_env.add_config(r#"revset-aliases."immutable_heads(foo)" = "none()""#);
129 let output = work_dir.run_jj(["edit", "root()"]);
130 insta::assert_snapshot!(output, @"
131 ------- stderr -------
132 Error: The root commit 000000000000 is immutable
133 [EOF]
134 [exit status: 1]
135 ");
136 }
137
138 #[test]
139 fn test_new_wc_commit_when_wc_immutable() {
140 let test_env = TestEnvironment::default();
141 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
142 let work_dir = test_env.work_dir("repo");
143 work_dir
144 .run_jj(["bookmark", "create", "-r@", "main"])
145 .success();
146 work_dir.run_jj(["new", "-m=a"]).success();
147 let output = work_dir.run_jj(["bookmark", "set", "main", "-r@"]);
148 insta::assert_snapshot!(output, @"
149 ------- stderr -------
150 Moved 1 bookmarks to kkmpptxz e1cb4cf3 main | (empty) a
151 [EOF]
152 ");
153 // Make the working copy immutable after the fact
154 test_env.add_config(r#"revset-aliases."immutable_heads()" = "main""#);
155 work_dir.write_file("file", "a");
156 let output = work_dir.run_jj(["log", "-r.."]);
157 insta::assert_snapshot!(output, @"
158 @ mzvwutvl [email protected] 2001-02-03 08:05:11 49ad4c46
159 │ (no description set)
160 ◆ kkmpptxz [email protected] 2001-02-03 08:05:09 main e1cb4cf3
161 │ (empty) a
162 ◆ qpvuntsm [email protected] 2001-02-03 08:05:07 e8849ae1
163 │ (empty) (no description set)
164 ~
165 [EOF]
166 ------- stderr -------
167 Warning: The working-copy commit is immutable; a new commit has been created on top of it.
168 [EOF]
169 ");
170 }
171
172 #[test]
173 fn test_immutable_heads_set_to_working_copy() {
174 let test_env = TestEnvironment::default();
175 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
176 let work_dir = test_env.work_dir("repo");
177 work_dir
178 .run_jj(["bookmark", "create", "-r@", "main"])
179 .success();
180 test_env.add_config(r#"revset-aliases."immutable_heads()" = "@""#);
181 // New working-copy commit is created to mitigate weird UX
182 let output = work_dir.run_jj(["new", "-m=a"]);
183 insta::assert_snapshot!(output, @"
184 ------- stderr -------
185 Warning: The working-copy commit became immutable; a new commit has been created on top of it.
186 Working copy (@) now at: pmmvwywv 08e27304 (empty) (no description set)
187 Parent commit (@-) : kkmpptxz e1cb4cf3 (empty) a
188 [EOF]
189 ");
190 // New working-copy commit is created again because @ is still immutable
191 work_dir.write_file("file", "a");
192 let output = work_dir.run_jj(["log", "-r.."]);
193 insta::assert_snapshot!(output, @"
194 @ zsuskuln [email protected] 2001-02-03 08:05:10 2e9c5f50
195 │ (no description set)
196 ◆ pmmvwywv [email protected] 2001-02-03 08:05:09 08e27304
197 │ (empty) (no description set)
198 ◆ kkmpptxz [email protected] 2001-02-03 08:05:09 e1cb4cf3
199 │ (empty) a
200 ◆ qpvuntsm [email protected] 2001-02-03 08:05:07 main e8849ae1
201 │ (empty) (no description set)
202 ~
203 [EOF]
204 ------- stderr -------
205 Warning: The working-copy commit is immutable; a new commit has been created on top of it.
206 [EOF]
207 ");
208 // New working-copy commit shouldn't be created repeatedly with no changes
209 let output = work_dir.run_jj(["status"]);
210 insta::assert_snapshot!(output, @"
211 Working copy changes:
212 A file
213 Working copy (@) : zsuskuln 2e9c5f50 (no description set)
214 Parent commit (@-): pmmvwywv 08e27304 (empty) (no description set)
215 [EOF]
216 ");
217 }
218
219 #[test]
220 fn test_new_wc_commit_when_wc_immutable_multi_workspace() {
221 let test_env = TestEnvironment::default();
222 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
223 let work_dir = test_env.work_dir("repo");
224 work_dir
225 .run_jj(["bookmark", "create", "-r@", "main"])
226 .success();
227 test_env.add_config(r#"revset-aliases."immutable_heads()" = "main""#);
228 work_dir.run_jj(["new", "-m=a"]).success();
229 work_dir
230 .run_jj(["workspace", "add", "../workspace1"])
231 .success();
232 let workspace1_dir = test_env.work_dir("workspace1");
233 workspace1_dir.run_jj(["edit", "default@"]).success();
234
235 // New working-copy commit is created early for the current workspace
236 let output = work_dir.run_jj(["bookmark", "set", "main", "-r@"]);
237 insta::assert_snapshot!(output, @"
238 ------- stderr -------
239 Moved 1 bookmarks to kkmpptxz e1cb4cf3 main | (empty) a
240 Warning: The working-copy commit became immutable; a new commit has been created on top of it.
241 Working copy (@) now at: royxmykx cec19492 (empty) (no description set)
242 Parent commit (@-) : kkmpptxz e1cb4cf3 main | (empty) a
243 [EOF]
244 ");
245 work_dir.write_file("file", "a");
246 let output = work_dir.run_jj(["log", "-r.."]);
247 insta::assert_snapshot!(output, @"
248 @ royxmykx [email protected] 2001-02-03 08:05:13 default@ acbba76f
249 │ (no description set)
250 ◆ kkmpptxz [email protected] 2001-02-03 08:05:09 main workspace1@ e1cb4cf3
251 │ (empty) a
252 ◆ qpvuntsm [email protected] 2001-02-03 08:05:07 e8849ae1
253 │ (empty) (no description set)
254 ~
255 [EOF]
256 ");
257
258 // New working-copy commit is created for the other workspaces as needed
259 workspace1_dir.write_file("file", "a");
260 let output = workspace1_dir.run_jj(["log", "-r.."]);
261 insta::assert_snapshot!(output, @"
262 @ vruxwmqv [email protected] 2001-02-03 08:05:14 workspace1@ bbc55980
263 │ (no description set)
264 │ ○ royxmykx [email protected] 2001-02-03 08:05:13 default@ acbba76f
265 ├─╯ (no description set)
266 ◆ kkmpptxz [email protected] 2001-02-03 08:05:09 main e1cb4cf3
267 │ (empty) a
268 ◆ qpvuntsm [email protected] 2001-02-03 08:05:07 e8849ae1
269 │ (empty) (no description set)
270 ~
271 [EOF]
272 ------- stderr -------
273 Warning: The working-copy commit is immutable; a new commit has been created on top of it.
274 [EOF]
275 ");
276 }
277
278 #[test]
279 fn test_new_wc_commit_when_wc_immutable_multi_workspace_already_immutable() {
280 let test_env = TestEnvironment::default();
281 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
282 let work_dir = test_env.work_dir("repo");
283 // Consider other working copies immutable
284 test_env.add_config(r#"revset-aliases."immutable_heads()" = "working_copies() ~ @""#);
285 work_dir.run_jj(["new", "-m=a"]).success();
286 let output = work_dir
287 .run_jj(["workspace", "add", "../workspace1"])
288 .success();
289 // The current workspace is immutable from the new workspace's perspective,
290 // but we should not create a new commit for it.
291 insta::assert_snapshot!(output, @r#"
292 ------- stderr -------
293 Created workspace in "../workspace1"
294 Working copy (@) now at: pmmvwywv 1cd27236 (empty) (no description set)
295 Parent commit (@-) : qpvuntsm e8849ae1 (empty) (no description set)
296 [EOF]
297 "#);
298 let output = work_dir.run_jj(["log", "-r=::"]);
299 insta::assert_snapshot!(output, @"
300 @ rlvkpnrz [email protected] 2001-02-03 08:05:08 default@ 167b8dbf
301 │ (empty) a
302 │ ◆ pmmvwywv [email protected] 2001-02-03 08:05:09 workspace1@ 1cd27236
303 ├─╯ (empty) (no description set)
304 ◆ qpvuntsm [email protected] 2001-02-03 08:05:07 e8849ae1
305 │ (empty) (no description set)
306 ◆ zzzzzzzz root() 00000000
307 [EOF]
308 ");
309 // The other workspace was already immutable from the current workspace's
310 // perspective, so we don't create a new commit for it.
311 let output = work_dir.run_jj(["new"]);
312 insta::assert_snapshot!(output, @"
313 ------- stderr -------
314 Working copy (@) now at: mzvwutvl b6d970c6 (empty) (no description set)
315 Parent commit (@-) : rlvkpnrz 167b8dbf (empty) a
316 [EOF]
317 ");
318 }
319
320 #[test]
321 fn test_rewrite_immutable_commands() {
322 let test_env = TestEnvironment::default();
323 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
324 let work_dir = test_env.work_dir("repo");
325 work_dir.write_file("file", "a");
326 work_dir.run_jj(["describe", "-m=a"]).success();
327 work_dir.run_jj(["new", "-m=b"]).success();
328 work_dir.write_file("file", "b");
329 work_dir.run_jj(["new", "@-", "-m=c"]).success();
330 work_dir.write_file("file", "c");
331 work_dir
332 .run_jj(["new", "visible_heads()", "-m=merge"])
333 .success();
334 // Create another file to make sure the merge commit isn't empty (to satisfy `jj
335 // split`) and still has a conflict (to satisfy `jj resolve`).
336 work_dir.write_file("file2", "merged");
337 work_dir
338 .run_jj(["bookmark", "create", "-r@", "main"])
339 .success();
340 work_dir.run_jj(["new", "subject(b)"]).success();
341 work_dir.write_file("file", "w");
342 test_env.add_config(r#"revset-aliases."immutable_heads()" = "main""#);
343 test_env.add_config(r#"revset-aliases."trunk()" = "main""#);
344
345 // Log shows mutable commits, their parents, and trunk() by default
346 let output = work_dir.run_jj(["log"]);
347 insta::assert_snapshot!(output, @"
348 @ yqosqzyt [email protected] 2001-02-03 08:05:14 55c97dc7
349 │ (no description set)
350 │ ◆ mzvwutvl [email protected] 2001-02-03 08:05:12 main 1ca17106 (conflict)
351 ╭─┤ merge
352 │ │
353 │ ~
354 │
355 ◆ kkmpptxz [email protected] 2001-02-03 08:05:10 9d190342
356 │ b
357 ~
358 [EOF]
359 ");
360
361 // abandon
362 let output = work_dir.run_jj(["abandon", "main"]);
363 insta::assert_snapshot!(output, @r#"
364 ------- stderr -------
365 Error: Commit 1ca17106e94f is immutable
366 Hint: Could not modify commit: mzvwutvl 1ca17106 main | (conflict) merge
367 Hint: Immutable commits are used to protect shared history.
368 Hint: For more information, see:
369 - https://docs.jj-vcs.dev/latest/config/#set-of-immutable-commits
370 - `jj help -k config`, "Set of immutable commits"
371 Hint: This operation would rewrite 1 immutable commits.
372 [EOF]
373 [exit status: 1]
374 "#);
375 // absorb
376 let output = work_dir.run_jj(["absorb", "--into=::@-"]);
377 insta::assert_snapshot!(output, @r#"
378 ------- stderr -------
379 Error: Commit 9d190342454d is immutable
380 Hint: Could not modify commit: kkmpptxz 9d190342 b
381 Hint: Immutable commits are used to protect shared history.
382 Hint: For more information, see:
383 - https://docs.jj-vcs.dev/latest/config/#set-of-immutable-commits
384 - `jj help -k config`, "Set of immutable commits"
385 Hint: This operation would rewrite 2 immutable commits.
386 [EOF]
387 [exit status: 1]
388 "#);
389 // arrange
390 let output = work_dir.run_jj(["arrange", "-r=main"]);
391 insta::assert_snapshot!(output, @r#"
392 ------- stderr -------
393 Error: Commit 1ca17106e94f is immutable
394 Hint: Could not modify commit: mzvwutvl 1ca17106 main | (conflict) merge
395 Hint: Immutable commits are used to protect shared history.
396 Hint: For more information, see:
397 - https://docs.jj-vcs.dev/latest/config/#set-of-immutable-commits
398 - `jj help -k config`, "Set of immutable commits"
399 Hint: This operation would rewrite 1 immutable commits.
400 [EOF]
401 [exit status: 1]
402 "#);
403 // chmod
404 let output = work_dir.run_jj(["file", "chmod", "-r=main", "x", "file"]);
405 insta::assert_snapshot!(output, @r#"
406 ------- stderr -------
407 Error: Commit 1ca17106e94f is immutable
408 Hint: Could not modify commit: mzvwutvl 1ca17106 main | (conflict) merge
409 Hint: Immutable commits are used to protect shared history.
410 Hint: For more information, see:
411 - https://docs.jj-vcs.dev/latest/config/#set-of-immutable-commits
412 - `jj help -k config`, "Set of immutable commits"
413 Hint: This operation would rewrite 1 immutable commits.
414 [EOF]
415 [exit status: 1]
416 "#);
417 // describe
418 let output = work_dir.run_jj(["describe", "main"]);
419 insta::assert_snapshot!(output, @r#"
420 ------- stderr -------
421 Error: Commit 1ca17106e94f is immutable
422 Hint: Could not modify commit: mzvwutvl 1ca17106 main | (conflict) merge
423 Hint: Immutable commits are used to protect shared history.
424 Hint: For more information, see:
425 - https://docs.jj-vcs.dev/latest/config/#set-of-immutable-commits
426 - `jj help -k config`, "Set of immutable commits"
427 Hint: This operation would rewrite 1 immutable commits.
428 [EOF]
429 [exit status: 1]
430 "#);
431 // diffedit
432 let output = work_dir.run_jj(["diffedit", "-r=main"]);
433 insta::assert_snapshot!(output, @r#"
434 ------- stderr -------
435 Error: Commit 1ca17106e94f is immutable
436 Hint: Could not modify commit: mzvwutvl 1ca17106 main | (conflict) merge
437 Hint: Immutable commits are used to protect shared history.
438 Hint: For more information, see:
439 - https://docs.jj-vcs.dev/latest/config/#set-of-immutable-commits
440 - `jj help -k config`, "Set of immutable commits"
441 Hint: This operation would rewrite 1 immutable commits.
442 [EOF]
443 [exit status: 1]
444 "#);
445 // edit
446 let output = work_dir.run_jj(["edit", "main"]);
447 insta::assert_snapshot!(output, @r#"
448 ------- stderr -------
449 Error: Commit 1ca17106e94f is immutable
450 Hint: Could not modify commit: mzvwutvl 1ca17106 main | (conflict) merge
451 Hint: Immutable commits are used to protect shared history.
452 Hint: For more information, see:
453 - https://docs.jj-vcs.dev/latest/config/#set-of-immutable-commits
454 - `jj help -k config`, "Set of immutable commits"
455 Hint: This operation would rewrite 1 immutable commits.
456 [EOF]
457 [exit status: 1]
458 "#);
459 // metaedit
460 let output = work_dir.run_jj(["metaedit", "-r=main"]);
461 insta::assert_snapshot!(output, @r#"
462 ------- stderr -------
463 Error: Commit 1ca17106e94f is immutable
464 Hint: Could not modify commit: mzvwutvl 1ca17106 main | (conflict) merge
465 Hint: Immutable commits are used to protect shared history.
466 Hint: For more information, see:
467 - https://docs.jj-vcs.dev/latest/config/#set-of-immutable-commits
468 - `jj help -k config`, "Set of immutable commits"
469 Hint: This operation would rewrite 1 immutable commits.
470 [EOF]
471 [exit status: 1]
472 "#);
473 // new --insert-before
474 let output = work_dir.run_jj(["new", "--insert-before", "main"]);
475 insta::assert_snapshot!(output, @r#"
476 ------- stderr -------
477 Error: Commit 1ca17106e94f is immutable
478 Hint: Could not modify commit: mzvwutvl 1ca17106 main | (conflict) merge
479 Hint: Immutable commits are used to protect shared history.
480 Hint: For more information, see:
481 - https://docs.jj-vcs.dev/latest/config/#set-of-immutable-commits
482 - `jj help -k config`, "Set of immutable commits"
483 Hint: This operation would rewrite 1 immutable commits.
484 [EOF]
485 [exit status: 1]
486 "#);
487 // new --insert-after parent_of_main
488 let output = work_dir.run_jj(["new", "--insert-after", "subject(b)"]);
489 insta::assert_snapshot!(output, @r#"
490 ------- stderr -------
491 Error: Commit 1ca17106e94f is immutable
492 Hint: Could not modify commit: mzvwutvl 1ca17106 main | (conflict) merge
493 Hint: Immutable commits are used to protect shared history.
494 Hint: For more information, see:
495 - https://docs.jj-vcs.dev/latest/config/#set-of-immutable-commits
496 - `jj help -k config`, "Set of immutable commits"
497 Hint: This operation would rewrite 1 immutable commits.
498 [EOF]
499 [exit status: 1]
500 "#);
501 // parallelize
502 let output = work_dir.run_jj(["parallelize", "subject(b)", "main"]);
503 insta::assert_snapshot!(output, @r#"
504 ------- stderr -------
505 Error: Commit 1ca17106e94f is immutable
506 Hint: Could not modify commit: mzvwutvl 1ca17106 main | (conflict) merge
507 Hint: Immutable commits are used to protect shared history.
508 Hint: For more information, see:
509 - https://docs.jj-vcs.dev/latest/config/#set-of-immutable-commits
510 - `jj help -k config`, "Set of immutable commits"
511 Hint: This operation would rewrite 1 immutable commits.
512 [EOF]
513 [exit status: 1]
514 "#);
515 // rebase -s
516 let output = work_dir.run_jj(["rebase", "-s=main", "-d=@"]);
517 insta::assert_snapshot!(output, @r#"
518 ------- stderr -------
519 Error: Commit 1ca17106e94f is immutable
520 Hint: Could not modify commit: mzvwutvl 1ca17106 main | (conflict) merge
521 Hint: Immutable commits are used to protect shared history.
522 Hint: For more information, see:
523 - https://docs.jj-vcs.dev/latest/config/#set-of-immutable-commits
524 - `jj help -k config`, "Set of immutable commits"
525 Hint: This operation would rewrite 1 immutable commits.
526 [EOF]
527 [exit status: 1]
528 "#);
529 // rebase -b
530 let output = work_dir.run_jj(["rebase", "-b=main", "-d=@"]);
531 insta::assert_snapshot!(output, @r#"
532 ------- stderr -------
533 Error: Commit dfa21421ac56 is immutable
534 Hint: Could not modify commit: zsuskuln dfa21421 c
535 Hint: Immutable commits are used to protect shared history.
536 Hint: For more information, see:
537 - https://docs.jj-vcs.dev/latest/config/#set-of-immutable-commits
538 - `jj help -k config`, "Set of immutable commits"
539 Hint: This operation would rewrite 2 immutable commits.
540 [EOF]
541 [exit status: 1]
542 "#);
543 // rebase -r
544 let output = work_dir.run_jj(["rebase", "-r=main", "-d=@"]);
545 insta::assert_snapshot!(output, @r#"
546 ------- stderr -------
547 Error: Commit 1ca17106e94f is immutable
548 Hint: Could not modify commit: mzvwutvl 1ca17106 main | (conflict) merge
549 Hint: Immutable commits are used to protect shared history.
550 Hint: For more information, see:
551 - https://docs.jj-vcs.dev/latest/config/#set-of-immutable-commits
552 - `jj help -k config`, "Set of immutable commits"
553 Hint: This operation would rewrite 1 immutable commits.
554 [EOF]
555 [exit status: 1]
556 "#);
557 // resolve
558 let output = work_dir.run_jj(["resolve", "-r=subject(merge)", "file"]);
559 insta::assert_snapshot!(output, @r#"
560 ------- stderr -------
561 Error: Commit 1ca17106e94f is immutable
562 Hint: Could not modify commit: mzvwutvl 1ca17106 main | (conflict) merge
563 Hint: Immutable commits are used to protect shared history.
564 Hint: For more information, see:
565 - https://docs.jj-vcs.dev/latest/config/#set-of-immutable-commits
566 - `jj help -k config`, "Set of immutable commits"
567 Hint: This operation would rewrite 1 immutable commits.
568 [EOF]
569 [exit status: 1]
570 "#);
571 // restore -c
572 let output = work_dir.run_jj(["restore", "-c=main"]);
573 insta::assert_snapshot!(output, @r#"
574 ------- stderr -------
575 Error: Commit 1ca17106e94f is immutable
576 Hint: Could not modify commit: mzvwutvl 1ca17106 main | (conflict) merge
577 Hint: Immutable commits are used to protect shared history.
578 Hint: For more information, see:
579 - https://docs.jj-vcs.dev/latest/config/#set-of-immutable-commits
580 - `jj help -k config`, "Set of immutable commits"
581 Hint: This operation would rewrite 1 immutable commits.
582 [EOF]
583 [exit status: 1]
584 "#);
585 // restore --into
586 let output = work_dir.run_jj(["restore", "--into=main"]);
587 insta::assert_snapshot!(output, @r#"
588 ------- stderr -------
589 Error: Commit 1ca17106e94f is immutable
590 Hint: Could not modify commit: mzvwutvl 1ca17106 main | (conflict) merge
591 Hint: Immutable commits are used to protect shared history.
592 Hint: For more information, see:
593 - https://docs.jj-vcs.dev/latest/config/#set-of-immutable-commits
594 - `jj help -k config`, "Set of immutable commits"
595 Hint: This operation would rewrite 1 immutable commits.
596 [EOF]
597 [exit status: 1]
598 "#);
599 // split
600 let output = work_dir.run_jj(["split", "-r=main"]);
601 insta::assert_snapshot!(output, @r#"
602 ------- stderr -------
603 Error: Commit 1ca17106e94f is immutable
604 Hint: Could not modify commit: mzvwutvl 1ca17106 main | (conflict) merge
605 Hint: Immutable commits are used to protect shared history.
606 Hint: For more information, see:
607 - https://docs.jj-vcs.dev/latest/config/#set-of-immutable-commits
608 - `jj help -k config`, "Set of immutable commits"
609 Hint: This operation would rewrite 1 immutable commits.
610 [EOF]
611 [exit status: 1]
612 "#);
613 // split -B
614 let output = work_dir.run_jj(["split", "-B=main", "-m", "will fail", "file"]);
615 insta::assert_snapshot!(output, @r#"
616 ------- stderr -------
617 Error: Commit 1ca17106e94f is immutable
618 Hint: Could not modify commit: mzvwutvl 1ca17106 main | (conflict) merge
619 Hint: Immutable commits are used to protect shared history.
620 Hint: For more information, see:
621 - https://docs.jj-vcs.dev/latest/config/#set-of-immutable-commits
622 - `jj help -k config`, "Set of immutable commits"
623 Hint: This operation would rewrite 1 immutable commits.
624 [EOF]
625 [exit status: 1]
626 "#);
627 // squash -r
628 let output = work_dir.run_jj(["squash", "-r=subject(b)"]);
629 insta::assert_snapshot!(output, @r#"
630 ------- stderr -------
631 Error: Commit 9d190342454d is immutable
632 Hint: Could not modify commit: kkmpptxz 9d190342 b
633 Hint: Immutable commits are used to protect shared history.
634 Hint: For more information, see:
635 - https://docs.jj-vcs.dev/latest/config/#set-of-immutable-commits
636 - `jj help -k config`, "Set of immutable commits"
637 Hint: This operation would rewrite 4 immutable commits.
638 [EOF]
639 [exit status: 1]
640 "#);
641 // squash --from
642 let output = work_dir.run_jj(["squash", "--from=main"]);
643 insta::assert_snapshot!(output, @r#"
644 ------- stderr -------
645 Error: Commit 1ca17106e94f is immutable
646 Hint: Could not modify commit: mzvwutvl 1ca17106 main | (conflict) merge
647 Hint: Immutable commits are used to protect shared history.
648 Hint: For more information, see:
649 - https://docs.jj-vcs.dev/latest/config/#set-of-immutable-commits
650 - `jj help -k config`, "Set of immutable commits"
651 Hint: This operation would rewrite 1 immutable commits.
652 [EOF]
653 [exit status: 1]
654 "#);
655 // squash --into
656 let output = work_dir.run_jj(["squash", "--into=main"]);
657 insta::assert_snapshot!(output, @r#"
658 ------- stderr -------
659 Error: Commit 1ca17106e94f is immutable
660 Hint: Could not modify commit: mzvwutvl 1ca17106 main | (conflict) merge
661 Hint: Immutable commits are used to protect shared history.
662 Hint: For more information, see:
663 - https://docs.jj-vcs.dev/latest/config/#set-of-immutable-commits
664 - `jj help -k config`, "Set of immutable commits"
665 Hint: This operation would rewrite 1 immutable commits.
666 [EOF]
667 [exit status: 1]
668 "#);
669 // squash --after
670 let output = work_dir.run_jj(["squash", "--after=main-"]);
671 insta::assert_snapshot!(output, @r#"
672 ------- stderr -------
673 Error: Commit 1ca17106e94f is immutable
674 Hint: Could not modify commit: mzvwutvl 1ca17106 main | (conflict) merge
675 Hint: Immutable commits are used to protect shared history.
676 Hint: For more information, see:
677 - https://docs.jj-vcs.dev/latest/config/#set-of-immutable-commits
678 - `jj help -k config`, "Set of immutable commits"
679 Hint: This operation would rewrite 1 immutable commits.
680 [EOF]
681 [exit status: 1]
682 "#);
683 // squash --before
684 let output = work_dir.run_jj(["squash", "--before=main"]);
685 insta::assert_snapshot!(output, @r#"
686 ------- stderr -------
687 Error: Commit 1ca17106e94f is immutable
688 Hint: Could not modify commit: mzvwutvl 1ca17106 main | (conflict) merge
689 Hint: Immutable commits are used to protect shared history.
690 Hint: For more information, see:
691 - https://docs.jj-vcs.dev/latest/config/#set-of-immutable-commits
692 - `jj help -k config`, "Set of immutable commits"
693 Hint: This operation would rewrite 1 immutable commits.
694 [EOF]
695 [exit status: 1]
696 "#);
697 // sign
698 let output = work_dir.run_jj(["sign", "-r=main", "--config=signing.backend=test"]);
699 insta::assert_snapshot!(output, @r#"
700 ------- stderr -------
701 Error: Commit 1ca17106e94f is immutable
702 Hint: Could not modify commit: mzvwutvl 1ca17106 main | (conflict) merge
703 Hint: Immutable commits are used to protect shared history.
704 Hint: For more information, see:
705 - https://docs.jj-vcs.dev/latest/config/#set-of-immutable-commits
706 - `jj help -k config`, "Set of immutable commits"
707 Hint: This operation would rewrite 1 immutable commits.
708 [EOF]
709 [exit status: 1]
710 "#);
711 // unsign
712 let output = work_dir.run_jj(["unsign", "-r=main"]);
713 insta::assert_snapshot!(output, @r#"
714 ------- stderr -------
715 Error: Commit 1ca17106e94f is immutable
716 Hint: Could not modify commit: mzvwutvl 1ca17106 main | (conflict) merge
717 Hint: Immutable commits are used to protect shared history.
718 Hint: For more information, see:
719 - https://docs.jj-vcs.dev/latest/config/#set-of-immutable-commits
720 - `jj help -k config`, "Set of immutable commits"
721 Hint: This operation would rewrite 1 immutable commits.
722 [EOF]
723 [exit status: 1]
724 "#);
725 }
726
727 #[test]
728 fn test_immutable_log() {
729 let test_env = TestEnvironment::default();
730 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
731 let work_dir = test_env.work_dir("repo");
732 work_dir.run_jj(["new"]).success();
733 test_env.add_config(r#"revset-aliases."immutable_heads()" = "@-""#);
734 // The immutable commits should be indicated in the graph even with
735 // `--ignore-immutable`
736 let output = work_dir.run_jj(["log", "--ignore-immutable"]);
737 insta::assert_snapshot!(output, @"
738 @ rlvkpnrz [email protected] 2001-02-03 08:05:08 43444d88
739 │ (empty) (no description set)
740 ◆ qpvuntsm [email protected] 2001-02-03 08:05:07 e8849ae1
741 │ (empty) (no description set)
742 ◆ zzzzzzzz root() 00000000
743 [EOF]
744 ");
745 }