Debian Codegraph @

cli/tests/test_git_push.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 indoc::indoc;
16 use testutils::TestResult;
17 use testutils::git;
18
19 use crate::common::CommandOutput;
20 use crate::common::TestEnvironment;
21 use crate::common::TestWorkDir;
22 use crate::common::to_toml_value;
23
24 fn git_repo_dir_for_jj_repo(work_dir: &TestWorkDir<'_>) -> std::path::PathBuf {
25 work_dir
26 .root()
27 .join(".jj")
28 .join("repo")
29 .join("store")
30 .join("git")
31 }
32
33 fn set_up(test_env: &TestEnvironment) {
34 test_env.run_jj_in(".", ["git", "init", "origin"]).success();
35 let origin_dir = test_env.work_dir("origin");
36 let origin_git_repo_path = git_repo_dir_for_jj_repo(&origin_dir);
37
38 origin_dir
39 .run_jj(["describe", "-m=description 1"])
40 .success();
41 origin_dir
42 .run_jj(["bookmark", "create", "-r@", "bookmark1"])
43 .success();
44 origin_dir
45 .run_jj(["new", "root()", "-m=description 2"])
46 .success();
47 origin_dir
48 .run_jj(["bookmark", "create", "-r@", "bookmark2"])
49 .success();
50 origin_dir.run_jj(["git", "export"]).success();
51
52 test_env
53 .run_jj_in(
54 ".",
55 [
56 "git",
57 "clone",
58 "--config=remotes.origin.auto-track-bookmarks='*'",
59 origin_git_repo_path.to_str().unwrap(),
60 "local",
61 ],
62 )
63 .success();
64 }
65
66 #[test]
67 fn test_git_push_nothing() {
68 let test_env = TestEnvironment::default();
69 set_up(&test_env);
70 let work_dir = test_env.work_dir("local");
71 // Show the setup. `insta` has trouble if this is done inside `set_up()`
72 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
73 bookmark1: qpvuntsm 9b2e76de (empty) description 1
74 @origin: qpvuntsm 9b2e76de (empty) description 1
75 bookmark2: zsuskuln 38a20473 (empty) description 2
76 @origin: zsuskuln 38a20473 (empty) description 2
77 [EOF]
78 ");
79
80 // No bookmarks to push yet
81 let output = work_dir.run_jj(["git", "push", "--all"]);
82 insta::assert_snapshot!(output, @"
83 ------- stderr -------
84 Nothing changed.
85 [EOF]
86 ");
87
88 // Tracked bookmark is up to date
89 work_dir
90 .run_jj(["bookmark", "track", "bookmark1@origin"])
91 .success();
92 let output = work_dir.run_jj(["git", "push", "--tracked"]);
93 insta::assert_snapshot!(output, @"
94 ------- stderr -------
95 Nothing changed.
96 [EOF]
97 ");
98 }
99
100 #[test]
101 fn test_git_push_default_remote_selection() {
102 let test_env = TestEnvironment::default();
103 set_up(&test_env);
104 let work_dir = test_env.work_dir("local");
105
106 // add a second remote (actually the same)
107 let other_remote_path = test_env
108 .env_root()
109 .join("origin")
110 .join(".jj")
111 .join("repo")
112 .join("store")
113 .join("git");
114 work_dir
115 .run_jj([
116 "git",
117 "remote",
118 "add",
119 "other",
120 other_remote_path.to_str().unwrap(),
121 ])
122 .success();
123
124 // select remote based on git.push config
125 let output = work_dir.run_jj(["git", "push", "--config=git.push=other", "-b", "bookmark1"]);
126 insta::assert_snapshot!(output, @"
127 ------- stderr -------
128 Error: Refusing to create new remote bookmark bookmark1@other
129 Hint: Run `jj bookmark track bookmark1@other` and try again.
130 [EOF]
131 [exit status: 1]
132 ");
133
134 // remove origin, should select other (with hint)
135 work_dir
136 .run_jj(["git", "remote", "remove", "origin"])
137 .success();
138 let output = work_dir.run_jj(["git", "push", "-b", "bookmark1"]);
139 insta::assert_snapshot!(output, @"
140 ------- stderr -------
141 Hint: Pushing to the only existing remote: other
142 Changes to push to other:
143 bookmark: bookmark1 [add to 9b2e76de3920]
144 [EOF]
145 ");
146 }
147
148 #[test]
149 fn test_git_push_current_bookmark() {
150 let test_env = TestEnvironment::default();
151 set_up(&test_env);
152 test_env.add_config("remotes.origin.auto-track-bookmarks = '*'");
153 let work_dir = test_env.work_dir("local");
154 test_env.add_config(r#"revset-aliases."immutable_heads()" = "none()""#);
155 // Update some bookmarks. `bookmark1` is not a current bookmark, but
156 // `bookmark2` and `my-bookmark` are.
157 work_dir
158 .run_jj(["describe", "bookmark1", "-m", "modified bookmark1 commit"])
159 .success();
160 work_dir.run_jj(["new", "bookmark2"]).success();
161 work_dir
162 .run_jj(["bookmark", "set", "bookmark2", "-r@"])
163 .success();
164 work_dir
165 .run_jj(["bookmark", "create", "-r@", "my-bookmark"])
166 .success();
167 work_dir.run_jj(["describe", "-m", "foo"]).success();
168 // Check the setup
169 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
170 bookmark1: qpvuntsm e5ce6d9a (empty) modified bookmark1 commit
171 @origin (ahead by 1 commits, behind by 1 commits): qpvuntsm/1 9b2e76de (hidden) (empty) description 1
172 bookmark2: yostqsxw 88ca14a7 (empty) foo
173 @origin (behind by 1 commits): zsuskuln 38a20473 (empty) description 2
174 my-bookmark: yostqsxw 88ca14a7 (empty) foo
175 @origin (not created yet)
176 [EOF]
177 ");
178 // First dry-run. `bookmark1` should not get pushed.
179 let output = work_dir.run_jj(["git", "push", "--dry-run"]);
180 insta::assert_snapshot!(output, @"
181 ------- stderr -------
182 Changes to push to origin:
183 bookmark: bookmark2 [move forward from 38a204733702 to 88ca14a7d46f]
184 bookmark: my-bookmark [add to 88ca14a7d46f]
185 Dry-run requested, not pushing.
186 [EOF]
187 ");
188 let output = work_dir.run_jj(["git", "push", "--no-integrate-operation"]);
189 insta::assert_snapshot!(output, @"
190 ------- stderr -------
191 Error: --no-integrate-operation is not respected; use --dry-run
192 [EOF]
193 [exit status: 2]
194 ");
195 let output = work_dir.run_jj(["git", "push"]);
196 insta::assert_snapshot!(output, @"
197 ------- stderr -------
198 Changes to push to origin:
199 bookmark: bookmark2 [move forward from 38a204733702 to 88ca14a7d46f]
200 bookmark: my-bookmark [add to 88ca14a7d46f]
201 [EOF]
202 ");
203 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
204 bookmark1: qpvuntsm e5ce6d9a (empty) modified bookmark1 commit
205 @origin (ahead by 1 commits, behind by 1 commits): qpvuntsm/1 9b2e76de (hidden) (empty) description 1
206 bookmark2: yostqsxw 88ca14a7 (empty) foo
207 @origin: yostqsxw 88ca14a7 (empty) foo
208 my-bookmark: yostqsxw 88ca14a7 (empty) foo
209 @origin: yostqsxw 88ca14a7 (empty) foo
210 [EOF]
211 ");
212
213 // Try pushing backwards
214 work_dir
215 .run_jj([
216 "bookmark",
217 "set",
218 "bookmark2",
219 "-rbookmark2-",
220 "--allow-backwards",
221 ])
222 .success();
223 // This behavior is a strangeness of our definition of the default push revset.
224 // We could consider changing it.
225 let output = work_dir.run_jj(["git", "push"]);
226 insta::assert_snapshot!(output, @"
227 ------- stderr -------
228 Warning: No bookmarks/tags found in the default push revset: remote_bookmarks(remote=origin)..@
229 Nothing changed.
230 [EOF]
231 ");
232 // We can move a bookmark backwards
233 let output = work_dir.run_jj(["git", "push", "-bbookmark2"]);
234 insta::assert_snapshot!(output, @"
235 ------- stderr -------
236 Changes to push to origin:
237 bookmark: bookmark2 [move backward from 88ca14a7d46f to 38a204733702]
238 [EOF]
239 ");
240 }
241
242 #[test]
243 fn test_git_push_parent_bookmark() {
244 let test_env = TestEnvironment::default();
245 set_up(&test_env);
246 let work_dir = test_env.work_dir("local");
247 test_env.add_config(r#"revset-aliases."immutable_heads()" = "none()""#);
248 work_dir.run_jj(["edit", "bookmark1"]).success();
249 work_dir
250 .run_jj(["describe", "-m", "modified bookmark1 commit"])
251 .success();
252 work_dir
253 .run_jj(["new", "-m", "non-empty description"])
254 .success();
255 work_dir.write_file("file", "file");
256 let output = work_dir.run_jj(["git", "push"]);
257 insta::assert_snapshot!(output, @"
258 ------- stderr -------
259 Changes to push to origin:
260 bookmark: bookmark1 [move sideways from 9b2e76de3920 to 80560a3e08e2]
261 [EOF]
262 ");
263 }
264
265 #[test]
266 fn test_git_push_tag_in_default_target() {
267 let test_env = TestEnvironment::default();
268 test_env
269 .run_jj_in(".", ["git", "init", "--colocate", "origin"])
270 .success();
271 let origin_dir = test_env.work_dir("origin");
272 origin_dir.run_jj(["commit", "-morigin"]).success();
273 origin_dir.run_jj(["tag", "set", "-r@-", "tag1"]).success();
274 test_env
275 .run_jj_in(".", ["git", "clone", "--tag=*", "origin", "local"])
276 .success();
277 let work_dir = test_env.work_dir("local");
278
279 work_dir.run_jj(["commit", "-mlocal"]).success();
280 work_dir
281 .run_jj(["tag", "set", "--allow-move", "-r@-", "tag1"])
282 .success();
283 let output = work_dir.run_jj(["git", "push"]);
284 insta::assert_snapshot!(output, @"
285 ------- stderr -------
286 Changes to push to origin:
287 tag: tag1 [move sideways from 110db8edfa5f to b60842ac7691]
288 [EOF]
289 ");
290 }
291
292 #[test]
293 fn test_git_push_no_matching_bookmark() {
294 let test_env = TestEnvironment::default();
295 set_up(&test_env);
296 let work_dir = test_env.work_dir("local");
297 work_dir.run_jj(["new"]).success();
298 let output = work_dir.run_jj(["git", "push"]);
299 insta::assert_snapshot!(output, @"
300 ------- stderr -------
301 Warning: No bookmarks/tags found in the default push revset: remote_bookmarks(remote=origin)..@
302 Nothing changed.
303 [EOF]
304 ");
305 }
306
307 #[test]
308 fn test_git_push_matching_bookmark_unchanged() {
309 let test_env = TestEnvironment::default();
310 set_up(&test_env);
311 let work_dir = test_env.work_dir("local");
312 work_dir.run_jj(["new", "bookmark1"]).success();
313 let output = work_dir.run_jj(["git", "push"]);
314 insta::assert_snapshot!(output, @"
315 ------- stderr -------
316 Warning: No bookmarks/tags found in the default push revset: remote_bookmarks(remote=origin)..@
317 Nothing changed.
318 [EOF]
319 ");
320 }
321
322 /// Test that `jj git push` without arguments pushes a bookmark to the specified
323 /// remote even if it's already up to date on another remote
324 /// (`remote_bookmarks(remote=<remote>)..@` vs. `remote_bookmarks()..@`).
325 #[test]
326 fn test_git_push_other_remote_has_bookmark() {
327 let test_env = TestEnvironment::default();
328 set_up(&test_env);
329 let work_dir = test_env.work_dir("local");
330 test_env.add_config(r#"revset-aliases."immutable_heads()" = "none()""#);
331 // Create another remote (but actually the same)
332 let other_remote_path = test_env
333 .env_root()
334 .join("origin")
335 .join(".jj")
336 .join("repo")
337 .join("store")
338 .join("git");
339 work_dir
340 .run_jj([
341 "git",
342 "remote",
343 "add",
344 "other",
345 other_remote_path.to_str().unwrap(),
346 ])
347 .success();
348 // Modify bookmark1 and push it to `origin`
349 work_dir.run_jj(["edit", "bookmark1"]).success();
350 work_dir.run_jj(["describe", "-m=modified"]).success();
351 let output = work_dir.run_jj(["git", "push"]);
352 insta::assert_snapshot!(output, @"
353 ------- stderr -------
354 Changes to push to origin:
355 bookmark: bookmark1 [move sideways from 9b2e76de3920 to a843bfad2abb]
356 [EOF]
357 ");
358 // Since it's already pushed to origin, nothing will happen if push again
359 let output = work_dir.run_jj(["git", "push"]);
360 insta::assert_snapshot!(output, @"
361 ------- stderr -------
362 Warning: No bookmarks/tags found in the default push revset: remote_bookmarks(remote=origin)..@
363 Nothing changed.
364 [EOF]
365 ");
366 // The bookmark was moved on the "other" remote as well (since it's actually the
367 // same remote), but `jj` is not aware of that since it thinks this is a
368 // different remote. So, the push should fail.
369 //
370 // But it succeeds! That's because the bookmark is created at the same location
371 // as it is on the remote. This would also work for a descendant.
372 //
373 // TODO: Saner test?
374 work_dir
375 .run_jj(["bookmark", "track", "bookmark1", "--remote=other"])
376 .success();
377 let output = work_dir.run_jj(["git", "push", "--remote=other"]);
378 insta::assert_snapshot!(output, @"
379 ------- stderr -------
380 Changes to push to other:
381 bookmark: bookmark1 [add to a843bfad2abb]
382 [EOF]
383 ");
384 }
385
386 #[test]
387 fn test_git_push_forward_unexpectedly_moved() {
388 let test_env = TestEnvironment::default();
389 set_up(&test_env);
390 let work_dir = test_env.work_dir("local");
391
392 // Move bookmark1 forward on the remote
393 let origin_dir = test_env.work_dir("origin");
394 origin_dir
395 .run_jj(["new", "bookmark1", "-m=remote"])
396 .success();
397 origin_dir.write_file("remote", "remote");
398 origin_dir
399 .run_jj(["bookmark", "set", "bookmark1", "-r@"])
400 .success();
401 origin_dir.run_jj(["git", "export"]).success();
402
403 // Move bookmark1 forward to another commit locally
404 work_dir.run_jj(["new", "bookmark1", "-m=local"]).success();
405 work_dir.write_file("local", "local");
406 work_dir
407 .run_jj(["bookmark", "set", "bookmark1", "-r@"])
408 .success();
409
410 // Pushing should fail
411 let output = work_dir.run_jj(["git", "push"]);
412 insta::assert_snapshot!(output, @"
413 ------- stderr -------
414 Changes to push to origin:
415 bookmark: bookmark1 [move forward from 9b2e76de3920 to 624f94a35f00]
416 Warning: The following references unexpectedly moved on the remote:
417 refs/heads/bookmark1 (reason: stale info)
418 Hint: Try fetching from the remote, then make the bookmark point to where you want it to be, and push again.
419 Error: Failed to push some bookmarks
420 [EOF]
421 [exit status: 1]
422 ");
423
424 // The ref name should be colorized
425 let output = work_dir.run_jj(["git", "push", "--color=always"]);
426 insta::assert_snapshot!(output, @"
427 ------- stderr -------
428 Changes to push to origin:
429 bookmark: bookmark1 [move forward from 9b2e76de3920 to 624f94a35f00]
430 Warning: The following references unexpectedly moved on the remote:
431 refs/heads/bookmark1 (reason: stale info)
432 Hint: Try fetching from the remote, then make the bookmark point to where you want it to be, and push again.
433 Error: Failed to push some bookmarks
434 [EOF]
435 [exit status: 1]
436 ");
437 }
438
439 #[test]
440 fn test_git_push_sideways_unexpectedly_moved() {
441 let test_env = TestEnvironment::default();
442 set_up(&test_env);
443 let work_dir = test_env.work_dir("local");
444
445 // Move bookmark1 forward on the remote
446 let origin_dir = test_env.work_dir("origin");
447 origin_dir
448 .run_jj(["new", "bookmark1", "-m=remote"])
449 .success();
450 origin_dir.write_file("remote", "remote");
451 origin_dir
452 .run_jj(["bookmark", "set", "bookmark1", "-r@"])
453 .success();
454 insta::assert_snapshot!(get_bookmark_output(&origin_dir), @"
455 bookmark1: vruxwmqv 7ce4029e remote
456 @git (behind by 1 commits): qpvuntsm 9b2e76de (empty) description 1
457 bookmark2: zsuskuln 38a20473 (empty) description 2
458 @git: zsuskuln 38a20473 (empty) description 2
459 [EOF]
460 ");
461 origin_dir.run_jj(["git", "export"]).success();
462
463 // Move bookmark1 sideways to another commit locally
464 work_dir.run_jj(["new", "root()", "-m=local"]).success();
465 work_dir.write_file("local", "local");
466 work_dir
467 .run_jj(["bookmark", "set", "bookmark1", "--allow-backwards", "-r@"])
468 .success();
469 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
470 bookmark1: kmkuslsw 827b8a38 local
471 @origin (ahead by 1 commits, behind by 1 commits): qpvuntsm 9b2e76de (empty) description 1
472 bookmark2: zsuskuln 38a20473 (empty) description 2
473 @origin: zsuskuln 38a20473 (empty) description 2
474 [EOF]
475 ");
476
477 let output = work_dir.run_jj(["git", "push"]);
478 insta::assert_snapshot!(output, @"
479 ------- stderr -------
480 Changes to push to origin:
481 bookmark: bookmark1 [move sideways from 9b2e76de3920 to 827b8a385853]
482 Warning: The following references unexpectedly moved on the remote:
483 refs/heads/bookmark1 (reason: stale info)
484 Hint: Try fetching from the remote, then make the bookmark point to where you want it to be, and push again.
485 Error: Failed to push some bookmarks
486 [EOF]
487 [exit status: 1]
488 ");
489
490 // The ref name should be colorized
491 let output = work_dir.run_jj(["git", "push", "--color=always"]);
492 insta::assert_snapshot!(output, @"
493 ------- stderr -------
494 Changes to push to origin:
495 bookmark: bookmark1 [move sideways from 9b2e76de3920 to 827b8a385853]
496 Warning: The following references unexpectedly moved on the remote:
497 refs/heads/bookmark1 (reason: stale info)
498 Hint: Try fetching from the remote, then make the bookmark point to where you want it to be, and push again.
499 Error: Failed to push some bookmarks
500 [EOF]
501 [exit status: 1]
502 ");
503 }
504
505 // This tests whether the push checks that the remote bookmarks are in expected
506 // positions.
507 #[test]
508 fn test_git_push_deletion_unexpectedly_moved() {
509 let test_env = TestEnvironment::default();
510 set_up(&test_env);
511 let work_dir = test_env.work_dir("local");
512
513 // Move bookmark1 forward on the remote
514 let origin_dir = test_env.work_dir("origin");
515 origin_dir
516 .run_jj(["new", "bookmark1", "-m=remote"])
517 .success();
518 origin_dir.write_file("remote", "remote");
519 origin_dir
520 .run_jj(["bookmark", "set", "bookmark1", "-r@"])
521 .success();
522 insta::assert_snapshot!(get_bookmark_output(&origin_dir), @"
523 bookmark1: vruxwmqv 7ce4029e remote
524 @git (behind by 1 commits): qpvuntsm 9b2e76de (empty) description 1
525 bookmark2: zsuskuln 38a20473 (empty) description 2
526 @git: zsuskuln 38a20473 (empty) description 2
527 [EOF]
528 ");
529 origin_dir.run_jj(["git", "export"]).success();
530
531 // Delete bookmark1 locally
532 work_dir
533 .run_jj(["bookmark", "delete", "bookmark1"])
534 .success();
535 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
536 bookmark1 (deleted)
537 @origin: qpvuntsm 9b2e76de (empty) description 1
538 bookmark2: zsuskuln 38a20473 (empty) description 2
539 @origin: zsuskuln 38a20473 (empty) description 2
540 [EOF]
541 ");
542
543 let output = work_dir.run_jj(["git", "push", "--bookmark", "bookmark1"]);
544 insta::assert_snapshot!(output, @"
545 ------- stderr -------
546 Changes to push to origin:
547 bookmark: bookmark1 [delete from 9b2e76de3920]
548 Warning: The following references unexpectedly moved on the remote:
549 refs/heads/bookmark1 (reason: stale info)
550 Hint: Try fetching from the remote, then make the bookmark point to where you want it to be, and push again.
551 Error: Failed to push some bookmarks
552 [EOF]
553 [exit status: 1]
554 ");
555 }
556
557 #[test]
558 fn test_git_push_unexpectedly_deleted() {
559 let test_env = TestEnvironment::default();
560 set_up(&test_env);
561 let work_dir = test_env.work_dir("local");
562
563 // Delete bookmark1 forward on the remote
564 let origin_dir = test_env.work_dir("origin");
565 origin_dir
566 .run_jj(["bookmark", "delete", "bookmark1"])
567 .success();
568 insta::assert_snapshot!(get_bookmark_output(&origin_dir), @"
569 bookmark1 (deleted)
570 @git: qpvuntsm 9b2e76de (empty) description 1
571 bookmark2: zsuskuln 38a20473 (empty) description 2
572 @git: zsuskuln 38a20473 (empty) description 2
573 [EOF]
574 ");
575 origin_dir.run_jj(["git", "export"]).success();
576
577 // Move bookmark1 sideways to another commit locally
578 work_dir.run_jj(["new", "root()", "-m=local"]).success();
579 work_dir.write_file("local", "local");
580 work_dir
581 .run_jj(["bookmark", "set", "bookmark1", "--allow-backwards", "-r@"])
582 .success();
583 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
584 bookmark1: kpqxywon 09919fb0 local
585 @origin (ahead by 1 commits, behind by 1 commits): qpvuntsm 9b2e76de (empty) description 1
586 bookmark2: zsuskuln 38a20473 (empty) description 2
587 @origin: zsuskuln 38a20473 (empty) description 2
588 [EOF]
589 ");
590
591 // Pushing a moved bookmark fails if deleted on remote
592 let output = work_dir.run_jj(["git", "push"]);
593 insta::assert_snapshot!(output, @"
594 ------- stderr -------
595 Changes to push to origin:
596 bookmark: bookmark1 [move sideways from 9b2e76de3920 to 09919fb051bf]
597 Warning: The following references unexpectedly moved on the remote:
598 refs/heads/bookmark1 (reason: stale info)
599 Hint: Try fetching from the remote, then make the bookmark point to where you want it to be, and push again.
600 Error: Failed to push some bookmarks
601 [EOF]
602 [exit status: 1]
603 ");
604
605 work_dir
606 .run_jj(["bookmark", "delete", "bookmark1"])
607 .success();
608 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
609 bookmark1 (deleted)
610 @origin: qpvuntsm 9b2e76de (empty) description 1
611 bookmark2: zsuskuln 38a20473 (empty) description 2
612 @origin: zsuskuln 38a20473 (empty) description 2
613 [EOF]
614 ");
615
616 // git does not allow to push a deleted bookmark if we expect it to exist even
617 // though it was already deleted
618 let output = work_dir.run_jj(["git", "push", "-bbookmark1"]);
619 insta::assert_snapshot!(output, @"
620 ------- stderr -------
621 Changes to push to origin:
622 bookmark: bookmark1 [delete from 9b2e76de3920]
623 Warning: The following references unexpectedly moved on the remote:
624 refs/heads/bookmark1 (reason: stale info)
625 Hint: Try fetching from the remote, then make the bookmark point to where you want it to be, and push again.
626 Error: Failed to push some bookmarks
627 [EOF]
628 [exit status: 1]
629 ");
630 }
631
632 #[test]
633 fn test_git_push_creation_unexpectedly_already_exists() {
634 let test_env = TestEnvironment::default();
635 set_up(&test_env);
636 test_env.add_config("remotes.origin.auto-track-bookmarks = '*'");
637 let work_dir = test_env.work_dir("local");
638
639 // Forget bookmark1 locally
640 work_dir
641 .run_jj(["bookmark", "forget", "--include-remotes", "bookmark1"])
642 .success();
643
644 // Create a new bookmark1
645 work_dir
646 .run_jj(["new", "root()", "-m=new bookmark1"])
647 .success();
648 work_dir.write_file("local", "local");
649 work_dir
650 .run_jj(["bookmark", "create", "-r@", "bookmark1"])
651 .success();
652 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
653 bookmark1: yostqsxw a43cb801 new bookmark1
654 @origin (not created yet)
655 bookmark2: zsuskuln 38a20473 (empty) description 2
656 @origin: zsuskuln 38a20473 (empty) description 2
657 [EOF]
658 ");
659
660 let output = work_dir.run_jj(["git", "push"]);
661 insta::assert_snapshot!(output, @"
662 ------- stderr -------
663 Changes to push to origin:
664 bookmark: bookmark1 [add to a43cb8011c85]
665 Warning: The following references unexpectedly moved on the remote:
666 refs/heads/bookmark1 (reason: stale info)
667 Hint: Try fetching from the remote, then make the bookmark point to where you want it to be, and push again.
668 Error: Failed to push some bookmarks
669 [EOF]
670 [exit status: 1]
671 ");
672 }
673
674 #[test]
675 fn test_git_push_locally_created_and_rewritten() {
676 let test_env = TestEnvironment::default();
677 set_up(&test_env);
678 let work_dir = test_env.work_dir("local");
679 // Ensure that remote bookmarks aren't tracked automatically
680 test_env.add_config("remotes.origin.auto-track-bookmarks = '~*'");
681
682 // Push locally-created bookmark
683 work_dir.run_jj(["new", "root()", "-mlocal 1"]).success();
684 work_dir
685 .run_jj(["bookmark", "create", "-r@", "my"])
686 .success();
687 let output = work_dir.run_jj(["git", "push"]);
688 insta::assert_snapshot!(output, @"
689 ------- stderr -------
690 Warning: Refusing to create new remote bookmark my@origin
691 Hint: Run `jj bookmark track my@origin` and try again.
692 Nothing changed.
693 [EOF]
694 ");
695 // Absent-tracked bookmark can be pushed
696 work_dir
697 .run_jj(["bookmark", "track", "my", "--remote=origin"])
698 .success();
699 let output = work_dir.run_jj(["git", "push"]);
700 insta::assert_snapshot!(output, @"
701 ------- stderr -------
702 Changes to push to origin:
703 bookmark: my [add to e0cba5e497ee]
704 [EOF]
705 ");
706
707 // Rewrite it and push again, which would fail if the pushed bookmark weren't
708 // set to "tracking"
709 work_dir.run_jj(["describe", "-mlocal 2"]).success();
710 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
711 bookmark1: qpvuntsm 9b2e76de (empty) description 1
712 @origin: qpvuntsm 9b2e76de (empty) description 1
713 bookmark2: zsuskuln 38a20473 (empty) description 2
714 @origin: zsuskuln 38a20473 (empty) description 2
715 my: vruxwmqv 5eb416c1 (empty) local 2
716 @origin (ahead by 1 commits, behind by 1 commits): vruxwmqv/1 e0cba5e4 (hidden) (empty) local 1
717 [EOF]
718 ");
719 let output = work_dir.run_jj(["git", "push"]);
720 insta::assert_snapshot!(output, @"
721 ------- stderr -------
722 Changes to push to origin:
723 bookmark: my [move sideways from e0cba5e497ee to 5eb416c1ff97]
724 [EOF]
725 ");
726 }
727
728 #[test]
729 fn test_git_push_multiple() {
730 let test_env = TestEnvironment::default();
731 set_up(&test_env);
732 test_env.add_config("remotes.origin.auto-track-bookmarks = '*'");
733 test_env.add_config("revset-aliases.'immutable_heads()' = 'none()'");
734 let origin_dir = test_env.work_dir("origin");
735 let work_dir = test_env.work_dir("local");
736 // Add tracked tag
737 origin_dir
738 .run_jj(["tag", "set", "tag1", "-rbookmark1"])
739 .success();
740 origin_dir.run_jj(["git", "export"]).success();
741 work_dir.run_jj(["git", "fetch", "--tag=*"]).success();
742 // Update bookmarks and tags
743 work_dir
744 .run_jj(["bookmark", "delete", "bookmark1"])
745 .success();
746 work_dir
747 .run_jj(["bookmark", "set", "--allow-backwards", "bookmark2", "-r@"])
748 .success();
749 work_dir
750 .run_jj(["bookmark", "create", "-r@", "my-bookmark"])
751 .success();
752 work_dir.run_jj(["describe", "-m", "foo"]).success();
753 work_dir
754 .run_jj(["tag", "set", "--allow-move", "tag1", "-r@"])
755 .success();
756 work_dir.run_jj(["tag", "set", "tag2", "-r@"]).success();
757 // Make conflicting changes on bookmark3
758 work_dir
759 .run_jj(["bookmark", "set", "bookmark3", "-rbookmark2"])
760 .success();
761 origin_dir
762 .run_jj(["bookmark", "set", "bookmark3", "-rbookmark1"])
763 .success();
764 origin_dir.run_jj(["git", "export"]).success();
765 // Check the setup
766 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
767 bookmark1 (deleted)
768 @origin: qpvuntsm 9b2e76de (empty) description 1
769 bookmark2: yqosqzyt 0cb91ecd (empty) foo
770 @origin (ahead by 1 commits, behind by 1 commits): zsuskuln 38a20473 (empty) description 2
771 bookmark3: yqosqzyt 0cb91ecd (empty) foo
772 @origin (not created yet)
773 my-bookmark: yqosqzyt 0cb91ecd (empty) foo
774 @origin (not created yet)
775 [EOF]
776 ");
777 insta::assert_snapshot!(get_tag_output(&work_dir), @"
778 tag1: yqosqzyt 0cb91ecd (empty) foo
779 @origin (ahead by 1 commits, behind by 1 commits): qpvuntsm 9b2e76de (empty) description 1
780 tag2: yqosqzyt 0cb91ecd (empty) foo
781 [EOF]
782 ");
783
784 // First dry-run
785 let output = work_dir.run_jj(["git", "push", "--all", "--deleted", "--dry-run"]);
786 insta::assert_snapshot!(output, @"
787 ------- stderr -------
788 Changes to push to origin:
789 bookmark: bookmark1 [delete from 9b2e76de3920]
790 bookmark: bookmark2 [move sideways from 38a204733702 to 0cb91ecd4965]
791 bookmark: bookmark3 [add to 0cb91ecd4965]
792 bookmark: my-bookmark [add to 0cb91ecd4965]
793 tag: tag1 [move sideways from 9b2e76de3920 to 0cb91ecd4965]
794 tag: tag2 [add to 0cb91ecd4965]
795 Dry-run requested, not pushing.
796 [EOF]
797 ");
798 // Dry run requesting two specific bookmarks and one tag
799 let output = work_dir.run_jj([
800 "git",
801 "push",
802 "--bookmark=bookmark1|my-bookmark",
803 "--tag=tag2",
804 "--dry-run",
805 ]);
806 insta::assert_snapshot!(output, @"
807 ------- stderr -------
808 Changes to push to origin:
809 bookmark: bookmark1 [delete from 9b2e76de3920]
810 bookmark: my-bookmark [add to 0cb91ecd4965]
811 tag: tag2 [add to 0cb91ecd4965]
812 Dry-run requested, not pushing.
813 [EOF]
814 ");
815 // Dry run requesting two specific bookmarks twice
816 let output = work_dir.run_jj([
817 "git",
818 "push",
819 "-b=bookmark1",
820 "-b=my-bookmark",
821 "-b=bookmark1",
822 "-b=my-*",
823 "--dry-run",
824 ]);
825 insta::assert_snapshot!(output, @"
826 ------- stderr -------
827 Changes to push to origin:
828 bookmark: bookmark1 [delete from 9b2e76de3920]
829 bookmark: my-bookmark [add to 0cb91ecd4965]
830 Dry-run requested, not pushing.
831 [EOF]
832 ");
833 // Dry run with glob pattern
834 let output = work_dir.run_jj(["git", "push", "-b='bookmark?'", "--dry-run"]);
835 insta::assert_snapshot!(output, @"
836 ------- stderr -------
837 Changes to push to origin:
838 bookmark: bookmark1 [delete from 9b2e76de3920]
839 bookmark: bookmark2 [move sideways from 38a204733702 to 0cb91ecd4965]
840 bookmark: bookmark3 [add to 0cb91ecd4965]
841 Dry-run requested, not pushing.
842 [EOF]
843 ");
844
845 // Unmatched bookmark/tag name
846 let output = work_dir.run_jj(["git", "push", "--bookmark=foo", "--tag=bar"]);
847 insta::assert_snapshot!(output, @"
848 ------- stderr -------
849 Warning: No matching bookmarks for names: foo
850 Warning: No matching tags for names: bar
851 Nothing changed.
852 [EOF]
853 ");
854 let output = work_dir.run_jj(["git", "push", "-b=foo", "-b='?bookmark'"]);
855 insta::assert_snapshot!(output, @"
856 ------- stderr -------
857 Warning: No matching bookmarks for names: foo
858 Nothing changed.
859 [EOF]
860 ");
861
862 // --deleted is required to push deleted bookmarks even with --all
863 let output = work_dir.run_jj(["git", "push", "--all", "--dry-run"]);
864 insta::assert_snapshot!(output, @"
865 ------- stderr -------
866 Warning: Refusing to push deleted bookmark bookmark1
867 Hint: Push deleted bookmarks with --deleted or forget the bookmark to suppress this warning.
868 Changes to push to origin:
869 bookmark: bookmark2 [move sideways from 38a204733702 to 0cb91ecd4965]
870 bookmark: bookmark3 [add to 0cb91ecd4965]
871 bookmark: my-bookmark [add to 0cb91ecd4965]
872 tag: tag1 [move sideways from 9b2e76de3920 to 0cb91ecd4965]
873 tag: tag2 [add to 0cb91ecd4965]
874 Dry-run requested, not pushing.
875 [EOF]
876 ");
877 let output = work_dir.run_jj(["git", "push", "--all", "--deleted", "--dry-run"]);
878 insta::assert_snapshot!(output, @"
879 ------- stderr -------
880 Changes to push to origin:
881 bookmark: bookmark1 [delete from 9b2e76de3920]
882 bookmark: bookmark2 [move sideways from 38a204733702 to 0cb91ecd4965]
883 bookmark: bookmark3 [add to 0cb91ecd4965]
884 bookmark: my-bookmark [add to 0cb91ecd4965]
885 tag: tag1 [move sideways from 9b2e76de3920 to 0cb91ecd4965]
886 tag: tag2 [add to 0cb91ecd4965]
887 Dry-run requested, not pushing.
888 [EOF]
889 ");
890
891 // All pushed bookmarks/tags should be committed to the operation.
892 // Therefore, the subsequent "git import" should be noop.
893 let output = work_dir.run_jj(["git", "push", "--all", "--deleted"]);
894 insta::assert_snapshot!(output, @"
895 ------- stderr -------
896 Changes to push to origin:
897 bookmark: bookmark1 [delete from 9b2e76de3920]
898 bookmark: bookmark2 [move sideways from 38a204733702 to 0cb91ecd4965]
899 bookmark: bookmark3 [add to 0cb91ecd4965]
900 bookmark: my-bookmark [add to 0cb91ecd4965]
901 tag: tag1 [move sideways from 9b2e76de3920 to 0cb91ecd4965]
902 tag: tag2 [add to 0cb91ecd4965]
903 Warning: The following references unexpectedly moved on the remote:
904 refs/heads/bookmark3 (reason: stale info)
905 Hint: Try fetching from the remote, then make the bookmark point to where you want it to be, and push again.
906 Error: Failed to push some bookmarks
907 [EOF]
908 [exit status: 1]
909 ");
910 let output = work_dir.run_jj(["git", "import"]);
911 insta::assert_snapshot!(output, @"
912 ------- stderr -------
913 Nothing changed.
914 [EOF]
915 ");
916 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
917 bookmark2: yqosqzyt 0cb91ecd (empty) foo
918 @origin: yqosqzyt 0cb91ecd (empty) foo
919 bookmark3: yqosqzyt 0cb91ecd (empty) foo
920 @origin (not created yet)
921 my-bookmark: yqosqzyt 0cb91ecd (empty) foo
922 @origin: yqosqzyt 0cb91ecd (empty) foo
923 [EOF]
924 ");
925 insta::assert_snapshot!(get_tag_output(&work_dir), @"
926 tag1: yqosqzyt 0cb91ecd (empty) foo
927 @origin: yqosqzyt 0cb91ecd (empty) foo
928 tag2: yqosqzyt 0cb91ecd (empty) foo
929 @origin: yqosqzyt 0cb91ecd (empty) foo
930 [EOF]
931 ");
932 let output = work_dir.run_jj(["log", "-rall()"]);
933 insta::assert_snapshot!(output, @"
934 @ yqosqzyt [email protected] 2001-02-03 08:05:20 bookmark2 bookmark3* my-bookmark tag1 tag2 0cb91ecd
935 │ (empty) foo
936 │ ○ zsuskuln [email protected] 2001-02-03 08:05:10 38a20473
937 ├─╯ (empty) description 2
938 │ ○ qpvuntsm [email protected] 2001-02-03 08:05:08 9b2e76de
939 ├─╯ (empty) description 1
940 ◆ zzzzzzzz root() 00000000
941 [EOF]
942 ");
943
944 // Specified branch is up to date
945 let output = work_dir.run_jj(["git", "push", "--branch", "bookmark2"]);
946 insta::assert_snapshot!(output, @"
947 ------- stderr -------
948 Bookmark bookmark2@origin already matches bookmark2
949 Nothing changed.
950 [EOF]
951 ");
952 }
953
954 #[test]
955 fn test_git_push_changes() {
956 let test_env = TestEnvironment::default();
957 set_up(&test_env);
958 let work_dir = test_env.work_dir("local");
959 work_dir.run_jj(["describe", "-m", "foo"]).success();
960 work_dir.write_file("file", "contents");
961 work_dir.run_jj(["new", "-m", "bar"]).success();
962 work_dir.write_file("file", "modified");
963
964 let output = work_dir.run_jj(["git", "push", "--change", "@"]);
965 insta::assert_snapshot!(output, @"
966 ------- stderr -------
967 Creating bookmark push-yostqsxwqrlt for revision yostqsxwqrlt
968 Changes to push to origin:
969 bookmark: push-yostqsxwqrlt [add to 916414184c47]
970 [EOF]
971 ");
972
973 // specified bookmark is up to date
974 let output = work_dir.run_jj(["git", "push", "--change", "@"]);
975 insta::assert_snapshot!(output, @"
976 ------- stderr -------
977 Bookmark push-yostqsxwqrlt@origin already matches push-yostqsxwqrlt
978 Nothing changed.
979 [EOF]
980 ");
981
982 // test pushing two changes at once
983 work_dir.write_file("file", "modified2");
984 let output = work_dir.run_jj(["git", "push", "-c=(@|@-)"]);
985 insta::assert_snapshot!(output, @"
986 ------- stderr -------
987 Creating bookmark push-yqosqzytrlsw for revision yqosqzytrlsw
988 Changes to push to origin:
989 bookmark: push-yostqsxwqrlt [move sideways from 916414184c47 to 107f11285524]
990 bookmark: push-yqosqzytrlsw [add to 0f8164cd580b]
991 [EOF]
992 ");
993
994 // specifying the same change twice doesn't break things
995 work_dir.write_file("file", "modified3");
996 let output = work_dir.run_jj(["git", "push", "-c=(@|@)"]);
997 insta::assert_snapshot!(output, @"
998 ------- stderr -------
999 Changes to push to origin:
1000 bookmark: push-yostqsxwqrlt [move sideways from 107f11285524 to 7436a8a600a4]
1001 [EOF]
1002 ");
1003
1004 // specifying the same bookmark with --change/--bookmark doesn't break things
1005 work_dir.write_file("file", "modified4");
1006 let output = work_dir.run_jj(["git", "push", "-c=@", "-b=push-yostqsxwqrlt"]);
1007 insta::assert_snapshot!(output, @"
1008 ------- stderr -------
1009 Changes to push to origin:
1010 bookmark: push-yostqsxwqrlt [move sideways from 7436a8a600a4 to a8b93bdd0f68]
1011 [EOF]
1012 ");
1013
1014 // try again with --change that could move the bookmark forward
1015 work_dir.write_file("file", "modified5");
1016 work_dir
1017 .run_jj([
1018 "bookmark",
1019 "set",
1020 "-r=@-",
1021 "--allow-backwards",
1022 "push-yostqsxwqrlt",
1023 ])
1024 .success();
1025 let output = work_dir.run_jj(["status"]);
1026 insta::assert_snapshot!(output, @"
1027 Working copy changes:
1028 M file
1029 Working copy (@) : yostqsxw 4b18f5ea bar
1030 Parent commit (@-): yqosqzyt 0f8164cd push-yostqsxwqrlt* push-yqosqzytrlsw | foo
1031 [EOF]
1032 ");
1033 let output = work_dir.run_jj(["git", "push", "-c=@", "-b=push-yostqsxwqrlt"]);
1034 insta::assert_snapshot!(output, @"
1035 ------- stderr -------
1036 Error: Bookmark already exists: push-yostqsxwqrlt
1037 Hint: Use 'jj bookmark move' to move it, and 'jj git push -b push-yostqsxwqrlt' to push it
1038 [EOF]
1039 [exit status: 1]
1040 ");
1041 let output = work_dir.run_jj(["status"]);
1042 insta::assert_snapshot!(output, @"
1043 Working copy changes:
1044 M file
1045 Working copy (@) : yostqsxw 4b18f5ea bar
1046 Parent commit (@-): yqosqzyt 0f8164cd push-yostqsxwqrlt* push-yqosqzytrlsw | foo
1047 [EOF]
1048 ");
1049
1050 // Test changing `git_push_bookmark` template. It causes us to push again.
1051 let output = work_dir.run_jj([
1052 "git",
1053 "push",
1054 &format!(
1055 "--config=templates.git_push_bookmark={}",
1056 to_toml_value("'test-' ++ change_id.short()")
1057 ),
1058 "--change=@",
1059 ]);
1060 insta::assert_snapshot!(output, @"
1061 ------- stderr -------
1062 Creating bookmark test-yostqsxwqrlt for revision yostqsxwqrlt
1063 Changes to push to origin:
1064 bookmark: test-yostqsxwqrlt [add to 4b18f5ea2994]
1065 [EOF]
1066 ");
1067
1068 // Generating duplicate bookmarks should not be allowed
1069 let output = work_dir.run_jj([
1070 "git",
1071 "push",
1072 "--config=templates.git_push_bookmark=\"'dupe-bookmark'\"",
1073 "--change=(@|root()+)",
1074 ]);
1075 insta::assert_snapshot!(output, @"
1076 ------- stderr -------
1077 Creating bookmark dupe-bookmark for revision yostqsxwqrlt
1078 Error: Bookmark already exists: dupe-bookmark
1079 Hint: Use 'jj bookmark move' to move it, and 'jj git push -b dupe-bookmark' to push it
1080 [EOF]
1081 [exit status: 1]
1082 ");
1083
1084 // Bad `git_push_bookmark` templates
1085 let output = work_dir.run_jj([
1086 "git",
1087 "push",
1088 r#"--config=templates.git_push_bookmark='""'"#,
1089 "--change=@",
1090 ]);
1091 insta::assert_snapshot!(output, @"
1092 ------- stderr -------
1093 Error: Empty bookmark name generated
1094 [EOF]
1095 [exit status: 1]
1096 ");
1097
1098 // Generate a bookmark name with non-utf8 content
1099 work_dir.write_file("file", vec![b'\xff']);
1100 let output = work_dir.run_jj([
1101 "git",
1102 "push",
1103 "--config=templates.git_push_bookmark=self.diff().git()",
1104 "--change=@",
1105 ]);
1106 insta::assert_snapshot!(output, @"
1107 ------- stderr -------
1108 Error: Invalid character in bookmark name
1109 Caused by: invalid utf-8 sequence of 1 bytes from index 138
1110 [EOF]
1111 [exit status: 1]
1112 ");
1113 }
1114
1115 #[test]
1116 fn test_git_push_changes_with_name() {
1117 let test_env = TestEnvironment::default();
1118 set_up(&test_env);
1119 let work_dir = test_env.work_dir("local");
1120 work_dir.run_jj(["describe", "-m", "foo"]).success();
1121 work_dir.write_file("file", "contents");
1122 work_dir.run_jj(["new", "-m", "pushed"]).success();
1123 work_dir.write_file("file", "modified");
1124
1125 // Normal behavior.
1126 let output = work_dir.run_jj(["git", "push", "--named", "b1=@"]);
1127 insta::assert_snapshot!(output, @"
1128 ------- stderr -------
1129 Changes to push to origin:
1130 bookmark: b1 [add to 5f4f9a466c96]
1131 [EOF]
1132 ");
1133 // Spaces before the = sign are treated like part of the bookmark name and such
1134 // bookmarks cannot be pushed.
1135 let output = work_dir.run_jj(["git", "push", "--named", "b1 = @"]);
1136 insta::assert_snapshot!(output, @"
1137 ------- stderr -------
1138 Error: Could not parse 'b1 ' as a bookmark name
1139 Caused by:
1140 1: Failed to parse bookmark name: Syntax error
1141 2: --> 1:3
1142 |
1143 1 | b1
1144 | ^---
1145 |
1146 = expected <EOI>
1147 Hint: For example, `--named myfeature=@` is valid syntax
1148 [EOF]
1149 [exit status: 2]
1150 ");
1151 // test pushing a change with an empty name
1152 let output = work_dir.run_jj(["git", "push", "--named", "=@"]);
1153 insta::assert_snapshot!(output, @"
1154 ------- stderr -------
1155 Error: Argument '=@' must have the form NAME=REVISION, with both NAME and REVISION non-empty
1156 Hint: For example, `--named myfeature=@` is valid syntax
1157 [EOF]
1158 [exit status: 2]
1159 ");
1160 // Unparsable name
1161 let output = work_dir.run_jj(["git", "push", "--named", ":!:=@"]);
1162 insta::assert_snapshot!(output, @"
1163 ------- stderr -------
1164 Error: Could not parse ':!:' as a bookmark name
1165 Caused by:
1166 1: Failed to parse bookmark name: Syntax error
1167 2: --> 1:1
1168 |
1169 1 | :!:
1170 | ^---
1171 |
1172 = expected <identifier>, <string_literal>, or <raw_string_literal>
1173 Hint: For example, `--named myfeature=@` is valid syntax
1174 [EOF]
1175 [exit status: 2]
1176 ");
1177 // test pushing a change with an empty revision
1178 let output = work_dir.run_jj(["git", "push", "--named", "b2="]);
1179 insta::assert_snapshot!(output, @"
1180 ------- stderr -------
1181 Error: Argument 'b2=' must have the form NAME=REVISION, with both NAME and REVISION non-empty
1182 Hint: For example, `--named myfeature=@` is valid syntax
1183 [EOF]
1184 [exit status: 2]
1185 ");
1186 // test pushing a change with no equals sign
1187 let output = work_dir.run_jj(["git", "push", "--named", "b2"]);
1188 insta::assert_snapshot!(output, @"
1189 ------- stderr -------
1190 Error: Argument 'b2' must include '=' and have the form NAME=REVISION
1191 Hint: For example, `--named myfeature=@` is valid syntax
1192 [EOF]
1193 [exit status: 2]
1194 ");
1195
1196 // test pushing the same change with the same name again
1197 let output = work_dir.run_jj(["git", "push", "--named", "b1=@"]);
1198 insta::assert_snapshot!(output, @"
1199 ------- stderr -------
1200 Error: Bookmark already exists: b1
1201 Hint: Use 'jj bookmark move' to move it, and 'jj git push -b b1' to push it
1202 [EOF]
1203 [exit status: 1]
1204 ");
1205 // test pushing two changes at once
1206 work_dir.write_file("file", "modified2");
1207 let output = work_dir.run_jj(["git", "push", "--named=b2=(@|@-)"]);
1208 insta::assert_snapshot!(output, @"
1209 ------- stderr -------
1210 Error: Revset `(@|@-)` resolved to more than one revision
1211 Hint: The revset `(@|@-)` resolved to these revisions:
1212 yostqsxw 1b2bd869 b1* | pushed
1213 yqosqzyt 0f8164cd foo
1214 [EOF]
1215 [exit status: 1]
1216 ");
1217
1218 // specifying the same bookmark with --named/--bookmark
1219 work_dir.write_file("file", "modified4");
1220 let output = work_dir.run_jj(["git", "push", "--named=b2=@", "-b=b2"]);
1221 insta::assert_snapshot!(output, @"
1222 ------- stderr -------
1223 Changes to push to origin:
1224 bookmark: b2 [add to 95ba7bdacb38]
1225 [EOF]
1226 ");
1227 }
1228
1229 #[test]
1230 fn test_git_push_changes_with_name_deleted_tracked() {
1231 let test_env = TestEnvironment::default();
1232 set_up(&test_env);
1233 // Unset immutable_heads so that untracking branches does not move the working
1234 // copy
1235 test_env.add_config(r#"revset-aliases."immutable_heads()" = "none()""#);
1236 let work_dir = test_env.work_dir("local");
1237 // Create a second empty remote `another_remote`
1238 test_env
1239 .run_jj_in(".", ["git", "init", "another_remote"])
1240 .success();
1241 let another_remote_git_repo_path =
1242 git_repo_dir_for_jj_repo(&test_env.work_dir("another_remote"));
1243 work_dir
1244 .run_jj([
1245 "git",
1246 "remote",
1247 "add",
1248 "another_remote",
1249 another_remote_git_repo_path.to_str().unwrap(),
1250 ])
1251 .success();
1252 work_dir.run_jj(["describe", "-m", "foo"]).success();
1253 work_dir.write_file("file", "contents");
1254 work_dir.run_jj(["new", "-m", "pushed"]).success();
1255 work_dir.write_file("file", "modified");
1256 // Normal push as part of the test setup
1257 let output = work_dir.run_jj(["git", "push", "--named", "b1=@"]);
1258 insta::assert_snapshot!(output, @"
1259 ------- stderr -------
1260 Changes to push to origin:
1261 bookmark: b1 [add to 08f401c17d51]
1262 [EOF]
1263 ");
1264 work_dir.run_jj(["bookmark", "delete", "b1"]).success();
1265
1266 // Test the setup
1267 let output = work_dir
1268 .run_jj(["bookmark", "list", "--all", "b1"])
1269 .success();
1270 insta::assert_snapshot!(output, @"
1271 b1 (deleted)
1272 @origin: kpqxywon 08f401c1 pushed
1273 [EOF]
1274 ------- stderr -------
1275 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.
1276 [EOF]
1277 ");
1278
1279 // Can't push `b1` with --named to the same or another remote if it's deleted
1280 // locally and still tracked on `origin`
1281 let output = work_dir.run_jj(["git", "push", "--named", "b1=@", "--remote=another_remote"]);
1282 insta::assert_snapshot!(output, @"
1283 ------- stderr -------
1284 Error: Tracked remote bookmarks exist for deleted bookmark: b1
1285 Hint: Use `jj bookmark set` to recreate the local bookmark. Run `jj bookmark untrack b1` to disassociate them.
1286 [EOF]
1287 [exit status: 1]
1288 ");
1289 let output = work_dir.run_jj(["git", "push", "--named", "b1=@", "--remote=origin"]);
1290 insta::assert_snapshot!(output, @"
1291 ------- stderr -------
1292 Error: Tracked remote bookmarks exist for deleted bookmark: b1
1293 Hint: Use `jj bookmark set` to recreate the local bookmark. Run `jj bookmark untrack b1` to disassociate them.
1294 [EOF]
1295 [exit status: 1]
1296 ");
1297
1298 // OK to push to a different remote once the bookmark is no longer tracked on
1299 // `origin`
1300 work_dir
1301 .run_jj(["bookmark", "untrack", "b1", "--remote=origin"])
1302 .success();
1303 let output = work_dir
1304 .run_jj(["bookmark", "list", "--all", "b1"])
1305 .success();
1306 insta::assert_snapshot!(output, @"
1307 b1@origin: kpqxywon 08f401c1 pushed
1308 [EOF]
1309 ");
1310 let output = work_dir.run_jj(["git", "push", "--named", "b1=@", "--remote=another_remote"]);
1311 insta::assert_snapshot!(output, @"
1312 ------- stderr -------
1313 Changes to push to another_remote:
1314 bookmark: b1 [add to 08f401c17d51]
1315 [EOF]
1316 ");
1317 let output = work_dir
1318 .run_jj(["bookmark", "list", "--all", "b1"])
1319 .success();
1320 insta::assert_snapshot!(output, @"
1321 b1: kpqxywon 08f401c1 pushed
1322 @another_remote: kpqxywon 08f401c1 pushed
1323 b1@origin: kpqxywon 08f401c1 pushed
1324 [EOF]
1325 ");
1326 }
1327
1328 #[test]
1329 fn test_git_push_changes_with_name_untracked_or_forgotten() {
1330 let test_env = TestEnvironment::default();
1331 set_up(&test_env);
1332 let work_dir = test_env.work_dir("local");
1333 // Unset immutable_heads so that untracking branches does not move the working
1334 // copy
1335 test_env.add_config(r#"revset-aliases."immutable_heads()" = "none()""#);
1336 work_dir.run_jj(["describe", "-m", "parent"]).success();
1337 work_dir.run_jj(["new", "-m", "pushed_to_remote"]).success();
1338 work_dir.write_file("file", "contents");
1339 work_dir
1340 .run_jj(["new", "-m", "child", "--no-edit"])
1341 .success();
1342 work_dir.write_file("file", "modified");
1343
1344 // Push a branch to a remote, but forget the local branch
1345 work_dir
1346 .run_jj(["git", "push", "--named", "b1=@"])
1347 .success();
1348 work_dir.run_jj(["bookmark", "untrack", "b1"]).success();
1349 work_dir.run_jj(["bookmark", "delete", "b1"]).success();
1350
1351 let output = work_dir
1352 .run_jj(&[
1353 "log",
1354 "-r=::@+",
1355 r#"-T=separate(" ", commit_id.shortest(3), bookmarks, description)"#,
1356 ])
1357 .success();
1358 insta::assert_snapshot!(output, @"
1359 ○ 9a0 child
1360 @ 767 b1@origin pushed_to_remote
1361 ○ aa9 parent
1362 ◆ 000
1363 [EOF]
1364 ");
1365 let output = work_dir
1366 .run_jj(["bookmark", "list", "--all", "b1"])
1367 .success();
1368 insta::assert_snapshot!(output, @"
1369 b1@origin: yostqsxw 767b63a5 pushed_to_remote
1370 [EOF]
1371 ");
1372
1373 let output = work_dir.run_jj(["git", "push", "--named", "b1=@"]);
1374 insta::assert_snapshot!(output, @"
1375 ------- stderr -------
1376 Error: Non-tracking remote bookmark b1@origin exists
1377 Hint: Run `jj bookmark track b1@origin` to import the remote bookmark.
1378 [EOF]
1379 [exit status: 1]
1380 ");
1381
1382 let output = work_dir.run_jj(["git", "push", "--named", "b1=@+"]);
1383 insta::assert_snapshot!(output, @"
1384 ------- stderr -------
1385 Error: Non-tracking remote bookmark b1@origin exists
1386 Hint: Run `jj bookmark track b1@origin` to import the remote bookmark.
1387 [EOF]
1388 [exit status: 1]
1389 ");
1390
1391 // The bookmarked is still pushed to the remote, but let's entirely forget
1392 // it. In other words, let's forget the remote-tracking bookmarks.
1393 work_dir
1394 .run_jj(&["bookmark", "forget", "b1", "--include-remotes"])
1395 .success();
1396 let output = work_dir
1397 .run_jj(["bookmark", "list", "--all", "b1"])
1398 .success();
1399 insta::assert_snapshot!(output, @"
1400 ------- stderr -------
1401 Warning: No matching bookmarks for names: b1
1402 [EOF]
1403 ");
1404
1405 // Make sure push still errors if we try to push a bookmark with the same name
1406 // to a different location.
1407 let output = work_dir.run_jj(["git", "push", "--named", "b1=@-"]);
1408 insta::assert_snapshot!(output, @"
1409 ------- stderr -------
1410 Changes to push to origin:
1411 bookmark: b1 [add to aa9ad64cb4ce]
1412 Warning: The following references unexpectedly moved on the remote:
1413 refs/heads/b1 (reason: stale info)
1414 Hint: Try fetching from the remote, then make the bookmark point to where you want it to be, and push again.
1415 Error: Failed to push some bookmarks
1416 [EOF]
1417 [exit status: 1]
1418 ");
1419
1420 // The bookmark is still forgotten
1421 let output = work_dir.run_jj(["bookmark", "list", "--all", "b1"]);
1422 insta::assert_snapshot!(output, @"
1423 ------- stderr -------
1424 Warning: No matching bookmarks for names: b1
1425 [EOF]
1426 ");
1427 let output = work_dir.run_jj(["git", "push", "--named", "b1=@+"]);
1428 insta::assert_snapshot!(output, @"
1429 ------- stderr -------
1430 Changes to push to origin:
1431 bookmark: b1 [add to 9a0f76645905]
1432 Warning: The following references unexpectedly moved on the remote:
1433 refs/heads/b1 (reason: stale info)
1434 Hint: Try fetching from the remote, then make the bookmark point to where you want it to be, and push again.
1435 Error: Failed to push some bookmarks
1436 [EOF]
1437 [exit status: 1]
1438 ");
1439 // In this case, pushing the bookmark to the same location where it already is
1440 // succeeds. TODO: This seems pretty safe, but perhaps it should still show
1441 // an error or some sort of warning?
1442 let output = work_dir.run_jj(["git", "push", "--named", "b1=@"]);
1443 insta::assert_snapshot!(output, @"
1444 ------- stderr -------
1445 Changes to push to origin:
1446 bookmark: b1 [add to 767b63a598e1]
1447 [EOF]
1448 ");
1449 }
1450
1451 #[test]
1452 fn test_git_push_revisions() {
1453 let test_env = TestEnvironment::default();
1454 set_up(&test_env);
1455 test_env.add_config("remotes.origin.auto-track-bookmarks = '*'");
1456 test_env.add_config("revset-aliases.'immutable_heads()' = 'none()'");
1457 let origin_dir = test_env.work_dir("origin");
1458 let work_dir = test_env.work_dir("local");
1459 // Add tracked tags
1460 origin_dir
1461 .run_jj(["tag", "set", "tag-1", "tag-2", "tag-3", "-rbookmark1"])
1462 .success();
1463 origin_dir.run_jj(["git", "export"]).success();
1464 work_dir.run_jj(["git", "fetch", "--tag=*"]).success();
1465 // Update bookmarks and tags
1466 work_dir.run_jj(["describe", "-m", "foo"]).success();
1467 work_dir.write_file("file", "contents");
1468 work_dir.run_jj(["new", "-m", "bar"]).success();
1469 work_dir
1470 .run_jj(["bookmark", "create", "-r@", "bookmark-1"])
1471 .success();
1472 work_dir.write_file("file", "modified");
1473 work_dir.run_jj(["new", "-m", "baz"]).success();
1474 work_dir
1475 .run_jj(["bookmark", "create", "-r@", "bookmark-2a"])
1476 .success();
1477 work_dir
1478 .run_jj(["bookmark", "create", "-r@", "bookmark-2b"])
1479 .success();
1480 work_dir.write_file("file", "modified again");
1481 work_dir
1482 .run_jj(["tag", "set", "--allow-move", "-r@", "tag-2"])
1483 .success();
1484 work_dir
1485 .run_jj(["new", "root()", "--no-edit", "-mnew3"])
1486 .success();
1487 work_dir
1488 .run_jj(["tag", "set", "--allow-move", "-rsubject(new3)", "tag-3"])
1489 .success();
1490 insta::assert_snapshot!(work_dir.run_jj(["log"]), @"
1491 @ lylxulpl [email protected] 2001-02-03 08:05:23 bookmark-2a* bookmark-2b* tag-2* 6bc5860f
1492 │ baz
1493 ○ kmkuslsw [email protected] 2001-02-03 08:05:20 bookmark-1* 3c179a96
1494 │ bar
1495 ○ yqosqzyt [email protected] 2001-02-03 08:05:18 33b167f8
1496 │ foo
1497 │ ○ xznxytkn [email protected] 2001-02-03 08:05:24 tag-3* 14504d39
1498 ├─╯ (empty) new3
1499 │ ○ zsuskuln [email protected] 2001-02-03 08:05:10 bookmark2 38a20473
1500 ├─╯ (empty) description 2
1501 │ ○ qpvuntsm [email protected] 2001-02-03 08:05:08 bookmark1 tag-1 tag-2@origin tag-3@origin 9b2e76de
1502 ├─╯ (empty) description 1
1503 ◆ zzzzzzzz root() 00000000
1504 [EOF]
1505 ");
1506
1507 // Bookmark/tag at revision is up to date
1508 let output = work_dir.run_jj(["git", "push", "--revisions", "bookmark1"]);
1509 insta::assert_snapshot!(output, @"
1510 ------- stderr -------
1511 Nothing changed.
1512 [EOF]
1513 ");
1514 // Push an empty set
1515 let output = work_dir.run_jj(["git", "push", "-r=none()"]);
1516 insta::assert_snapshot!(output, @"
1517 ------- stderr -------
1518 Warning: No bookmarks/tags point to the specified revisions: none()
1519 Nothing changed.
1520 [EOF]
1521 ");
1522 // Push a revision with no bookmarks/tags
1523 let output = work_dir.run_jj(["git", "push", "-r=@--"]);
1524 insta::assert_snapshot!(output, @"
1525 ------- stderr -------
1526 Warning: No bookmarks/tags point to the specified revisions: @--
1527 Nothing changed.
1528 [EOF]
1529 ");
1530 // Push a revision with a single bookmark
1531 let output = work_dir.run_jj(["git", "push", "-r=@-", "--dry-run"]);
1532 insta::assert_snapshot!(output, @"
1533 ------- stderr -------
1534 Changes to push to origin:
1535 bookmark: bookmark-1 [add to 3c179a96c972]
1536 Dry-run requested, not pushing.
1537 [EOF]
1538 ");
1539 // Push a revision with a single tag
1540 let output = work_dir.run_jj(["git", "push", "-r=subject(new3)", "--dry-run"]);
1541 insta::assert_snapshot!(output, @"
1542 ------- stderr -------
1543 Changes to push to origin:
1544 tag: tag-3 [move sideways from 9b2e76de3920 to 14504d39da71]
1545 Dry-run requested, not pushing.
1546 [EOF]
1547 ");
1548 // Push multiple revisions of which some have bookmarks
1549 let output = work_dir.run_jj(["git", "push", "-r=@--", "-r=@-", "--dry-run"]);
1550 insta::assert_snapshot!(output, @"
1551 ------- stderr -------
1552 Warning: No bookmarks/tags point to the specified revisions: @--
1553 Changes to push to origin:
1554 bookmark: bookmark-1 [add to 3c179a96c972]
1555 Dry-run requested, not pushing.
1556 [EOF]
1557 ");
1558 // Push a revision with a multiple bookmarks and tags
1559 let output = work_dir.run_jj(["git", "push", "-r=@", "--dry-run"]);
1560 insta::assert_snapshot!(output, @"
1561 ------- stderr -------
1562 Changes to push to origin:
1563 bookmark: bookmark-2a [add to 6bc5860f95fb]
1564 bookmark: bookmark-2b [add to 6bc5860f95fb]
1565 tag: tag-2 [move sideways from 9b2e76de3920 to 6bc5860f95fb]
1566 Dry-run requested, not pushing.
1567 [EOF]
1568 ");
1569 // Repeating a commit doesn't result in repeated messages about the bookmark
1570 let output = work_dir.run_jj(["git", "push", "-r=@-", "-r=@-", "--dry-run"]);
1571 insta::assert_snapshot!(output, @"
1572 ------- stderr -------
1573 Changes to push to origin:
1574 bookmark: bookmark-1 [add to 3c179a96c972]
1575 Dry-run requested, not pushing.
1576 [EOF]
1577 ");
1578 // Repetition via name and commit doesn't result in repeated messages either
1579 let output = work_dir.run_jj(["git", "push", "-r=@-", "-b", "bookmark-1", "--dry-run"]);
1580 insta::assert_snapshot!(output, @"
1581 ------- stderr -------
1582 Changes to push to origin:
1583 bookmark: bookmark-1 [add to 3c179a96c972]
1584 Dry-run requested, not pushing.
1585 [EOF]
1586 ");
1587 }
1588
1589 #[test]
1590 fn test_git_push_mixed() {
1591 let test_env = TestEnvironment::default();
1592 set_up(&test_env);
1593 test_env.add_config("revset-aliases.'immutable_heads()' = 'none()'");
1594 let work_dir = test_env.work_dir("local");
1595 work_dir.run_jj(["describe", "-m", "foo"]).success();
1596 work_dir.write_file("file", "contents");
1597 work_dir.run_jj(["new", "-m", "bar"]).success();
1598 work_dir
1599 .run_jj(["bookmark", "create", "-r@", "bookmark-1"])
1600 .success();
1601 work_dir.run_jj(["tag", "set", "-r@", "tag-1"]).success();
1602 work_dir.write_file("file", "modified");
1603 work_dir.run_jj(["new", "-m", "baz"]).success();
1604 work_dir
1605 .run_jj(["bookmark", "create", "-r@", "bookmark-2a"])
1606 .success();
1607 work_dir
1608 .run_jj(["bookmark", "create", "-r@", "bookmark-2b"])
1609 .success();
1610 work_dir.write_file("file", "modified again");
1611
1612 // New bookmark shouldn't be pushed by -r=..
1613 let output = work_dir.run_jj([
1614 "git",
1615 "push",
1616 "--change=@--",
1617 "--bookmark=bookmark-1",
1618 "--tag=tag-1",
1619 "-r=@",
1620 ]);
1621 insta::assert_snapshot!(output, @"
1622 ------- stderr -------
1623 Creating bookmark push-yqosqzytrlsw for revision yqosqzytrlsw
1624 Warning: Refusing to create new remote bookmark bookmark-2a@origin
1625 Hint: Run `jj bookmark track bookmark-2a@origin` and try again.
1626 Warning: Refusing to create new remote bookmark bookmark-2b@origin
1627 Hint: Run `jj bookmark track bookmark-2b@origin` and try again.
1628 Changes to push to origin:
1629 bookmark: push-yqosqzytrlsw [add to 0f8164cd580b]
1630 bookmark: bookmark-1 [add to bc7f5ebae839]
1631 tag: tag-1 [add to 9b467a2a0cdf]
1632 [EOF]
1633 ");
1634 }
1635
1636 #[test]
1637 fn test_git_push_bookmarks_and_tags_of_same_name() {
1638 let test_env = TestEnvironment::default();
1639 test_env
1640 .run_jj_in(".", ["git", "init", "--colocate", "origin"])
1641 .success();
1642 let origin_dir = test_env.work_dir("origin");
1643 origin_dir.run_jj(["describe", "-morigin"]).success();
1644 origin_dir.run_jj(["new"]).success();
1645 origin_dir
1646 .run_jj(["bookmark", "set", "-r@-", "foo", "bar"])
1647 .success();
1648 origin_dir
1649 .run_jj(["tag", "set", "-r@-", "foo", "bar"])
1650 .success();
1651 test_env
1652 .run_jj_in(".", ["git", "clone", "origin", "local"])
1653 .success();
1654 let work_dir = test_env.work_dir("local");
1655 work_dir.run_jj(["bookmark", "track", "*"]).success();
1656
1657 // Move bookmarks and tags
1658 work_dir.run_jj(["new", "foo", "-mlocal"]).success();
1659 work_dir.run_jj(["new"]).success();
1660 work_dir
1661 .run_jj(["bookmark", "set", "-r@-", "foo", "bar"])
1662 .success();
1663 work_dir
1664 .run_jj(["tag", "set", "-r@-", "--allow-move", "foo", "bar"])
1665 .success();
1666 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
1667 bar: vruxwmqv 5058996c (empty) local
1668 @origin (behind by 1 commits): qpvuntsm 110db8ed (empty) origin
1669 foo: vruxwmqv 5058996c (empty) local
1670 @origin (behind by 1 commits): qpvuntsm 110db8ed (empty) origin
1671 [EOF]
1672 ");
1673 insta::assert_snapshot!(get_tag_output(&work_dir), @"
1674 bar: vruxwmqv 5058996c (empty) local
1675 @origin (behind by 1 commits): qpvuntsm 110db8ed (empty) origin
1676 foo: vruxwmqv 5058996c (empty) local
1677 @origin (behind by 1 commits): qpvuntsm 110db8ed (empty) origin
1678 [EOF]
1679 ");
1680
1681 // Both bookmark and tag of the same name can be selected
1682 let output = work_dir.run_jj(["git", "push", "--dry-run", "--bookmark=foo", "--tag=foo"]);
1683 insta::assert_snapshot!(output, @"
1684 ------- stderr -------
1685 Changes to push to origin:
1686 bookmark: foo [move forward from 110db8edfa5f to 5058996c52e2]
1687 tag: foo [move forward from 110db8edfa5f to 5058996c52e2]
1688 Dry-run requested, not pushing.
1689 [EOF]
1690 ");
1691 let output = work_dir.run_jj(["git", "push", "--dry-run", "-r@-"]);
1692 insta::assert_snapshot!(output, @"
1693 ------- stderr -------
1694 Changes to push to origin:
1695 bookmark: bar [move forward from 110db8edfa5f to 5058996c52e2]
1696 bookmark: foo [move forward from 110db8edfa5f to 5058996c52e2]
1697 tag: bar [move forward from 110db8edfa5f to 5058996c52e2]
1698 tag: foo [move forward from 110db8edfa5f to 5058996c52e2]
1699 Dry-run requested, not pushing.
1700 [EOF]
1701 ");
1702
1703 // Bookmark and tag can be selected individually
1704 let output = work_dir.run_jj(["git", "push", "--dry-run", "--bookmark=foo", "--tag=bar"]);
1705 insta::assert_snapshot!(output, @"
1706 ------- stderr -------
1707 Changes to push to origin:
1708 bookmark: foo [move forward from 110db8edfa5f to 5058996c52e2]
1709 tag: bar [move forward from 110db8edfa5f to 5058996c52e2]
1710 Dry-run requested, not pushing.
1711 [EOF]
1712 ");
1713 }
1714
1715 #[test]
1716 fn test_git_push_allow_new_heuristics() {
1717 let test_env = TestEnvironment::default();
1718 set_up(&test_env);
1719 let work_dir = test_env.work_dir("local");
1720 test_env
1721 .run_jj_in(".", ["git", "init", "--colocate", "upstream"])
1722 .success();
1723 work_dir
1724 .run_jj([
1725 "git",
1726 "remote",
1727 "add",
1728 "upstream",
1729 test_env
1730 .work_dir("upstream")
1731 .root()
1732 .join(".git")
1733 .to_str()
1734 .unwrap(),
1735 ])
1736 .success();
1737 work_dir.run_jj(["describe", "-m", "foo"]).success();
1738 work_dir.write_file("file", "contents");
1739
1740 work_dir
1741 .run_jj(["bookmark", "create", "untracked"])
1742 .success();
1743 work_dir.run_jj(["tag", "set", "untracked"]).success();
1744
1745 let start_op = work_dir.current_operation_id();
1746
1747 // Pushing untracked refs with --bookmark/--tag automatically tracks it.
1748 let output = work_dir.run_jj(["git", "push", "--bookmark=untracked", "--tag=untracked"]);
1749 insta::assert_snapshot!(output, @"
1750 ------- stderr -------
1751 Changes to push to origin:
1752 bookmark: untracked [add to b9124726209b]
1753 tag: untracked [add to b9124726209b]
1754 [EOF]
1755 ");
1756
1757 work_dir.run_jj(["op", "restore", &start_op]).success();
1758 work_dir
1759 .run_jj([
1760 "git",
1761 "push",
1762 "--bookmark=untracked",
1763 "--tag=untracked",
1764 "--remote=upstream",
1765 ])
1766 .success();
1767
1768 // ...unless the ref is already tracked with a different remote, in
1769 // which case the user may have simply forgotten to specify --remote.
1770 let output = work_dir.run_jj(["git", "push", "--bookmark=untracked"]);
1771 insta::assert_snapshot!(output, @"
1772 ------- stderr -------
1773 Error: Refusing to create new remote bookmark untracked@origin
1774 Hint: Run `jj bookmark track untracked@origin` and try again.
1775 [EOF]
1776 [exit status: 1]
1777 ");
1778 let output = work_dir.run_jj(["git", "push", "--tag=untracked"]);
1779 insta::assert_snapshot!(output, @"
1780 ------- stderr -------
1781 Error: Refusing to create new remote tag untracked@origin
1782 Hint: Run `jj tag track untracked@origin` and try again.
1783 [EOF]
1784 [exit status: 1]
1785 ");
1786 }
1787
1788 #[test]
1789 fn test_git_push_unsnapshotted_change() {
1790 let test_env = TestEnvironment::default();
1791 set_up(&test_env);
1792 let work_dir = test_env.work_dir("local");
1793 work_dir.run_jj(["describe", "-m", "foo"]).success();
1794 work_dir.write_file("file", "contents");
1795 work_dir.run_jj(["git", "push", "--change", "@"]).success();
1796 work_dir.write_file("file", "modified");
1797 work_dir.run_jj(["git", "push", "--change", "@"]).success();
1798 }
1799
1800 #[test]
1801 fn test_git_push_conflict() {
1802 let test_env = TestEnvironment::default();
1803 set_up(&test_env);
1804 let work_dir = test_env.work_dir("local");
1805 work_dir.write_file("file", "first");
1806 work_dir.run_jj(["commit", "-m", "first"]).success();
1807 work_dir.write_file("file", "second");
1808 work_dir.run_jj(["commit", "-m", "second"]).success();
1809 work_dir.write_file("file", "third");
1810 work_dir
1811 .run_jj(["rebase", "-r", "@", "-o", "@--"])
1812 .success();
1813 work_dir
1814 .run_jj(["bookmark", "create", "-r@", "my-bookmark"])
1815 .success();
1816 work_dir.run_jj(["describe", "-m", "third"]).success();
1817 let output = work_dir.run_jj(["git", "push", "--all"]);
1818 insta::assert_snapshot!(output, @"
1819 ------- stderr -------
1820 Warning: Won't push bookmark my-bookmark: commit b96eaa9bb3d8 has conflicts
1821 yostqsxw b96eaa9b my-bookmark | (conflict) third
1822 Nothing changed.
1823 [EOF]
1824 ");
1825 work_dir
1826 .run_jj(["git", "push", "--all", "--allow-conflicts"])
1827 .success();
1828 let origin_dir = test_env.work_dir("origin");
1829 origin_dir.run_jj(["git", "import"]).success();
1830 let output = origin_dir.run_jj(["log", "-r=my-bookmark"]);
1831 insta::assert_snapshot!(output, @"
1832 × yostqsxw [email protected] 2001-02-03 08:05:18 my-bookmark b96eaa9b (conflict)
1833 │ third
1834 ~
1835 [EOF]
1836 ");
1837 }
1838
1839 #[test]
1840 fn test_git_push_no_description() {
1841 let test_env = TestEnvironment::default();
1842 set_up(&test_env);
1843 test_env.add_config("remotes.origin.auto-track-bookmarks = '*'");
1844 let work_dir = test_env.work_dir("local");
1845 work_dir
1846 .run_jj(["bookmark", "create", "-r@", "my-bookmark"])
1847 .success();
1848 work_dir.run_jj(["describe", "-m="]).success();
1849 let output = work_dir.run_jj(["git", "push", "--bookmark", "my-bookmark"]);
1850 insta::assert_snapshot!(output, @"
1851 ------- stderr -------
1852 Error: Won't push commit 8d23abddc924 since it has no description
1853 Hint: Rejected commit: yqosqzyt 8d23abdd my-bookmark* | (empty) (no description set)
1854 [EOF]
1855 [exit status: 1]
1856 ");
1857 work_dir
1858 .run_jj([
1859 "git",
1860 "push",
1861 "--bookmark",
1862 "my-bookmark",
1863 "--allow-empty-description",
1864 ])
1865 .success();
1866 }
1867
1868 #[test]
1869 fn test_git_push_no_description_in_immutable() {
1870 let test_env = TestEnvironment::default();
1871 set_up(&test_env);
1872 test_env.add_config("remotes.origin.auto-track-bookmarks = '*'");
1873 let work_dir = test_env.work_dir("local");
1874 work_dir
1875 .run_jj(["bookmark", "create", "-r@", "imm"])
1876 .success();
1877 work_dir.run_jj(["describe", "-m="]).success();
1878 work_dir.run_jj(["new", "-m", "foo"]).success();
1879 work_dir.write_file("file", "contents");
1880 work_dir
1881 .run_jj(["bookmark", "create", "-r@", "my-bookmark"])
1882 .success();
1883
1884 let output = work_dir.run_jj(["git", "push", "--bookmark=my-bookmark", "--dry-run"]);
1885 insta::assert_snapshot!(output, @"
1886 ------- stderr -------
1887 Error: Won't push commit 8d23abddc924 since it has no description
1888 Hint: Rejected commit: yqosqzyt 8d23abdd imm* | (empty) (no description set)
1889 [EOF]
1890 [exit status: 1]
1891 ");
1892
1893 test_env.add_config(r#"revset-aliases."immutable_heads()" = "imm""#);
1894 let output = work_dir.run_jj(["git", "push", "--bookmark=my-bookmark", "--dry-run"]);
1895 insta::assert_snapshot!(output, @"
1896 ------- stderr -------
1897 Changes to push to origin:
1898 bookmark: my-bookmark [add to 240e2e89abb2]
1899 Dry-run requested, not pushing.
1900 [EOF]
1901 ");
1902 }
1903
1904 #[test]
1905 fn test_git_push_missing_author() {
1906 let test_env = TestEnvironment::default();
1907 set_up(&test_env);
1908 test_env.add_config("remotes.origin.auto-track-bookmarks = '*'");
1909 let work_dir = test_env.work_dir("local");
1910 let run_without_var = |var: &str, args: &[&str]| {
1911 work_dir
1912 .run_jj_with(|cmd| cmd.args(args).env_remove(var))
1913 .success();
1914 };
1915 run_without_var("JJ_USER", &["new", "root()", "-m=initial"]);
1916 run_without_var("JJ_USER", &["bookmark", "create", "-r@", "missing-name"]);
1917 let output = work_dir.run_jj(["git", "push", "--bookmark", "missing-name"]);
1918 insta::assert_snapshot!(output, @"
1919 ------- stderr -------
1920 Error: Won't push commit 613adaba9d49 since it has no author and/or committer set
1921 Hint: Rejected commit: vruxwmqv 613adaba missing-name* | (empty) initial
1922 [EOF]
1923 [exit status: 1]
1924 ");
1925 run_without_var("JJ_EMAIL", &["new", "root()", "-m=initial"]);
1926 run_without_var("JJ_EMAIL", &["bookmark", "create", "-r@", "missing-email"]);
1927 let output = work_dir.run_jj(["git", "push", "--bookmark=missing-email"]);
1928 insta::assert_snapshot!(output, @"
1929 ------- stderr -------
1930 Error: Won't push commit bb4ea60fc9ba since it has no author and/or committer set
1931 Hint: Rejected commit: kpqxywon bb4ea60f missing-email* | (empty) initial
1932 [EOF]
1933 [exit status: 1]
1934 ");
1935 }
1936
1937 #[test]
1938 fn test_git_push_missing_author_in_immutable() {
1939 let test_env = TestEnvironment::default();
1940 set_up(&test_env);
1941 test_env.add_config("remotes.origin.auto-track-bookmarks = '*'");
1942 let work_dir = test_env.work_dir("local");
1943 let run_without_var = |var: &str, args: &[&str]| {
1944 work_dir
1945 .run_jj_with(|cmd| cmd.args(args).env_remove(var))
1946 .success();
1947 };
1948 run_without_var("JJ_USER", &["new", "root()", "-m=no author name"]);
1949 run_without_var("JJ_EMAIL", &["new", "-m=no author email"]);
1950 work_dir
1951 .run_jj(["bookmark", "create", "-r@", "imm"])
1952 .success();
1953 work_dir.run_jj(["new", "-m", "foo"]).success();
1954 work_dir.write_file("file", "contents");
1955 work_dir
1956 .run_jj(["bookmark", "create", "-r@", "my-bookmark"])
1957 .success();
1958
1959 let output = work_dir.run_jj(["git", "push", "--bookmark=my-bookmark", "--dry-run"]);
1960 insta::assert_snapshot!(output, @"
1961 ------- stderr -------
1962 Error: Won't push commit 5c3cc711907f since it has no author and/or committer set
1963 Hint: Rejected commit: yostqsxw 5c3cc711 imm* | (empty) no author email
1964 [EOF]
1965 [exit status: 1]
1966 ");
1967
1968 test_env.add_config(r#"revset-aliases."immutable_heads()" = "imm""#);
1969 let output = work_dir.run_jj(["git", "push", "--bookmark=my-bookmark", "--dry-run"]);
1970 insta::assert_snapshot!(output, @"
1971 ------- stderr -------
1972 Changes to push to origin:
1973 bookmark: my-bookmark [add to 96080b93b4ce]
1974 Dry-run requested, not pushing.
1975 [EOF]
1976 ");
1977 }
1978
1979 #[test]
1980 fn test_git_push_missing_committer() {
1981 let test_env = TestEnvironment::default();
1982 set_up(&test_env);
1983 test_env.add_config("remotes.origin.auto-track-bookmarks = '*'");
1984 let work_dir = test_env.work_dir("local");
1985 let run_without_var = |var: &str, args: &[&str]| {
1986 work_dir
1987 .run_jj_with(|cmd| cmd.args(args).env_remove(var))
1988 .success();
1989 };
1990 work_dir
1991 .run_jj(["bookmark", "create", "-r@", "missing-name"])
1992 .success();
1993 run_without_var("JJ_USER", &["describe", "-m=no committer name"]);
1994 let output = work_dir.run_jj(["git", "push", "--bookmark=missing-name"]);
1995 insta::assert_snapshot!(output, @"
1996 ------- stderr -------
1997 Error: Won't push commit e8a77cb24da9 since it has no author and/or committer set
1998 Hint: Rejected commit: yqosqzyt e8a77cb2 missing-name* | (empty) no committer name
1999 [EOF]
2000 [exit status: 1]
2001 ");
2002 work_dir.run_jj(["new", "root()"]).success();
2003 work_dir
2004 .run_jj(["bookmark", "create", "-r@", "missing-email"])
2005 .success();
2006 run_without_var("JJ_EMAIL", &["describe", "-m=no committer email"]);
2007 let output = work_dir.run_jj(["git", "push", "--bookmark=missing-email"]);
2008 insta::assert_snapshot!(output, @"
2009 ------- stderr -------
2010 Error: Won't push commit 971c50fd8d1d since it has no author and/or committer set
2011 Hint: Rejected commit: kpqxywon 971c50fd missing-email* | (empty) no committer email
2012 [EOF]
2013 [exit status: 1]
2014 ");
2015
2016 // Test message when there are multiple reasons (missing committer and
2017 // description)
2018 run_without_var("JJ_EMAIL", &["describe", "-m=", "missing-email"]);
2019 let output = work_dir.run_jj(["git", "push", "--bookmark=missing-email"]);
2020 insta::assert_snapshot!(output, @"
2021 ------- stderr -------
2022 Error: Won't push commit 4bd3b55c7759 since it has no description and has no author and/or committer set
2023 Hint: Rejected commit: kpqxywon 4bd3b55c missing-email* | (empty) (no description set)
2024 [EOF]
2025 [exit status: 1]
2026 ");
2027 }
2028
2029 #[test]
2030 fn test_git_push_missing_committer_in_immutable() {
2031 let test_env = TestEnvironment::default();
2032 set_up(&test_env);
2033 test_env.add_config("remotes.origin.auto-track-bookmarks = '*'");
2034 let work_dir = test_env.work_dir("local");
2035 let run_without_var = |var: &str, args: &[&str]| {
2036 work_dir
2037 .run_jj_with(|cmd| cmd.args(args).env_remove(var))
2038 .success();
2039 };
2040 run_without_var("JJ_USER", &["describe", "-m=no committer name"]);
2041 work_dir.run_jj(["new"]).success();
2042 run_without_var("JJ_EMAIL", &["describe", "-m=no committer email"]);
2043 work_dir
2044 .run_jj(["bookmark", "create", "-r@", "imm"])
2045 .success();
2046 work_dir.run_jj(["new", "-m", "foo"]).success();
2047 work_dir.write_file("file", "contents");
2048 work_dir
2049 .run_jj(["bookmark", "create", "-r@", "my-bookmark"])
2050 .success();
2051
2052 let output = work_dir.run_jj(["git", "push", "--bookmark=my-bookmark", "--dry-run"]);
2053 insta::assert_snapshot!(output, @"
2054 ------- stderr -------
2055 Error: Won't push commit ab230f98c812 since it has no author and/or committer set
2056 Hint: Rejected commit: yostqsxw ab230f98 imm* | (empty) no committer email
2057 [EOF]
2058 [exit status: 1]
2059 ");
2060
2061 test_env.add_config(r#"revset-aliases."immutable_heads()" = "imm""#);
2062 let output = work_dir.run_jj(["git", "push", "--bookmark=my-bookmark", "--dry-run"]);
2063 insta::assert_snapshot!(output, @"
2064 ------- stderr -------
2065 Changes to push to origin:
2066 bookmark: my-bookmark [add to e0dff9c29479]
2067 Dry-run requested, not pushing.
2068 [EOF]
2069 ");
2070 }
2071
2072 #[test]
2073 fn test_git_push_deleted() {
2074 let test_env = TestEnvironment::default();
2075 set_up(&test_env);
2076 let origin_dir = test_env.work_dir("origin");
2077 let work_dir = test_env.work_dir("local");
2078 // Add tracked tag
2079 origin_dir
2080 .run_jj(["tag", "set", "tag1", "-rbookmark1"])
2081 .success();
2082 origin_dir.run_jj(["git", "export"]).success();
2083 work_dir.run_jj(["git", "fetch", "--tag=*"]).success();
2084
2085 work_dir
2086 .run_jj(["bookmark", "delete", "bookmark1"])
2087 .success();
2088 work_dir.run_jj(["tag", "delete", "tag1"]).success();
2089 let output = work_dir.run_jj(["git", "push", "--deleted"]);
2090 insta::assert_snapshot!(output, @"
2091 ------- stderr -------
2092 Changes to push to origin:
2093 bookmark: bookmark1 [delete from 9b2e76de3920]
2094 tag: tag1 [delete from 9b2e76de3920]
2095 [EOF]
2096 ");
2097 let output = work_dir.run_jj(["log", "-rall()"]);
2098 insta::assert_snapshot!(output, @"
2099 @ yqosqzyt [email protected] 2001-02-03 08:05:13 8d23abdd
2100 │ (empty) (no description set)
2101 │ ○ zsuskuln [email protected] 2001-02-03 08:05:10 bookmark2 38a20473
2102 ├─╯ (empty) description 2
2103 │ ○ qpvuntsm [email protected] 2001-02-03 08:05:08 9b2e76de
2104 ├─╯ (empty) description 1
2105 ◆ zzzzzzzz root() 00000000
2106 [EOF]
2107 ");
2108 let output = work_dir.run_jj(["git", "push", "--deleted"]);
2109 insta::assert_snapshot!(output, @"
2110 ------- stderr -------
2111 Nothing changed.
2112 [EOF]
2113 ");
2114 }
2115
2116 #[test]
2117 fn test_git_push_conflicting_bookmarks() -> TestResult {
2118 let test_env = TestEnvironment::default();
2119 set_up(&test_env);
2120 let work_dir = test_env.work_dir("local");
2121 test_env.add_config("remotes.origin.auto-track-bookmarks = '*'");
2122 let git_repo = {
2123 let mut git_repo_path = work_dir.root().to_owned();
2124 git_repo_path.extend([".jj", "repo", "store", "git"]);
2125 git::open(&git_repo_path)
2126 };
2127
2128 // Forget remote ref, move local ref, then fetch to create conflict.
2129 git_repo
2130 .find_reference("refs/remotes/origin/bookmark2")?
2131 .delete()?;
2132 work_dir.run_jj(["git", "import"]).success();
2133 work_dir
2134 .run_jj(["new", "root()", "-m=description 3"])
2135 .success();
2136 work_dir
2137 .run_jj(["bookmark", "create", "-r@", "bookmark2"])
2138 .success();
2139 work_dir.run_jj(["git", "fetch"]).success();
2140 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
2141 bookmark1: qpvuntsm 9b2e76de (empty) description 1
2142 @origin: qpvuntsm 9b2e76de (empty) description 1
2143 bookmark2 (conflicted):
2144 + yostqsxw ebedbe63 (empty) description 3
2145 + zsuskuln 38a20473 (empty) description 2
2146 @origin (behind by 1 commits): zsuskuln 38a20473 (empty) description 2
2147 [EOF]
2148 ");
2149
2150 let bump_bookmark1 = || {
2151 work_dir.run_jj(["new", "bookmark1", "-m=bump"]).success();
2152 work_dir
2153 .run_jj(["bookmark", "set", "bookmark1", "-r@"])
2154 .success();
2155 };
2156
2157 // Conflicting bookmark at @
2158 let output = work_dir.run_jj(["git", "push"]);
2159 insta::assert_snapshot!(output, @"
2160 ------- stderr -------
2161 Warning: Bookmark bookmark2 is conflicted
2162 Hint: Run `jj bookmark list` to inspect, and use `jj bookmark set` to fix it up.
2163 Nothing changed.
2164 [EOF]
2165 ");
2166
2167 // --bookmark should be blocked by conflicting bookmark
2168 let output = work_dir.run_jj(["git", "push", "--bookmark", "bookmark2"]);
2169 insta::assert_snapshot!(output, @"
2170 ------- stderr -------
2171 Error: Bookmark bookmark2 is conflicted
2172 Hint: Run `jj bookmark list` to inspect, and use `jj bookmark set` to fix it up.
2173 [EOF]
2174 [exit status: 1]
2175 ");
2176
2177 // --all shouldn't be blocked by conflicting bookmark
2178 bump_bookmark1();
2179 let output = work_dir.run_jj(["git", "push", "--all"]);
2180 insta::assert_snapshot!(output, @"
2181 ------- stderr -------
2182 Warning: Bookmark bookmark2 is conflicted
2183 Hint: Run `jj bookmark list` to inspect, and use `jj bookmark set` to fix it up.
2184 Changes to push to origin:
2185 bookmark: bookmark1 [move forward from 9b2e76de3920 to 749c2e6d999f]
2186 [EOF]
2187 ");
2188
2189 // --revisions shouldn't be blocked by conflicting bookmark
2190 bump_bookmark1();
2191 let output = work_dir.run_jj(["git", "push", "-rall()"]);
2192 insta::assert_snapshot!(output, @"
2193 ------- stderr -------
2194 Warning: Bookmark bookmark2 is conflicted
2195 Hint: Run `jj bookmark list` to inspect, and use `jj bookmark set` to fix it up.
2196 Changes to push to origin:
2197 bookmark: bookmark1 [move forward from 749c2e6d999f to 9bb0f427b517]
2198 [EOF]
2199 ");
2200 Ok(())
2201 }
2202
2203 #[test]
2204 fn test_git_push_deleted_untracked() {
2205 let test_env = TestEnvironment::default();
2206 set_up(&test_env);
2207 let work_dir = test_env.work_dir("local");
2208
2209 // Absent local bookmark shouldn't be considered "deleted" compared to
2210 // non-tracking remote bookmark.
2211 // TODO: include tag if we add "tag untrack" command
2212 work_dir
2213 .run_jj(["bookmark", "delete", "bookmark1"])
2214 .success();
2215 work_dir
2216 .run_jj(["bookmark", "untrack", "bookmark1"])
2217 .success();
2218 let output = work_dir.run_jj(["git", "push", "--deleted"]);
2219 insta::assert_snapshot!(output, @"
2220 ------- stderr -------
2221 Nothing changed.
2222 [EOF]
2223 ");
2224 let output = work_dir.run_jj(["git", "push", "--bookmark=bookmark1"]);
2225 insta::assert_snapshot!(output, @"
2226 ------- stderr -------
2227 Warning: No matching bookmarks for names: bookmark1
2228 Nothing changed.
2229 [EOF]
2230 ");
2231 }
2232
2233 #[test]
2234 fn test_git_push_deleted_remote_conflict() {
2235 let test_env = TestEnvironment::default();
2236
2237 // create origin
2238 test_env.run_jj_in(".", ["git", "init", "origin"]).success();
2239 let origin_dir = test_env.work_dir("origin");
2240 let origin_git_repo_path = git_repo_dir_for_jj_repo(&origin_dir);
2241 origin_dir
2242 .run_jj(["describe", "-m=description 1"])
2243 .success();
2244 origin_dir
2245 .run_jj(["bookmark", "create", "-r@", "my-bookmark"])
2246 .success();
2247 origin_dir.run_jj(["git", "export"]).success();
2248
2249 // clone without colocation
2250 test_env
2251 .run_jj_in(
2252 ".",
2253 [
2254 "git",
2255 "clone",
2256 "--no-colocate",
2257 "--config=remotes.origin.auto-track-bookmarks='*'",
2258 origin_git_repo_path.to_str().unwrap(),
2259 "local",
2260 ],
2261 )
2262 .success();
2263 let work_dir = test_env.work_dir("local");
2264
2265 // advance the origin, fetch it
2266 let origin_dir = test_env.work_dir("origin");
2267 origin_dir.run_jj(["new", "-m", "description 2"]).success();
2268 origin_dir
2269 .run_jj(["bookmark", "move", "my-bookmark", "--to", "@"])
2270 .success();
2271 origin_dir.run_jj(["git", "export"]).success();
2272 work_dir.run_jj(["git", "fetch"]).success();
2273
2274 // adjust the origin again, fetch concurrently
2275 let origin_dir = test_env.work_dir("origin");
2276 origin_dir
2277 .run_jj(["new", "root()", "-m", "description 3"])
2278 .success();
2279 origin_dir
2280 .run_jj([
2281 "bookmark",
2282 "move",
2283 "my-bookmark",
2284 "--to",
2285 "@",
2286 "--allow-backwards",
2287 ])
2288 .success();
2289 origin_dir.run_jj(["git", "export"]).success();
2290 work_dir.run_jj(["git", "fetch", "--at-op=@-"]).success();
2291 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
2292 my-bookmark (conflicted):
2293 - qpvuntsm/0 9b2e76de (hidden) (empty) description 1
2294 + royxmykx d7d20286 (empty) description 2
2295 + znkkpsqq 7b393945 (empty) description 3
2296 @origin (ahead by 2 commits, behind by 1 commits) (conflicted):
2297 - qpvuntsm/0 9b2e76de (hidden) (empty) description 1
2298 + royxmykx/1 8a615f93 (hidden) (empty) description 2
2299 + znkkpsqq 7b393945 (empty) description 3
2300 [EOF]
2301 ");
2302
2303 // fix the local conflict, unpushable remote conflict remains
2304 work_dir
2305 .run_jj(["bookmark", "delete", "my-bookmark"])
2306 .success();
2307 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
2308 my-bookmark (deleted)
2309 @origin (conflicted):
2310 - qpvuntsm/0 9b2e76de (hidden) (empty) description 1
2311 + royxmykx/1 8a615f93 (hidden) (empty) description 2
2312 + znkkpsqq 7b393945 (empty) description 3
2313 [EOF]
2314 ");
2315 let output = work_dir.run_jj(["git", "push", "--deleted"]);
2316 insta::assert_snapshot!(output, @"
2317 ------- stderr -------
2318 Warning: Bookmark my-bookmark@origin is conflicted
2319 Hint: Run `jj git fetch` to update the conflicted remote bookmark.
2320 Nothing changed.
2321 [EOF]
2322 ");
2323 }
2324
2325 #[test]
2326 fn test_git_push_tracked_vs_all() {
2327 let test_env = TestEnvironment::default();
2328 set_up(&test_env);
2329 test_env.add_config("revset-aliases.'immutable_heads()' = 'none()'");
2330 let origin_dir = test_env.work_dir("origin");
2331 let work_dir = test_env.work_dir("local");
2332 // Add tracked tag
2333 origin_dir
2334 .run_jj(["tag", "set", "tag1", "-rbookmark1"])
2335 .success();
2336 origin_dir
2337 .run_jj(["tag", "set", "tag2", "-rbookmark2"])
2338 .success();
2339 origin_dir.run_jj(["git", "export"]).success();
2340 work_dir.run_jj(["git", "fetch", "--tag=*"]).success();
2341 // Update bookmarks and tags
2342 work_dir
2343 .run_jj(["new", "bookmark1", "-mmoved bookmark1"])
2344 .success();
2345 work_dir
2346 .run_jj(["bookmark", "set", "bookmark1", "-r@"])
2347 .success();
2348 work_dir
2349 .run_jj(["new", "bookmark2", "-mmoved bookmark2"])
2350 .success();
2351 work_dir
2352 .run_jj(["bookmark", "delete", "bookmark2"])
2353 .success();
2354 work_dir.run_jj(["tag", "delete", "tag2"]).success();
2355 work_dir
2356 .run_jj(["bookmark", "untrack", "bookmark1"])
2357 .success();
2358 work_dir
2359 .run_jj(["bookmark", "create", "-r@", "bookmark3"])
2360 .success();
2361 work_dir.run_jj(["tag", "set", "-r@", "tag3"]).success();
2362 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
2363 bookmark1: kmkuslsw f8cde667 (empty) moved bookmark1
2364 bookmark1@origin: qpvuntsm 9b2e76de (empty) description 1
2365 bookmark2 (deleted)
2366 @origin: zsuskuln 38a20473 (empty) description 2
2367 bookmark3: lylxulpl db4b9518 (empty) moved bookmark2
2368 [EOF]
2369 ");
2370 insta::assert_snapshot!(get_tag_output(&work_dir), @"
2371 tag1: qpvuntsm 9b2e76de (empty) description 1
2372 @origin: qpvuntsm 9b2e76de (empty) description 1
2373 tag2 (deleted)
2374 @origin: zsuskuln 38a20473 (empty) description 2
2375 tag3: lylxulpl db4b9518 (empty) moved bookmark2
2376 [EOF]
2377 ");
2378
2379 // At this point, only bookmark2 and tags are still tracked.
2380 // `jj git push --tracked --deleted` would try to push them and no other
2381 // bookmarks nor tags.
2382 let output = work_dir.run_jj(["git", "push", "--tracked", "--dry-run"]);
2383 insta::assert_snapshot!(output, @"
2384 ------- stderr -------
2385 Warning: Refusing to push deleted bookmark bookmark2
2386 Hint: Push deleted bookmarks with --deleted or forget the bookmark to suppress this warning.
2387 Warning: Refusing to push deleted tag tag2
2388 Hint: Push deleted tags with --deleted.
2389 Nothing changed.
2390 [EOF]
2391 ");
2392 let output = work_dir.run_jj(["git", "push", "--tracked", "--deleted", "--dry-run"]);
2393 insta::assert_snapshot!(output, @"
2394 ------- stderr -------
2395 Changes to push to origin:
2396 bookmark: bookmark2 [delete from 38a204733702]
2397 tag: tag2 [delete from 38a204733702]
2398 Dry-run requested, not pushing.
2399 [EOF]
2400 ");
2401
2402 // Untrack the last remaining tracked bookmark.
2403 work_dir
2404 .run_jj(["bookmark", "untrack", "bookmark2"])
2405 .success();
2406 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
2407 bookmark1: kmkuslsw f8cde667 (empty) moved bookmark1
2408 bookmark1@origin: qpvuntsm 9b2e76de (empty) description 1
2409 bookmark2@origin: zsuskuln 38a20473 (empty) description 2
2410 bookmark3: lylxulpl db4b9518 (empty) moved bookmark2
2411 [EOF]
2412 ");
2413
2414 // Now, no bookmarks are tracked. --tracked would push tags only
2415 let output = work_dir.run_jj(["git", "push", "--tracked"]);
2416 insta::assert_snapshot!(output, @"
2417 ------- stderr -------
2418 Warning: Refusing to push deleted tag tag2
2419 Hint: Push deleted tags with --deleted.
2420 Nothing changed.
2421 [EOF]
2422 ");
2423
2424 // All bookmarks are still untracked.
2425 // - --all tries to push bookmark1, but fails because a bookmark with the same
2426 // name exist on the remote.
2427 // - --all succeeds in pushing bookmark3, since there is no bookmark of the same
2428 // name on the remote.
2429 // - It does not try to push bookmark2.
2430 //
2431 // TODO: Not trying to push bookmark2 could be considered correct, or perhaps
2432 // we want to consider this as a deletion of the bookmark that failed because
2433 // the bookmark was untracked. In the latter case, an error message should be
2434 // printed. Some considerations:
2435 // - Whatever we do should be consistent with what `jj bookmark list` does; it
2436 // currently does *not* list bookmarks like bookmark2 as "about to be
2437 // deleted", as can be seen above.
2438 // - We could consider showing some hint on `jj bookmark untrack bookmark2
2439 // --remote=origin` instead of showing an error here.
2440 let output = work_dir.run_jj(["git", "push", "--all"]);
2441 insta::assert_snapshot!(output, @"
2442 ------- stderr -------
2443 Warning: Non-tracking remote bookmark bookmark1@origin exists
2444 Hint: Run `jj bookmark track bookmark1@origin` to import the remote bookmark.
2445 Warning: Refusing to push deleted tag tag2
2446 Hint: Push deleted tags with --deleted.
2447 Changes to push to origin:
2448 bookmark: bookmark3 [add to db4b95184aca]
2449 tag: tag3 [add to db4b95184aca]
2450 [EOF]
2451 ");
2452 }
2453
2454 #[test]
2455 fn test_git_push_moved_forward_untracked() {
2456 let test_env = TestEnvironment::default();
2457 set_up(&test_env);
2458 let work_dir = test_env.work_dir("local");
2459
2460 work_dir
2461 .run_jj(["new", "bookmark1", "-mmoved bookmark1"])
2462 .success();
2463 work_dir
2464 .run_jj(["bookmark", "set", "bookmark1", "-r@"])
2465 .success();
2466 work_dir
2467 .run_jj(["bookmark", "untrack", "bookmark1"])
2468 .success();
2469 let output = work_dir.run_jj(["git", "push"]);
2470 insta::assert_snapshot!(output, @"
2471 ------- stderr -------
2472 Warning: Non-tracking remote bookmark bookmark1@origin exists
2473 Hint: Run `jj bookmark track bookmark1@origin` to import the remote bookmark.
2474 Nothing changed.
2475 [EOF]
2476 ");
2477 }
2478
2479 #[test]
2480 fn test_git_push_moved_sideways_untracked() {
2481 let test_env = TestEnvironment::default();
2482 set_up(&test_env);
2483 let work_dir = test_env.work_dir("local");
2484
2485 work_dir
2486 .run_jj(["new", "root()", "-mmoved bookmark1"])
2487 .success();
2488 work_dir
2489 .run_jj(["bookmark", "set", "--allow-backwards", "bookmark1", "-r@"])
2490 .success();
2491 work_dir
2492 .run_jj(["bookmark", "untrack", "bookmark1"])
2493 .success();
2494 let output = work_dir.run_jj(["git", "push"]);
2495 insta::assert_snapshot!(output, @"
2496 ------- stderr -------
2497 Warning: Non-tracking remote bookmark bookmark1@origin exists
2498 Hint: Run `jj bookmark track bookmark1@origin` to import the remote bookmark.
2499 Nothing changed.
2500 [EOF]
2501 ");
2502 }
2503
2504 #[test]
2505 fn test_git_push_to_remote_named_git() {
2506 let test_env = TestEnvironment::default();
2507 set_up(&test_env);
2508 let work_dir = test_env.work_dir("local");
2509 let git_repo_path = {
2510 let mut git_repo_path = work_dir.root().to_owned();
2511 git_repo_path.extend([".jj", "repo", "store", "git"]);
2512 git_repo_path
2513 };
2514 git::rename_remote(&git_repo_path, "origin", "git");
2515
2516 let output = work_dir.run_jj(["git", "push", "--all", "--remote=git"]);
2517 insta::assert_snapshot!(output, @"
2518 ------- stderr -------
2519 Changes to push to git:
2520 bookmark: bookmark1 [add to 9b2e76de3920]
2521 bookmark: bookmark2 [add to 38a204733702]
2522 Error: Git remote named 'git' is reserved for local Git repository
2523 Hint: Run `jj git remote rename` to give a different name.
2524 [EOF]
2525 [exit status: 1]
2526 ");
2527 }
2528
2529 #[test]
2530 fn test_git_push_to_remote_with_slashes() {
2531 let test_env = TestEnvironment::default();
2532 set_up(&test_env);
2533 let work_dir = test_env.work_dir("local");
2534 let git_repo_path = {
2535 let mut git_repo_path = work_dir.root().to_owned();
2536 git_repo_path.extend([".jj", "repo", "store", "git"]);
2537 git_repo_path
2538 };
2539 git::rename_remote(&git_repo_path, "origin", "slash/origin");
2540
2541 let output = work_dir.run_jj(["git", "push", "--all", "--remote=slash/origin"]);
2542 insta::assert_snapshot!(output, @"
2543 ------- stderr -------
2544 Changes to push to slash/origin:
2545 bookmark: bookmark1 [add to 9b2e76de3920]
2546 bookmark: bookmark2 [add to 38a204733702]
2547 Error: Git remotes with slashes are incompatible with jj: slash/origin
2548 Hint: Run `jj git remote rename` to give a different name.
2549 [EOF]
2550 [exit status: 1]
2551 ");
2552 }
2553
2554 #[test]
2555 fn test_git_push_commits_not_ready() {
2556 let test_env = TestEnvironment::default();
2557 set_up(&test_env);
2558 let work_dir = test_env.work_dir("local");
2559 work_dir
2560 .run_jj(["new", "bookmark2", "-m", "commit not suitable"])
2561 .success();
2562 work_dir
2563 .run_jj(["bookmark", "set", "bookmark2", "-r@"])
2564 .success();
2565
2566 // ready to push
2567 let output = work_dir.run_jj(["git", "push", "--dry-run"]);
2568 insta::assert_snapshot!(output, @"
2569 ------- stderr -------
2570 Changes to push to origin:
2571 bookmark: bookmark2 [move forward from 38a204733702 to 9e7e2853b980]
2572 Dry-run requested, not pushing.
2573 [EOF]
2574 ");
2575
2576 // rejected with empty username
2577 work_dir
2578 .run_jj_with(|cmd| {
2579 cmd.args(["metaedit", "--update-author"])
2580 .env_remove("JJ_USER")
2581 })
2582 .success();
2583 let output = work_dir.run_jj(["git", "push"]);
2584 insta::assert_snapshot!(output, @"
2585 ------- stderr -------
2586 Warning: Won't push bookmark bookmark2: commit b63db0e60f60 has no author and/or committer set
2587 vruxwmqv b63db0e6 bookmark2* | (empty) commit not suitable
2588 Nothing changed.
2589 [EOF]
2590 ");
2591
2592 // rejected for both private content and empty username
2593 let output = work_dir.run_jj(["git", "push", "--config", "git.private-commits=all()"]);
2594 insta::assert_snapshot!(output, @"
2595 ------- stderr -------
2596 Warning: Won't push bookmark bookmark2: commit b63db0e60f60 has no author and/or committer set and is private
2597 vruxwmqv b63db0e6 bookmark2* | (empty) commit not suitable
2598 Hint: Configured git.private-commits: 'all()'
2599 Nothing changed.
2600 [EOF]
2601 ");
2602
2603 // still rejected even with --allow-private
2604 let output = work_dir.run_jj([
2605 "git",
2606 "push",
2607 "--config",
2608 "git.private-commits=all()",
2609 "--allow-private",
2610 ]);
2611 insta::assert_snapshot!(output, @"
2612 ------- stderr -------
2613 Warning: Won't push bookmark bookmark2: commit b63db0e60f60 has no author and/or committer set
2614 vruxwmqv b63db0e6 bookmark2* | (empty) commit not suitable
2615 Nothing changed.
2616 [EOF]
2617 ");
2618 }
2619
2620 #[test]
2621 fn test_git_push_sign_on_push() {
2622 let test_env = TestEnvironment::default();
2623 set_up(&test_env);
2624 let work_dir = test_env.work_dir("local");
2625 let template = r#"
2626 separate("\n",
2627 description.first_line(),
2628 if(signature,
2629 separate(", ",
2630 "Signature: " ++ signature.display(),
2631 "Status: " ++ signature.status(),
2632 "Key: " ++ signature.key(),
2633 )
2634 )
2635 )
2636 "#;
2637 work_dir
2638 .run_jj(["new", "bookmark2", "-m", "commit to be signed 1"])
2639 .success();
2640 work_dir
2641 .run_jj(["new", "-m", "commit to be signed 2"])
2642 .success();
2643 work_dir
2644 .run_jj(["bookmark", "set", "bookmark2", "-r@"])
2645 .success();
2646 work_dir
2647 .run_jj(["new", "-m", "commit which should not be signed 1"])
2648 .success();
2649 work_dir
2650 .run_jj(["new", "-m", "commit which should not be signed 2"])
2651 .success();
2652 // There should be no signed commits initially
2653 let output = work_dir.run_jj(["log", "-T", template]);
2654 insta::assert_snapshot!(output, @"
2655 @ commit which should not be signed 2
2656 ○ commit which should not be signed 1
2657 ○ commit to be signed 2
2658 ○ commit to be signed 1
2659 ○ description 2
2660 │ ○ description 1
2661 ├─╯
2662 ◆
2663 [EOF]
2664 ");
2665 test_env.add_config(
2666 r#"
2667 signing.backend = "test"
2668 signing.key = "impeccable"
2669 git.sign-on-push = true
2670 "#,
2671 );
2672 let output = work_dir.run_jj(["git", "push", "--dry-run"]);
2673 insta::assert_snapshot!(output, @"
2674 ------- stderr -------
2675 Changes to push to origin:
2676 bookmark: bookmark2 [move forward from 38a204733702 to 3779ed7f18df]
2677 Dry-run requested, not pushing.
2678 [EOF]
2679 ");
2680 // There should be no signed commits after performing a dry run
2681 let output = work_dir.run_jj(["log", "-T", template]);
2682 insta::assert_snapshot!(output, @"
2683 @ commit which should not be signed 2
2684 ○ commit which should not be signed 1
2685 ○ commit to be signed 2
2686 ○ commit to be signed 1
2687 ○ description 2
2688 │ ○ description 1
2689 ├─╯
2690 ◆
2691 [EOF]
2692 ");
2693 let output = work_dir.run_jj(["git", "push"]);
2694 insta::assert_snapshot!(output, @r"
2695 ------- stderr -------
2696 Updated signatures of 2 commits.
2697 Rebased 2 descendant commits.
2698 Changes to push to origin:
2699 bookmark: bookmark2 [move forward from 38a204733702 to d45e2adce0ad]
2700 Working copy (@) now at: kmkuslsw 3d5a9465 (empty) commit which should not be signed 2
2701 Parent commit (@-) : kpqxywon 48ea83e9 (empty) commit which should not be signed 1
2702 [EOF]
2703 ");
2704 // Only commits which are being pushed should be signed
2705 let output = work_dir.run_jj(["log", "-T", template]);
2706 insta::assert_snapshot!(output, @"
2707 @ commit which should not be signed 2
2708 ○ commit which should not be signed 1
2709 ○ commit to be signed 2
2710 │ Signature: test-display, Status: good, Key: impeccable
2711 ○ commit to be signed 1
2712 │ Signature: test-display, Status: good, Key: impeccable
2713 ○ description 2
2714 │ ○ description 1
2715 ├─╯
2716 ◆
2717 [EOF]
2718 ");
2719
2720 // Immutable commits should not be signed
2721 let output = work_dir.run_jj(["bookmark", "move", "bookmark2", "--to", "@-"]);
2722 insta::assert_snapshot!(output, @"
2723 ------- stderr -------
2724 Moved 1 bookmarks to kpqxywon 48ea83e9 bookmark2* | (empty) commit which should not be signed 1
2725 [EOF]
2726 ");
2727 test_env.add_config(r#"revset-aliases."immutable_heads()" = "bookmark2""#);
2728 let output = work_dir.run_jj(["git", "push"]);
2729 insta::assert_snapshot!(output, @"
2730 ------- stderr -------
2731 Warning: Skipped signing 1 immutable commits:
2732 kpqxywon 48ea83e9 bookmark2* | (empty) commit which should not be signed 1
2733 Changes to push to origin:
2734 bookmark: bookmark2 [move forward from d45e2adce0ad to 48ea83e9499c]
2735 [EOF]
2736 ");
2737 let output = work_dir.run_jj(["log", "-T", template, "-r", "::"]);
2738 insta::assert_snapshot!(output, @"
2739 @ commit which should not be signed 2
2740 ◆ commit which should not be signed 1
2741 ◆ commit to be signed 2
2742 │ Signature: test-display, Status: good, Key: impeccable
2743 ◆ commit to be signed 1
2744 │ Signature: test-display, Status: good, Key: impeccable
2745 ◆ description 2
2746 │ ○ description 1
2747 ├─╯
2748 ◆
2749 [EOF]
2750 ");
2751
2752 // Do not sign commits from other authors or re-sign unnecessarily
2753 work_dir
2754 .run_jj([
2755 "metaedit",
2756 "--author",
2757 "Test User <[email protected]>",
2758 ])
2759 .success();
2760 work_dir
2761 .run_jj(["new", "-B@", "--no-edit", "-m", "pre-signed commit"])
2762 .success();
2763 work_dir.run_jj(["sign", "-r", "@-"]).success();
2764 work_dir
2765 .run_jj(["new", "-m", "commit to be signed 3"])
2766 .success();
2767 work_dir
2768 .run_jj(["bookmark", "set", "bookmark1", "-r@", "--allow-backwards"])
2769 .success();
2770 let output = work_dir.run_jj(["log", "-T", template]);
2771 insta::assert_snapshot!(output, @"
2772 @ commit to be signed 3
2773 ○ commit which should not be signed 2
2774 ○ pre-signed commit
2775 │ Signature: test-display, Status: good, Key: impeccable
2776 ◆ commit which should not be signed 1
2777 ~ (elided revisions)
2778 │ ○ description 1
2779 ├─╯
2780 ◆
2781 [EOF]
2782 ");
2783 let output = work_dir.run_jj(["git", "push"]);
2784 insta::assert_snapshot!(output, @r"
2785 ------- stderr -------
2786 Updated signatures of 1 commits.
2787 Changes to push to origin:
2788 bookmark: bookmark1 [move sideways from 9b2e76de3920 to 0617b6813c01]
2789 Working copy (@) now at: pzsxstzt 0617b681 bookmark1 | (empty) commit to be signed 3
2790 Parent commit (@-) : kmkuslsw 5114df95 (empty) commit which should not be signed 2
2791 [EOF]
2792 ");
2793 let output = work_dir.run_jj(["log", "-T", template]);
2794 insta::assert_snapshot!(output, @"
2795 @ commit to be signed 3
2796 │ Signature: test-display, Status: good, Key: impeccable
2797 ○ commit which should not be signed 2
2798 ○ pre-signed commit
2799 │ Signature: test-display, Status: good, Key: impeccable
2800 ◆ commit which should not be signed 1
2801 ~ (elided revisions)
2802 │ ○ description 1
2803 ├─╯
2804 ◆
2805 [EOF]
2806 ");
2807 }
2808
2809 #[test]
2810 fn test_git_push_rejected_by_remote() -> TestResult {
2811 let test_env = TestEnvironment::default();
2812 set_up(&test_env);
2813 let work_dir = test_env.work_dir("local");
2814 // show repo state
2815 insta::assert_snapshot!(get_bookmark_output(&work_dir), @"
2816 bookmark1: qpvuntsm 9b2e76de (empty) description 1
2817 @origin: qpvuntsm 9b2e76de (empty) description 1
2818 bookmark2: zsuskuln 38a20473 (empty) description 2
2819 @origin: zsuskuln 38a20473 (empty) description 2
2820 [EOF]
2821 ");
2822
2823 // create a hook on the remote that prevents pushing
2824 let hook_path = test_env
2825 .env_root()
2826 .join("origin")
2827 .join(".jj")
2828 .join("repo")
2829 .join("store")
2830 .join("git")
2831 .join("hooks")
2832 .join("update");
2833
2834 std::fs::write(&hook_path, "#!/bin/sh\nexit 1")?;
2835 #[cfg(unix)]
2836 {
2837 use std::os::unix::fs::PermissionsExt as _;
2838
2839 std::fs::set_permissions(&hook_path, std::fs::Permissions::from_mode(0o700))?;
2840 }
2841
2842 // create new commit on top of bookmark1
2843 work_dir.run_jj(["new", "bookmark1"]).success();
2844 work_dir.write_file("file", "file");
2845 work_dir.run_jj(["describe", "-m=update"]).success();
2846
2847 // update bookmark
2848 work_dir.run_jj(["bookmark", "move", "bookmark1"]).success();
2849
2850 // push bookmark
2851 let output = work_dir.run_jj(["git", "push"]);
2852
2853 // The git remote sideband adds a dummy suffix of 8 spaces to attempt to clear
2854 // any leftover data. This is done to help with cases where the line is
2855 // rewritten.
2856 //
2857 // However, a common option in a lot of editors removes trailing whitespace.
2858 // This means that anyone with that option that opens this file would make the
2859 // following snapshot fail. Using the insta filter here normalizes the
2860 // output.
2861 let mut settings = insta::Settings::clone_current();
2862 settings.add_filter(r"\s*\n", "\n");
2863 settings.bind(|| {
2864 insta::assert_snapshot!(output, @"
2865 ------- stderr -------
2866 Changes to push to origin:
2867 bookmark: bookmark1 [move forward from 9b2e76de3920 to 0fc4cf312e83]
2868 remote: error: hook declined to update refs/heads/bookmark1
2869 Warning: The remote rejected the following updates:
2870 refs/heads/bookmark1 (reason: hook declined)
2871 Hint: Try checking if you have permission to push to all the bookmarks.
2872 Error: Failed to push some bookmarks
2873 [EOF]
2874 [exit status: 1]
2875 ");
2876 });
2877 Ok(())
2878 }
2879
2880 #[test]
2881 fn test_git_push_unmapped_refs() {
2882 let test_env = TestEnvironment::default();
2883 test_env
2884 .run_jj_in(".", ["git", "init", "--colocate", "origin"])
2885 .success();
2886 test_env
2887 .run_jj_in(".", ["git", "init", "--colocate", "local"])
2888 .success();
2889 let local_dir = test_env.work_dir("local");
2890
2891 // Set up remote with refspecs that map only specific branch
2892 let mut data = local_dir.read_file(".git/config");
2893 data.extend(indoc! {br#"
2894 [remote "origin"]
2895 url = updated-later
2896 fetch = +refs/heads/dummy:refs/remotes/origin/dummy
2897 "#});
2898 local_dir.write_file(".git/config", data);
2899 local_dir
2900 .run_jj(["git", "remote", "set-url", "origin", "../origin"])
2901 .success();
2902
2903 local_dir.run_jj(["commit", "-mcommit1"]).success();
2904 local_dir
2905 .run_jj(["bookmark", "set", "-r@-", "bookmark1"])
2906 .success();
2907 local_dir.run_jj(["commit", "-mcommit2"]).success();
2908 local_dir
2909 .run_jj(["bookmark", "set", "-r@-", "bookmark2"])
2910 .success();
2911 local_dir.run_jj(["bookmark", "track", "*"]).success();
2912
2913 // bookmark1 isn't mapped in Git, but can still be pushed
2914 let output = local_dir.run_jj(["git", "push", "--bookmark=bookmark1"]);
2915 insta::assert_snapshot!(output, @"
2916 ------- stderr -------
2917 Changes to push to origin:
2918 bookmark: bookmark1 [add to 5792bfac70a2]
2919 [EOF]
2920 ");
2921
2922 // Remote bookmark for bookmark1 is created and exported by jj
2923 insta::assert_snapshot!(get_bookmark_output(&local_dir), @"
2924 bookmark1: rlvkpnrz 5792bfac (empty) commit1
2925 @git: rlvkpnrz 5792bfac (empty) commit1
2926 @origin: rlvkpnrz 5792bfac (empty) commit1
2927 bookmark2: zsuskuln aa5df56a (empty) commit2
2928 @git: zsuskuln aa5df56a (empty) commit2
2929 @origin (not created yet)
2930 [EOF]
2931 ");
2932
2933 // Make export of bookmark2 fail by creating non-empty directory
2934 local_dir.write_file(".git/refs/remotes/origin/bookmark2/dummy.lock", "");
2935 let output = local_dir.run_jj(["git", "push", "--bookmark=bookmark2"]);
2936 insta::assert_snapshot!(output, @r#"
2937 ------- stderr -------
2938 Changes to push to origin:
2939 bookmark: bookmark2 [add to aa5df56a071b]
2940 Warning: The following bookmarks couldn't be updated locally:
2941 bookmark2@origin: Failed to set: The change for reference "refs/remotes/origin/bookmark2" could not be committed: Directory not empty
2942 Error: Failed to push some bookmarks
2943 [EOF]
2944 [exit status: 1]
2945 "#);
2946
2947 // Since export failed, bookmark2@origin isn't created. If it were created,
2948 // this command would import "deletion" of bookmark2@origin as an external
2949 // change, and abandon commit2.
2950 insta::assert_snapshot!(get_bookmark_output(&local_dir), @"
2951 bookmark1: rlvkpnrz 5792bfac (empty) commit1
2952 @git: rlvkpnrz 5792bfac (empty) commit1
2953 @origin: rlvkpnrz 5792bfac (empty) commit1
2954 bookmark2: zsuskuln aa5df56a (empty) commit2
2955 @git: zsuskuln aa5df56a (empty) commit2
2956 @origin (not created yet)
2957 [EOF]
2958 ");
2959 }
2960
2961 #[must_use]
2962 fn get_bookmark_output(work_dir: &TestWorkDir) -> CommandOutput {
2963 // --quiet to suppress deleted bookmarks hint
2964 work_dir.run_jj(["bookmark", "list", "--all-remotes", "--quiet"])
2965 }
2966
2967 #[must_use]
2968 fn get_tag_output(work_dir: &TestWorkDir) -> CommandOutput {
2969 work_dir.run_jj(["tag", "list", "--all-remotes"])
2970 }