Debian Codegraph @

cli/tests/test_bookmark_command.rs

raw
1 // Copyright 2022 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 testutils::TestResult;
16 use testutils::git;
17
18 use crate::common::CommandOutput;
19 use crate::common::TestEnvironment;
20 use crate::common::TestWorkDir;
21
22 fn create_commit_with_refs(
23 repo: &gix::Repository,
24 message: &str,
25 content: &[u8],
26 ref_names: &[&str],
27 ) {
28 let git::CommitResult {
29 tree_id: _,
30 commit_id,
31 } = git::add_commit(repo, "refs/heads/dummy", "file", content, message, &[]);
32 repo.find_reference("dummy").unwrap().delete().unwrap();
33
34 for name in ref_names {
35 repo.reference(
36 *name,
37 commit_id,
38 gix::refs::transaction::PreviousValue::Any,
39 "log message",
40 )
41 .unwrap();
42 }
43 }
44
45 #[test]
46 fn test_bookmark_multiple_names() {
47 let test_env = TestEnvironment::default();
48 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
49 let work_dir = test_env.work_dir("repo");
50
51 let output = work_dir.run_jj(["bookmark", "create", "-r@", "foo", "bar"]);
52 insta::assert_snapshot!(output, @"
53 ------- stderr -------
54 Warning: Target revision is empty.
55 Created 2 bookmarks pointing to qpvuntsm e8849ae1 bar foo | (empty) (no description set)
56 [EOF]
57 ");
58 insta::assert_snapshot!(get_log_output(&work_dir), @"
59 @ bar foo e8849ae12c70
60 ◆ 000000000000
61 [EOF]
62 ");
63
64 work_dir.run_jj(["new"]).success();
65 let output = work_dir.run_jj(["bookmark", "set", "foo", "bar"]);
66 insta::assert_snapshot!(output, @"
67 ------- stderr -------
68 Warning: Target revision is empty.
69 Moved 2 bookmarks to zsuskuln 0e555a27 bar foo | (empty) (no description set)
70 [EOF]
71 ");
72 insta::assert_snapshot!(get_log_output(&work_dir), @"
73 @ bar foo 0e555a27ac99
74 ○ e8849ae12c70
75 ◆ 000000000000
76 [EOF]
77 ");
78
79 let output = work_dir.run_jj(["bookmark", "delete", "foo", "bar", "foo"]);
80 insta::assert_snapshot!(output, @"
81 ------- stderr -------
82 Deleted 2 bookmarks.
83 [EOF]
84 ");
85 insta::assert_snapshot!(get_log_output(&work_dir), @"
86 @ 0e555a27ac99
87 ○ e8849ae12c70
88 ◆ 000000000000
89 [EOF]
90 ");
91
92 // Hint should be omitted if -r is specified
93 let output = work_dir.run_jj(["bookmark", "create", "-r@-", "foo", "bar"]);
94 insta::assert_snapshot!(output, @"
95 ------- stderr -------
96 Warning: Target revision is empty.
97 Created 2 bookmarks pointing to qpvuntsm e8849ae1 bar foo | (empty) (no description set)
98 [EOF]
99 ");
100
101 // Create and move with explicit -r
102 let output = work_dir.run_jj(["bookmark", "set", "-r@", "bar", "baz"]);
103 insta::assert_snapshot!(output, @"
104 ------- stderr -------
105 Warning: Target revision is empty.
106 Created 1 bookmarks pointing to zsuskuln 0e555a27 bar baz | (empty) (no description set)
107 Moved 1 bookmarks to zsuskuln 0e555a27 bar baz | (empty) (no description set)
108 [EOF]
109 ");
110
111 // Noop changes should not be included in the stats
112 let output = work_dir.run_jj(["bookmark", "set", "-r@", "foo", "bar", "baz"]);
113 insta::assert_snapshot!(output, @"
114 ------- stderr -------
115 Warning: Target revision is empty.
116 Moved 1 bookmarks to zsuskuln 0e555a27 bar baz foo | (empty) (no description set)
117 [EOF]
118 ");
119 }
120
121 #[test]
122 fn test_bookmark_at_root() {
123 let test_env = TestEnvironment::default();
124 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
125 let work_dir = test_env.work_dir("repo");
126
127 let output = work_dir.run_jj(["bookmark", "create", "fred", "-r=root()"]);
128 insta::assert_snapshot!(output, @"
129 ------- stderr -------
130 Warning: Target revision is empty.
131 Created 1 bookmarks pointing to zzzzzzzz 00000000 fred | (empty) (no description set)
132 [EOF]
133 ");
134 let output = work_dir.run_jj(["git", "export"]);
135 insta::assert_snapshot!(output, @"
136 ------- stderr -------
137 Nothing changed.
138 Warning: Failed to export some bookmarks:
139 fred@git: Ref cannot point to the root commit in Git
140 [EOF]
141 ");
142 }
143
144 #[test]
145 fn test_bookmark_bad_name() {
146 let test_env = TestEnvironment::default();
147 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
148 let work_dir = test_env.work_dir("repo");
149
150 let output = work_dir.run_jj(["bookmark", "create", ""]);
151 insta::assert_snapshot!(output, @"
152 ------- stderr -------
153 error: invalid value '' for '<NAMES>...': Failed to parse bookmark name: Syntax error
154
155 For more information, try '--help'.
156 Caused by: --> 1:1
157 |
158 1 |
159 | ^---
160 |
161 = expected <identifier>, <string_literal>, or <raw_string_literal>
162 Hint: See https://docs.jj-vcs.dev/latest/revsets/ or use `jj help -k revsets` for how to quote symbols.
163 [EOF]
164 [exit status: 2]
165 ");
166
167 let output = work_dir.run_jj(["bookmark", "set", "''"]);
168 insta::assert_snapshot!(output, @"
169 ------- stderr -------
170 error: invalid value '''' for '<NAMES>...': Failed to parse bookmark name: Expected non-empty string
171
172 For more information, try '--help'.
173 Caused by: --> 1:1
174 |
175 1 | ''
176 | ^^
177 |
178 = Expected non-empty string
179 Hint: See https://docs.jj-vcs.dev/latest/revsets/ or use `jj help -k revsets` for how to quote symbols.
180 [EOF]
181 [exit status: 2]
182 ");
183
184 let output = work_dir.run_jj(["bookmark", "rename", "x", ""]);
185 insta::assert_snapshot!(output, @"
186 ------- stderr -------
187 error: invalid value '' for '<NEW>': Failed to parse bookmark name: Syntax error
188
189 For more information, try '--help'.
190 Caused by: --> 1:1
191 |
192 1 |
193 | ^---
194 |
195 = expected <identifier>, <string_literal>, or <raw_string_literal>
196 Hint: See https://docs.jj-vcs.dev/latest/revsets/ or use `jj help -k revsets` for how to quote symbols.
197 [EOF]
198 [exit status: 2]
199 ");
200
201 // common errors
202 let output = work_dir.run_jj(["bookmark", "set", "@-", "foo"]);
203 insta::assert_snapshot!(output, @"
204 ------- stderr -------
205 error: invalid value '@-' for '<NAMES>...': Failed to parse bookmark name: Syntax error
206
207 For more information, try '--help'.
208 Caused by: --> 1:1
209 |
210 1 | @-
211 | ^---
212 |
213 = expected <identifier>, <string_literal>, or <raw_string_literal>
214 Hint: See https://docs.jj-vcs.dev/latest/revsets/ or use `jj help -k revsets` for how to quote symbols.
215 [EOF]
216 [exit status: 2]
217 ");
218
219 let stderr = work_dir.run_jj(["bookmark", "set", "-r@-", "foo@bar"]);
220 insta::assert_snapshot!(stderr, @"
221 ------- stderr -------
222 error: invalid value 'foo@bar' for '<NAMES>...': Failed to parse bookmark name: Syntax error
223
224 For more information, try '--help'.
225 Caused by: --> 1:4
226 |
227 1 | foo@bar
228 | ^---
229 |
230 = expected <EOI>
231 Hint: Looks like remote bookmark. Run `jj bookmark track foo@bar` to track it.
232 [EOF]
233 [exit status: 2]
234 ");
235
236 // quoted name works
237 let output = work_dir.run_jj(["bookmark", "create", "'foo@bar'"]);
238 insta::assert_snapshot!(output, @r#"
239 ------- stderr -------
240 Warning: Target revision is empty.
241 Created 1 bookmarks pointing to qpvuntsm e8849ae1 "foo@bar" | (empty) (no description set)
242 [EOF]
243 "#);
244 }
245
246 #[test]
247 fn test_bookmark_move() {
248 let test_env = TestEnvironment::default();
249 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
250 let work_dir = test_env.work_dir("repo");
251
252 // Set up remote
253 let git_repo_path = test_env.env_root().join("git-repo");
254 git::init_bare(git_repo_path);
255 work_dir
256 .run_jj(["git", "remote", "add", "origin", "../git-repo"])
257 .success();
258
259 let output = work_dir.run_jj(["bookmark", "move", "foo"]);
260 insta::assert_snapshot!(output, @"
261 ------- stderr -------
262 Warning: No matching bookmarks for names: foo
263 No bookmarks to update.
264 [EOF]
265 ");
266
267 let output = work_dir.run_jj(["bookmark", "set", "foo"]);
268 insta::assert_snapshot!(output, @"
269 ------- stderr -------
270 Warning: Target revision is empty.
271 Created 1 bookmarks pointing to qpvuntsm e8849ae1 foo | (empty) (no description set)
272 [EOF]
273 ");
274
275 work_dir.run_jj(["new"]).success();
276 let output = work_dir.run_jj(["bookmark", "create", "foo"]);
277 insta::assert_snapshot!(output, @"
278 ------- stderr -------
279 Error: Bookmark already exists: foo
280 Hint: Use `jj bookmark set` to update it.
281 [EOF]
282 [exit status: 1]
283 ");
284
285 let output = work_dir.run_jj(["bookmark", "set", "foo", "--revision", "@"]);
286 insta::assert_snapshot!(output, @"
287 ------- stderr -------
288 Warning: Target revision is empty.
289 Moved 1 bookmarks to mzvwutvl 8afc18ff foo | (empty) (no description set)
290 [EOF]
291 ");
292
293 let output = work_dir.run_jj(["bookmark", "set", "-r@-", "foo"]);
294 insta::assert_snapshot!(output, @"
295 ------- stderr -------
296 Error: Refusing to move bookmark backwards or sideways: foo
297 Hint: Use --allow-backwards to allow it.
298 [EOF]
299 [exit status: 1]
300 ");
301
302 let output = work_dir.run_jj(["bookmark", "set", "-r@-", "--allow-backwards", "foo"]);
303 insta::assert_snapshot!(output, @"
304 ------- stderr -------
305 Warning: Target revision is empty.
306 Moved 1 bookmarks to qpvuntsm e8849ae1 foo | (empty) (no description set)
307 [EOF]
308 ");
309
310 let output = work_dir.run_jj(["bookmark", "move", "foo"]);
311 insta::assert_snapshot!(output, @"
312 ------- stderr -------
313 Warning: Target revision is empty.
314 Moved 1 bookmarks to mzvwutvl 8afc18ff foo | (empty) (no description set)
315 [EOF]
316 ");
317
318 let output = work_dir.run_jj(["bookmark", "move", "--to=@-", "foo"]);
319 insta::assert_snapshot!(output, @"
320 ------- stderr -------
321 Error: Refusing to move bookmark backwards or sideways: foo
322 Hint: Use --allow-backwards to allow it.
323 [EOF]
324 [exit status: 1]
325 ");
326
327 let output = work_dir.run_jj(["bookmark", "move", "--to=@-", "--allow-backwards", "foo"]);
328 insta::assert_snapshot!(output, @"
329 ------- stderr -------
330 Warning: Target revision is empty.
331 Moved 1 bookmarks to qpvuntsm e8849ae1 foo | (empty) (no description set)
332 [EOF]
333 ");
334
335 // Delete bookmark locally, but is still tracking remote
336 work_dir.run_jj(["describe", "@-", "-mcommit"]).success();
337 work_dir.run_jj(["git", "push", "--bookmark=foo"]).success();
338 work_dir.run_jj(["bookmark", "delete", "foo"]).success();
339 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
340 foo (deleted)
341 @origin: qpvuntsm 5f3ceb1e (empty) commit
342 [EOF]
343 ");
344
345 // Deleted tracking bookmark name should still be allocated
346 let output = work_dir.run_jj(["bookmark", "create", "foo"]);
347 insta::assert_snapshot!(output, @"
348 ------- stderr -------
349 Error: Tracked remote bookmarks exist for deleted bookmark: foo
350 Hint: Use `jj bookmark set` to recreate the local bookmark. Run `jj bookmark untrack foo` to disassociate them.
351 [EOF]
352 [exit status: 1]
353 ");
354
355 // Restoring local target shouldn't invalidate tracking state
356 let output = work_dir.run_jj(["bookmark", "set", "foo"]);
357 insta::assert_snapshot!(output, @"
358 ------- stderr -------
359 Warning: Target revision is empty.
360 Moved 1 bookmarks to mzvwutvl 91b59745 foo* | (empty) (no description set)
361 [EOF]
362 ");
363 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
364 foo: mzvwutvl 91b59745 (empty) (no description set)
365 @origin (behind by 1 commits): qpvuntsm 5f3ceb1e (empty) commit
366 [EOF]
367 ");
368
369 // Untracked remote bookmark shouldn't block creation of local bookmark
370 work_dir.run_jj(["bookmark", "untrack", "foo"]).success();
371 work_dir.run_jj(["bookmark", "delete", "foo"]).success();
372 let output = work_dir.run_jj(["bookmark", "create", "foo"]);
373 insta::assert_snapshot!(output, @"
374 ------- stderr -------
375 Warning: Target revision is empty.
376 Created 1 bookmarks pointing to mzvwutvl 91b59745 foo | (empty) (no description set)
377 [EOF]
378 ");
379 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
380 foo: mzvwutvl 91b59745 (empty) (no description set)
381 foo@origin: qpvuntsm 5f3ceb1e (empty) commit
382 [EOF]
383 ");
384 }
385
386 #[test]
387 fn test_bookmark_move_matching() {
388 let test_env = TestEnvironment::default();
389 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
390 let work_dir = test_env.work_dir("repo");
391
392 work_dir
393 .run_jj(["bookmark", "create", "a1", "a2"])
394 .success();
395 work_dir.run_jj(["new", "-mhead1"]).success();
396 work_dir.run_jj(["new", "root()"]).success();
397 work_dir.run_jj(["bookmark", "create", "b1"]).success();
398 work_dir.run_jj(["new"]).success();
399 work_dir.run_jj(["bookmark", "create", "c1"]).success();
400 work_dir.run_jj(["new", "-mhead2"]).success();
401 insta::assert_snapshot!(get_log_output(&work_dir), @"
402 @ 0dd9a4b12283
403 ○ c1 2cbf65662e56
404 ○ b1 c2934cfbfb19
405 │ ○ 9328ecc52471
406 │ ○ a1 a2 e8849ae12c70
407 ├─╯
408 ◆ 000000000000
409 [EOF]
410 ");
411 let setup_opid = work_dir.current_operation_id();
412
413 // The default could be considered "--from=all() *", but is disabled
414 let output = work_dir.run_jj(["bookmark", "move"]);
415 insta::assert_snapshot!(output, @"
416 ------- stderr -------
417 error: the following required arguments were not provided:
418 <NAMES|--from <REVSETS>>
419
420 Usage: jj bookmark move <NAMES|--from <REVSETS>>
421
422 For more information, try '--help'.
423 [EOF]
424 [exit status: 2]
425 ");
426
427 // No bookmarks pointing to the source revisions
428 let output = work_dir.run_jj(["bookmark", "move", "--from=none()"]);
429 insta::assert_snapshot!(output, @"
430 ------- stderr -------
431 No bookmarks to update.
432 [EOF]
433 ");
434
435 // No matching bookmarks within the source revisions
436 let output = work_dir.run_jj(["bookmark", "move", "--from=::@", "'a?'"]);
437 insta::assert_snapshot!(output, @"
438 ------- stderr -------
439 No bookmarks to update.
440 [EOF]
441 ");
442
443 // Noop move
444 let output = work_dir.run_jj(["bookmark", "move", "--to=a1", "a2"]);
445 insta::assert_snapshot!(output, @"
446 ------- stderr -------
447 No bookmarks to update.
448 [EOF]
449 ");
450
451 // Move from multiple revisions
452 let output = work_dir.run_jj(["bookmark", "move", "--from=::@"]);
453 insta::assert_snapshot!(output, @"
454 ------- stderr -------
455 Moved 2 bookmarks to vruxwmqv 0dd9a4b1 b1 c1 | (empty) head2
456 Hint: Specify bookmark by name to update just one of the bookmarks.
457 [EOF]
458 ");
459 insta::assert_snapshot!(get_log_output(&work_dir), @"
460 @ b1 c1 0dd9a4b12283
461 ○ 2cbf65662e56
462 ○ c2934cfbfb19
463 │ ○ 9328ecc52471
464 │ ○ a1 a2 e8849ae12c70
465 ├─╯
466 ◆ 000000000000
467 [EOF]
468 ");
469 work_dir.run_jj(["op", "restore", &setup_opid]).success();
470
471 // Move multiple bookmarks by name
472 let output = work_dir.run_jj(["bookmark", "move", "b1", "c1"]);
473 insta::assert_snapshot!(output, @"
474 ------- stderr -------
475 Moved 2 bookmarks to vruxwmqv 0dd9a4b1 b1 c1 | (empty) head2
476 [EOF]
477 ");
478 insta::assert_snapshot!(get_log_output(&work_dir), @"
479 @ b1 c1 0dd9a4b12283
480 ○ 2cbf65662e56
481 ○ c2934cfbfb19
482 │ ○ 9328ecc52471
483 │ ○ a1 a2 e8849ae12c70
484 ├─╯
485 ◆ 000000000000
486 [EOF]
487 ");
488 work_dir.run_jj(["op", "restore", &setup_opid]).success();
489
490 // Try to move multiple bookmarks, but one of them isn't fast-forward
491 let output = work_dir.run_jj(["bookmark", "move", "'?1'"]);
492 insta::assert_snapshot!(output, @"
493 ------- stderr -------
494 Error: Refusing to move bookmark backwards or sideways: a1
495 Hint: Use --allow-backwards to allow it.
496 [EOF]
497 [exit status: 1]
498 ");
499 insta::assert_snapshot!(get_log_output(&work_dir), @"
500 @ 0dd9a4b12283
501 ○ c1 2cbf65662e56
502 ○ b1 c2934cfbfb19
503 │ ○ 9328ecc52471
504 │ ○ a1 a2 e8849ae12c70
505 ├─╯
506 ◆ 000000000000
507 [EOF]
508 ");
509
510 // Select by revision and name
511 let output = work_dir.run_jj(["bookmark", "move", "--from=::a1+", "--to=a1+", "'?1'"]);
512 insta::assert_snapshot!(output, @"
513 ------- stderr -------
514 Moved 1 bookmarks to kkmpptxz 9328ecc5 a1 | (empty) head1
515 [EOF]
516 ");
517 insta::assert_snapshot!(get_log_output(&work_dir), @"
518 @ 0dd9a4b12283
519 ○ c1 2cbf65662e56
520 ○ b1 c2934cfbfb19
521 │ ○ a1 9328ecc52471
522 │ ○ a2 e8849ae12c70
523 ├─╯
524 ◆ 000000000000
525 [EOF]
526 ");
527 }
528
529 #[test]
530 fn test_bookmark_move_conflicting() {
531 let test_env = TestEnvironment::default();
532 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
533 let work_dir = test_env.work_dir("repo");
534 let get_log = || {
535 let template = r#"separate(" ", description.first_line(), bookmarks)"#;
536 work_dir.run_jj(["log", "-T", template])
537 };
538
539 work_dir.run_jj(["new", "root()", "-mA0"]).success();
540 work_dir.run_jj(["new", "root()", "-mB0"]).success();
541 work_dir.run_jj(["new", "root()", "-mC0"]).success();
542 work_dir.run_jj(["new", "subject(A0)", "-mA1"]).success();
543
544 // Set up conflicting bookmark.
545 work_dir
546 .run_jj(["bookmark", "create", "-rsubject(A0)", "foo"])
547 .success();
548 work_dir
549 .run_jj(["bookmark", "create", "--at-op=@-", "-rsubject(B0)", "foo"])
550 .success();
551 insta::assert_snapshot!(get_log(), @"
552 @ A1
553 ○ A0 foo??
554 │ ○ C0
555 ├─╯
556 │ ○ B0 foo??
557 ├─╯
558 ◆
559 [EOF]
560 ------- stderr -------
561 Concurrent modification detected, resolving automatically.
562 [EOF]
563 ");
564
565 // Can't move the bookmark to C0 since it's sibling.
566 let output = work_dir.run_jj(["bookmark", "set", "-rsubject(C0)", "foo"]);
567 insta::assert_snapshot!(output, @"
568 ------- stderr -------
569 Error: Refusing to move bookmark backwards or sideways: foo
570 Hint: Use --allow-backwards to allow it.
571 [EOF]
572 [exit status: 1]
573 ");
574
575 // Can move the bookmark to A1 since it's descendant of A0. It's not
576 // descendant of B0, though.
577 let output = work_dir.run_jj(["bookmark", "set", "-rsubject(A1)", "foo"]);
578 insta::assert_snapshot!(output, @"
579 ------- stderr -------
580 Moved 1 bookmarks to mzvwutvl 0f5f3e2c foo | (empty) A1
581 [EOF]
582 ");
583 insta::assert_snapshot!(get_log(), @"
584 @ A1 foo
585 ○ A0
586 │ ○ C0
587 ├─╯
588 │ ○ B0
589 ├─╯
590 ◆
591 [EOF]
592 ");
593 }
594
595 #[test]
596 fn test_bookmark_rename() {
597 let test_env = TestEnvironment::default();
598 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
599 let work_dir = test_env.work_dir("repo");
600
601 // Set up remote
602 let git_repo_path = test_env.env_root().join("git-repo");
603 git::init_bare(git_repo_path);
604 work_dir
605 .run_jj(["git", "remote", "add", "origin", "../git-repo"])
606 .success();
607
608 let output = work_dir.run_jj(["bookmark", "rename", "bnoexist", "blocal"]);
609 insta::assert_snapshot!(output, @"
610 ------- stderr -------
611 Error: No such bookmark: bnoexist
612 [EOF]
613 [exit status: 1]
614 ");
615
616 work_dir.run_jj(["describe", "-m=commit-0"]).success();
617 work_dir.run_jj(["bookmark", "create", "blocal"]).success();
618 let output = work_dir.run_jj(["bookmark", "rename", "blocal", "blocal1"]);
619 insta::assert_snapshot!(output, @"");
620
621 work_dir.run_jj(["new"]).success();
622 work_dir.run_jj(["describe", "-m=commit-1"]).success();
623 work_dir.run_jj(["bookmark", "create", "bexist"]).success();
624 let output = work_dir.run_jj(["bookmark", "rename", "blocal1", "bexist"]);
625 insta::assert_snapshot!(output, @"
626 ------- stderr -------
627 Error: Bookmark already exists: bexist
628 [EOF]
629 [exit status: 1]
630 ");
631
632 // Rename to the same name is an error (bookmark already exists)
633 let output = work_dir.run_jj(["bookmark", "rename", "blocal1", "blocal1"]);
634 insta::assert_snapshot!(output, @"
635 ------- stderr -------
636 Error: Bookmark already exists: blocal1
637 [EOF]
638 [exit status: 1]
639 ");
640
641 work_dir.run_jj(["new"]).success();
642 work_dir.run_jj(["describe", "-m=commit-2"]).success();
643 work_dir
644 .run_jj(["bookmark", "create", "bremote", "buntracked"])
645 .success();
646 work_dir
647 .run_jj(["git", "push", "-b=bremote", "-b=buntracked"])
648 .success();
649
650 let output = work_dir.run_jj(["bookmark", "rename", "bremote", "bremote2"]);
651 insta::assert_snapshot!(output, @"
652 ------- stderr -------
653 Warning: Tracked remote bookmarks for bookmark bremote were not renamed.
654 Hint: To rename the bookmark on the remote, you can `jj git push --bookmark bremote` first (to delete it on the remote), and then `jj git push --bookmark bremote2`. `jj git push --all --deleted` would also be sufficient.
655 [EOF]
656 ");
657 let op_id_after_rename = work_dir.current_operation_id();
658 let output = work_dir.run_jj(["bookmark", "rename", "bremote2", "bremote"]);
659 insta::assert_snapshot!(output, @"
660 ------- stderr -------
661 Warning: Tracked remote bookmarks for bookmark bremote exist.
662 Hint: Run `jj bookmark untrack bremote` to disassociate them.
663 [EOF]
664 ");
665 work_dir
666 .run_jj(["op", "restore", &op_id_after_rename])
667 .success();
668 let output = work_dir.run_jj(["git", "push", "--bookmark", "bremote2"]);
669 insta::assert_snapshot!(output, @"
670 ------- stderr -------
671 Changes to push to origin:
672 bookmark: bremote2 [add to 1e76d54fcfce]
673 [EOF]
674 ");
675 work_dir
676 .run_jj(["git", "push", "--named", "bremote-untracked=@"])
677 .success();
678 work_dir
679 .run_jj(["bookmark", "forget", "bremote-untracked"])
680 .success();
681 let output = work_dir.run_jj(["bookmark", "rename", "bremote2", "bremote-untracked"]);
682 insta::assert_snapshot!(output, @"
683 ------- stderr -------
684 Warning: The renamed bookmark already exists on the remote 'origin', tracking state was dropped.
685 Hint: To track the existing remote bookmark, run `jj bookmark track bremote-untracked@origin`.
686 Warning: Tracked remote bookmarks for bookmark bremote2 were not renamed.
687 Hint: To rename the bookmark on the remote, you can `jj git push --bookmark bremote2` first (to delete it on the remote), and then `jj git push --bookmark bremote-untracked`. `jj git push --all --deleted` would also be sufficient.
688 [EOF]
689 ");
690
691 // rename an untracked bookmark
692 work_dir
693 .run_jj(["bookmark", "untrack", "buntracked"])
694 .success();
695 let output = work_dir.run_jj(["bookmark", "rename", "buntracked", "buntracked2"]);
696 insta::assert_snapshot!(output, @"");
697 }
698
699 #[test]
700 fn test_bookmark_rename_overwrite() {
701 let test_env = TestEnvironment::default();
702 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
703 let work_dir = test_env.work_dir("repo");
704
705 // Set up commits
706 work_dir.run_jj(["describe", "-m=DST"]).success();
707 work_dir.run_jj(["bookmark", "create", "DST"]).success();
708 work_dir.run_jj(["new", "root()", "-m=SRC"]).success();
709 work_dir.run_jj(["bookmark", "create", "SRC"]).success();
710
711 // Set up remote
712 let remote_path = test_env.env_root().join("git-repo");
713 git::init_bare(remote_path);
714 work_dir
715 .run_jj(["git", "remote", "add", "origin", "../git-repo"])
716 .success();
717
718 // Construct old bookmark state
719 work_dir
720 .run_jj(["bookmark", "create", "-r=SRC", "a-absent-tracked"])
721 .success();
722 work_dir
723 .run_jj([
724 "git",
725 "push",
726 "--named=a-present-tracked=SRC",
727 "--named=a-present-untracked=SRC",
728 ])
729 .success();
730 work_dir
731 .run_jj(["bookmark", "track", "*-tracked", "--remote=origin"])
732 .success();
733 work_dir
734 .run_jj(["bookmark", "untrack", "*-untracked"])
735 .success();
736 let setup_opid = work_dir.current_operation_id();
737
738 // Overwriting an existing bookmark with itself is a no-op
739 let output = work_dir.run_jj([
740 "bookmark",
741 "rename",
742 "--overwrite-existing",
743 "a-present-tracked",
744 "a-present-tracked",
745 ]);
746 insta::assert_snapshot!(output, @"");
747
748 // Overwrite absent, tracked bookmarks
749 work_dir
750 .run_jj([
751 "bookmark",
752 "create",
753 "-r=SRC",
754 "b-absent-tracked",
755 "c-absent-tracked",
756 "d-absent-tracked",
757 ])
758 .success();
759 work_dir
760 .run_jj(["bookmark", "track", "*-tracked", "--remote=origin"])
761 .success();
762 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
763 DST: qpvuntsm b3bfa1df (empty) DST
764 SRC: zsuskuln 1acdc981 (empty) SRC
765 a-absent-tracked: zsuskuln 1acdc981 (empty) SRC
766 @origin (not created yet)
767 a-present-tracked: zsuskuln 1acdc981 (empty) SRC
768 @origin: zsuskuln 1acdc981 (empty) SRC
769 a-present-untracked: zsuskuln 1acdc981 (empty) SRC
770 a-present-untracked@origin: zsuskuln 1acdc981 (empty) SRC
771 b-absent-tracked: zsuskuln 1acdc981 (empty) SRC
772 @origin (not created yet)
773 c-absent-tracked: zsuskuln 1acdc981 (empty) SRC
774 @origin (not created yet)
775 d-absent-tracked: zsuskuln 1acdc981 (empty) SRC
776 @origin (not created yet)
777 [EOF]
778 ");
779 let output = work_dir.run_jj([
780 "bookmark",
781 "rename",
782 "--overwrite-existing",
783 "a-absent-tracked",
784 "b-absent-tracked",
785 ]);
786 insta::assert_snapshot!(output, @"");
787 let output = work_dir.run_jj([
788 "bookmark",
789 "rename",
790 "--overwrite-existing",
791 "a-present-tracked",
792 "c-absent-tracked",
793 ]);
794 insta::assert_snapshot!(output, @"
795 ------- stderr -------
796 Warning: Tracked remote bookmarks for bookmark a-present-tracked were not renamed.
797 Hint: To rename the bookmark on the remote, you can `jj git push --bookmark a-present-tracked` first (to delete it on the remote), and then `jj git push --bookmark c-absent-tracked`. `jj git push --all --deleted` would also be sufficient.
798 [EOF]
799 ");
800 let output = work_dir.run_jj([
801 "bookmark",
802 "rename",
803 "--overwrite-existing",
804 "a-present-untracked",
805 "d-absent-tracked",
806 ]);
807 insta::assert_snapshot!(output, @"");
808 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
809 DST: qpvuntsm b3bfa1df (empty) DST
810 SRC: zsuskuln 1acdc981 (empty) SRC
811 a-present-tracked (deleted)
812 @origin: zsuskuln 1acdc981 (empty) SRC
813 a-present-untracked@origin: zsuskuln 1acdc981 (empty) SRC
814 b-absent-tracked: zsuskuln 1acdc981 (empty) SRC
815 @origin (not created yet)
816 c-absent-tracked: zsuskuln 1acdc981 (empty) SRC
817 @origin (not created yet)
818 d-absent-tracked: zsuskuln 1acdc981 (empty) SRC
819 [EOF]
820 ");
821 work_dir.run_jj(["op", "restore", &setup_opid]).success();
822
823 // Overwrite absent, untracked (non-existent) bookmarks
824 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
825 DST: qpvuntsm b3bfa1df (empty) DST
826 SRC: zsuskuln 1acdc981 (empty) SRC
827 a-absent-tracked: zsuskuln 1acdc981 (empty) SRC
828 @origin (not created yet)
829 a-present-tracked: zsuskuln 1acdc981 (empty) SRC
830 @origin: zsuskuln 1acdc981 (empty) SRC
831 a-present-untracked: zsuskuln 1acdc981 (empty) SRC
832 a-present-untracked@origin: zsuskuln 1acdc981 (empty) SRC
833 [EOF]
834 ");
835 let output = work_dir.run_jj([
836 "bookmark",
837 "rename",
838 "--overwrite-existing",
839 "a-absent-tracked",
840 "b-absent-untracked",
841 ]);
842 insta::assert_snapshot!(output, @"");
843 let output = work_dir.run_jj([
844 "bookmark",
845 "rename",
846 "--overwrite-existing",
847 "a-present-tracked",
848 "c-absent-untracked",
849 ]);
850 insta::assert_snapshot!(output, @"
851 ------- stderr -------
852 Warning: Tracked remote bookmarks for bookmark a-present-tracked were not renamed.
853 Hint: To rename the bookmark on the remote, you can `jj git push --bookmark a-present-tracked` first (to delete it on the remote), and then `jj git push --bookmark c-absent-untracked`. `jj git push --all --deleted` would also be sufficient.
854 [EOF]
855 ");
856 let output = work_dir.run_jj([
857 "bookmark",
858 "rename",
859 "--overwrite-existing",
860 "a-present-untracked",
861 "d-absent-untracked",
862 ]);
863 insta::assert_snapshot!(output, @"");
864 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
865 DST: qpvuntsm b3bfa1df (empty) DST
866 SRC: zsuskuln 1acdc981 (empty) SRC
867 a-present-tracked (deleted)
868 @origin: zsuskuln 1acdc981 (empty) SRC
869 a-present-untracked@origin: zsuskuln 1acdc981 (empty) SRC
870 b-absent-untracked: zsuskuln 1acdc981 (empty) SRC
871 @origin (not created yet)
872 c-absent-untracked: zsuskuln 1acdc981 (empty) SRC
873 @origin (not created yet)
874 d-absent-untracked: zsuskuln 1acdc981 (empty) SRC
875 [EOF]
876 ");
877 work_dir.run_jj(["op", "restore", &setup_opid]).success();
878
879 // Overwrite present, tracked bookmarks
880 work_dir
881 .run_jj([
882 "git",
883 "push",
884 "--named=b-present-tracked=DST",
885 "--named=c-present-tracked=DST",
886 "--named=d-present-tracked=DST",
887 ])
888 .success();
889 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
890 DST: qpvuntsm b3bfa1df (empty) DST
891 SRC: zsuskuln 1acdc981 (empty) SRC
892 a-absent-tracked: zsuskuln 1acdc981 (empty) SRC
893 @origin (not created yet)
894 a-present-tracked: zsuskuln 1acdc981 (empty) SRC
895 @origin: zsuskuln 1acdc981 (empty) SRC
896 a-present-untracked: zsuskuln 1acdc981 (empty) SRC
897 a-present-untracked@origin: zsuskuln 1acdc981 (empty) SRC
898 b-present-tracked: qpvuntsm b3bfa1df (empty) DST
899 @origin: qpvuntsm b3bfa1df (empty) DST
900 c-present-tracked: qpvuntsm b3bfa1df (empty) DST
901 @origin: qpvuntsm b3bfa1df (empty) DST
902 d-present-tracked: qpvuntsm b3bfa1df (empty) DST
903 @origin: qpvuntsm b3bfa1df (empty) DST
904 [EOF]
905 ");
906 let output = work_dir.run_jj([
907 "bookmark",
908 "rename",
909 "--overwrite-existing",
910 "a-absent-tracked",
911 "b-present-tracked",
912 ]);
913 insta::assert_snapshot!(output, @"
914 ------- stderr -------
915 Warning: The renamed bookmark already exists on the remote 'origin', tracking state was dropped.
916 Hint: To track the existing remote bookmark, run `jj bookmark track b-present-tracked@origin`.
917 [EOF]
918 ");
919 let output = work_dir.run_jj([
920 "bookmark",
921 "rename",
922 "--overwrite-existing",
923 "a-present-tracked",
924 "c-present-tracked",
925 ]);
926 insta::assert_snapshot!(output, @"
927 ------- stderr -------
928 Warning: The renamed bookmark already exists on the remote 'origin', tracking state was dropped.
929 Hint: To track the existing remote bookmark, run `jj bookmark track c-present-tracked@origin`.
930 Warning: Tracked remote bookmarks for bookmark a-present-tracked were not renamed.
931 Hint: To rename the bookmark on the remote, you can `jj git push --bookmark a-present-tracked` first (to delete it on the remote), and then `jj git push --bookmark c-present-tracked`. `jj git push --all --deleted` would also be sufficient.
932 [EOF]
933 ");
934 let output = work_dir.run_jj([
935 "bookmark",
936 "rename",
937 "--overwrite-existing",
938 "a-present-untracked",
939 "d-present-tracked",
940 ]);
941 insta::assert_snapshot!(output, @"
942 ------- stderr -------
943 Warning: Tracking of remote bookmark d-present-tracked@origin was dropped.
944 Hint: Use `jj bookmark track` to re-track if needed.
945 [EOF]
946 ");
947 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
948 DST: qpvuntsm b3bfa1df (empty) DST
949 SRC: zsuskuln 1acdc981 (empty) SRC
950 a-present-tracked (deleted)
951 @origin: zsuskuln 1acdc981 (empty) SRC
952 a-present-untracked@origin: zsuskuln 1acdc981 (empty) SRC
953 b-present-tracked: zsuskuln 1acdc981 (empty) SRC
954 b-present-tracked@origin: qpvuntsm b3bfa1df (empty) DST
955 c-present-tracked: zsuskuln 1acdc981 (empty) SRC
956 c-present-tracked@origin: qpvuntsm b3bfa1df (empty) DST
957 d-present-tracked: zsuskuln 1acdc981 (empty) SRC
958 d-present-tracked@origin: qpvuntsm b3bfa1df (empty) DST
959 [EOF]
960 ");
961 work_dir.run_jj(["op", "restore", &setup_opid]).success();
962
963 // Overwrite present, untracked bookmarks
964 work_dir
965 .run_jj([
966 "git",
967 "push",
968 "--named=b-present-untracked=DST",
969 "--named=c-present-untracked=DST",
970 "--named=d-present-untracked=DST",
971 ])
972 .success();
973 work_dir
974 .run_jj(["bookmark", "untrack", "*-untracked"])
975 .success();
976 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
977 DST: qpvuntsm b3bfa1df (empty) DST
978 SRC: zsuskuln 1acdc981 (empty) SRC
979 a-absent-tracked: zsuskuln 1acdc981 (empty) SRC
980 @origin (not created yet)
981 a-present-tracked: zsuskuln 1acdc981 (empty) SRC
982 @origin: zsuskuln 1acdc981 (empty) SRC
983 a-present-untracked: zsuskuln 1acdc981 (empty) SRC
984 a-present-untracked@origin: zsuskuln 1acdc981 (empty) SRC
985 b-present-untracked: qpvuntsm b3bfa1df (empty) DST
986 b-present-untracked@origin: qpvuntsm b3bfa1df (empty) DST
987 c-present-untracked: qpvuntsm b3bfa1df (empty) DST
988 c-present-untracked@origin: qpvuntsm b3bfa1df (empty) DST
989 d-present-untracked: qpvuntsm b3bfa1df (empty) DST
990 d-present-untracked@origin: qpvuntsm b3bfa1df (empty) DST
991 [EOF]
992 ");
993 let output = work_dir.run_jj([
994 "bookmark",
995 "rename",
996 "--overwrite-existing",
997 "a-absent-tracked",
998 "b-present-untracked",
999 ]);
1000 insta::assert_snapshot!(output, @"
1001 ------- stderr -------
1002 Warning: The renamed bookmark already exists on the remote 'origin', tracking state was dropped.
1003 Hint: To track the existing remote bookmark, run `jj bookmark track b-present-untracked@origin`.
1004 [EOF]
1005 ");
1006 let output = work_dir.run_jj([
1007 "bookmark",
1008 "rename",
1009 "--overwrite-existing",
1010 "a-present-tracked",
1011 "c-present-untracked",
1012 ]);
1013 insta::assert_snapshot!(output, @"
1014 ------- stderr -------
1015 Warning: The renamed bookmark already exists on the remote 'origin', tracking state was dropped.
1016 Hint: To track the existing remote bookmark, run `jj bookmark track c-present-untracked@origin`.
1017 Warning: Tracked remote bookmarks for bookmark a-present-tracked were not renamed.
1018 Hint: To rename the bookmark on the remote, you can `jj git push --bookmark a-present-tracked` first (to delete it on the remote), and then `jj git push --bookmark c-present-untracked`. `jj git push --all --deleted` would also be sufficient.
1019 [EOF]
1020 ");
1021 let output = work_dir.run_jj([
1022 "bookmark",
1023 "rename",
1024 "--overwrite-existing",
1025 "a-present-untracked",
1026 "d-present-untracked",
1027 ]);
1028 insta::assert_snapshot!(output, @"");
1029 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
1030 DST: qpvuntsm b3bfa1df (empty) DST
1031 SRC: zsuskuln 1acdc981 (empty) SRC
1032 a-present-tracked (deleted)
1033 @origin: zsuskuln 1acdc981 (empty) SRC
1034 a-present-untracked@origin: zsuskuln 1acdc981 (empty) SRC
1035 b-present-untracked: zsuskuln 1acdc981 (empty) SRC
1036 b-present-untracked@origin: qpvuntsm b3bfa1df (empty) DST
1037 c-present-untracked: zsuskuln 1acdc981 (empty) SRC
1038 c-present-untracked@origin: qpvuntsm b3bfa1df (empty) DST
1039 d-present-untracked: zsuskuln 1acdc981 (empty) SRC
1040 d-present-untracked@origin: qpvuntsm b3bfa1df (empty) DST
1041 [EOF]
1042 ");
1043 }
1044
1045 #[test]
1046 fn test_bookmark_rename_colocated() {
1047 let test_env = TestEnvironment::default();
1048 test_env
1049 .run_jj_in(".", ["git", "init", "repo", "--colocate"])
1050 .success();
1051 let work_dir = test_env.work_dir("repo");
1052
1053 work_dir.run_jj(["describe", "-m=commit-0"]).success();
1054 work_dir.run_jj(["bookmark", "create", "blocal"]).success();
1055
1056 // Make sure that git tracking bookmarks don't cause a warning
1057 let output = work_dir.run_jj(["bookmark", "rename", "blocal", "blocal1"]);
1058 insta::assert_snapshot!(output, @"");
1059
1060 // overwrite-existing in a colocated repo with a real remote:
1061 // @git is filtered out by remote_matcher, but @origin should be handled.
1062 let git_repo_path = test_env.env_root().join("git-repo");
1063 git::init_bare(git_repo_path);
1064 work_dir
1065 .run_jj(["git", "remote", "add", "origin", "../git-repo"])
1066 .success();
1067
1068 work_dir.run_jj(["new"]).success();
1069 work_dir.run_jj(["describe", "-m=commit-1"]).success();
1070 work_dir.run_jj(["bookmark", "create", "bpushed"]).success();
1071 work_dir.run_jj(["git", "push", "-b=bpushed"]).success();
1072 // blocal1 is local-only (no tracked @origin). Overwriting bpushed should
1073 // warn about bpushed@origin tracking being dropped, while @git stays quiet.
1074 let output = work_dir.run_jj([
1075 "bookmark",
1076 "rename",
1077 "--overwrite-existing",
1078 "blocal1",
1079 "bpushed",
1080 ]);
1081 insta::assert_snapshot!(output, @"
1082 ------- stderr -------
1083 Warning: Tracking of remote bookmark bpushed@origin was dropped.
1084 Hint: Use `jj bookmark track` to re-track if needed.
1085 Warning: The working-copy commit became immutable; a new commit has been created on top of it.
1086 Working copy (@) now at: znkkpsqq cf8db4ba (empty) (no description set)
1087 Parent commit (@-) : royxmykx b6e46c10 bpushed@origin | (empty) commit-1
1088 [EOF]
1089 ");
1090 let output = work_dir.run_jj(["bookmark", "list", "--all", "bpushed"]);
1091 insta::assert_snapshot!(output, @"
1092 bpushed: qpvuntsm f18f73f2 (empty) commit-0
1093 @git: qpvuntsm f18f73f2 (empty) commit-0
1094 bpushed@origin: royxmykx b6e46c10 (empty) commit-1
1095 [EOF]
1096 ");
1097 }
1098
1099 #[test]
1100 fn test_bookmark_forget_glob() {
1101 let test_env = TestEnvironment::default();
1102 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
1103 let work_dir = test_env.work_dir("repo");
1104
1105 work_dir.run_jj(["bookmark", "create", "foo-1"]).success();
1106 work_dir.run_jj(["bookmark", "create", "bar-2"]).success();
1107 work_dir.run_jj(["bookmark", "create", "foo-3"]).success();
1108 work_dir.run_jj(["bookmark", "create", "foo-4"]).success();
1109 let setup_opid = work_dir.current_operation_id();
1110
1111 insta::assert_snapshot!(get_log_output(&work_dir), @"
1112 @ bar-2 foo-1 foo-3 foo-4 e8849ae12c70
1113 ◆ 000000000000
1114 [EOF]
1115 ");
1116 let output = work_dir.run_jj(["bookmark", "forget", "'foo-[1-3]'"]);
1117 insta::assert_snapshot!(output, @"
1118 ------- stderr -------
1119 Forgot 2 local bookmarks.
1120 [EOF]
1121 ");
1122 work_dir.run_jj(["op", "restore", &setup_opid]).success();
1123 let output = work_dir.run_jj(["bookmark", "forget", "'foo-[1-3]'"]);
1124 insta::assert_snapshot!(output, @"
1125 ------- stderr -------
1126 Forgot 2 local bookmarks.
1127 [EOF]
1128 ");
1129 insta::assert_snapshot!(get_log_output(&work_dir), @"
1130 @ bar-2 foo-4 e8849ae12c70
1131 ◆ 000000000000
1132 [EOF]
1133 ");
1134
1135 // Forgetting a bookmark via both explicit name and glob pattern, or with
1136 // multiple glob patterns, shouldn't produce an error.
1137 let output = work_dir.run_jj(["bookmark", "forget", "foo-4", "foo-*", "foo-*"]);
1138 insta::assert_snapshot!(output, @"
1139 ------- stderr -------
1140 Forgot 1 local bookmarks.
1141 [EOF]
1142 ");
1143 insta::assert_snapshot!(get_log_output(&work_dir), @"
1144 @ bar-2 e8849ae12c70
1145 ◆ 000000000000
1146 [EOF]
1147 ");
1148
1149 // Malformed glob
1150 let output = work_dir.run_jj(["bookmark", "forget", "glob:'foo-[1-3'"]);
1151 insta::assert_snapshot!(output, @"
1152 ------- stderr -------
1153 Error: Failed to parse name pattern: Invalid string pattern
1154 Caused by:
1155 1: --> 1:1
1156 |
1157 1 | glob:'foo-[1-3'
1158 | ^-------------^
1159 |
1160 = Invalid string pattern
1161 2: error parsing glob 'foo-[1-3': unclosed character class; missing ']'
1162 [EOF]
1163 [exit status: 1]
1164 ");
1165
1166 // None of the globs match anything
1167 let output = work_dir.run_jj(["bookmark", "forget", "baz*", "boom*"]);
1168 insta::assert_snapshot!(output, @"
1169 ------- stderr -------
1170 No bookmarks to forget.
1171 [EOF]
1172 ");
1173 }
1174
1175 #[test]
1176 fn test_bookmark_delete_glob() -> TestResult {
1177 // Set up a git repo with a bookmark and a jj repo that has it as a remote.
1178 let test_env = TestEnvironment::default();
1179 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
1180 let work_dir = test_env.work_dir("repo");
1181 let git_repo_path = test_env.env_root().join("git-repo");
1182 let git_repo = git::init_bare(git_repo_path);
1183 let blob_oid = git_repo.write_blob(b"content")?;
1184 let mut tree_editor =
1185 git_repo.edit_tree(gix::ObjectId::empty_tree(gix::hash::Kind::default()))?;
1186 tree_editor.upsert("file", gix::object::tree::EntryKind::Blob, blob_oid)?;
1187 let _tree_id = tree_editor.write()?;
1188 work_dir
1189 .run_jj(["git", "remote", "add", "origin", "../git-repo"])
1190 .success();
1191
1192 work_dir.run_jj(["describe", "-m=commit"]).success();
1193 work_dir.run_jj(["bookmark", "create", "foo-1"]).success();
1194 work_dir.run_jj(["bookmark", "create", "bar-2"]).success();
1195 work_dir.run_jj(["bookmark", "create", "foo-3"]).success();
1196 work_dir.run_jj(["bookmark", "create", "foo-4"]).success();
1197 // Push to create remote-tracking bookmarks
1198 work_dir.run_jj(["git", "push", "--all"]).success();
1199 // Add absent-tracked bookmark
1200 work_dir.run_jj(["bookmark", "create", "foo-5"]).success();
1201 work_dir.run_jj(["bookmark", "track", "foo-5"]).success();
1202 let setup_opid = work_dir.current_operation_id();
1203
1204 insta::assert_snapshot!(get_log_output(&work_dir), @"
1205 @ bar-2 foo-1 foo-3 foo-4 foo-5* 8e056f6b8c37
1206 ◆ 000000000000
1207 [EOF]
1208 ");
1209 let output = work_dir.run_jj(["bookmark", "delete", "'foo-[1-3]'"]);
1210 insta::assert_snapshot!(output, @"
1211 ------- stderr -------
1212 Deleted 2 bookmarks.
1213 [EOF]
1214 ");
1215 work_dir.run_jj(["op", "restore", &setup_opid]).success();
1216 let output = work_dir.run_jj(["bookmark", "delete", "'foo-[1-3]'"]);
1217 insta::assert_snapshot!(output, @"
1218 ------- stderr -------
1219 Deleted 2 bookmarks.
1220 [EOF]
1221 ");
1222 insta::assert_snapshot!(get_log_output(&work_dir), @"
1223 @ bar-2 foo-1@origin foo-3@origin foo-4 foo-5* 8e056f6b8c37
1224 ◆ 000000000000
1225 [EOF]
1226 ");
1227
1228 // We get an error if none of the globs match live bookmarks. Unlike `jj
1229 // bookmark forget`, it's not allowed to delete already deleted bookmarks.
1230 let output = work_dir.run_jj(["bookmark", "delete", "'foo-[1-3]'"]);
1231 insta::assert_snapshot!(output, @"
1232 ------- stderr -------
1233 No bookmarks to delete.
1234 [EOF]
1235 ");
1236
1237 // Deleting a bookmark via both explicit name and glob pattern, or with
1238 // multiple glob patterns, shouldn't produce an error.
1239 let output = work_dir.run_jj(["bookmark", "delete", "foo-4", "foo-*", "foo-*"]);
1240 insta::assert_snapshot!(output, @"
1241 ------- stderr -------
1242 Deleted 2 bookmarks.
1243 [EOF]
1244 ");
1245 insta::assert_snapshot!(get_log_output(&work_dir), @"
1246 @ bar-2 foo-1@origin foo-3@origin foo-4@origin 8e056f6b8c37
1247 ◆ 000000000000
1248 [EOF]
1249 ");
1250
1251 // The deleted bookmarks are still there, whereas absent-tracked bookmarks
1252 // aren't.
1253 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
1254 bar-2: qpvuntsm 8e056f6b (empty) commit
1255 @origin: qpvuntsm 8e056f6b (empty) commit
1256 foo-1 (deleted)
1257 @origin: qpvuntsm 8e056f6b (empty) commit
1258 foo-3 (deleted)
1259 @origin: qpvuntsm 8e056f6b (empty) commit
1260 foo-4 (deleted)
1261 @origin: qpvuntsm 8e056f6b (empty) commit
1262 [EOF]
1263 ");
1264
1265 // Malformed glob
1266 let output = work_dir.run_jj(["bookmark", "delete", "glob:'foo-[1-3'"]);
1267 insta::assert_snapshot!(output, @"
1268 ------- stderr -------
1269 Error: Failed to parse name pattern: Invalid string pattern
1270 Caused by:
1271 1: --> 1:1
1272 |
1273 1 | glob:'foo-[1-3'
1274 | ^-------------^
1275 |
1276 = Invalid string pattern
1277 2: error parsing glob 'foo-[1-3': unclosed character class; missing ']'
1278 [EOF]
1279 [exit status: 1]
1280 ");
1281
1282 // Unknown pattern kind
1283 let output = work_dir.run_jj(["bookmark", "forget", "whatever:bookmark"]);
1284 insta::assert_snapshot!(output, @"
1285 ------- stderr -------
1286 Error: Failed to parse name pattern: Invalid string pattern
1287 Caused by:
1288 1: --> 1:1
1289 |
1290 1 | whatever:bookmark
1291 | ^---------------^
1292 |
1293 = Invalid string pattern
1294 2: Invalid string pattern kind `whatever:`
1295 Hint: Try prefixing with one of `exact:`, `glob:`, `regex:`, `substring:`, or one of these with `-i` suffix added (e.g. `glob-i:`) for case-insensitive matching
1296 [EOF]
1297 [exit status: 1]
1298 ");
1299 Ok(())
1300 }
1301
1302 #[test]
1303 fn test_bookmark_delete_export() {
1304 let test_env = TestEnvironment::default();
1305 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
1306 let work_dir = test_env.work_dir("repo");
1307
1308 work_dir.run_jj(["new"]).success();
1309 work_dir.run_jj(["bookmark", "create", "foo"]).success();
1310 work_dir.run_jj(["git", "export"]).success();
1311
1312 work_dir.run_jj(["bookmark", "delete", "foo"]).success();
1313 let output = work_dir.run_jj(["bookmark", "list", "--all-remotes"]);
1314 insta::assert_snapshot!(output, @"
1315 foo (deleted)
1316 @git: rlvkpnrz 43444d88 (empty) (no description set)
1317 [EOF]
1318 ------- stderr -------
1319 Hint: Bookmarks marked as deleted will be deleted from the underlying Git repo on the next `jj git export`.
1320 [EOF]
1321 ");
1322
1323 work_dir.run_jj(["git", "export"]).success();
1324 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"");
1325 }
1326
1327 #[test]
1328 fn test_bookmark_forget_export() {
1329 let test_env = TestEnvironment::default();
1330 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
1331 let work_dir = test_env.work_dir("repo");
1332
1333 work_dir.run_jj(["new"]).success();
1334 work_dir.run_jj(["bookmark", "create", "foo"]).success();
1335 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
1336 foo: rlvkpnrz 43444d88 (empty) (no description set)
1337 [EOF]
1338 ");
1339
1340 // Exporting the bookmark to git creates a local-git tracking bookmark
1341 let output = work_dir.run_jj(["git", "export"]);
1342 insta::assert_snapshot!(output, @"");
1343 let output = work_dir.run_jj(["bookmark", "forget", "--include-remotes", "foo"]);
1344 insta::assert_snapshot!(output, @"
1345 ------- stderr -------
1346 Forgot 1 local bookmarks.
1347 Forgot 1 remote bookmarks.
1348 [EOF]
1349 ");
1350 // Forgetting a bookmark with --include-remotes deletes local and
1351 // remote-tracking bookmarks including the corresponding git-tracking bookmark.
1352 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"");
1353 let output = work_dir.run_jj(["log", "-r=foo", "--no-graph"]);
1354 insta::assert_snapshot!(output, @"
1355 ------- stderr -------
1356 Error: Revision `foo` doesn't exist
1357 [EOF]
1358 [exit status: 1]
1359 ");
1360
1361 // `jj git export` will delete the bookmark from git. In a colocated
1362 // workspace, this will happen automatically immediately after a `jj bookmark
1363 // forget`. This is demonstrated in `test_git_colocated_bookmark_forget` in
1364 // test_git_colocated.rs
1365 let output = work_dir.run_jj(["git", "export"]);
1366 insta::assert_snapshot!(output, @"");
1367 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"");
1368 }
1369
1370 #[test]
1371 fn test_bookmark_forget_fetched_bookmark() {
1372 // Much of this test is borrowed from `test_git_fetch_remote_only_bookmark` in
1373 // test_git_fetch.rs
1374
1375 // Set up a git repo with a bookmark and a jj repo that has it as a remote.
1376 let test_env = TestEnvironment::default();
1377 test_env.add_config("remotes.origin.auto-track-bookmarks = '*'");
1378 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
1379 let work_dir = test_env.work_dir("repo");
1380 let git_repo_path = test_env.env_root().join("git-repo");
1381 let git_repo = git::init_bare(git_repo_path);
1382 work_dir
1383 .run_jj(["git", "remote", "add", "origin", "../git-repo"])
1384 .success();
1385 // Create a commit and a bookmark in the git repo
1386 let git::CommitResult {
1387 tree_id,
1388 commit_id: first_git_repo_commit,
1389 } = git::add_commit(
1390 &git_repo,
1391 "refs/heads/feature1",
1392 "file",
1393 b"content",
1394 "message",
1395 &[],
1396 );
1397
1398 // Fetch normally
1399 work_dir
1400 .run_jj(["git", "fetch", "--remote=origin"])
1401 .success();
1402 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
1403 feature1: qomsplrm ebeb70d8 message
1404 @origin: qomsplrm ebeb70d8 message
1405 [EOF]
1406 ");
1407
1408 // TEST 1: with export-import
1409 // Forget the bookmark with --include-remotes
1410 work_dir
1411 .run_jj(["bookmark", "forget", "--include-remotes", "feature1"])
1412 .success();
1413 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"");
1414
1415 // At this point `jj git export && jj git import` does *not* recreate the
1416 // bookmark. This behavior is important in colocated workspaces, as otherwise a
1417 // forgotten bookmark would be immediately resurrected.
1418 //
1419 // Technically, this is because `jj bookmark forget` preserved
1420 // the ref in jj view's `git_refs` tracking the local git repo's remote-tracking
1421 // bookmark.
1422 // TODO: Show that jj git push is also a no-op
1423 let output = work_dir.run_jj(["git", "export"]);
1424 insta::assert_snapshot!(output, @"");
1425 let output = work_dir.run_jj(["git", "import"]);
1426 insta::assert_snapshot!(output, @"
1427 ------- stderr -------
1428 Nothing changed.
1429 [EOF]
1430 ");
1431 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"");
1432
1433 // We can fetch feature1 again.
1434 let output = work_dir.run_jj(["git", "fetch", "--remote=origin"]);
1435 insta::assert_snapshot!(output, @"
1436 ------- stderr -------
1437 bookmark: feature1@origin [new] tracked
1438 [EOF]
1439 ");
1440 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
1441 feature1: qomsplrm ebeb70d8 message
1442 @origin: qomsplrm ebeb70d8 message
1443 [EOF]
1444 ");
1445
1446 // TEST 2: No export/import (otherwise the same as test 1)
1447 work_dir
1448 .run_jj(["bookmark", "forget", "--include-remotes", "feature1"])
1449 .success();
1450 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"");
1451 // Fetch works even without the export-import
1452 let output = work_dir.run_jj(["git", "fetch", "--remote=origin"]);
1453 insta::assert_snapshot!(output, @"
1454 ------- stderr -------
1455 bookmark: feature1@origin [new] tracked
1456 [EOF]
1457 ");
1458 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
1459 feature1: qomsplrm ebeb70d8 message
1460 @origin: qomsplrm ebeb70d8 message
1461 [EOF]
1462 ");
1463
1464 // TEST 3: fetch bookmark that was moved & forgotten with --include-remotes
1465
1466 // Move the bookmark in the git repo.
1467 git::write_commit(
1468 &git_repo,
1469 "refs/heads/feature1",
1470 tree_id,
1471 "another message",
1472 &[first_git_repo_commit],
1473 );
1474 let output = work_dir.run_jj(["bookmark", "forget", "--include-remotes", "feature1"]);
1475 insta::assert_snapshot!(output, @"
1476 ------- stderr -------
1477 Forgot 1 local bookmarks.
1478 Forgot 1 remote bookmarks.
1479 [EOF]
1480 ");
1481
1482 // Fetching a moved bookmark does not create a conflict
1483 let output = work_dir.run_jj(["git", "fetch", "--remote=origin"]);
1484 insta::assert_snapshot!(output, @"
1485 ------- stderr -------
1486 bookmark: feature1@origin [new] tracked
1487 [EOF]
1488 ");
1489 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
1490 feature1: tyvxnvqr 9175cb32 (empty) another message
1491 @origin: tyvxnvqr 9175cb32 (empty) another message
1492 [EOF]
1493 ");
1494
1495 // TEST 4: If `--include-remotes` isn't used, remote bookmarks are untracked
1496 work_dir
1497 .run_jj(["bookmark", "forget", "feature1"])
1498 .success();
1499 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
1500 feature1@origin: tyvxnvqr 9175cb32 (empty) another message
1501 [EOF]
1502 ");
1503 // There should be no output here since the remote bookmark wasn't forgotten
1504 let output = work_dir.run_jj(["git", "fetch", "--remote=origin"]);
1505 insta::assert_snapshot!(output, @"
1506 ------- stderr -------
1507 Nothing changed.
1508 [EOF]
1509 ");
1510 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
1511 feature1@origin: tyvxnvqr 9175cb32 (empty) another message
1512 [EOF]
1513 ");
1514 }
1515
1516 #[test]
1517 fn test_bookmark_forget_deleted_or_nonexistent_bookmark() {
1518 // Much of this test is borrowed from `test_git_fetch_remote_only_bookmark` in
1519 // test_git_fetch.rs
1520
1521 // ======== Beginning of test setup ========
1522 // Set up a git repo with a bookmark and a jj repo that has it as a remote.
1523 let test_env = TestEnvironment::default();
1524 test_env.add_config("remotes.origin.auto-track-bookmarks = '*'");
1525 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
1526 let work_dir = test_env.work_dir("repo");
1527 let git_repo_path = test_env.env_root().join("git-repo");
1528 let git_repo = git::init_bare(git_repo_path);
1529 // Create a commit and a bookmark in the git repo
1530 git::add_commit(
1531 &git_repo,
1532 "refs/heads/feature1",
1533 "file",
1534 b"content",
1535 "message",
1536 &[],
1537 );
1538 work_dir
1539 .run_jj(["git", "remote", "add", "origin", "../git-repo"])
1540 .success();
1541
1542 // Fetch and then delete the bookmark
1543 work_dir
1544 .run_jj(["git", "fetch", "--remote=origin"])
1545 .success();
1546 work_dir
1547 .run_jj(["bookmark", "delete", "feature1"])
1548 .success();
1549 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
1550 feature1 (deleted)
1551 @origin: qomsplrm ebeb70d8 message
1552 [EOF]
1553 ");
1554
1555 // ============ End of test setup ============
1556
1557 // We can forget a deleted bookmark. The local bookmark was already absent,
1558 // so only the remote count is reported.
1559 let output = work_dir.run_jj(["bookmark", "forget", "--include-remotes", "feature1"]);
1560 insta::assert_snapshot!(output, @"
1561 ------- stderr -------
1562 Forgot 1 remote bookmarks.
1563 [EOF]
1564 ");
1565 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"");
1566
1567 // Can't forget a non-existent bookmark
1568 let output = work_dir.run_jj(["bookmark", "forget", "i_do_not_exist"]);
1569 insta::assert_snapshot!(output, @"
1570 ------- stderr -------
1571 Warning: No matching bookmarks for names: i_do_not_exist
1572 No bookmarks to forget.
1573 [EOF]
1574 ");
1575 }
1576
1577 #[test]
1578 fn test_bookmark_forget_untracked_remote_only_bookmark() {
1579 // Regression test for https://github.com/jj-vcs/jj/issues/9181:
1580 // `jj bookmark forget` on a remote-only, untracked bookmark used to print
1581 // a contradictory "Forgot 1 local bookmarks." line followed by "Nothing
1582 // changed." Now neither line is printed since nothing was forgotten.
1583 let test_env = TestEnvironment::default();
1584 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
1585 let work_dir = test_env.work_dir("repo");
1586 let git_repo_path = test_env.env_root().join("git-repo");
1587 let git_repo = git::init_bare(git_repo_path);
1588 git::add_commit(
1589 &git_repo,
1590 "refs/heads/feature1",
1591 "file",
1592 b"content",
1593 "message",
1594 &[],
1595 );
1596 work_dir
1597 .run_jj(["git", "remote", "add", "origin", "../git-repo"])
1598 .success();
1599
1600 // Fetch without auto-tracking, so feature1@origin is untracked and there
1601 // is no local feature1 bookmark.
1602 let output = work_dir.run_jj(["git", "fetch", "--remote=origin"]);
1603 insta::assert_snapshot!(output, @r"
1604 ------- stderr -------
1605 bookmark: feature1@origin [new] untracked
1606 [EOF]
1607 ");
1608 insta::assert_snapshot!(get_bookmark_output(&work_dir), @r"
1609 feature1@origin: qomsplrm ebeb70d8 message
1610 [EOF]
1611 ");
1612
1613 // Without `--include-remotes`, forgetting an untracked remote-only
1614 // bookmark is a no-op. We should not claim any local bookmarks were
1615 // forgotten.
1616 let output = work_dir.run_jj(["bookmark", "forget", "feature1"]);
1617 insta::assert_snapshot!(output, @r"
1618 ------- stderr -------
1619 Nothing changed.
1620 [EOF]
1621 ");
1622 insta::assert_snapshot!(get_bookmark_output(&work_dir), @r"
1623 feature1@origin: qomsplrm ebeb70d8 message
1624 [EOF]
1625 ");
1626 }
1627
1628 #[test]
1629 fn test_bookmark_track_untrack() -> TestResult {
1630 let test_env = TestEnvironment::default();
1631 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
1632 let work_dir = test_env.work_dir("repo");
1633
1634 // Set up remote
1635 let git_repo_path = test_env.env_root().join("git-repo");
1636 let git_repo = git::init(git_repo_path);
1637 work_dir
1638 .run_jj(["git", "remote", "add", "origin", "../git-repo"])
1639 .success();
1640
1641 // Fetch new commit without auto tracking. No local bookmarks should be
1642 // created.
1643 create_commit_with_refs(
1644 &git_repo,
1645 "commit 1",
1646 b"content 1",
1647 &[
1648 "refs/heads/main",
1649 "refs/heads/feature1",
1650 "refs/heads/feature2",
1651 ],
1652 );
1653 test_env.add_config("remotes.origin.auto-track-bookmarks = '~*'");
1654 let output = work_dir.run_jj(["git", "fetch"]);
1655 insta::assert_snapshot!(output, @"
1656 ------- stderr -------
1657 bookmark: feature1@origin [new] untracked
1658 bookmark: feature2@origin [new] untracked
1659 bookmark: main@origin [new] untracked
1660 [EOF]
1661 ");
1662 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
1663 feature1@origin: qxxqrkql bd843888 commit 1
1664 feature2@origin: qxxqrkql bd843888 commit 1
1665 main@origin: qxxqrkql bd843888 commit 1
1666 [EOF]
1667 ");
1668 insta::assert_snapshot!(get_log_output(&work_dir), @"
1669 @ e8849ae12c70
1670 │ ◆ feature1@origin feature2@origin main@origin bd843888ee66
1671 ├─╯
1672 ◆ 000000000000
1673 [EOF]
1674 ");
1675
1676 // Track new bookmark. Local bookmark should be created.
1677 let output = work_dir.run_jj([
1678 "bookmark",
1679 "track",
1680 "feature1@origin",
1681 "main@origin",
1682 "nonexistent@origin",
1683 ]);
1684 insta::assert_snapshot!(output, @"
1685 ------- stderr -------
1686 Warning: No matching remote bookmarks for names: nonexistent@origin
1687 Started tracking 2 remote bookmarks.
1688 [EOF]
1689 ");
1690 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
1691 feature1: qxxqrkql bd843888 commit 1
1692 @origin: qxxqrkql bd843888 commit 1
1693 feature2@origin: qxxqrkql bd843888 commit 1
1694 main: qxxqrkql bd843888 commit 1
1695 @origin: qxxqrkql bd843888 commit 1
1696 [EOF]
1697 ");
1698
1699 // Track non-existent remote bookmark
1700 let output = work_dir.run_jj(["bookmark", "track", "feature3", "--remote=origin"]);
1701 insta::assert_snapshot!(output, @"
1702 ------- stderr -------
1703 Warning: No matching bookmarks for names: feature3
1704 Nothing changed.
1705 [EOF]
1706 ");
1707
1708 // Track existing bookmark. Local bookmark should result in conflict.
1709 work_dir
1710 .run_jj(["bookmark", "create", "-r@", "feature2"])
1711 .success();
1712 work_dir.run_jj(["bookmark", "track", "feature2"]).success();
1713 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
1714 feature1: qxxqrkql bd843888 commit 1
1715 @origin: qxxqrkql bd843888 commit 1
1716 feature2 (conflicted):
1717 + qpvuntsm e8849ae1 (empty) (no description set)
1718 + qxxqrkql bd843888 commit 1
1719 @origin (behind by 1 commits): qxxqrkql bd843888 commit 1
1720 main: qxxqrkql bd843888 commit 1
1721 @origin: qxxqrkql bd843888 commit 1
1722 [EOF]
1723 ");
1724
1725 // Untrack existing and locally-deleted bookmarks. Bookmark targets should be
1726 // unchanged
1727 work_dir
1728 .run_jj(["bookmark", "delete", "feature2"])
1729 .success();
1730 let output = work_dir.run_jj(["bookmark", "untrack", "feature1@origin", "feature2@origin"]);
1731 insta::assert_snapshot!(output, @"
1732 ------- stderr -------
1733 Stopped tracking 2 remote bookmarks.
1734 [EOF]
1735 ");
1736 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
1737 feature1: qxxqrkql bd843888 commit 1
1738 feature1@origin: qxxqrkql bd843888 commit 1
1739 feature2@origin: qxxqrkql bd843888 commit 1
1740 main: qxxqrkql bd843888 commit 1
1741 @origin: qxxqrkql bd843888 commit 1
1742 [EOF]
1743 ");
1744 insta::assert_snapshot!(get_log_output(&work_dir), @"
1745 @ e8849ae12c70
1746 │ ◆ feature1 feature1@origin feature2@origin main bd843888ee66
1747 ├─╯
1748 ◆ 000000000000
1749 [EOF]
1750 ");
1751
1752 // Fetch new commit. Only tracking bookmark "main" should be merged.
1753 create_commit_with_refs(
1754 &git_repo,
1755 "commit 2",
1756 b"content 2",
1757 &[
1758 "refs/heads/main",
1759 "refs/heads/feature1",
1760 "refs/heads/feature2",
1761 ],
1762 );
1763 let output = work_dir.run_jj(["git", "fetch"]);
1764 insta::assert_snapshot!(output, @"
1765 ------- stderr -------
1766 bookmark: feature1@origin [updated] untracked
1767 bookmark: feature2@origin [updated] untracked
1768 bookmark: main@origin [updated] tracked
1769 [EOF]
1770 ");
1771 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
1772 feature1: qxxqrkql bd843888 commit 1
1773 feature1@origin: psynomvr 48ec79a4 commit 2
1774 feature2@origin: psynomvr 48ec79a4 commit 2
1775 main: psynomvr 48ec79a4 commit 2
1776 @origin: psynomvr 48ec79a4 commit 2
1777 [EOF]
1778 ");
1779 insta::assert_snapshot!(get_log_output(&work_dir), @"
1780 @ e8849ae12c70
1781 │ ◆ feature1@origin feature2@origin main 48ec79a430e9
1782 ├─╯
1783 │ ○ feature1 bd843888ee66
1784 ├─╯
1785 ◆ 000000000000
1786 [EOF]
1787 ");
1788
1789 // Fetch new commit with auto tracking. Tracking bookmark "main" and new
1790 // bookmark "feature3" should be merged.
1791 create_commit_with_refs(
1792 &git_repo,
1793 "commit 3",
1794 b"content 3",
1795 &[
1796 "refs/heads/main",
1797 "refs/heads/feature1",
1798 "refs/heads/feature2",
1799 "refs/heads/feature3",
1800 ],
1801 );
1802 test_env.add_config("remotes.origin.auto-track-bookmarks = '*'");
1803 let output = work_dir.run_jj(["git", "fetch"]);
1804 insta::assert_snapshot!(output, @"
1805 ------- stderr -------
1806 bookmark: feature1@origin [updated] untracked
1807 bookmark: feature2@origin [updated] untracked
1808 bookmark: feature3@origin [new] tracked
1809 bookmark: main@origin [updated] tracked
1810 Abandoned 1 commits that are no longer reachable:
1811 psynomvr 48ec79a4 commit 2
1812 [EOF]
1813 ");
1814 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
1815 feature1: qxxqrkql bd843888 commit 1
1816 feature1@origin: yumopmsr d8cd3e02 commit 3
1817 feature2@origin: yumopmsr d8cd3e02 commit 3
1818 feature3: yumopmsr d8cd3e02 commit 3
1819 @origin: yumopmsr d8cd3e02 commit 3
1820 main: yumopmsr d8cd3e02 commit 3
1821 @origin: yumopmsr d8cd3e02 commit 3
1822 [EOF]
1823 ");
1824 insta::assert_snapshot!(get_log_output(&work_dir), @"
1825 @ e8849ae12c70
1826 │ ◆ feature1@origin feature2@origin feature3 main d8cd3e020382
1827 ├─╯
1828 │ ○ feature1 bd843888ee66
1829 ├─╯
1830 ◆ 000000000000
1831 [EOF]
1832 ");
1833 Ok(())
1834 }
1835
1836 #[test]
1837 fn test_bookmark_track_conflict() {
1838 let test_env = TestEnvironment::default();
1839 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
1840 let work_dir = test_env.work_dir("repo");
1841
1842 // add three remotes
1843 let git_repo_path = test_env.env_root().join("git-repo");
1844 git::init_bare(git_repo_path);
1845 work_dir
1846 .run_jj(["git", "remote", "add", "origin", "../git-repo"])
1847 .success();
1848 let git_repo_path = test_env.env_root().join("git-repo2");
1849 git::init_bare(git_repo_path);
1850 work_dir
1851 .run_jj(["git", "remote", "add", "origin2", "../git-repo2"])
1852 .success();
1853 let git_repo_path = test_env.env_root().join("git-repo3");
1854 git::init_bare(git_repo_path);
1855 work_dir
1856 .run_jj(["git", "remote", "add", "origin3", "../git-repo3"])
1857 .success();
1858
1859 // create bookmark and push to origin
1860 work_dir.run_jj(["bookmark", "create", "main"]).success();
1861 work_dir.run_jj(["bookmark", "track", "main"]).success();
1862 work_dir.run_jj(["describe", "-m", "a"]).success();
1863 work_dir.run_jj(["git", "push", "-b", "main"]).success();
1864
1865 // adjust main and push to origin2, again for origin3
1866 work_dir
1867 .run_jj(["describe", "-m", "b", "-r", "main", "--ignore-immutable"])
1868 .success();
1869 work_dir
1870 .run_jj(["git", "push", "-b", "main", "--remote=origin2"])
1871 .success();
1872 work_dir
1873 .run_jj(["describe", "-m", "c", "-r", "main", "--ignore-immutable"])
1874 .success();
1875 work_dir
1876 .run_jj(["git", "push", "-b", "main", "--remote=origin3"])
1877 .success();
1878
1879 // stop and retrack origin; creates conflict
1880 // origin2 and origin3 are not shown
1881 work_dir
1882 .run_jj(["bookmark", "untrack", "main", "--remote=origin"])
1883 .success();
1884 let output = work_dir.run_jj(["bookmark", "track", "main", "--remote=origin"]);
1885 insta::assert_snapshot!(output, @"
1886 ------- stderr -------
1887 Started tracking 1 remote bookmarks.
1888 main (conflicted):
1889 + qpvuntsm/0 cfb13288 (divergent) (empty) c
1890 + qpvuntsm/2 6b9445d7 (divergent) (empty) a
1891 @origin (behind by 1 commits): qpvuntsm/2 6b9445d7 (divergent) (empty) a
1892 [EOF]
1893 ");
1894
1895 // origin2 differs but is not in conflict
1896 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
1897 main (conflicted):
1898 + qpvuntsm/0 cfb13288 (divergent) (empty) c
1899 + qpvuntsm/2 6b9445d7 (divergent) (empty) a
1900 @origin (behind by 1 commits): qpvuntsm/2 6b9445d7 (divergent) (empty) a
1901 @origin2 (ahead by 1 commits, behind by 2 commits): qpvuntsm/1 bdc03fa9 (hidden) (empty) b
1902 @origin3 (behind by 1 commits): qpvuntsm/0 cfb13288 (divergent) (empty) c
1903 [EOF]
1904 ");
1905
1906 // retracking origin2 adds to the conflict
1907 work_dir
1908 .run_jj(["bookmark", "untrack", "main", "--remote=origin2"])
1909 .success();
1910 let output = work_dir.run_jj(["bookmark", "track", "main", "--remote=origin2"]);
1911 insta::assert_snapshot!(output, @"
1912 ------- stderr -------
1913 Started tracking 1 remote bookmarks.
1914 main (conflicted):
1915 + qpvuntsm/0 cfb13288 (divergent) (empty) c
1916 + qpvuntsm/2 6b9445d7 (divergent) (empty) a
1917 + qpvuntsm/1 bdc03fa9 (divergent) (empty) b
1918 @origin2 (behind by 2 commits): qpvuntsm/1 bdc03fa9 (divergent) (empty) b
1919 [EOF]
1920 ");
1921 }
1922
1923 #[test]
1924 fn test_bookmark_track_untrack_patterns() -> TestResult {
1925 let test_env = TestEnvironment::default();
1926 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
1927 let work_dir = test_env.work_dir("repo");
1928
1929 // Set up remote
1930 let git_repo_path = test_env.env_root().join("git-repo");
1931 let git_repo = git::init(git_repo_path);
1932 work_dir
1933 .run_jj(["git", "remote", "add", "origin", "../git-repo"])
1934 .success();
1935
1936 // Create remote commit
1937 create_commit_with_refs(
1938 &git_repo,
1939 "commit",
1940 b"content",
1941 &["refs/heads/feature1", "refs/heads/feature2"],
1942 );
1943
1944 // Fetch new commit without auto tracking
1945 test_env.add_config("remotes.origin.auto-track-bookmarks = '~*'");
1946 let output = work_dir.run_jj(["git", "fetch"]);
1947 insta::assert_snapshot!(output, @"
1948 ------- stderr -------
1949 bookmark: feature1@origin [new] untracked
1950 bookmark: feature2@origin [new] untracked
1951 [EOF]
1952 ");
1953
1954 // Track/untrack new bookmark that doesn't exist at remote
1955 work_dir.run_jj(["bookmark", "create", "main"]).success();
1956 insta::assert_snapshot!(work_dir.run_jj(["bookmark", "track", "main"]), @"
1957 ------- stderr -------
1958 Started tracking 1 remote bookmarks.
1959 [EOF]
1960 ");
1961 insta::assert_snapshot!(work_dir.run_jj(["bookmark", "untrack", "main"]), @"
1962 ------- stderr -------
1963 Stopped tracking 1 remote bookmarks.
1964 [EOF]
1965 ");
1966 insta::assert_snapshot!(
1967 work_dir.run_jj(["bookmark", "untrack", "main", "--remote=o*"]), @"
1968 ------- stderr -------
1969 Warning: Remote bookmark not tracked yet: main@origin
1970 Nothing changed.
1971 [EOF]
1972 ");
1973
1974 // Track/untrack unknown bookmark
1975 insta::assert_snapshot!(work_dir.run_jj(["bookmark", "track", "maine*"]), @"
1976 ------- stderr -------
1977 Nothing changed.
1978 [EOF]
1979 ");
1980 insta::assert_snapshot!(
1981 work_dir.run_jj(["bookmark", "untrack", "maine", "--remote=o* | unknown"]), @"
1982 ------- stderr -------
1983 Warning: No matching bookmarks for names: maine
1984 Warning: No matching remotes for names: unknown
1985 Nothing changed.
1986 [EOF]
1987 ");
1988
1989 // Track already tracked bookmark
1990 work_dir.run_jj(["bookmark", "track", "feature1"]).success();
1991 let output = work_dir.run_jj(["bookmark", "track", "feature1"]);
1992 insta::assert_snapshot!(output, @"
1993 ------- stderr -------
1994 Warning: Remote bookmark already tracked: feature1@origin
1995 Nothing changed.
1996 [EOF]
1997 ");
1998
1999 // Untrack non-tracking bookmark
2000 let output = work_dir.run_jj(["bookmark", "untrack", "feature2"]);
2001 insta::assert_snapshot!(output, @"
2002 ------- stderr -------
2003 Warning: Remote bookmark not tracked yet: feature2@origin
2004 Nothing changed.
2005 [EOF]
2006 ");
2007
2008 // Track/untrack Git-tracking bookmark
2009 work_dir.run_jj(["git", "export"]).success();
2010 let output = work_dir.run_jj(["bookmark", "track", "main", "--remote=git"]);
2011 insta::assert_snapshot!(output, @"
2012 ------- stderr -------
2013 Warning: Remote bookmark already tracked: main@git
2014 Nothing changed.
2015 [EOF]
2016 ");
2017 let output = work_dir.run_jj(["bookmark", "untrack", "main", "--remote=git"]);
2018 insta::assert_snapshot!(output, @"
2019 ------- stderr -------
2020 Warning: Git-tracking bookmark cannot be untracked: main@git
2021 Nothing changed.
2022 [EOF]
2023 ");
2024 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
2025 feature1: yrnqsqlx 41e7a49d commit
2026 @git: yrnqsqlx 41e7a49d commit
2027 @origin: yrnqsqlx 41e7a49d commit
2028 feature2@origin: yrnqsqlx 41e7a49d commit
2029 main: qpvuntsm e8849ae1 (empty) (no description set)
2030 @git: qpvuntsm e8849ae1 (empty) (no description set)
2031 [EOF]
2032 ");
2033
2034 // Git-tracking remote should not be warned by default
2035 let output = work_dir.run_jj(["bookmark", "track", "main"]);
2036 insta::assert_snapshot!(output, @"
2037 ------- stderr -------
2038 Started tracking 1 remote bookmarks.
2039 [EOF]
2040 ");
2041
2042 // Untrack by pattern
2043 let output = work_dir.run_jj(["bookmark", "untrack", "~main", "--remote=*"]);
2044 insta::assert_snapshot!(output, @"
2045 ------- stderr -------
2046 Warning: Git-tracking bookmark cannot be untracked: feature1@git
2047 Warning: Remote bookmark not tracked yet: feature2@origin
2048 Stopped tracking 1 remote bookmarks.
2049 [EOF]
2050 ");
2051 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
2052 feature1: yrnqsqlx 41e7a49d commit
2053 @git: yrnqsqlx 41e7a49d commit
2054 feature1@origin: yrnqsqlx 41e7a49d commit
2055 feature2@origin: yrnqsqlx 41e7a49d commit
2056 main: qpvuntsm e8849ae1 (empty) (no description set)
2057 @git: qpvuntsm e8849ae1 (empty) (no description set)
2058 @origin (not created yet)
2059 [EOF]
2060 ");
2061
2062 // Track by pattern
2063 let output = work_dir.run_jj(["bookmark", "track", "'feature?' | main", "--remote=~git"]);
2064 insta::assert_snapshot!(output, @"
2065 ------- stderr -------
2066 Warning: Remote bookmark already tracked: main@origin
2067 Started tracking 2 remote bookmarks.
2068 [EOF]
2069 ");
2070 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
2071 feature1: yrnqsqlx 41e7a49d commit
2072 @git: yrnqsqlx 41e7a49d commit
2073 @origin: yrnqsqlx 41e7a49d commit
2074 feature2: yrnqsqlx 41e7a49d commit
2075 @origin: yrnqsqlx 41e7a49d commit
2076 main: qpvuntsm e8849ae1 (empty) (no description set)
2077 @git: qpvuntsm e8849ae1 (empty) (no description set)
2078 @origin (not created yet)
2079 [EOF]
2080 ");
2081 Ok(())
2082 }
2083
2084 #[test]
2085 fn test_bookmark_track_untrack_bad_args() {
2086 let test_env = TestEnvironment::default();
2087 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
2088 let work_dir = test_env.work_dir("repo");
2089
2090 let output = work_dir.run_jj(["bookmark", "track", "--remote=foo", "bar@baz"]);
2091 insta::assert_snapshot!(output, @"
2092 ------- stderr -------
2093 Error: --remote cannot be used with <bookmark>@<remote> symbols
2094 [EOF]
2095 [exit status: 2]
2096 ");
2097
2098 let output = work_dir.run_jj(["bookmark", "track", "foo", "bar@baz"]);
2099 insta::assert_snapshot!(output, @"
2100 ------- stderr -------
2101 Error: Cannot specify both <bookmark> patterns and <bookmark>@<remote> symbols
2102 [EOF]
2103 [exit status: 2]
2104 ");
2105
2106 let output = work_dir.run_jj(["bookmark", "track", "~foo@bar"]);
2107 insta::assert_snapshot!(output, @"
2108 ------- stderr -------
2109 Error: Failed to parse name pattern or remote symbol: Invalid string expression
2110 Caused by: --> 1:2
2111 |
2112 1 | ~foo@bar
2113 | ^-----^
2114 |
2115 = Invalid string expression
2116 [EOF]
2117 [exit status: 1]
2118 ");
2119
2120 let output = work_dir.run_jj(["bookmark", "untrack", "--remote=foo", "bar@baz"]);
2121 insta::assert_snapshot!(output, @"
2122 ------- stderr -------
2123 Error: --remote cannot be used with <bookmark>@<remote> symbols
2124 [EOF]
2125 [exit status: 2]
2126 ");
2127
2128 let output = work_dir.run_jj(["bookmark", "untrack", "foo", "bar@baz"]);
2129 insta::assert_snapshot!(output, @"
2130 ------- stderr -------
2131 Error: Cannot specify both <bookmark> patterns and <bookmark>@<remote> symbols
2132 [EOF]
2133 [exit status: 2]
2134 ");
2135 }
2136
2137 #[test]
2138 fn test_bookmark_track_absent() -> TestResult {
2139 let test_env = TestEnvironment::default();
2140 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
2141 let work_dir = test_env.work_dir("repo");
2142
2143 // Set up remotes
2144 let git_repo1 = {
2145 let git_repo_path = test_env.env_root().join("remote1");
2146 let git_repo = git::init(git_repo_path);
2147 work_dir
2148 .run_jj(["git", "remote", "add", "remote1", "../remote1"])
2149 .success();
2150 git_repo
2151 };
2152 let _git_repo2 = {
2153 let git_repo_path = test_env.env_root().join("remote2");
2154 let git_repo = git::init(git_repo_path);
2155 work_dir
2156 .run_jj(["git", "remote", "add", "remote2", "../remote2"])
2157 .success();
2158 git_repo
2159 };
2160
2161 // Create feature1@remote1
2162 create_commit_with_refs(&git_repo1, "commit", b"", &["refs/heads/feature1"]);
2163
2164 let output = work_dir.run_jj(["git", "fetch", "--all-remotes"]);
2165 insta::assert_snapshot!(output, @"
2166 ------- stderr -------
2167 bookmark: feature1@remote1 [new] untracked
2168 [EOF]
2169 ");
2170
2171 // Track feature1: remote2 isn't tracked because there's no local bookmark
2172 insta::assert_snapshot!(
2173 work_dir.run_jj(["bookmark", "track", "feature1", "--remote=*"]), @"
2174 ------- stderr -------
2175 Started tracking 1 remote bookmarks.
2176 [EOF]
2177 ");
2178 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
2179 feature1: quutswnw 3fb14832 commit
2180 @remote1: quutswnw 3fb14832 commit
2181 [EOF]
2182 ");
2183
2184 // Track feature1 again: remote2 is now tracked
2185 insta::assert_snapshot!(
2186 work_dir.run_jj(["bookmark", "track", "feature1", "--remote=*"]), @"
2187 ------- stderr -------
2188 Warning: Remote bookmark already tracked: feature1@remote1
2189 Started tracking 1 remote bookmarks.
2190 [EOF]
2191 ");
2192 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
2193 feature1: quutswnw 3fb14832 commit
2194 @remote1: quutswnw 3fb14832 commit
2195 @remote2 (not created yet)
2196 [EOF]
2197 ");
2198
2199 // Track newly-created bookmark: both remotes are tracked
2200 work_dir
2201 .run_jj(["bookmark", "create", "new-feature"])
2202 .success();
2203 insta::assert_snapshot!(
2204 work_dir.run_jj(["bookmark", "track", "new-feature", "--remote=*"]), @"
2205 ------- stderr -------
2206 Started tracking 2 remote bookmarks.
2207 [EOF]
2208 ");
2209 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
2210 feature1: quutswnw 3fb14832 commit
2211 @remote1: quutswnw 3fb14832 commit
2212 @remote2 (not created yet)
2213 new-feature: qpvuntsm e8849ae1 (empty) (no description set)
2214 @remote1 (not created yet)
2215 @remote2 (not created yet)
2216 [EOF]
2217 ");
2218
2219 // Track newly-created bookmarks by <name>@<remote> syntax
2220 work_dir
2221 .run_jj(["bookmark", "create", "new2", "'new 3'"])
2222 .success();
2223 let output = work_dir.run_jj([
2224 "bookmark",
2225 "track",
2226 "new2@remote1",
2227 "'new 3'@remote2",
2228 "unknown@remote1",
2229 "'new 3'@unknown",
2230 ]);
2231 insta::assert_snapshot!(output, @r#"
2232 ------- stderr -------
2233 Warning: No matching remote bookmarks for names: unknown@remote1, "new 3"@unknown
2234 Started tracking 2 remote bookmarks.
2235 [EOF]
2236 "#);
2237 insta::assert_snapshot!(get_bookmark_output(&work_dir), @r#"
2238 feature1: quutswnw 3fb14832 commit
2239 @remote1: quutswnw 3fb14832 commit
2240 @remote2 (not created yet)
2241 "new 3": qpvuntsm e8849ae1 (empty) (no description set)
2242 @remote2 (not created yet)
2243 new-feature: qpvuntsm e8849ae1 (empty) (no description set)
2244 @remote1 (not created yet)
2245 @remote2 (not created yet)
2246 new2: qpvuntsm e8849ae1 (empty) (no description set)
2247 @remote1 (not created yet)
2248 [EOF]
2249 "#);
2250
2251 Ok(())
2252 }
2253
2254 #[test]
2255 fn test_bookmark_list() -> TestResult {
2256 let test_env = TestEnvironment::default();
2257 test_env.add_config("remotes.origin.auto-track-bookmarks = '*'");
2258
2259 // Initialize remote refs
2260 test_env.run_jj_in(".", ["git", "init", "remote"]).success();
2261 let remote_dir = test_env.work_dir("remote");
2262 for bookmark in [
2263 "remote-sync",
2264 "remote-unsync",
2265 "remote-untrack",
2266 "remote-delete",
2267 ] {
2268 remote_dir
2269 .run_jj(["new", "root()", "-m", bookmark])
2270 .success();
2271 remote_dir
2272 .run_jj(["bookmark", "create", bookmark])
2273 .success();
2274 }
2275 remote_dir.run_jj(["new"]).success();
2276 remote_dir.run_jj(["git", "export"]).success();
2277
2278 // Initialize local refs
2279 let mut remote_git_path = remote_dir.root().to_owned();
2280 remote_git_path.extend([".jj", "repo", "store", "git"]);
2281 test_env
2282 .run_jj_in(
2283 ".",
2284 ["git", "clone", remote_git_path.to_str().unwrap(), "local"],
2285 )
2286 .success();
2287 let local_dir = test_env.work_dir("local");
2288 local_dir
2289 .run_jj(["new", "root()", "-m", "local-only"])
2290 .success();
2291 local_dir
2292 .run_jj([
2293 "--config=remotes.origin.auto-track-bookmarks='~*'",
2294 "bookmark",
2295 "create",
2296 "local-only",
2297 "absent-tracked",
2298 ])
2299 .success();
2300
2301 // Mutate refs in local repository
2302 local_dir
2303 .run_jj(["bookmark", "delete", "remote-delete"])
2304 .success();
2305 local_dir
2306 .run_jj(["bookmark", "delete", "remote-untrack"])
2307 .success();
2308 local_dir
2309 .run_jj(["bookmark", "track", "absent-tracked"])
2310 .success();
2311 local_dir
2312 .run_jj(["bookmark", "untrack", "remote-untrack"])
2313 .success();
2314 local_dir
2315 .run_jj(["bookmark", "set", "--allow-backwards", "remote-unsync"])
2316 .success();
2317
2318 // Synchronized tracking remotes and non-tracking remotes aren't listed by
2319 // default
2320 let output = local_dir.run_jj(["bookmark", "list"]);
2321 insta::assert_snapshot!(output, @"
2322 absent-tracked: wqnwkozp 0353dd35 (empty) local-only
2323 @origin (not created yet)
2324 local-only: wqnwkozp 0353dd35 (empty) local-only
2325 remote-delete (deleted)
2326 @origin: vruxwmqv b32031cf (empty) remote-delete
2327 remote-sync: rlvkpnrz 7a07dbee (empty) remote-sync
2328 remote-unsync: wqnwkozp 0353dd35 (empty) local-only
2329 @origin (ahead by 1 commits, behind by 1 commits): zsuskuln 553203ba (empty) remote-unsync
2330 [EOF]
2331 ------- stderr -------
2332 Hint: Bookmarks marked as deleted can be *deleted permanently* on the remote by running `jj git push --deleted`. Use `jj bookmark forget` if you don't want that.
2333 [EOF]
2334 ");
2335
2336 let output = local_dir.run_jj(["bookmark", "list", "--all-remotes"]);
2337 insta::assert_snapshot!(output, @"
2338 absent-tracked: wqnwkozp 0353dd35 (empty) local-only
2339 @origin (not created yet)
2340 local-only: wqnwkozp 0353dd35 (empty) local-only
2341 remote-delete (deleted)
2342 @origin: vruxwmqv b32031cf (empty) remote-delete
2343 remote-sync: rlvkpnrz 7a07dbee (empty) remote-sync
2344 @origin: rlvkpnrz 7a07dbee (empty) remote-sync
2345 remote-unsync: wqnwkozp 0353dd35 (empty) local-only
2346 @origin (ahead by 1 commits, behind by 1 commits): zsuskuln 553203ba (empty) remote-unsync
2347 remote-untrack@origin: royxmykx 149bc756 (empty) remote-untrack
2348 [EOF]
2349 ------- stderr -------
2350 Hint: Bookmarks marked as deleted can be *deleted permanently* on the remote by running `jj git push --deleted`. Use `jj bookmark forget` if you don't want that.
2351 [EOF]
2352 ");
2353
2354 let output = local_dir.run_jj(["bookmark", "list", "--all-remotes", "--color=always"]);
2355 insta::assert_snapshot!(output, @"
2356 absent-tracked: wqnwkozp 0353dd35 (empty) local-only
2357 @origin (not created yet)
2358 local-only: wqnwkozp 0353dd35 (empty) local-only
2359 remote-delete (deleted)
2360 @origin: vruxwmqv b32031cf (empty) remote-delete
2361 remote-sync: rlvkpnrz 7a07dbee (empty) remote-sync
2362 @origin: rlvkpnrz 7a07dbee (empty) remote-sync
2363 remote-unsync: wqnwkozp 0353dd35 (empty) local-only
2364 @origin (ahead by 1 commits, behind by 1 commits): zsuskuln 553203ba (empty) remote-unsync
2365 remote-untrack@origin: royxmykx 149bc756 (empty) remote-untrack
2366 [EOF]
2367 ------- stderr -------
2368 Hint: Bookmarks marked as deleted can be *deleted permanently* on the remote by running `jj git push --deleted`. Use `jj bookmark forget` if you don't want that.
2369 [EOF]
2370 ");
2371
2372 let template = r#"
2373 concat(
2374 "[" ++ name ++ if(remote, "@" ++ remote) ++ "]\n",
2375 separate(" ", "present:", present) ++ "\n",
2376 separate(" ", "conflict:", conflict) ++ "\n",
2377 separate(" ", "normal_target:", normal_target.description().first_line()) ++ "\n",
2378 separate(" ", "removed_targets:", removed_targets.map(|c| c.description().first_line())) ++ "\n",
2379 separate(" ", "added_targets:", added_targets.map(|c| c.description().first_line())) ++ "\n",
2380 separate(" ", "tracked:", tracked) ++ "\n",
2381 separate(" ", "tracking_present:", tracking_present) ++ "\n",
2382 separate(" ", "tracking_ahead_count:", tracking_ahead_count.lower()) ++ "\n",
2383 separate(" ", "tracking_behind_count:", tracking_behind_count.lower()) ++ "\n",
2384 )
2385 "#;
2386 let output = local_dir.run_jj(["bookmark", "list", "--all-remotes", "-T", template]);
2387 insta::assert_snapshot!(output, @"
2388 [absent-tracked]
2389 present: true
2390 conflict: false
2391 normal_target: local-only
2392 removed_targets:
2393 added_targets: local-only
2394 tracked: false
2395 tracking_present: false
2396 tracking_ahead_count: <Error: Not a tracked remote ref>
2397 tracking_behind_count: <Error: Not a tracked remote ref>
2398 [absent-tracked@origin]
2399 present: false
2400 conflict: false
2401 normal_target: <Error: No Commit available>
2402 removed_targets:
2403 added_targets:
2404 tracked: true
2405 tracking_present: true
2406 tracking_ahead_count: 0
2407 tracking_behind_count: 2
2408 [local-only]
2409 present: true
2410 conflict: false
2411 normal_target: local-only
2412 removed_targets:
2413 added_targets: local-only
2414 tracked: false
2415 tracking_present: false
2416 tracking_ahead_count: <Error: Not a tracked remote ref>
2417 tracking_behind_count: <Error: Not a tracked remote ref>
2418 [remote-delete]
2419 present: false
2420 conflict: false
2421 normal_target: <Error: No Commit available>
2422 removed_targets:
2423 added_targets:
2424 tracked: false
2425 tracking_present: false
2426 tracking_ahead_count: <Error: Not a tracked remote ref>
2427 tracking_behind_count: <Error: Not a tracked remote ref>
2428 [remote-delete@origin]
2429 present: true
2430 conflict: false
2431 normal_target: remote-delete
2432 removed_targets:
2433 added_targets: remote-delete
2434 tracked: true
2435 tracking_present: false
2436 tracking_ahead_count: 2
2437 tracking_behind_count: 0
2438 [remote-sync]
2439 present: true
2440 conflict: false
2441 normal_target: remote-sync
2442 removed_targets:
2443 added_targets: remote-sync
2444 tracked: false
2445 tracking_present: false
2446 tracking_ahead_count: <Error: Not a tracked remote ref>
2447 tracking_behind_count: <Error: Not a tracked remote ref>
2448 [remote-sync@origin]
2449 present: true
2450 conflict: false
2451 normal_target: remote-sync
2452 removed_targets:
2453 added_targets: remote-sync
2454 tracked: true
2455 tracking_present: true
2456 tracking_ahead_count: 0
2457 tracking_behind_count: 0
2458 [remote-unsync]
2459 present: true
2460 conflict: false
2461 normal_target: local-only
2462 removed_targets:
2463 added_targets: local-only
2464 tracked: false
2465 tracking_present: false
2466 tracking_ahead_count: <Error: Not a tracked remote ref>
2467 tracking_behind_count: <Error: Not a tracked remote ref>
2468 [remote-unsync@origin]
2469 present: true
2470 conflict: false
2471 normal_target: remote-unsync
2472 removed_targets:
2473 added_targets: remote-unsync
2474 tracked: true
2475 tracking_present: true
2476 tracking_ahead_count: 1
2477 tracking_behind_count: 1
2478 [remote-untrack@origin]
2479 present: true
2480 conflict: false
2481 normal_target: remote-untrack
2482 removed_targets:
2483 added_targets: remote-untrack
2484 tracked: false
2485 tracking_present: false
2486 tracking_ahead_count: <Error: Not a tracked remote ref>
2487 tracking_behind_count: <Error: Not a tracked remote ref>
2488 [EOF]
2489 ------- stderr -------
2490 Hint: Bookmarks marked as deleted can be *deleted permanently* on the remote by running `jj git push --deleted`. Use `jj bookmark forget` if you don't want that.
2491 [EOF]
2492 ");
2493
2494 let output = local_dir.run_jj(["bookmark", "list", r#"-Tjson(self) ++ "\n""#]);
2495 insta::assert_snapshot!(output, @r#"
2496 {"name":"absent-tracked","target":["0353dd35c56156971ce5f023a1db7a6196160a8a"]}
2497 {"name":"absent-tracked","remote":"origin","target":[null],"tracking_target":["0353dd35c56156971ce5f023a1db7a6196160a8a"]}
2498 {"name":"local-only","target":["0353dd35c56156971ce5f023a1db7a6196160a8a"]}
2499 {"name":"remote-delete","target":[null]}
2500 {"name":"remote-delete","remote":"origin","target":["b32031cf329fbb90d042635c295b4e3fa2ca2651"],"tracking_target":[null]}
2501 {"name":"remote-sync","target":["7a07dbeef135886b7ba7adb27d05190c39cd92ab"]}
2502 {"name":"remote-unsync","target":["0353dd35c56156971ce5f023a1db7a6196160a8a"]}
2503 {"name":"remote-unsync","remote":"origin","target":["553203baa52803406124962dbc0bcdc0227b20b2"],"tracking_target":["0353dd35c56156971ce5f023a1db7a6196160a8a"]}
2504 [EOF]
2505 ------- stderr -------
2506 Hint: Bookmarks marked as deleted can be *deleted permanently* on the remote by running `jj git push --deleted`. Use `jj bookmark forget` if you don't want that.
2507 [EOF]
2508 "#);
2509 Ok(())
2510 }
2511
2512 #[test]
2513 fn test_bookmark_list_filtered() -> TestResult {
2514 let test_env = TestEnvironment::default();
2515 test_env.add_config("remotes.origin.auto-track-bookmarks = '*'");
2516 test_env.add_config(r#"revset-aliases."immutable_heads()" = "none()""#);
2517
2518 // Initialize remote refs
2519 test_env.run_jj_in(".", ["git", "init", "remote"]).success();
2520 let remote_dir = test_env.work_dir("remote");
2521 for bookmark in ["remote-keep", "remote-delete", "remote-rewrite"] {
2522 remote_dir
2523 .run_jj(["new", "root()", "-m", bookmark])
2524 .success();
2525 remote_dir
2526 .run_jj(["bookmark", "create", bookmark])
2527 .success();
2528 }
2529 remote_dir.run_jj(["new"]).success();
2530 remote_dir.run_jj(["git", "export"]).success();
2531
2532 // Initialize local refs
2533 let mut remote_git_path = remote_dir.root().to_owned();
2534 remote_git_path.extend([".jj", "repo", "store", "git"]);
2535 test_env
2536 .run_jj_in(
2537 ".",
2538 ["git", "clone", remote_git_path.to_str().unwrap(), "local"],
2539 )
2540 .success();
2541 let local_dir = test_env.work_dir("local");
2542 local_dir
2543 .run_jj(["new", "root()", "-m", "local-keep"])
2544 .success();
2545 local_dir
2546 .run_jj([
2547 "--config=remotes.origin.auto-track-bookmarks='~*'",
2548 "bookmark",
2549 "create",
2550 "local-keep",
2551 ])
2552 .success();
2553
2554 // Mutate refs in local repository
2555 local_dir
2556 .run_jj(["bookmark", "delete", "remote-delete"])
2557 .success();
2558 local_dir
2559 .run_jj(["describe", "-mrewritten", "remote-rewrite"])
2560 .success();
2561
2562 let template = r#"separate(" ", commit_id.short(), bookmarks, if(hidden, "(hidden)"))"#;
2563 insta::assert_snapshot!(
2564 local_dir.run_jj(["log", "-r::(bookmarks() | remote_bookmarks())", "-T", template]), @"
2565 @ 4b2bc95cbda6 local-keep
2566 │ ○ e6970e0e1f55 remote-rewrite*
2567 ├─╯
2568 │ ○ 331d500d2fda remote-rewrite@origin (hidden)
2569 ├─╯
2570 │ ○ 0e6b796871e6 remote-delete@origin
2571 ├─╯
2572 │ ○ c2f2ee40f03a remote-keep
2573 ├─╯
2574 ◆ 000000000000
2575 [EOF]
2576 ");
2577
2578 // All bookmarks are listed by default.
2579 let output = local_dir.run_jj(["bookmark", "list"]);
2580 insta::assert_snapshot!(output, @"
2581 local-keep: kpqxywon 4b2bc95c (empty) local-keep
2582 remote-delete (deleted)
2583 @origin: zsuskuln 0e6b7968 (empty) remote-delete
2584 remote-keep: rlvkpnrz c2f2ee40 (empty) remote-keep
2585 remote-rewrite: royxmykx e6970e0e (empty) rewritten
2586 @origin (ahead by 1 commits, behind by 1 commits): royxmykx/1 331d500d (hidden) (empty) remote-rewrite
2587 [EOF]
2588 ------- stderr -------
2589 Hint: Bookmarks marked as deleted can be *deleted permanently* on the remote by running `jj git push --deleted`. Use `jj bookmark forget` if you don't want that.
2590 [EOF]
2591 ");
2592
2593 let query =
2594 |args: &[&str]| local_dir.run_jj_with(|cmd| cmd.args(["bookmark", "list"]).args(args));
2595
2596 // "all()" doesn't include deleted bookmarks since they have no local targets.
2597 // So "all()" is identical to "bookmarks()".
2598 insta::assert_snapshot!(query(&["-rall()"]), @"
2599 local-keep: kpqxywon 4b2bc95c (empty) local-keep
2600 remote-keep: rlvkpnrz c2f2ee40 (empty) remote-keep
2601 remote-rewrite: royxmykx e6970e0e (empty) rewritten
2602 @origin (ahead by 1 commits, behind by 1 commits): royxmykx/1 331d500d (hidden) (empty) remote-rewrite
2603 [EOF]
2604 ");
2605
2606 // Exclude remote-only bookmarks. "remote-rewrite@origin" is included since
2607 // local "remote-rewrite" target matches.
2608 insta::assert_snapshot!(query(&["-rbookmarks()"]), @"
2609 local-keep: kpqxywon 4b2bc95c (empty) local-keep
2610 remote-keep: rlvkpnrz c2f2ee40 (empty) remote-keep
2611 remote-rewrite: royxmykx e6970e0e (empty) rewritten
2612 @origin (ahead by 1 commits, behind by 1 commits): royxmykx/1 331d500d (hidden) (empty) remote-rewrite
2613 [EOF]
2614 ");
2615
2616 // Select bookmarks by name.
2617 insta::assert_snapshot!(query(&["remote-rewrite"]), @"
2618 remote-rewrite: royxmykx e6970e0e (empty) rewritten
2619 @origin (ahead by 1 commits, behind by 1 commits): royxmykx/1 331d500d (hidden) (empty) remote-rewrite
2620 [EOF]
2621 ");
2622 insta::assert_snapshot!(query(&["-rbookmarks(remote-rewrite)"]), @"
2623 remote-rewrite: royxmykx e6970e0e (empty) rewritten
2624 @origin (ahead by 1 commits, behind by 1 commits): royxmykx/1 331d500d (hidden) (empty) remote-rewrite
2625 [EOF]
2626 ");
2627
2628 // Select bookmarks by name, combined with --all-remotes
2629 local_dir.run_jj(["git", "export"]).success();
2630 insta::assert_snapshot!(query(&["--all-remotes", "remote-rewrite"]), @"
2631 remote-rewrite: royxmykx e6970e0e (empty) rewritten
2632 @git: royxmykx e6970e0e (empty) rewritten
2633 @origin (ahead by 1 commits, behind by 1 commits): royxmykx/1 331d500d (hidden) (empty) remote-rewrite
2634 [EOF]
2635 ");
2636 insta::assert_snapshot!(query(&["--all-remotes", "-rbookmarks(remote-rewrite)"]), @"
2637 remote-rewrite: royxmykx e6970e0e (empty) rewritten
2638 @git: royxmykx e6970e0e (empty) rewritten
2639 @origin (ahead by 1 commits, behind by 1 commits): royxmykx/1 331d500d (hidden) (empty) remote-rewrite
2640 [EOF]
2641 ");
2642
2643 // Select bookmarks with --remote
2644 insta::assert_snapshot!(query(&["--remote", "origin"]), @"
2645 remote-delete (deleted)
2646 @origin: zsuskuln 0e6b7968 (empty) remote-delete
2647 remote-keep: rlvkpnrz c2f2ee40 (empty) remote-keep
2648 @origin: rlvkpnrz c2f2ee40 (empty) remote-keep
2649 remote-rewrite: royxmykx e6970e0e (empty) rewritten
2650 @origin (ahead by 1 commits, behind by 1 commits): royxmykx/1 331d500d (hidden) (empty) remote-rewrite
2651 [EOF]
2652 ------- stderr -------
2653 Hint: Bookmarks marked as deleted can be *deleted permanently* on the remote by running `jj git push --deleted`. Use `jj bookmark forget` if you don't want that.
2654 [EOF]
2655 ");
2656 insta::assert_snapshot!(query(&["--remote", "'gi?'"]), @"
2657 local-keep: kpqxywon 4b2bc95c (empty) local-keep
2658 @git: kpqxywon 4b2bc95c (empty) local-keep
2659 remote-keep: rlvkpnrz c2f2ee40 (empty) remote-keep
2660 @git: rlvkpnrz c2f2ee40 (empty) remote-keep
2661 remote-rewrite: royxmykx e6970e0e (empty) rewritten
2662 @git: royxmykx e6970e0e (empty) rewritten
2663 [EOF]
2664 ");
2665 insta::assert_snapshot!(query(&["--remote", "origin", "--remote", "git"]), @"
2666 local-keep: kpqxywon 4b2bc95c (empty) local-keep
2667 @git: kpqxywon 4b2bc95c (empty) local-keep
2668 remote-delete (deleted)
2669 @origin: zsuskuln 0e6b7968 (empty) remote-delete
2670 remote-keep: rlvkpnrz c2f2ee40 (empty) remote-keep
2671 @git: rlvkpnrz c2f2ee40 (empty) remote-keep
2672 @origin: rlvkpnrz c2f2ee40 (empty) remote-keep
2673 remote-rewrite: royxmykx e6970e0e (empty) rewritten
2674 @git: royxmykx e6970e0e (empty) rewritten
2675 @origin (ahead by 1 commits, behind by 1 commits): royxmykx/1 331d500d (hidden) (empty) remote-rewrite
2676 [EOF]
2677 ------- stderr -------
2678 Hint: Bookmarks marked as deleted can be *deleted permanently* on the remote by running `jj git push --deleted`. Use `jj bookmark forget` if you don't want that.
2679 [EOF]
2680 ");
2681
2682 // Can select deleted bookmark by name pattern, but not by revset.
2683 insta::assert_snapshot!(query(&["remote-delete"]), @"
2684 remote-delete (deleted)
2685 @origin: zsuskuln 0e6b7968 (empty) remote-delete
2686 [EOF]
2687 ------- stderr -------
2688 Hint: Bookmarks marked as deleted can be *deleted permanently* on the remote by running `jj git push --deleted`. Use `jj bookmark forget` if you don't want that.
2689 [EOF]
2690 ");
2691 insta::assert_snapshot!(query(&["-rbookmarks(remote-delete)"]), @"");
2692 insta::assert_snapshot!(query(&["-rremote-delete"]), @"
2693 ------- stderr -------
2694 Error: Revision `remote-delete` doesn't exist
2695 Hint: Did you mean `remote-delete@origin`, `remote-keep`, `remote-rewrite`, `remote-rewrite@origin`?
2696 [EOF]
2697 [exit status: 1]
2698 ");
2699
2700 // Name patterns are OR-ed.
2701 insta::assert_snapshot!(query(&["*-keep", "remote-* & *-delete"]), @"
2702 local-keep: kpqxywon 4b2bc95c (empty) local-keep
2703 remote-delete (deleted)
2704 @origin: zsuskuln 0e6b7968 (empty) remote-delete
2705 remote-keep: rlvkpnrz c2f2ee40 (empty) remote-keep
2706 [EOF]
2707 ------- stderr -------
2708 Hint: Bookmarks marked as deleted can be *deleted permanently* on the remote by running `jj git push --deleted`. Use `jj bookmark forget` if you don't want that.
2709 [EOF]
2710 ");
2711
2712 // Unmatched exact name pattern should be warned. "remote-delete" exists in
2713 // remote. "remote-rewrite" exists, but isn't included in the match.
2714 insta::assert_snapshot!(
2715 query(&["local-keep", "push-*", "unknown | remote-delete ~ remote-rewrite"]), @"
2716 local-keep: kpqxywon 4b2bc95c (empty) local-keep
2717 remote-delete (deleted)
2718 @origin: zsuskuln 0e6b7968 (empty) remote-delete
2719 [EOF]
2720 ------- stderr -------
2721 Warning: No matching bookmarks for names: unknown
2722 Hint: Bookmarks marked as deleted can be *deleted permanently* on the remote by running `jj git push --deleted`. Use `jj bookmark forget` if you don't want that.
2723 [EOF]
2724 ");
2725
2726 // Name pattern and revset are OR-ed.
2727 insta::assert_snapshot!(query(&["local-keep", "-rbookmarks(remote-rewrite)"]), @"
2728 local-keep: kpqxywon 4b2bc95c (empty) local-keep
2729 remote-rewrite: royxmykx e6970e0e (empty) rewritten
2730 @origin (ahead by 1 commits, behind by 1 commits): royxmykx/1 331d500d (hidden) (empty) remote-rewrite
2731 [EOF]
2732 ");
2733
2734 // … but still filtered by --remote
2735 insta::assert_snapshot!(query(&[
2736 "local-keep",
2737 "-rbookmarks(remote-rewrite)",
2738 "--remote",
2739 "git",
2740 ]), @"
2741 local-keep: kpqxywon 4b2bc95c (empty) local-keep
2742 @git: kpqxywon 4b2bc95c (empty) local-keep
2743 remote-rewrite: royxmykx e6970e0e (empty) rewritten
2744 @git: royxmykx e6970e0e (empty) rewritten
2745 [EOF]
2746 ");
2747
2748 // Syntax error in name pattern
2749 insta::assert_snapshot!(query(&["foo &"]), @"
2750 ------- stderr -------
2751 Error: Failed to parse name pattern: Syntax error
2752 Caused by: --> 1:6
2753 |
2754 1 | foo &
2755 | ^---
2756 |
2757 = expected `::`, `..`, `~`, or <primary>
2758 Hint: See https://docs.jj-vcs.dev/latest/revsets/ or use `jj help -k revsets` for revsets syntax and how to quote symbols.
2759 [EOF]
2760 [exit status: 1]
2761 ");
2762 Ok(())
2763 }
2764
2765 #[test]
2766 fn test_bookmark_list_quoted_name() {
2767 let test_env = TestEnvironment::default();
2768 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
2769 let work_dir = test_env.work_dir("repo");
2770
2771 work_dir
2772 .run_jj(["bookmark", "create", "-r@", "'with space'"])
2773 .success();
2774
2775 // quoted by default
2776 let output = work_dir.run_jj(["bookmark", "list"]);
2777 insta::assert_snapshot!(output, @r#"
2778 "with space": qpvuntsm e8849ae1 (empty) (no description set)
2779 [EOF]
2780 "#);
2781
2782 // string method should apply to the original (unquoted) name
2783 let template = r#"
2784 separate(' ',
2785 self,
2786 name.contains('"'),
2787 name.len(),
2788 ) ++ "\n"
2789 "#;
2790 let output = work_dir.run_jj(["bookmark", "list", "-T", template]);
2791 insta::assert_snapshot!(output, @r#"
2792 "with space" false 10
2793 [EOF]
2794 "#);
2795 }
2796
2797 #[test]
2798 fn test_bookmark_list_much_remote_divergence() -> TestResult {
2799 let test_env = TestEnvironment::default();
2800 test_env.add_config("remotes.origin.auto-track-bookmarks = '*'");
2801
2802 // Initialize remote refs
2803 test_env.run_jj_in(".", ["git", "init", "remote"]).success();
2804 let remote_dir = test_env.work_dir("remote");
2805 remote_dir
2806 .run_jj(["new", "root()", "-m", "remote-unsync"])
2807 .success();
2808 for _ in 0..15 {
2809 remote_dir.run_jj(["new", "-m", "remote-unsync"]).success();
2810 }
2811 remote_dir
2812 .run_jj(["bookmark", "create", "-r@", "remote-unsync"])
2813 .success();
2814 remote_dir.run_jj(["new"]).success();
2815 remote_dir.run_jj(["git", "export"]).success();
2816
2817 // Initialize local refs
2818 let mut remote_git_path = remote_dir.root().to_owned();
2819 remote_git_path.extend([".jj", "repo", "store", "git"]);
2820 test_env
2821 .run_jj_in(
2822 ".",
2823 ["git", "clone", remote_git_path.to_str().unwrap(), "local"],
2824 )
2825 .success();
2826 let local_dir = test_env.work_dir("local");
2827 local_dir
2828 .run_jj(["new", "root()", "-m", "local-only"])
2829 .success();
2830 for _ in 0..15 {
2831 local_dir.run_jj(["new", "-m", "local-only"]).success();
2832 }
2833 local_dir
2834 .run_jj([
2835 "--config=remotes.origin.auto-track-bookmarks='~*'",
2836 "bookmark",
2837 "create",
2838 "local-only",
2839 ])
2840 .success();
2841
2842 // Mutate refs in local repository
2843 local_dir
2844 .run_jj(["bookmark", "set", "--allow-backwards", "remote-unsync"])
2845 .success();
2846
2847 let output = local_dir.run_jj(["bookmark", "list"]);
2848 insta::assert_snapshot!(output, @"
2849 local-only: zkyosouw a30800ad (empty) local-only
2850 remote-unsync: zkyosouw a30800ad (empty) local-only
2851 @origin (ahead by at least 10 commits, behind by at least 10 commits): uyznsvlq a52367f8 (empty) remote-unsync
2852 [EOF]
2853 ");
2854 Ok(())
2855 }
2856
2857 #[test]
2858 fn test_bookmark_list_tracked() -> TestResult {
2859 let test_env = TestEnvironment::default();
2860 test_env.add_config("remotes.origin.auto-track-bookmarks = '*'");
2861 test_env.add_config("remotes.upstream.auto-track-bookmarks = '*'");
2862
2863 // Initialize remote refs
2864 test_env.run_jj_in(".", ["git", "init", "remote"]).success();
2865 let remote_dir = test_env.work_dir("remote");
2866 for bookmark in [
2867 "remote-sync",
2868 "remote-unsync",
2869 "remote-untrack",
2870 "remote-delete",
2871 ] {
2872 remote_dir
2873 .run_jj(["new", "root()", "-m", bookmark])
2874 .success();
2875 remote_dir
2876 .run_jj(["bookmark", "create", bookmark])
2877 .success();
2878 }
2879 remote_dir.run_jj(["new"]).success();
2880 remote_dir.run_jj(["git", "export"]).success();
2881
2882 // Initialize local refs
2883 let mut remote_git_path = remote_dir.root().to_owned();
2884 remote_git_path.extend([".jj", "repo", "store", "git"]);
2885 test_env
2886 .run_jj_in(
2887 ".",
2888 [
2889 "git",
2890 "clone",
2891 "--colocate",
2892 remote_git_path.to_str().unwrap(),
2893 "local",
2894 ],
2895 )
2896 .success();
2897
2898 test_env
2899 .run_jj_in(".", ["git", "init", "upstream"])
2900 .success();
2901
2902 // Initialize a second remote
2903 let upstream_dir = test_env.work_dir("upstream");
2904 upstream_dir
2905 .run_jj(["new", "root()", "-m", "upstream-sync"])
2906 .success();
2907 upstream_dir
2908 .run_jj(["bookmark", "create", "upstream-sync"])
2909 .success();
2910 upstream_dir.run_jj(["new"]).success();
2911 upstream_dir.run_jj(["git", "export"]).success();
2912
2913 let mut upstream_git_path = upstream_dir.root().to_owned();
2914 upstream_git_path.extend([".jj", "repo", "store", "git"]);
2915
2916 let local_dir = test_env.work_dir("local");
2917
2918 local_dir
2919 .run_jj([
2920 "git",
2921 "remote",
2922 "add",
2923 "upstream",
2924 upstream_git_path.to_str().unwrap(),
2925 ])
2926 .success();
2927 local_dir
2928 .run_jj(["git", "fetch", "--all-remotes"])
2929 .success();
2930
2931 local_dir
2932 .run_jj(["new", "root()", "-m", "local-only"])
2933 .success();
2934 local_dir
2935 .run_jj([
2936 "--config=remotes.origin.auto-track-bookmarks='~*'",
2937 "--config=remotes.upstream.auto-track-bookmarks='~*'",
2938 "bookmark",
2939 "create",
2940 "local-only",
2941 ])
2942 .success();
2943
2944 // Mutate refs in local repository
2945 local_dir
2946 .run_jj(["bookmark", "delete", "remote-delete"])
2947 .success();
2948 local_dir
2949 .run_jj(["bookmark", "delete", "remote-untrack"])
2950 .success();
2951 local_dir
2952 .run_jj(["bookmark", "untrack", "remote-untrack", "--remote=origin"])
2953 .success();
2954 local_dir
2955 .run_jj(["bookmark", "track", "remote-unsync", "--remote=upstream"])
2956 .success();
2957 local_dir
2958 .run_jj([
2959 "git",
2960 "push",
2961 "--remote=upstream",
2962 "--bookmark=remote-unsync",
2963 ])
2964 .success();
2965 local_dir
2966 .run_jj(["bookmark", "set", "--allow-backwards", "remote-unsync"])
2967 .success();
2968
2969 let output = local_dir.run_jj(["bookmark", "list", "--all-remotes"]);
2970 insta::assert_snapshot!(output, @"
2971 local-only: nmzmmopx 2a685e16 (empty) local-only
2972 @git: nmzmmopx 2a685e16 (empty) local-only
2973 remote-delete (deleted)
2974 @origin: vruxwmqv b32031cf (empty) remote-delete
2975 remote-sync: rlvkpnrz 7a07dbee (empty) remote-sync
2976 @git: rlvkpnrz 7a07dbee (empty) remote-sync
2977 @origin: rlvkpnrz 7a07dbee (empty) remote-sync
2978 remote-unsync: nmzmmopx 2a685e16 (empty) local-only
2979 @git: nmzmmopx 2a685e16 (empty) local-only
2980 @origin (ahead by 1 commits, behind by 1 commits): zsuskuln 553203ba (empty) remote-unsync
2981 @upstream (ahead by 1 commits, behind by 1 commits): zsuskuln 553203ba (empty) remote-unsync
2982 remote-untrack@origin: royxmykx 149bc756 (empty) remote-untrack
2983 upstream-sync: lylxulpl 169ba7d9 (empty) upstream-sync
2984 @git: lylxulpl 169ba7d9 (empty) upstream-sync
2985 @upstream: lylxulpl 169ba7d9 (empty) upstream-sync
2986 [EOF]
2987 ------- stderr -------
2988 Hint: Bookmarks marked as deleted can be *deleted permanently* on the remote by running `jj git push --deleted`. Use `jj bookmark forget` if you don't want that.
2989 [EOF]
2990 ");
2991
2992 let output = local_dir.run_jj(["bookmark", "list", "--tracked"]);
2993 insta::assert_snapshot!(output, @"
2994 remote-delete (deleted)
2995 @origin: vruxwmqv b32031cf (empty) remote-delete
2996 remote-sync: rlvkpnrz 7a07dbee (empty) remote-sync
2997 @origin: rlvkpnrz 7a07dbee (empty) remote-sync
2998 remote-unsync: nmzmmopx 2a685e16 (empty) local-only
2999 @origin (ahead by 1 commits, behind by 1 commits): zsuskuln 553203ba (empty) remote-unsync
3000 @upstream (ahead by 1 commits, behind by 1 commits): zsuskuln 553203ba (empty) remote-unsync
3001 upstream-sync: lylxulpl 169ba7d9 (empty) upstream-sync
3002 @upstream: lylxulpl 169ba7d9 (empty) upstream-sync
3003 [EOF]
3004 ------- stderr -------
3005 Hint: Bookmarks marked as deleted can be *deleted permanently* on the remote by running `jj git push --deleted`. Use `jj bookmark forget` if you don't want that.
3006 [EOF]
3007 ");
3008
3009 let output = local_dir.run_jj(["bookmark", "list", "--tracked", "--remote", "origin"]);
3010 insta::assert_snapshot!(output, @"
3011 remote-delete (deleted)
3012 @origin: vruxwmqv b32031cf (empty) remote-delete
3013 remote-sync: rlvkpnrz 7a07dbee (empty) remote-sync
3014 @origin: rlvkpnrz 7a07dbee (empty) remote-sync
3015 remote-unsync: nmzmmopx 2a685e16 (empty) local-only
3016 @origin (ahead by 1 commits, behind by 1 commits): zsuskuln 553203ba (empty) remote-unsync
3017 [EOF]
3018 ------- stderr -------
3019 Hint: Bookmarks marked as deleted can be *deleted permanently* on the remote by running `jj git push --deleted`. Use `jj bookmark forget` if you don't want that.
3020 [EOF]
3021 ");
3022
3023 let output = local_dir.run_jj(["bookmark", "list", "--tracked", "--remote=git"]);
3024 insta::assert_snapshot!(output, @"
3025 local-only: nmzmmopx 2a685e16 (empty) local-only
3026 @git: nmzmmopx 2a685e16 (empty) local-only
3027 remote-sync: rlvkpnrz 7a07dbee (empty) remote-sync
3028 @git: rlvkpnrz 7a07dbee (empty) remote-sync
3029 remote-unsync: nmzmmopx 2a685e16 (empty) local-only
3030 @git: nmzmmopx 2a685e16 (empty) local-only
3031 upstream-sync: lylxulpl 169ba7d9 (empty) upstream-sync
3032 @git: lylxulpl 169ba7d9 (empty) upstream-sync
3033 [EOF]
3034 ");
3035
3036 let output = local_dir.run_jj(["bookmark", "list", "--tracked", "remote-unsync"]);
3037 insta::assert_snapshot!(output, @"
3038 remote-unsync: nmzmmopx 2a685e16 (empty) local-only
3039 @origin (ahead by 1 commits, behind by 1 commits): zsuskuln 553203ba (empty) remote-unsync
3040 @upstream (ahead by 1 commits, behind by 1 commits): zsuskuln 553203ba (empty) remote-unsync
3041 [EOF]
3042 ");
3043
3044 let output = local_dir.run_jj(["bookmark", "list", "--tracked", "remote-untrack"]);
3045 insta::assert_snapshot!(output, @"");
3046
3047 local_dir
3048 .run_jj(["bookmark", "untrack", "remote-unsync", "--remote=upstream"])
3049 .success();
3050
3051 let output = local_dir.run_jj(["bookmark", "list", "--tracked", "remote-unsync"]);
3052 insta::assert_snapshot!(output, @"
3053 remote-unsync: nmzmmopx 2a685e16 (empty) local-only
3054 @origin (ahead by 1 commits, behind by 1 commits): zsuskuln 553203ba (empty) remote-unsync
3055 [EOF]
3056 ");
3057 Ok(())
3058 }
3059
3060 #[test]
3061 fn test_bookmark_list_conflicted() {
3062 let test_env = TestEnvironment::default();
3063 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
3064 let work_dir = test_env.work_dir("repo");
3065
3066 // Track existing bookmark. Local bookmark should result in conflict.
3067 work_dir.run_jj(["new", "root()", "-m", "a"]).success();
3068 work_dir.run_jj(["new", "root()", "-m", "b"]).success();
3069 work_dir.run_jj(["bookmark", "create", "bar"]).success();
3070 work_dir
3071 .run_jj(["bookmark", "create", "foo", "-rsubject(a)"])
3072 .success();
3073 work_dir
3074 .run_jj(["bookmark", "create", "foo", "-rsubject(b)", "--at-op=@-"])
3075 .success();
3076 work_dir.run_jj(["status"]).success();
3077 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
3078 bar: kkmpptxz a82129fb (empty) b
3079 foo (conflicted):
3080 + rlvkpnrz 4e1b2d80 (empty) a
3081 + kkmpptxz a82129fb (empty) b
3082 [EOF]
3083 ");
3084 insta::assert_snapshot!(work_dir.run_jj(["bookmark", "list", "--conflicted"]), @"
3085 foo (conflicted):
3086 + rlvkpnrz 4e1b2d80 (empty) a
3087 + kkmpptxz a82129fb (empty) b
3088 [EOF]
3089 ------- stderr -------
3090 Hint: Some bookmarks have conflicts. Use `jj bookmark set <name> -r <rev>` to resolve.
3091 [EOF]
3092 ");
3093 }
3094
3095 #[test]
3096 fn test_bookmark_list_sort_unknown_key_error() {
3097 let test_env = TestEnvironment::default();
3098 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
3099 let work_dir = test_env.work_dir("repo");
3100
3101 insta::assert_snapshot!(work_dir.run_jj(["bookmark", "list", "--sort", "date"]), @"
3102 ------- stderr -------
3103 error: invalid value 'date' for '--sort <SORT_KEY>'
3104 [possible values: name, name-, author-name, author-name-, author-email, author-email-, author-date, author-date-, committer-name, committer-name-, committer-email, committer-email-, committer-date, committer-date-]
3105
3106 For more information, try '--help'.
3107 [EOF]
3108 [exit status: 2]
3109 ");
3110 }
3111
3112 #[test]
3113 fn test_bookmark_list_sort_multiple_keys() {
3114 let test_env = TestEnvironment::default();
3115 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
3116 let work_dir = test_env.work_dir("repo");
3117 for (bookmark, email) in [("c", "[email protected]"), ("b", "[email protected]"), ("a", "[email protected]")] {
3118 work_dir
3119 .run_jj([
3120 &format!("--config=user.email={email}"),
3121 "new",
3122 "root()",
3123 "-m",
3124 "fix",
3125 ])
3126 .success();
3127 work_dir.run_jj(["bookmark", "create", bookmark]).success();
3128 }
3129
3130 let template =
3131 r#"name ++ ": " ++ if(normal_target, normal_target.committer().email()) ++ "\n""#;
3132 insta::assert_snapshot!(work_dir.run_jj(["bookmark", "list", "-T", template, "--sort", "committer-email,committer-date-"]), @"
3133 b: [email protected]
3134 a: [email protected]
3135 c: [email protected]
3136 [EOF]
3137 ");
3138 }
3139
3140 #[test]
3141 fn test_bookmark_list_sort_using_config() {
3142 let test_env = TestEnvironment::default();
3143 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
3144 let work_dir = test_env.work_dir("repo");
3145 for (bookmark, email) in [("c", "[email protected]"), ("b", "[email protected]"), ("a", "[email protected]")] {
3146 work_dir
3147 .run_jj([
3148 &format!("--config=user.email={email}"),
3149 "new",
3150 "root()",
3151 "-m",
3152 "fix",
3153 ])
3154 .success();
3155 work_dir.run_jj(["bookmark", "create", bookmark]).success();
3156 }
3157
3158 let template = r#"name ++ ": " ++ if(normal_target, normal_target.author().email()) ++ "\n""#;
3159 insta::assert_snapshot!(work_dir.run_jj([
3160 "--config=ui.bookmark-list-sort-keys=['author-email', 'author-date-']",
3161 "bookmark",
3162 "list",
3163 "-T",
3164 template
3165 ]), @"
3166 b: [email protected]
3167 a: [email protected]
3168 c: [email protected]
3169 [EOF]
3170 ");
3171 }
3172
3173 #[test]
3174 fn test_bookmark_list_sort_overriding_config() {
3175 let test_env = TestEnvironment::default();
3176 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
3177 let work_dir = test_env.work_dir("repo");
3178 for (bookmark, email) in [("c", "[email protected]"), ("b", "[email protected]"), ("a", "[email protected]")] {
3179 work_dir
3180 .run_jj([
3181 &format!("--config=user.email={email}"),
3182 "new",
3183 "root()",
3184 "-m",
3185 "fix",
3186 ])
3187 .success();
3188 work_dir.run_jj(["bookmark", "create", bookmark]).success();
3189 }
3190
3191 let template = r#"name ++ ": " ++ if(normal_target, normal_target.author().email()) ++ "\n""#;
3192 insta::assert_snapshot!(work_dir.run_jj([
3193 "--config=ui.bookmark-list-sort-keys=['author-email', 'author-date-']",
3194 "bookmark",
3195 "list",
3196 "--sort=name-", // overriding config.
3197 "-T",
3198 template
3199 ]), @"
3200 c: [email protected]
3201 b: [email protected]
3202 a: [email protected]
3203 [EOF]
3204 ");
3205 }
3206
3207 #[test]
3208 fn test_create_and_set_auto_track_bookmarks() {
3209 let test_env = TestEnvironment::default();
3210 let root_dir = test_env.work_dir("");
3211 root_dir
3212 .run_jj(["git", "init", "--colocate", "origin"])
3213 .success();
3214
3215 // auto-tracking an unknown remote (upstream) will have no effect
3216 test_env.add_config(
3217 "
3218 [remotes.origin]
3219 auto-track-bookmarks = 'mine/*'
3220 [remotes.fork]
3221 auto-track-bookmarks = 'mine/* | not-mine/*'
3222 [remotes.upstream]
3223 auto-track-bookmarks = '*'
3224 ",
3225 );
3226
3227 root_dir.run_jj(["git", "init", "repo"]).success();
3228 let repo_dir = test_env.work_dir("repo");
3229 repo_dir
3230 .run_jj(["git", "remote", "add", "origin", "../origin/.git"])
3231 .success();
3232 repo_dir
3233 .run_jj(["git", "remote", "add", "fork", "dummy"])
3234 .success();
3235
3236 // jj bookmark create obeys remotes.<name>.auto-track-bookmarks
3237 repo_dir
3238 .run_jj(["bookmark", "create", "mine/create", "not-mine/create"])
3239 .success();
3240 let output = repo_dir.run_jj([
3241 "bookmark",
3242 "list",
3243 "--all",
3244 "mine/create",
3245 "not-mine/create",
3246 ]);
3247 insta::assert_snapshot!(output, @"
3248 mine/create: rlvkpnrz 7eb1c95e (empty) (no description set)
3249 @fork (not created yet)
3250 @origin (not created yet)
3251 not-mine/create: rlvkpnrz 7eb1c95e (empty) (no description set)
3252 @fork (not created yet)
3253 [EOF]
3254 ");
3255 repo_dir.run_jj(["commit", "--message", "create"]).success();
3256
3257 // jj bookmark set obeys remotes.<name>.auto-track-bookmarks
3258 repo_dir
3259 .run_jj(["bookmark", "set", "mine/set", "not-mine/set"])
3260 .success();
3261 let output = repo_dir.run_jj(["bookmark", "list", "--all", "mine/set", "not-mine/set"]);
3262 insta::assert_snapshot!(output, @"
3263 mine/set: yqosqzyt 5fbe2b20 (empty) (no description set)
3264 @fork (not created yet)
3265 @origin (not created yet)
3266 not-mine/set: yqosqzyt 5fbe2b20 (empty) (no description set)
3267 @fork (not created yet)
3268 [EOF]
3269 ");
3270 repo_dir.run_jj(["commit", "--message", "set"]).success();
3271
3272 // jj bookmark create/set warns when auto-tracking existing bookmark
3273 repo_dir.run_jj(["git", "push"]).success();
3274 repo_dir
3275 .run_jj(["bookmark", "forget", "mine/create", "mine/set"])
3276 .success();
3277 let output = repo_dir.run_jj(["bookmark", "create", "mine/create"]);
3278 insta::assert_snapshot!(output, @"
3279 ------- stderr -------
3280 Warning: Target revision is empty.
3281 Warning: Auto-tracking bookmark that exists on the remote: mine/create@origin
3282 Created 1 bookmarks pointing to znkkpsqq 2e899fb8 mine/create* | (empty) (no description set)
3283 [EOF]
3284 ");
3285 let output = repo_dir.run_jj(["bookmark", "set", "mine/set"]);
3286 insta::assert_snapshot!(output, @"
3287 ------- stderr -------
3288 Warning: Target revision is empty.
3289 Warning: Auto-tracking bookmark that exists on the remote: mine/set@origin
3290 Created 1 bookmarks pointing to znkkpsqq 2e899fb8 mine/create* mine/set* | (empty) (no description set)
3291 [EOF]
3292 ");
3293 }
3294
3295 #[test]
3296 fn test_create_and_set_auto_track_created_bookmarks() {
3297 let test_env = TestEnvironment::default();
3298 let root_dir = test_env.work_dir("");
3299 root_dir
3300 .run_jj(["git", "init", "--colocate", "origin"])
3301 .success();
3302
3303 test_env.add_config(
3304 "
3305 [remotes.origin]
3306 auto-track-created-bookmarks = 'mine/*'
3307 auto-track-bookmarks = 'also-mine/*'
3308 ",
3309 );
3310
3311 root_dir.run_jj(["git", "init", "repo"]).success();
3312 let repo_dir = test_env.work_dir("repo");
3313 repo_dir
3314 .run_jj(["git", "remote", "add", "origin", "../origin/.git"])
3315 .success();
3316
3317 repo_dir
3318 .run_jj([
3319 "bookmark",
3320 "create",
3321 "mine/create",
3322 "also-mine/create",
3323 "not-mine/create",
3324 ])
3325 .success();
3326 let output = repo_dir.run_jj(["bookmark", "list", "--all", "*/create"]);
3327 insta::assert_snapshot!(output, @"
3328 also-mine/create: rlvkpnrz 7eb1c95e (empty) (no description set)
3329 @origin (not created yet)
3330 mine/create: rlvkpnrz 7eb1c95e (empty) (no description set)
3331 @origin (not created yet)
3332 not-mine/create: rlvkpnrz 7eb1c95e (empty) (no description set)
3333 [EOF]
3334 ");
3335 repo_dir.run_jj(["commit", "--message", "create"]).success();
3336
3337 repo_dir
3338 .run_jj([
3339 "bookmark",
3340 "set",
3341 "mine/set",
3342 "also-mine/set",
3343 "not-mine/set",
3344 ])
3345 .success();
3346 let output = repo_dir.run_jj(["bookmark", "list", "--all", "*/set"]);
3347 insta::assert_snapshot!(output, @"
3348 also-mine/set: royxmykx 5fd666db (empty) (no description set)
3349 @origin (not created yet)
3350 mine/set: royxmykx 5fd666db (empty) (no description set)
3351 @origin (not created yet)
3352 not-mine/set: royxmykx 5fd666db (empty) (no description set)
3353 [EOF]
3354 ");
3355 repo_dir.run_jj(["commit", "--message", "set"]).success();
3356 }
3357
3358 #[test]
3359 fn test_bad_auto_track_bookmarks() {
3360 let test_env = TestEnvironment::default();
3361 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
3362 let work_dir = test_env.work_dir("repo");
3363
3364 // silence "Target revision is empty" warning
3365 work_dir.write_file("file", "");
3366
3367 let output = work_dir.run_jj([
3368 "bookmark",
3369 "create",
3370 "a",
3371 "--config=remotes.origin.auto-track-bookmarks=''",
3372 ]);
3373 insta::assert_snapshot!(output, @"
3374 ------- stderr -------
3375 Config error: Invalid `remotes.origin.auto-track-bookmarks`: Syntax error
3376 Caused by: --> 1:1
3377 |
3378 1 |
3379 | ^---
3380 |
3381 = expected <expression>
3382 Hint: See https://docs.jj-vcs.dev/latest/revsets/ or use `jj help -k revsets` for revsets syntax and how to quote symbols.
3383 For help, see https://docs.jj-vcs.dev/latest/config/ or use `jj help -k config`.
3384 [EOF]
3385 [exit status: 1]
3386 ");
3387
3388 let output = work_dir.run_jj([
3389 "bookmark",
3390 "create",
3391 "a",
3392 "--config=remotes.origin.auto-track-bookmarks='foo &'",
3393 ]);
3394 insta::assert_snapshot!(output, @"
3395 ------- stderr -------
3396 Config error: Invalid `remotes.origin.auto-track-bookmarks`: Syntax error
3397 Caused by: --> 1:6
3398 |
3399 1 | foo &
3400 | ^---
3401 |
3402 = expected `::`, `..`, `~`, or <primary>
3403 Hint: See https://docs.jj-vcs.dev/latest/revsets/ or use `jj help -k revsets` for revsets syntax and how to quote symbols.
3404 For help, see https://docs.jj-vcs.dev/latest/config/ or use `jj help -k config`.
3405 [EOF]
3406 [exit status: 1]
3407 ");
3408
3409 let output = work_dir.run_jj([
3410 "bookmark",
3411 "create",
3412 "a",
3413 "--config=remotes.origin.auto-track-bookmarks=[{}]",
3414 ]);
3415 insta::assert_snapshot!(output, @"
3416 ------- stderr -------
3417 Config error: Invalid type or value for remotes.origin
3418 Caused by: invalid type: sequence, expected a string
3419 in `auto-track-bookmarks`
3420
3421 For help, see https://docs.jj-vcs.dev/latest/config/ or use `jj help -k config`.
3422 [EOF]
3423 [exit status: 1]
3424 ");
3425 }
3426
3427 #[test]
3428 fn test_bookmark_advance_default() -> TestResult {
3429 let test_env = TestEnvironment::default();
3430 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
3431 let work_dir = test_env.work_dir("repo");
3432
3433 let get_log = || {
3434 let template = r#"
3435 separate(" ",
3436 change_id.shortest(8),
3437 description.first_line(),
3438 if(empty, "(empty)"),
3439 bookmarks,
3440 )
3441 "#;
3442 work_dir.run_jj(["log", "-T", template])
3443 };
3444
3445 work_dir.run_jj(["describe", "-m", "a"]).success();
3446 work_dir.run_jj(["bookmark", "create", "A"]).success();
3447 work_dir.run_jj(["new", "-m", "b"]).success();
3448 std::fs::write(work_dir.root().join("file"), "content")?;
3449 work_dir.run_jj(["bookmark", "create", "B"]).success();
3450 work_dir.run_jj(["new", "-m", "c"]).success();
3451 std::fs::write(work_dir.root().join("file"), "new_content")?;
3452 work_dir.run_jj(["new", "-m", "d"]).success();
3453 work_dir.run_jj(["new", "-m", "e"]).success();
3454 std::fs::write(work_dir.root().join("file"), "newer_content")?;
3455
3456 insta::assert_snapshot!(get_log(), @r"
3457 @ vruxwmqv e
3458 ○ yqosqzyt d (empty)
3459 ○ royxmykx c
3460 ○ zsuskuln b B
3461 ○ qpvuntsm a (empty) A
3462 ◆ zzzzzzzz (empty)
3463 [EOF]
3464 ");
3465
3466 let setup_opid = work_dir.current_operation_id();
3467
3468 // To default target.
3469 let output = work_dir.run_jj(["bookmark", "advance"]);
3470 insta::assert_snapshot!(output, @r"
3471 ------- stderr -------
3472 Advanced 1 bookmarks to vruxwmqv 7753a73e B | e
3473 [EOF]
3474 ");
3475 work_dir.run_jj(["op", "restore", &setup_opid]).success();
3476
3477 // To target specified by --to.
3478 let output = work_dir.run_jj(["bookmark", "advance", "--to", "royxmykx"]);
3479 insta::assert_snapshot!(output, @r"
3480 ------- stderr -------
3481 Advanced 1 bookmarks to royxmykx 26554c67 B | c
3482 [EOF]
3483 ");
3484 work_dir.run_jj(["op", "restore", &setup_opid]).success();
3485
3486 // A -> default target.
3487 let output = work_dir.run_jj(["bookmark", "advance", "A"]);
3488 insta::assert_snapshot!(output, @r"
3489 ------- stderr -------
3490 Advanced 1 bookmarks to vruxwmqv 7753a73e A | e
3491 [EOF]
3492 ");
3493 work_dir.run_jj(["op", "restore", &setup_opid]).success();
3494
3495 // A -> target specified by --to.
3496 let output = work_dir.run_jj(["bookmark", "advance", "A", "--to", "zsuskuln"]);
3497 insta::assert_snapshot!(output, @r"
3498 ------- stderr -------
3499 Advanced 1 bookmarks to zsuskuln 4112c46e A B | b
3500 [EOF]
3501 ");
3502 work_dir.run_jj(["op", "restore", &setup_opid]).success();
3503
3504 // A -> empty default target.
3505 work_dir.run_jj(["new"]).success();
3506 let output = work_dir.run_jj(["bookmark", "advance", "A"]);
3507 insta::assert_snapshot!(output, @"
3508 ------- stderr -------
3509 Warning: Target revision is empty.
3510 Advanced 1 bookmarks to xznxytkn ced0e1e4 A | (empty) (no description set)
3511 [EOF]
3512 ");
3513 work_dir.run_jj(["op", "restore", &setup_opid]).success();
3514
3515 // Multiple bookmarks by name.
3516 let output = work_dir.run_jj(["bookmark", "advance", "A|B"]);
3517 insta::assert_snapshot!(output, @"
3518 ------- stderr -------
3519 Advanced 2 bookmarks to vruxwmqv 7753a73e A B | e
3520 [EOF]
3521 ");
3522 work_dir.run_jj(["op", "restore", &setup_opid]).success();
3523
3524 // Multiple bookmarks from config.
3525 let output = work_dir.run_jj([
3526 "--config=revsets.bookmark-advance-from=A|B",
3527 "bookmark",
3528 "advance",
3529 ]);
3530 insta::assert_snapshot!(output, @"
3531 ------- stderr -------
3532 Advanced 2 bookmarks to vruxwmqv 7753a73e A B | e
3533 Hint: Specify bookmark by name to update just one of the bookmarks.
3534 [EOF]
3535 ");
3536 work_dir.run_jj(["op", "restore", &setup_opid]).success();
3537
3538 // At a bookmark.
3539 work_dir.run_jj(["edit", "zsuskuln"]).success();
3540 let output = work_dir.run_jj(["bookmark", "advance"]);
3541 insta::assert_snapshot!(output, @r"
3542 ------- stderr -------
3543 No bookmarks to update.
3544 [EOF]
3545 ");
3546 work_dir.run_jj(["op", "restore", &setup_opid]).success();
3547
3548 // Not fast-forward
3549 let output = work_dir.run_jj(["bookmark", "advance", "B", "--to", "A"]);
3550 insta::assert_snapshot!(output, @"
3551 ------- stderr -------
3552 Error: Refusing to advance bookmark backwards or sideways: B
3553 [EOF]
3554 [exit status: 1]
3555 ");
3556 work_dir.run_jj(["op", "restore", &setup_opid]).success();
3557
3558 // No bookmark to push.
3559 work_dir.run_jj(["new", "root()"]).success();
3560 std::fs::write(work_dir.root().join("file"), "content")?;
3561 work_dir.run_jj(["new"]).success();
3562 let output = work_dir.run_jj(["bookmark", "advance"]);
3563 insta::assert_snapshot!(output, @r"
3564 ------- stderr -------
3565 No bookmarks to update.
3566 [EOF]
3567 ");
3568 work_dir.run_jj(["op", "restore", &setup_opid]).success();
3569
3570 // Not valid target.
3571 work_dir.run_jj(["new", "root()"]).success();
3572 std::fs::write(work_dir.root().join("file"), "content")?;
3573 work_dir.run_jj(["new"]).success();
3574 let output = work_dir.run_jj(["bookmark", "advance", "-t", "none()"]);
3575 insta::assert_snapshot!(output, @"
3576 ------- stderr -------
3577 Error: Revset `none()` didn't resolve to any revisions
3578 [EOF]
3579 [exit status: 1]
3580 ");
3581 work_dir.run_jj(["op", "restore", &setup_opid]).success();
3582
3583 // Bad default target from config.
3584 let output = work_dir.run_jj([
3585 "--config=revsets.bookmark-advance-to=none()",
3586 "bookmark",
3587 "advance",
3588 ]);
3589 insta::assert_snapshot!(output, @"
3590 ------- stderr -------
3591 Error: Revset `none()` didn't resolve to any revisions
3592 Hint: `revsets.bookmark-advance-to` controls the default target. You can also specify a specific target with `--to`.
3593 [EOF]
3594 [exit status: 1]
3595 ");
3596 Ok(())
3597 }
3598
3599 #[must_use]
3600 fn get_log_output(work_dir: &TestWorkDir) -> CommandOutput {
3601 let template = r#"bookmarks ++ " " ++ commit_id.short()"#;
3602 work_dir.run_jj(["log", "-T", template])
3603 }
3604
3605 #[must_use]
3606 fn get_bookmark_output(work_dir: &TestWorkDir) -> CommandOutput {
3607 // --quiet to suppress deleted bookmarks hint
3608 work_dir.run_jj(["bookmark", "list", "--all-remotes", "--quiet"])
3609 }