1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530
|
// Copyright 2023 The Jujutsu Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use crate::common::create_commit;
use crate::common::CommandOutput;
use crate::common::TestEnvironment;
use crate::common::TestWorkDir;
#[test]
fn test_basics() {
let test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
create_commit(&work_dir, "a", &[]);
create_commit(&work_dir, "b", &["a"]);
create_commit(&work_dir, "c", &[]);
create_commit(&work_dir, "d", &["c"]);
create_commit(&work_dir, "e", &["a", "d"]);
// Test the setup
insta::assert_snapshot!(get_log_output(&work_dir), @r"
@ [znk] e
├─╮
│ ○ [vru] d
│ ○ [roy] c
│ │ ○ [zsu] b
├───╯
○ │ [rlv] a
├─╯
◆ [zzz]
[EOF]
");
let output = work_dir.run_jj(["abandon", "--retain-bookmarks", "d"]);
insta::assert_snapshot!(output, @r"
------- stderr -------
Abandoned 1 commits:
vruxwmqv 636920e4 d | d
Rebased 1 descendant commits onto parents of abandoned commits
Working copy (@) now at: znkkpsqq 38e96a1f e | e
Parent commit (@-) : rlvkpnrz 7d980be7 a | a
Parent commit (@-) : royxmykx c12952d9 c d | c
Added 0 files, modified 0 files, removed 1 files
[EOF]
");
insta::assert_snapshot!(get_log_output(&work_dir), @r"
@ [znk] e
├─╮
│ ○ [roy] c d
│ │ ○ [zsu] b
├───╯
○ │ [rlv] a
├─╯
◆ [zzz]
[EOF]
");
work_dir.run_jj(["undo"]).success();
let output = work_dir.run_jj(["abandon", "--retain-bookmarks"]); // abandons `e`
insta::assert_snapshot!(output, @r"
------- stderr -------
Abandoned 1 commits:
znkkpsqq 03e0d4bf e | e
Working copy (@) now at: nkmrtpmo 179731fc (empty) (no description set)
Parent commit (@-) : rlvkpnrz 7d980be7 a e?? | a
Parent commit (@-) : vruxwmqv 636920e4 d e?? | d
Added 0 files, modified 0 files, removed 1 files
[EOF]
");
insta::assert_snapshot!(get_log_output(&work_dir), @r"
@ [nkm]
├─╮
│ ○ [vru] d e??
│ ○ [roy] c
│ │ ○ [zsu] b
├───╯
○ │ [rlv] a e??
├─╯
◆ [zzz]
[EOF]
");
work_dir.run_jj(["undo"]).success();
let output = work_dir.run_jj(["abandon", "descendants(d)"]);
insta::assert_snapshot!(output, @r"
------- stderr -------
Abandoned 2 commits:
znkkpsqq 03e0d4bf e | e
vruxwmqv 636920e4 d | d
Deleted bookmarks: d, e
Working copy (@) now at: xtnwkqum 1c70f4d2 (empty) (no description set)
Parent commit (@-) : rlvkpnrz 7d980be7 a | a
Parent commit (@-) : royxmykx c12952d9 c | c
Added 0 files, modified 0 files, removed 2 files
[EOF]
");
insta::assert_snapshot!(get_log_output(&work_dir), @r"
@ [xtn]
├─╮
│ ○ [roy] c
│ │ ○ [zsu] b
├───╯
○ │ [rlv] a
├─╯
◆ [zzz]
[EOF]
");
// Test abandoning the same commit twice directly
work_dir.run_jj(["undo"]).success();
let output = work_dir.run_jj(["abandon", "-rb", "b"]);
insta::assert_snapshot!(output, @r"
------- stderr -------
Abandoned 1 commits:
zsuskuln 123b4d91 b | b
Deleted bookmarks: b
[EOF]
");
insta::assert_snapshot!(get_log_output(&work_dir), @r"
@ [znk] e
├─╮
│ ○ [vru] d
│ ○ [roy] c
○ │ [rlv] a
├─╯
◆ [zzz]
[EOF]
");
// Test abandoning the same commit twice indirectly
work_dir.run_jj(["undo"]).success();
let output = work_dir.run_jj(["abandon", "d::", "e"]);
insta::assert_snapshot!(output, @r"
------- stderr -------
Abandoned 2 commits:
znkkpsqq 03e0d4bf e | e
vruxwmqv 636920e4 d | d
Deleted bookmarks: d, e
Working copy (@) now at: xlzxqlsl 55d5c4c2 (empty) (no description set)
Parent commit (@-) : rlvkpnrz 7d980be7 a | a
Parent commit (@-) : royxmykx c12952d9 c | c
Added 0 files, modified 0 files, removed 2 files
[EOF]
");
insta::assert_snapshot!(get_log_output(&work_dir), @r"
@ [xlz]
├─╮
│ ○ [roy] c
│ │ ○ [zsu] b
├───╯
○ │ [rlv] a
├─╯
◆ [zzz]
[EOF]
");
let output = work_dir.run_jj(["abandon", "none()"]);
insta::assert_snapshot!(output, @r"
------- stderr -------
No revisions to abandon.
[EOF]
");
}
#[test]
fn test_abandon_many() {
let test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
for i in 0..10 {
work_dir.run_jj(["new", &format!("-mcommit{i}")]).success();
}
// The list of commits should be elided.
let output = work_dir.run_jj(["abandon", ".."]);
insta::assert_snapshot!(output, @r"
------- stderr -------
Abandoned 11 commits:
kpqxywon 6faec5d1 (empty) commit9
znkkpsqq 80f67a53 (empty) commit8
yostqsxw 8bd72fcc (empty) commit7
vruxwmqv 06c46771 (empty) commit6
yqosqzyt 168813e3 (empty) commit5
royxmykx bd8c3571 (empty) commit4
mzvwutvl 57958fa0 (empty) commit3
zsuskuln 59515644 (empty) commit2
kkmpptxz a969596d (empty) commit1
rlvkpnrz 02fe38c9 (empty) commit0
...
Working copy (@) now at: kmkuslsw a36a913b (empty) (no description set)
Parent commit (@-) : zzzzzzzz 00000000 (empty) (no description set)
[EOF]
");
}
// This behavior illustrates https://github.com/jj-vcs/jj/issues/2600.
// See also the corresponding test in `test_rebase_command`
#[test]
fn test_bug_2600() {
let test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
// We will not touch "nottherootcommit". See the
// `test_bug_2600_rootcommit_special_case` for the one case where base being the
// child of the root commit changes the expected behavior.
create_commit(&work_dir, "nottherootcommit", &[]);
create_commit(&work_dir, "base", &["nottherootcommit"]);
create_commit(&work_dir, "a", &["base"]);
create_commit(&work_dir, "b", &["base", "a"]);
create_commit(&work_dir, "c", &["b"]);
// Test the setup
insta::assert_snapshot!(get_log_output(&work_dir), @r"
@ [znk] c
○ [vru] b
├─╮
│ ○ [roy] a
├─╯
○ [zsu] base
○ [rlv] nottherootcommit
◆ [zzz]
[EOF]
");
let setup_opid = work_dir.current_operation_id();
work_dir.run_jj(["op", "restore", &setup_opid]).success();
let output = work_dir.run_jj(["abandon", "base"]);
insta::assert_snapshot!(output, @r"
------- stderr -------
Abandoned 1 commits:
zsuskuln 67c2f714 base | base
Deleted bookmarks: base
Rebased 3 descendant commits onto parents of abandoned commits
Working copy (@) now at: znkkpsqq 1e89909f c | c
Parent commit (@-) : vruxwmqv a3a61e53 b | b
Added 0 files, modified 0 files, removed 1 files
[EOF]
");
// Commits "a" and "b" should both have "nottherootcommit" as parent, and "b"
// should keep "a" as second parent.
insta::assert_snapshot!(get_log_output(&work_dir), @r"
@ [znk] c
○ [vru] b
├─╮
│ ○ [roy] a
├─╯
○ [rlv] nottherootcommit
◆ [zzz]
[EOF]
");
work_dir.run_jj(["op", "restore", &setup_opid]).success();
let output = work_dir.run_jj(["abandon", "a"]);
insta::assert_snapshot!(output, @r"
------- stderr -------
Abandoned 1 commits:
royxmykx 183dbbca a | a
Deleted bookmarks: a
Rebased 2 descendant commits onto parents of abandoned commits
Working copy (@) now at: znkkpsqq a9a97c4c c | c
Parent commit (@-) : vruxwmqv bccf7988 b | b
Added 0 files, modified 0 files, removed 1 files
[EOF]
");
// Commit "b" should have "base" as parent. It should not have two parent
// pointers to that commit even though it was a merge commit before we abandoned
// "a".
insta::assert_snapshot!(get_log_output(&work_dir), @r"
@ [znk] c
○ [vru] b
○ [zsu] base
○ [rlv] nottherootcommit
◆ [zzz]
[EOF]
");
work_dir.run_jj(["op", "restore", &setup_opid]).success();
let output = work_dir.run_jj(["abandon", "b"]);
insta::assert_snapshot!(output, @r"
------- stderr -------
Abandoned 1 commits:
vruxwmqv cedee197 b | b
Deleted bookmarks: b
Rebased 1 descendant commits onto parents of abandoned commits
Working copy (@) now at: znkkpsqq 8030a364 c | c
Parent commit (@-) : zsuskuln 67c2f714 base | base
Parent commit (@-) : royxmykx 183dbbca a | a
Added 0 files, modified 0 files, removed 1 files
[EOF]
");
// Commit "c" should inherit the parents from the abndoned commit "b".
insta::assert_snapshot!(get_log_output(&work_dir), @r"
@ [znk] c
├─╮
│ ○ [roy] a
├─╯
○ [zsu] base
○ [rlv] nottherootcommit
◆ [zzz]
[EOF]
");
work_dir.run_jj(["op", "restore", &setup_opid]).success();
// ========= Reminder of the setup ===========
insta::assert_snapshot!(get_log_output(&work_dir), @r"
@ [znk] c
○ [vru] b
├─╮
│ ○ [roy] a
├─╯
○ [zsu] base
○ [rlv] nottherootcommit
◆ [zzz]
[EOF]
");
let output = work_dir.run_jj(["abandon", "--retain-bookmarks", "a", "b"]);
insta::assert_snapshot!(output, @r"
------- stderr -------
Abandoned 2 commits:
vruxwmqv cedee197 b | b
royxmykx 183dbbca a | a
Rebased 1 descendant commits onto parents of abandoned commits
Working copy (@) now at: znkkpsqq 75bef1a6 c | c
Parent commit (@-) : zsuskuln 67c2f714 a b base | base
Added 0 files, modified 0 files, removed 2 files
[EOF]
");
// Commit "c" should have "base" as parent. As when we abandoned "a", it should
// not have two parent pointers to the same commit.
insta::assert_snapshot!(get_log_output(&work_dir), @r"
@ [znk] c
○ [zsu] a b base
○ [rlv] nottherootcommit
◆ [zzz]
[EOF]
");
let output = work_dir.run_jj(["bookmark", "list", "b"]);
insta::assert_snapshot!(output, @r"
b: zsuskuln 67c2f714 base
[EOF]
");
}
#[test]
fn test_bug_2600_rootcommit_special_case() {
let test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
// Set up like `test_bug_2600`, but without the `nottherootcommit` commit.
create_commit(&work_dir, "base", &[]);
create_commit(&work_dir, "a", &["base"]);
create_commit(&work_dir, "b", &["base", "a"]);
create_commit(&work_dir, "c", &["b"]);
// Setup
insta::assert_snapshot!(get_log_output(&work_dir), @r"
@ [vru] c
○ [roy] b
├─╮
│ ○ [zsu] a
├─╯
○ [rlv] base
◆ [zzz]
[EOF]
");
// Now, the test
let output = work_dir.run_jj(["abandon", "base"]);
insta::assert_snapshot!(output, @r"
------- stderr -------
Error: The Git backend does not support creating merge commits with the root commit as one of the parents.
[EOF]
[exit status: 1]
");
}
#[test]
fn test_double_abandon() {
let test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
create_commit(&work_dir, "a", &[]);
// Test the setup
insta::assert_snapshot!(work_dir.run_jj(["log", "--no-graph", "-r", "a"]), @r"
rlvkpnrz test.user@example.com 2001-02-03 08:05:09 a 7d980be7
a
[EOF]
");
let commit_id = work_dir
.run_jj(["log", "--no-graph", "--color=never", "-T=commit_id", "-r=a"])
.success()
.stdout
.into_raw();
let output = work_dir.run_jj(["abandon", &commit_id]);
insta::assert_snapshot!(output, @r"
------- stderr -------
Abandoned 1 commits:
rlvkpnrz 7d980be7 a | a
Deleted bookmarks: a
Working copy (@) now at: royxmykx 0cff017c (empty) (no description set)
Parent commit (@-) : zzzzzzzz 00000000 (empty) (no description set)
Added 0 files, modified 0 files, removed 1 files
[EOF]
");
let output = work_dir.run_jj(["abandon", &commit_id]);
insta::assert_snapshot!(output, @r"
------- stderr -------
Abandoned 1 commits:
rlvkpnrz hidden 7d980be7 a
Nothing changed.
[EOF]
");
}
#[test]
fn test_abandon_restore_descendants() {
let test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
work_dir.write_file("file", "foo\n");
work_dir.run_jj(["new"]).success();
work_dir.write_file("file", "bar\n");
work_dir.run_jj(["new"]).success();
work_dir.write_file("file", "baz\n");
// Remove the commit containing "bar"
let output = work_dir.run_jj(["abandon", "-r@-", "--restore-descendants"]);
insta::assert_snapshot!(output, @r"
------- stderr -------
Abandoned 1 commits:
rlvkpnrz b23f92c3 (no description set)
Rebased 1 descendant commits (while preserving their content) onto parents of abandoned commits
Working copy (@) now at: kkmpptxz 2b575035 (no description set)
Parent commit (@-) : qpvuntsm d0c049cd (no description set)
[EOF]
");
let output = work_dir.run_jj(["diff", "--git"]);
insta::assert_snapshot!(output, @r"
diff --git a/file b/file
index 257cc5642c..76018072e0 100644
--- a/file
+++ b/file
@@ -1,1 +1,1 @@
-foo
+baz
[EOF]
");
}
#[test]
fn test_abandon_tracking_bookmarks() {
let test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "remote"]).success();
let remote_dir = test_env.work_dir("remote");
remote_dir
.run_jj(["bookmark", "set", "-r@", "foo"])
.success();
remote_dir.run_jj(["git", "export"]).success();
// Create colocated Git repo which may have @git tracking bookmarks
test_env
.run_jj_in(
".",
[
"git",
"clone",
"--colocate",
"--config=git.auto-local-bookmark=true",
"remote/.jj/repo/store/git",
"local",
],
)
.success();
let local_dir = test_env.work_dir("local");
local_dir
.run_jj(["bookmark", "set", "-r@", "bar"])
.success();
insta::assert_snapshot!(get_log_output(&local_dir), @r"
@ [zsu] bar
│ ○ [qpv] foo
├─╯
◆ [zzz]
[EOF]
");
let output = local_dir.run_jj(["abandon", "foo"]);
insta::assert_snapshot!(output, @r"
------- stderr -------
Abandoned 1 commits:
qpvuntsm e8849ae1 foo | (empty) (no description set)
Deleted bookmarks: foo
Hint: Deleted bookmarks can be pushed by name or all at once with `jj git push --deleted`.
[EOF]
");
let output = local_dir.run_jj(["abandon", "bar"]);
insta::assert_snapshot!(output, @r"
------- stderr -------
Abandoned 1 commits:
zsuskuln c2934cfb bar | (empty) (no description set)
Deleted bookmarks: bar
Working copy (@) now at: vruxwmqv b64f323d (empty) (no description set)
Parent commit (@-) : zzzzzzzz 00000000 (empty) (no description set)
[EOF]
");
}
#[must_use]
fn get_log_output(work_dir: &TestWorkDir) -> CommandOutput {
let template = r#"separate(" ", "[" ++ change_id.short(3) ++ "]", bookmarks)"#;
work_dir.run_jj(["log", "-T", template])
}
|