| 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 crate::common::CommandOutput; |
| 16 |
use crate::common::TestEnvironment; |
| 17 |
use crate::common::TestWorkDir; |
| 18 |
use crate::common::create_commit; |
| 19 |
use crate::common::create_commit_with_files; |
| 20 |
|
| 21 |
#[test] |
| 22 |
fn test_rebase_invalid() { |
| 23 |
let test_env = TestEnvironment::default(); |
| 24 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 25 |
let work_dir = test_env.work_dir("repo"); |
| 26 |
|
| 27 |
create_commit(&work_dir, "a", &[]); |
| 28 |
create_commit(&work_dir, "b", &["a"]); |
| 29 |
|
| 30 |
// Missing destination |
| 31 |
let output = work_dir.run_jj(["rebase"]); |
| 32 |
insta::assert_snapshot!(output, @" |
| 33 |
------- stderr ------- |
| 34 |
error: the following required arguments were not provided: |
| 35 |
<--onto <REVSETS>|--insert-after <REVSETS>|--insert-before <REVSETS>> |
| 36 |
|
| 37 |
Usage: jj rebase <--onto <REVSETS>|--insert-after <REVSETS>|--insert-before <REVSETS>> |
| 38 |
|
| 39 |
For more information, try '--help'. |
| 40 |
[EOF] |
| 41 |
[exit status: 2] |
| 42 |
"); |
| 43 |
|
| 44 |
// Both -r and -s |
| 45 |
let output = work_dir.run_jj(["rebase", "-r", "a", "-s", "a", "-o", "b"]); |
| 46 |
insta::assert_snapshot!(output, @" |
| 47 |
------- stderr ------- |
| 48 |
error: the argument '--revision <REVSETS>' cannot be used with '--source <REVSETS>' |
| 49 |
|
| 50 |
Usage: jj rebase --revision <REVSETS> <--onto <REVSETS>|--insert-after <REVSETS>|--insert-before <REVSETS>> |
| 51 |
|
| 52 |
For more information, try '--help'. |
| 53 |
[EOF] |
| 54 |
[exit status: 2] |
| 55 |
"); |
| 56 |
|
| 57 |
// Both -b and -s |
| 58 |
let output = work_dir.run_jj(["rebase", "-b", "a", "-s", "a", "-o", "b"]); |
| 59 |
insta::assert_snapshot!(output, @" |
| 60 |
------- stderr ------- |
| 61 |
error: the argument '--branch <REVSETS>' cannot be used with '--source <REVSETS>' |
| 62 |
|
| 63 |
Usage: jj rebase --branch <REVSETS> <--onto <REVSETS>|--insert-after <REVSETS>|--insert-before <REVSETS>> |
| 64 |
|
| 65 |
For more information, try '--help'. |
| 66 |
[EOF] |
| 67 |
[exit status: 2] |
| 68 |
"); |
| 69 |
|
| 70 |
// Both -o and --after |
| 71 |
let output = work_dir.run_jj(["rebase", "-r", "a", "-o", "b", "--after", "b"]); |
| 72 |
insta::assert_snapshot!(output, @" |
| 73 |
------- stderr ------- |
| 74 |
error: the argument '--onto <REVSETS>' cannot be used with '--insert-after <REVSETS>' |
| 75 |
|
| 76 |
Usage: jj rebase --revision <REVSETS> <--onto <REVSETS>|--insert-after <REVSETS>|--insert-before <REVSETS>> |
| 77 |
|
| 78 |
For more information, try '--help'. |
| 79 |
[EOF] |
| 80 |
[exit status: 2] |
| 81 |
"); |
| 82 |
|
| 83 |
// Both -o and --before |
| 84 |
let output = work_dir.run_jj(["rebase", "-r", "a", "-o", "b", "--before", "b"]); |
| 85 |
insta::assert_snapshot!(output, @" |
| 86 |
------- stderr ------- |
| 87 |
error: the argument '--onto <REVSETS>' cannot be used with '--insert-before <REVSETS>' |
| 88 |
|
| 89 |
Usage: jj rebase --revision <REVSETS> <--onto <REVSETS>|--insert-after <REVSETS>|--insert-before <REVSETS>> |
| 90 |
|
| 91 |
For more information, try '--help'. |
| 92 |
[EOF] |
| 93 |
[exit status: 2] |
| 94 |
"); |
| 95 |
|
| 96 |
// Rebase onto self with -r |
| 97 |
let output = work_dir.run_jj(["rebase", "-r", "a", "-o", "a"]); |
| 98 |
insta::assert_snapshot!(output, @" |
| 99 |
------- stderr ------- |
| 100 |
Error: Cannot rebase 7d980be7a1d4 onto itself |
| 101 |
[EOF] |
| 102 |
[exit status: 1] |
| 103 |
"); |
| 104 |
|
| 105 |
// Rebase root with -r |
| 106 |
let output = work_dir.run_jj(["rebase", "-r", "root()", "-o", "a"]); |
| 107 |
insta::assert_snapshot!(output, @" |
| 108 |
------- stderr ------- |
| 109 |
Error: The root commit 000000000000 is immutable |
| 110 |
[EOF] |
| 111 |
[exit status: 1] |
| 112 |
"); |
| 113 |
|
| 114 |
// Rebase onto descendant with -s |
| 115 |
let output = work_dir.run_jj(["rebase", "-s", "a", "-o", "b"]); |
| 116 |
insta::assert_snapshot!(output, @" |
| 117 |
------- stderr ------- |
| 118 |
Error: Cannot rebase 7d980be7a1d4 onto descendant 123b4d91f6e5 |
| 119 |
[EOF] |
| 120 |
[exit status: 1] |
| 121 |
"); |
| 122 |
|
| 123 |
// Rebase onto itself with -s |
| 124 |
let output = work_dir.run_jj(["rebase", "-s", "a", "-o", "a"]); |
| 125 |
insta::assert_snapshot!(output, @" |
| 126 |
------- stderr ------- |
| 127 |
Error: Cannot rebase 7d980be7a1d4 onto itself |
| 128 |
[EOF] |
| 129 |
[exit status: 1] |
| 130 |
"); |
| 131 |
} |
| 132 |
|
| 133 |
#[test] |
| 134 |
fn test_rebase_empty_sets() { |
| 135 |
let test_env = TestEnvironment::default(); |
| 136 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 137 |
let work_dir = test_env.work_dir("repo"); |
| 138 |
|
| 139 |
create_commit(&work_dir, "a", &[]); |
| 140 |
create_commit(&work_dir, "b", &["a"]); |
| 141 |
|
| 142 |
let output = work_dir.run_jj(["rebase", "-r=none()", "-o=b"]); |
| 143 |
insta::assert_snapshot!(output, @" |
| 144 |
------- stderr ------- |
| 145 |
No revisions to rebase. |
| 146 |
[EOF] |
| 147 |
"); |
| 148 |
let output = work_dir.run_jj(["rebase", "-s=none()", "-o=b"]); |
| 149 |
insta::assert_snapshot!(output, @" |
| 150 |
------- stderr ------- |
| 151 |
No revisions to rebase. |
| 152 |
[EOF] |
| 153 |
"); |
| 154 |
let output = work_dir.run_jj(["rebase", "-b=none()", "-o=b"]); |
| 155 |
insta::assert_snapshot!(output, @" |
| 156 |
------- stderr ------- |
| 157 |
No revisions to rebase. |
| 158 |
[EOF] |
| 159 |
"); |
| 160 |
// Empty because "b..a" is empty |
| 161 |
let output = work_dir.run_jj(["rebase", "-b=a", "-o=b"]); |
| 162 |
insta::assert_snapshot!(output, @" |
| 163 |
------- stderr ------- |
| 164 |
No revisions to rebase. |
| 165 |
[EOF] |
| 166 |
"); |
| 167 |
} |
| 168 |
|
| 169 |
#[test] |
| 170 |
fn test_rebase_bookmark() { |
| 171 |
let test_env = TestEnvironment::default(); |
| 172 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 173 |
let work_dir = test_env.work_dir("repo"); |
| 174 |
|
| 175 |
create_commit(&work_dir, "a", &[]); |
| 176 |
create_commit(&work_dir, "b", &["a"]); |
| 177 |
create_commit(&work_dir, "c", &["b"]); |
| 178 |
create_commit(&work_dir, "d", &["b"]); |
| 179 |
create_commit(&work_dir, "e", &["a"]); |
| 180 |
// Test the setup |
| 181 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 182 |
@ e: a |
| 183 |
│ ○ d: b |
| 184 |
│ │ ○ c: b |
| 185 |
│ ├─╯ |
| 186 |
│ ○ b: a |
| 187 |
├─╯ |
| 188 |
○ a |
| 189 |
◆ |
| 190 |
[EOF] |
| 191 |
"); |
| 192 |
let setup_opid = work_dir.current_operation_id(); |
| 193 |
|
| 194 |
let output = work_dir.run_jj(["rebase", "-b", "c", "-o", "e"]); |
| 195 |
insta::assert_snapshot!(output, @r" |
| 196 |
------- stderr ------- |
| 197 |
Rebased 3 commits to destination. |
| 198 |
[EOF] |
| 199 |
"); |
| 200 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 201 |
○ d: b |
| 202 |
│ ○ c: b |
| 203 |
├─╯ |
| 204 |
○ b: e |
| 205 |
@ e: a |
| 206 |
○ a |
| 207 |
◆ |
| 208 |
[EOF] |
| 209 |
"); |
| 210 |
|
| 211 |
// Test rebasing multiple bookmarks at once |
| 212 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 213 |
let output = work_dir.run_jj(["rebase", "-b=e", "-b=d", "-d=b"]); |
| 214 |
insta::assert_snapshot!(output, @r" |
| 215 |
------- stderr ------- |
| 216 |
Skipped rebase of 1 commits that were already in place. |
| 217 |
Rebased 1 commits to destination. |
| 218 |
Working copy (@) now at: znkkpsqq bbfb8557 e | e |
| 219 |
Parent commit (@-) : zsuskuln 123b4d91 b | b |
| 220 |
Added 1 files, modified 0 files, removed 0 files |
| 221 |
[EOF] |
| 222 |
"); |
| 223 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 224 |
@ e: b |
| 225 |
│ ○ d: b |
| 226 |
├─╯ |
| 227 |
│ ○ c: b |
| 228 |
├─╯ |
| 229 |
○ b: a |
| 230 |
○ a |
| 231 |
◆ |
| 232 |
[EOF] |
| 233 |
"); |
| 234 |
|
| 235 |
// Same test but with more than one revision per argument |
| 236 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 237 |
let output = work_dir.run_jj(["rebase", "-b=e|d", "-d=b"]); |
| 238 |
insta::assert_snapshot!(output, @r" |
| 239 |
------- stderr ------- |
| 240 |
Skipped rebase of 1 commits that were already in place. |
| 241 |
Rebased 1 commits to destination. |
| 242 |
Working copy (@) now at: znkkpsqq 1ffd7890 e | e |
| 243 |
Parent commit (@-) : zsuskuln 123b4d91 b | b |
| 244 |
Added 1 files, modified 0 files, removed 0 files |
| 245 |
[EOF] |
| 246 |
"); |
| 247 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 248 |
@ e: b |
| 249 |
│ ○ d: b |
| 250 |
├─╯ |
| 251 |
│ ○ c: b |
| 252 |
├─╯ |
| 253 |
○ b: a |
| 254 |
○ a |
| 255 |
◆ |
| 256 |
[EOF] |
| 257 |
"); |
| 258 |
} |
| 259 |
|
| 260 |
#[test] |
| 261 |
fn test_rebase_bookmark_with_merge() { |
| 262 |
let test_env = TestEnvironment::default(); |
| 263 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 264 |
let work_dir = test_env.work_dir("repo"); |
| 265 |
|
| 266 |
create_commit(&work_dir, "a", &[]); |
| 267 |
create_commit(&work_dir, "b", &["a"]); |
| 268 |
create_commit(&work_dir, "c", &[]); |
| 269 |
create_commit(&work_dir, "d", &["c"]); |
| 270 |
create_commit(&work_dir, "e", &["a", "d"]); |
| 271 |
// Test the setup |
| 272 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 273 |
@ e: a d |
| 274 |
├─╮ |
| 275 |
│ ○ d: c |
| 276 |
│ ○ c |
| 277 |
│ │ ○ b: a |
| 278 |
├───╯ |
| 279 |
○ │ a |
| 280 |
├─╯ |
| 281 |
◆ |
| 282 |
[EOF] |
| 283 |
"); |
| 284 |
let setup_opid = work_dir.current_operation_id(); |
| 285 |
|
| 286 |
let output = work_dir.run_jj(["rebase", "-b", "d", "-o", "b"]); |
| 287 |
insta::assert_snapshot!(output, @r" |
| 288 |
------- stderr ------- |
| 289 |
Rebased 3 commits to destination. |
| 290 |
Working copy (@) now at: znkkpsqq d5360d09 e | e |
| 291 |
Parent commit (@-) : rlvkpnrz 7d980be7 a | a |
| 292 |
Parent commit (@-) : vruxwmqv 85a741d7 d | d |
| 293 |
Added 1 files, modified 0 files, removed 0 files |
| 294 |
[EOF] |
| 295 |
"); |
| 296 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 297 |
@ e: a d |
| 298 |
├─╮ |
| 299 |
│ ○ d: c |
| 300 |
│ ○ c: b |
| 301 |
│ ○ b: a |
| 302 |
├─╯ |
| 303 |
○ a |
| 304 |
◆ |
| 305 |
[EOF] |
| 306 |
"); |
| 307 |
|
| 308 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 309 |
let output = work_dir.run_jj(["rebase", "-o", "b"]); |
| 310 |
insta::assert_snapshot!(output, @r" |
| 311 |
------- stderr ------- |
| 312 |
Rebased 3 commits to destination. |
| 313 |
Working copy (@) now at: znkkpsqq d3091c0f e | e |
| 314 |
Parent commit (@-) : rlvkpnrz 7d980be7 a | a |
| 315 |
Parent commit (@-) : vruxwmqv 485905a3 d | d |
| 316 |
Added 1 files, modified 0 files, removed 0 files |
| 317 |
[EOF] |
| 318 |
"); |
| 319 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 320 |
@ e: a d |
| 321 |
├─╮ |
| 322 |
│ ○ d: c |
| 323 |
│ ○ c: b |
| 324 |
│ ○ b: a |
| 325 |
├─╯ |
| 326 |
○ a |
| 327 |
◆ |
| 328 |
[EOF] |
| 329 |
"); |
| 330 |
} |
| 331 |
|
| 332 |
#[test] |
| 333 |
fn test_rebase_single_revision() { |
| 334 |
let test_env = TestEnvironment::default(); |
| 335 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 336 |
let work_dir = test_env.work_dir("repo"); |
| 337 |
|
| 338 |
create_commit(&work_dir, "a", &[]); |
| 339 |
create_commit(&work_dir, "b", &["a"]); |
| 340 |
create_commit(&work_dir, "c", &["a"]); |
| 341 |
create_commit(&work_dir, "d", &["b", "c"]); |
| 342 |
create_commit(&work_dir, "e", &["d"]); |
| 343 |
// Test the setup |
| 344 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 345 |
@ e: d |
| 346 |
○ d: b c |
| 347 |
├─╮ |
| 348 |
│ ○ c: a |
| 349 |
○ │ b: a |
| 350 |
├─╯ |
| 351 |
○ a |
| 352 |
◆ |
| 353 |
[EOF] |
| 354 |
"); |
| 355 |
let setup_opid = work_dir.current_operation_id(); |
| 356 |
|
| 357 |
// Descendants of the rebased commit "c" should be rebased onto parents. First |
| 358 |
// we test with a non-merge commit. |
| 359 |
let output = work_dir.run_jj(["rebase", "-r", "c", "-o", "b"]); |
| 360 |
insta::assert_snapshot!(output, @r" |
| 361 |
------- stderr ------- |
| 362 |
Rebased 1 commits to destination. |
| 363 |
Rebased 2 descendant commits. |
| 364 |
Working copy (@) now at: znkkpsqq 2baedee4 e | e |
| 365 |
Parent commit (@-) : vruxwmqv 45142a83 d | d |
| 366 |
Added 0 files, modified 0 files, removed 1 files |
| 367 |
[EOF] |
| 368 |
"); |
| 369 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 370 |
@ e: d |
| 371 |
○ d: b a |
| 372 |
├─╮ |
| 373 |
│ │ ○ c: b |
| 374 |
├───╯ |
| 375 |
○ │ b: a |
| 376 |
├─╯ |
| 377 |
○ a |
| 378 |
◆ |
| 379 |
[EOF] |
| 380 |
"); |
| 381 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 382 |
|
| 383 |
// Now, let's try moving the merge commit. After, both parents of "d" ("b" and |
| 384 |
// "c") should become parents of "e". |
| 385 |
let output = work_dir.run_jj(["rebase", "-r", "d", "-o", "a"]); |
| 386 |
insta::assert_snapshot!(output, @r" |
| 387 |
------- stderr ------- |
| 388 |
Rebased 1 commits to destination. |
| 389 |
Rebased 1 descendant commits. |
| 390 |
Working copy (@) now at: znkkpsqq b981a2bc e | e |
| 391 |
Parent commit (@-) : zsuskuln 123b4d91 b | b |
| 392 |
Parent commit (@-) : royxmykx 991a7501 c | c |
| 393 |
Added 0 files, modified 0 files, removed 1 files |
| 394 |
[EOF] |
| 395 |
"); |
| 396 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 397 |
@ e: b c |
| 398 |
├─╮ |
| 399 |
│ ○ c: a |
| 400 |
○ │ b: a |
| 401 |
├─╯ |
| 402 |
│ ○ d: a |
| 403 |
├─╯ |
| 404 |
○ a |
| 405 |
◆ |
| 406 |
[EOF] |
| 407 |
"); |
| 408 |
} |
| 409 |
|
| 410 |
#[test] |
| 411 |
fn test_rebase_single_revision_merge_parent() { |
| 412 |
let test_env = TestEnvironment::default(); |
| 413 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 414 |
let work_dir = test_env.work_dir("repo"); |
| 415 |
|
| 416 |
create_commit(&work_dir, "a", &[]); |
| 417 |
create_commit(&work_dir, "b", &[]); |
| 418 |
create_commit(&work_dir, "c", &["b"]); |
| 419 |
create_commit(&work_dir, "d", &["a", "c"]); |
| 420 |
// Test the setup |
| 421 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 422 |
@ d: a c |
| 423 |
├─╮ |
| 424 |
│ ○ c: b |
| 425 |
│ ○ b |
| 426 |
○ │ a |
| 427 |
├─╯ |
| 428 |
◆ |
| 429 |
[EOF] |
| 430 |
"); |
| 431 |
|
| 432 |
// Descendants of the rebased commit should be rebased onto parents, and if |
| 433 |
// the descendant is a merge commit, it shouldn't forget its other parents. |
| 434 |
let output = work_dir.run_jj(["rebase", "-r", "c", "-o", "a"]); |
| 435 |
insta::assert_snapshot!(output, @r" |
| 436 |
------- stderr ------- |
| 437 |
Rebased 1 commits to destination. |
| 438 |
Rebased 1 descendant commits. |
| 439 |
Working copy (@) now at: vruxwmqv 0bb15a0f d | d |
| 440 |
Parent commit (@-) : rlvkpnrz 7d980be7 a | a |
| 441 |
Parent commit (@-) : zsuskuln d18ca3e8 b | b |
| 442 |
Added 0 files, modified 0 files, removed 1 files |
| 443 |
[EOF] |
| 444 |
"); |
| 445 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 446 |
@ d: a b |
| 447 |
├─╮ |
| 448 |
│ ○ b |
| 449 |
│ │ ○ c: a |
| 450 |
├───╯ |
| 451 |
○ │ a |
| 452 |
├─╯ |
| 453 |
◆ |
| 454 |
[EOF] |
| 455 |
"); |
| 456 |
} |
| 457 |
|
| 458 |
#[test] |
| 459 |
fn test_rebase_multiple_revisions() { |
| 460 |
let test_env = TestEnvironment::default(); |
| 461 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 462 |
let work_dir = test_env.work_dir("repo"); |
| 463 |
|
| 464 |
create_commit(&work_dir, "a", &[]); |
| 465 |
create_commit(&work_dir, "b", &["a"]); |
| 466 |
create_commit(&work_dir, "c", &["b"]); |
| 467 |
create_commit(&work_dir, "d", &["a"]); |
| 468 |
create_commit(&work_dir, "e", &["d"]); |
| 469 |
create_commit(&work_dir, "f", &["c", "e"]); |
| 470 |
create_commit(&work_dir, "g", &["f"]); |
| 471 |
create_commit(&work_dir, "h", &["g"]); |
| 472 |
create_commit(&work_dir, "i", &["f"]); |
| 473 |
// Test the setup |
| 474 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 475 |
@ i: f |
| 476 |
│ ○ h: g |
| 477 |
│ ○ g: f |
| 478 |
├─╯ |
| 479 |
○ f: c e |
| 480 |
├─╮ |
| 481 |
│ ○ e: d |
| 482 |
│ ○ d: a |
| 483 |
○ │ c: b |
| 484 |
○ │ b: a |
| 485 |
├─╯ |
| 486 |
○ a |
| 487 |
◆ |
| 488 |
[EOF] |
| 489 |
"); |
| 490 |
let setup_opid = work_dir.current_operation_id(); |
| 491 |
|
| 492 |
// Test with two non-related non-merge commits. |
| 493 |
let output = work_dir.run_jj(["rebase", "-r", "c", "-r", "e", "-o", "a"]); |
| 494 |
insta::assert_snapshot!(output, @r" |
| 495 |
------- stderr ------- |
| 496 |
Rebased 2 commits to destination. |
| 497 |
Rebased 4 descendant commits. |
| 498 |
Working copy (@) now at: xznxytkn 15078fab i | i |
| 499 |
Parent commit (@-) : kmkuslsw d8579ed7 f | f |
| 500 |
Added 0 files, modified 0 files, removed 2 files |
| 501 |
[EOF] |
| 502 |
"); |
| 503 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 504 |
@ i: f |
| 505 |
│ ○ h: g |
| 506 |
│ ○ g: f |
| 507 |
├─╯ |
| 508 |
○ f: b d |
| 509 |
├─╮ |
| 510 |
│ ○ d: a |
| 511 |
○ │ b: a |
| 512 |
├─╯ |
| 513 |
│ ○ e: a |
| 514 |
├─╯ |
| 515 |
│ ○ c: a |
| 516 |
├─╯ |
| 517 |
○ a |
| 518 |
◆ |
| 519 |
[EOF] |
| 520 |
"); |
| 521 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 522 |
|
| 523 |
// Test with two related non-merge commits. Since "b" is a parent of "c", when |
| 524 |
// rebasing commits "b" and "c", their ancestry relationship should be |
| 525 |
// preserved. |
| 526 |
let output = work_dir.run_jj(["rebase", "-r", "b", "-r", "c", "-o", "e"]); |
| 527 |
insta::assert_snapshot!(output, @r" |
| 528 |
------- stderr ------- |
| 529 |
Rebased 2 commits to destination. |
| 530 |
Rebased 4 descendant commits. |
| 531 |
Working copy (@) now at: xznxytkn 4dec544d i | i |
| 532 |
Parent commit (@-) : kmkuslsw b22816c9 f | f |
| 533 |
Added 0 files, modified 0 files, removed 2 files |
| 534 |
[EOF] |
| 535 |
"); |
| 536 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 537 |
@ i: f |
| 538 |
│ ○ h: g |
| 539 |
│ ○ g: f |
| 540 |
├─╯ |
| 541 |
○ f: a e |
| 542 |
├─╮ |
| 543 |
│ │ ○ c: b |
| 544 |
│ │ ○ b: e |
| 545 |
│ ├─╯ |
| 546 |
│ ○ e: d |
| 547 |
│ ○ d: a |
| 548 |
├─╯ |
| 549 |
○ a |
| 550 |
◆ |
| 551 |
[EOF] |
| 552 |
"); |
| 553 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 554 |
|
| 555 |
// Test with a subgraph containing a merge commit. Since the merge commit "f" |
| 556 |
// was extracted, its descendants which are not part of the subgraph will |
| 557 |
// inherit its descendants which are not in the subtree ("c" and "d"). |
| 558 |
// "f" will retain its parent "c" since "c" is outside the target set, and not |
| 559 |
// a descendant of any new children. |
| 560 |
let output = work_dir.run_jj(["rebase", "-r", "e::g", "-o", "a"]); |
| 561 |
insta::assert_snapshot!(output, @r" |
| 562 |
------- stderr ------- |
| 563 |
Rebased 3 commits to destination. |
| 564 |
Rebased 2 descendant commits. |
| 565 |
Working copy (@) now at: xznxytkn e73a0787 i | i |
| 566 |
Parent commit (@-) : royxmykx dffaa0d4 c | c |
| 567 |
Parent commit (@-) : vruxwmqv 6354123d d | d |
| 568 |
Added 0 files, modified 0 files, removed 2 files |
| 569 |
[EOF] |
| 570 |
"); |
| 571 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 572 |
@ i: c d |
| 573 |
├─╮ |
| 574 |
│ │ ○ h: c d |
| 575 |
╭─┬─╯ |
| 576 |
│ ○ d: a |
| 577 |
│ │ ○ g: f |
| 578 |
│ │ ○ f: c e |
| 579 |
╭───┤ |
| 580 |
│ │ ○ e: a |
| 581 |
│ ├─╯ |
| 582 |
○ │ c: b |
| 583 |
○ │ b: a |
| 584 |
├─╯ |
| 585 |
○ a |
| 586 |
◆ |
| 587 |
[EOF] |
| 588 |
"); |
| 589 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 590 |
|
| 591 |
// Test with commits in a disconnected subgraph. The subgraph has the |
| 592 |
// relationship d->e->f->g->h, but only "d", "f" and "h" are in the set of |
| 593 |
// rebased commits. "d" should be a new parent of "f", and "f" should be a |
| 594 |
// new parent of "h". "f" will retain its parent "c" since "c" is outside the |
| 595 |
// target set, and not a descendant of any new children. |
| 596 |
let output = work_dir.run_jj(["rebase", "-r", "d", "-r", "f", "-r", "h", "-o", "b"]); |
| 597 |
insta::assert_snapshot!(output, @r" |
| 598 |
------- stderr ------- |
| 599 |
Rebased 3 commits to destination. |
| 600 |
Rebased 3 descendant commits. |
| 601 |
Working copy (@) now at: xznxytkn f7c62b49 i | i |
| 602 |
Parent commit (@-) : royxmykx dffaa0d4 c | c |
| 603 |
Parent commit (@-) : znkkpsqq 1c3676c4 e | e |
| 604 |
Added 0 files, modified 0 files, removed 2 files |
| 605 |
[EOF] |
| 606 |
"); |
| 607 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 608 |
@ i: c e |
| 609 |
├─╮ |
| 610 |
│ │ ○ g: c e |
| 611 |
╭─┬─╯ |
| 612 |
│ ○ e: a |
| 613 |
│ │ ○ h: f |
| 614 |
│ │ ○ f: c d |
| 615 |
╭───┤ |
| 616 |
│ │ ○ d: b |
| 617 |
○ │ │ c: b |
| 618 |
├───╯ |
| 619 |
○ │ b: a |
| 620 |
├─╯ |
| 621 |
○ a |
| 622 |
◆ |
| 623 |
[EOF] |
| 624 |
"); |
| 625 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 626 |
|
| 627 |
// Test rebasing a subgraph onto its descendants. |
| 628 |
let output = work_dir.run_jj(["rebase", "-r", "d::e", "-o", "i"]); |
| 629 |
insta::assert_snapshot!(output, @r" |
| 630 |
------- stderr ------- |
| 631 |
Rebased 2 commits to destination. |
| 632 |
Rebased 4 descendant commits. |
| 633 |
Working copy (@) now at: xznxytkn b4ece7ad i | i |
| 634 |
Parent commit (@-) : kmkuslsw 1a05fe0d f | f |
| 635 |
Added 0 files, modified 0 files, removed 2 files |
| 636 |
[EOF] |
| 637 |
"); |
| 638 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 639 |
○ e: d |
| 640 |
○ d: i |
| 641 |
@ i: f |
| 642 |
│ ○ h: g |
| 643 |
│ ○ g: f |
| 644 |
├─╯ |
| 645 |
○ f: c a |
| 646 |
├─╮ |
| 647 |
○ │ c: b |
| 648 |
○ │ b: a |
| 649 |
├─╯ |
| 650 |
○ a |
| 651 |
◆ |
| 652 |
[EOF] |
| 653 |
"); |
| 654 |
} |
| 655 |
|
| 656 |
#[test] |
| 657 |
fn test_rebase_revision_onto_descendant() { |
| 658 |
let test_env = TestEnvironment::default(); |
| 659 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 660 |
let work_dir = test_env.work_dir("repo"); |
| 661 |
|
| 662 |
create_commit(&work_dir, "base", &[]); |
| 663 |
create_commit(&work_dir, "a", &["base"]); |
| 664 |
create_commit(&work_dir, "b", &["base"]); |
| 665 |
create_commit(&work_dir, "merge", &["b", "a"]); |
| 666 |
// Test the setup |
| 667 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 668 |
@ merge: b a |
| 669 |
├─╮ |
| 670 |
│ ○ a: base |
| 671 |
○ │ b: base |
| 672 |
├─╯ |
| 673 |
○ base |
| 674 |
◆ |
| 675 |
[EOF] |
| 676 |
"); |
| 677 |
let setup_opid = work_dir.current_operation_id(); |
| 678 |
|
| 679 |
// Simpler example |
| 680 |
let output = work_dir.run_jj(["rebase", "-r", "base", "-o", "a"]); |
| 681 |
insta::assert_snapshot!(output, @r" |
| 682 |
------- stderr ------- |
| 683 |
Rebased 1 commits to destination. |
| 684 |
Rebased 3 descendant commits. |
| 685 |
Working copy (@) now at: vruxwmqv 6a82c6c9 merge | merge |
| 686 |
Parent commit (@-) : royxmykx 934eadd8 b | b |
| 687 |
Parent commit (@-) : zsuskuln fd4e3113 a | a |
| 688 |
Added 0 files, modified 0 files, removed 1 files |
| 689 |
[EOF] |
| 690 |
"); |
| 691 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 692 |
@ merge: b a |
| 693 |
├─╮ |
| 694 |
○ │ b |
| 695 |
│ │ ○ base: a |
| 696 |
│ ├─╯ |
| 697 |
│ ○ a |
| 698 |
├─╯ |
| 699 |
◆ |
| 700 |
[EOF] |
| 701 |
"); |
| 702 |
|
| 703 |
// Now, let's rebase onto the descendant merge |
| 704 |
let output = work_dir.run_jj(["op", "restore", &setup_opid]); |
| 705 |
insta::assert_snapshot!(output, @" |
| 706 |
------- stderr ------- |
| 707 |
Restored to operation: 246c3972ba42 (2001-02-03 08:05:15) create bookmark merge pointing to commit 08c0951bf69d0362708a5223a78446d664823b50 |
| 708 |
Working copy (@) now at: vruxwmqv 08c0951b merge | merge |
| 709 |
Parent commit (@-) : royxmykx 6a7081ef b | b |
| 710 |
Parent commit (@-) : zsuskuln 68fbc443 a | a |
| 711 |
Added 1 files, modified 0 files, removed 0 files |
| 712 |
[EOF] |
| 713 |
"); |
| 714 |
let output = work_dir.run_jj(["rebase", "-r", "base", "-o", "merge"]); |
| 715 |
insta::assert_snapshot!(output, @r" |
| 716 |
------- stderr ------- |
| 717 |
Rebased 1 commits to destination. |
| 718 |
Rebased 3 descendant commits. |
| 719 |
Working copy (@) now at: vruxwmqv 6091a06e merge | merge |
| 720 |
Parent commit (@-) : royxmykx 072bc1fa b | b |
| 721 |
Parent commit (@-) : zsuskuln afb318cf a | a |
| 722 |
Added 0 files, modified 0 files, removed 1 files |
| 723 |
[EOF] |
| 724 |
"); |
| 725 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 726 |
○ base: merge |
| 727 |
@ merge: b a |
| 728 |
├─╮ |
| 729 |
│ ○ a |
| 730 |
○ │ b |
| 731 |
├─╯ |
| 732 |
◆ |
| 733 |
[EOF] |
| 734 |
"); |
| 735 |
|
| 736 |
// TODO(ilyagr): These will be good tests for `jj rebase --insert-after` and |
| 737 |
// `--insert-before`, once those are implemented. |
| 738 |
} |
| 739 |
|
| 740 |
#[test] |
| 741 |
fn test_rebase_multiple_destinations() { |
| 742 |
let test_env = TestEnvironment::default(); |
| 743 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 744 |
let work_dir = test_env.work_dir("repo"); |
| 745 |
|
| 746 |
create_commit(&work_dir, "a", &[]); |
| 747 |
create_commit(&work_dir, "b", &[]); |
| 748 |
create_commit(&work_dir, "c", &[]); |
| 749 |
// Test the setup |
| 750 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 751 |
@ c |
| 752 |
│ ○ b |
| 753 |
├─╯ |
| 754 |
│ ○ a |
| 755 |
├─╯ |
| 756 |
◆ |
| 757 |
[EOF] |
| 758 |
"); |
| 759 |
|
| 760 |
let output = work_dir.run_jj(["rebase", "-r", "a", "-o", "b", "-o", "c"]); |
| 761 |
insta::assert_snapshot!(output, @r" |
| 762 |
------- stderr ------- |
| 763 |
Rebased 1 commits to destination. |
| 764 |
[EOF] |
| 765 |
"); |
| 766 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 767 |
○ a: b c |
| 768 |
├─╮ |
| 769 |
│ @ c |
| 770 |
○ │ b |
| 771 |
├─╯ |
| 772 |
◆ |
| 773 |
[EOF] |
| 774 |
"); |
| 775 |
|
| 776 |
work_dir.run_jj(["rebase", "-r=a", "-d=b|c"]).success(); |
| 777 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 778 |
○ a: c b |
| 779 |
├─╮ |
| 780 |
│ ○ b |
| 781 |
@ │ c |
| 782 |
├─╯ |
| 783 |
◆ |
| 784 |
[EOF] |
| 785 |
"); |
| 786 |
|
| 787 |
let output = work_dir.run_jj(["rebase", "-r", "a", "-o", "b", "-o", "b"]); |
| 788 |
insta::assert_snapshot!(output, @r" |
| 789 |
------- stderr ------- |
| 790 |
Rebased 1 commits to destination. |
| 791 |
[EOF] |
| 792 |
"); |
| 793 |
|
| 794 |
let output = work_dir.run_jj(["rebase", "-r", "a", "-o", "b|c", "-o", "b"]); |
| 795 |
insta::assert_snapshot!(output, @r" |
| 796 |
------- stderr ------- |
| 797 |
Rebased 1 commits to destination. |
| 798 |
[EOF] |
| 799 |
"); |
| 800 |
|
| 801 |
let output = work_dir.run_jj(["rebase", "-r", "a", "-o", "b", "-o", "root()"]); |
| 802 |
insta::assert_snapshot!(output, @" |
| 803 |
------- stderr ------- |
| 804 |
Error: The Git backend does not support creating merge commits with the root commit as one of the parents. |
| 805 |
[EOF] |
| 806 |
[exit status: 1] |
| 807 |
"); |
| 808 |
} |
| 809 |
|
| 810 |
#[test] |
| 811 |
fn test_rebase_with_descendants() { |
| 812 |
let test_env = TestEnvironment::default(); |
| 813 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 814 |
let work_dir = test_env.work_dir("repo"); |
| 815 |
|
| 816 |
create_commit(&work_dir, "a", &[]); |
| 817 |
create_commit(&work_dir, "b", &[]); |
| 818 |
create_commit(&work_dir, "c", &["a", "b"]); |
| 819 |
create_commit(&work_dir, "d", &["c"]); |
| 820 |
// Test the setup |
| 821 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 822 |
@ d: c |
| 823 |
○ c: a b |
| 824 |
├─╮ |
| 825 |
│ ○ b |
| 826 |
○ │ a |
| 827 |
├─╯ |
| 828 |
◆ |
| 829 |
[EOF] |
| 830 |
"); |
| 831 |
let setup_opid = work_dir.current_operation_id(); |
| 832 |
|
| 833 |
let output = work_dir.run_jj(["rebase", "-s", "b", "-o", "a"]); |
| 834 |
insta::assert_snapshot!(output, @r" |
| 835 |
------- stderr ------- |
| 836 |
Rebased 3 commits to destination. |
| 837 |
Working copy (@) now at: vruxwmqv 7a9837e3 d | d |
| 838 |
Parent commit (@-) : royxmykx ee1edcc0 c | c |
| 839 |
[EOF] |
| 840 |
"); |
| 841 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 842 |
@ d: c |
| 843 |
○ c: a b |
| 844 |
├─╮ |
| 845 |
│ ○ b: a |
| 846 |
├─╯ |
| 847 |
○ a |
| 848 |
◆ |
| 849 |
[EOF] |
| 850 |
"); |
| 851 |
|
| 852 |
// Rebase several subtrees at once. |
| 853 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 854 |
let output = work_dir.run_jj(["rebase", "-s=c", "-s=d", "-d=a"]); |
| 855 |
insta::assert_snapshot!(output, @r" |
| 856 |
------- stderr ------- |
| 857 |
Rebased 2 commits to destination. |
| 858 |
Working copy (@) now at: vruxwmqv e7720369 d | d |
| 859 |
Parent commit (@-) : rlvkpnrz 7d980be7 a | a |
| 860 |
Added 0 files, modified 0 files, removed 2 files |
| 861 |
[EOF] |
| 862 |
"); |
| 863 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 864 |
@ d: a |
| 865 |
│ ○ c: a |
| 866 |
├─╯ |
| 867 |
○ a |
| 868 |
│ ○ b |
| 869 |
├─╯ |
| 870 |
◆ |
| 871 |
[EOF] |
| 872 |
"); |
| 873 |
|
| 874 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 875 |
// Reminder of the setup |
| 876 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 877 |
@ d: c |
| 878 |
○ c: a b |
| 879 |
├─╮ |
| 880 |
│ ○ b |
| 881 |
○ │ a |
| 882 |
├─╯ |
| 883 |
◆ |
| 884 |
[EOF] |
| 885 |
"); |
| 886 |
|
| 887 |
// `d` was a descendant of `b`, and both are moved to be direct descendants of |
| 888 |
// `a`. `c` remains a descendant of `b`. |
| 889 |
let output = work_dir.run_jj(["rebase", "-s=b", "-s=d", "-d=a"]); |
| 890 |
insta::assert_snapshot!(output, @r" |
| 891 |
------- stderr ------- |
| 892 |
Rebased 3 commits to destination. |
| 893 |
Working copy (@) now at: vruxwmqv 7186427a d | d |
| 894 |
Parent commit (@-) : rlvkpnrz 7d980be7 a | a |
| 895 |
Added 0 files, modified 0 files, removed 2 files |
| 896 |
[EOF] |
| 897 |
"); |
| 898 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 899 |
@ d: a |
| 900 |
│ ○ c: a b |
| 901 |
╭─┤ |
| 902 |
│ ○ b: a |
| 903 |
├─╯ |
| 904 |
○ a |
| 905 |
◆ |
| 906 |
[EOF] |
| 907 |
"); |
| 908 |
|
| 909 |
// Same test as above, but with multiple commits per argument |
| 910 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 911 |
let output = work_dir.run_jj(["rebase", "-s=b|d", "-d=a"]); |
| 912 |
insta::assert_snapshot!(output, @r" |
| 913 |
------- stderr ------- |
| 914 |
Rebased 3 commits to destination. |
| 915 |
Working copy (@) now at: vruxwmqv f6c6224e d | d |
| 916 |
Parent commit (@-) : rlvkpnrz 7d980be7 a | a |
| 917 |
Added 0 files, modified 0 files, removed 2 files |
| 918 |
[EOF] |
| 919 |
"); |
| 920 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 921 |
@ d: a |
| 922 |
│ ○ c: a b |
| 923 |
╭─┤ |
| 924 |
│ ○ b: a |
| 925 |
├─╯ |
| 926 |
○ a |
| 927 |
◆ |
| 928 |
[EOF] |
| 929 |
"); |
| 930 |
} |
| 931 |
|
| 932 |
#[test] |
| 933 |
fn test_rebase_error_revision_does_not_exist() { |
| 934 |
let test_env = TestEnvironment::default(); |
| 935 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 936 |
let work_dir = test_env.work_dir("repo"); |
| 937 |
|
| 938 |
work_dir.run_jj(["describe", "-m", "one"]).success(); |
| 939 |
work_dir |
| 940 |
.run_jj(["bookmark", "create", "-r@", "b-one"]) |
| 941 |
.success(); |
| 942 |
work_dir.run_jj(["new", "-r", "@-", "-m", "two"]).success(); |
| 943 |
|
| 944 |
let output = work_dir.run_jj(["rebase", "-b", "b-one", "-o", "this"]); |
| 945 |
insta::assert_snapshot!(output, @" |
| 946 |
------- stderr ------- |
| 947 |
Error: Revision `this` doesn't exist |
| 948 |
[EOF] |
| 949 |
[exit status: 1] |
| 950 |
"); |
| 951 |
|
| 952 |
let output = work_dir.run_jj(["rebase", "-b", "this", "-o", "b-one"]); |
| 953 |
insta::assert_snapshot!(output, @" |
| 954 |
------- stderr ------- |
| 955 |
Error: Revision `this` doesn't exist |
| 956 |
[EOF] |
| 957 |
[exit status: 1] |
| 958 |
"); |
| 959 |
} |
| 960 |
|
| 961 |
// This behavior illustrates https://github.com/jj-vcs/jj/issues/2600 |
| 962 |
#[test] |
| 963 |
fn test_rebase_with_child_and_descendant_bug_2600() { |
| 964 |
let test_env = TestEnvironment::default(); |
| 965 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 966 |
let work_dir = test_env.work_dir("repo"); |
| 967 |
|
| 968 |
create_commit(&work_dir, "notroot", &[]); |
| 969 |
create_commit(&work_dir, "base", &["notroot"]); |
| 970 |
create_commit(&work_dir, "a", &["base"]); |
| 971 |
create_commit(&work_dir, "b", &["base", "a"]); |
| 972 |
create_commit(&work_dir, "c", &["b"]); |
| 973 |
let setup_opid = work_dir.current_operation_id(); |
| 974 |
|
| 975 |
// Test the setup |
| 976 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 977 |
@ c: b |
| 978 |
○ b: base a |
| 979 |
├─╮ |
| 980 |
│ ○ a: base |
| 981 |
├─╯ |
| 982 |
○ base: notroot |
| 983 |
○ notroot |
| 984 |
◆ |
| 985 |
[EOF] |
| 986 |
"); |
| 987 |
|
| 988 |
// ===================== rebase -s tests ================= |
| 989 |
// This should be a no-op |
| 990 |
let output = work_dir.run_jj(["rebase", "-s", "base", "-o", "notroot"]); |
| 991 |
insta::assert_snapshot!(output, @r" |
| 992 |
------- stderr ------- |
| 993 |
Skipped rebase of 4 commits that were already in place. |
| 994 |
Nothing changed. |
| 995 |
[EOF] |
| 996 |
"); |
| 997 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 998 |
@ c: b |
| 999 |
○ b: base a |
| 1000 |
├─╮ |
| 1001 |
│ ○ a: base |
| 1002 |
├─╯ |
| 1003 |
○ base: notroot |
| 1004 |
○ notroot |
| 1005 |
◆ |
| 1006 |
[EOF] |
| 1007 |
"); |
| 1008 |
|
| 1009 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 1010 |
// This should be a no-op |
| 1011 |
let output = work_dir.run_jj(["rebase", "-s", "a", "-o", "base"]); |
| 1012 |
insta::assert_snapshot!(output, @r" |
| 1013 |
------- stderr ------- |
| 1014 |
Skipped rebase of 3 commits that were already in place. |
| 1015 |
Nothing changed. |
| 1016 |
[EOF] |
| 1017 |
"); |
| 1018 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1019 |
@ c: b |
| 1020 |
○ b: base a |
| 1021 |
├─╮ |
| 1022 |
│ ○ a: base |
| 1023 |
├─╯ |
| 1024 |
○ base: notroot |
| 1025 |
○ notroot |
| 1026 |
◆ |
| 1027 |
[EOF] |
| 1028 |
"); |
| 1029 |
|
| 1030 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 1031 |
let output = work_dir.run_jj(["rebase", "-s", "a", "-o", "root()"]); |
| 1032 |
insta::assert_snapshot!(output, @r" |
| 1033 |
------- stderr ------- |
| 1034 |
Rebased 3 commits to destination. |
| 1035 |
Working copy (@) now at: znkkpsqq b65f55fb c | c |
| 1036 |
Parent commit (@-) : vruxwmqv c90d30a4 b | b |
| 1037 |
[EOF] |
| 1038 |
"); |
| 1039 |
// Commit "a" should be rebased onto the root commit. Commit "b" should have |
| 1040 |
// "base" and "a" as parents as before. |
| 1041 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1042 |
@ c: b |
| 1043 |
○ b: base a |
| 1044 |
├─╮ |
| 1045 |
│ ○ a |
| 1046 |
○ │ base: notroot |
| 1047 |
○ │ notroot |
| 1048 |
├─╯ |
| 1049 |
◆ |
| 1050 |
[EOF] |
| 1051 |
"); |
| 1052 |
|
| 1053 |
// ===================== rebase -b tests ================= |
| 1054 |
// ====== Reminder of the setup ========= |
| 1055 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 1056 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1057 |
@ c: b |
| 1058 |
○ b: base a |
| 1059 |
├─╮ |
| 1060 |
│ ○ a: base |
| 1061 |
├─╯ |
| 1062 |
○ base: notroot |
| 1063 |
○ notroot |
| 1064 |
◆ |
| 1065 |
[EOF] |
| 1066 |
"); |
| 1067 |
|
| 1068 |
// The commits in roots(base..c), i.e. commit "a" should be rebased onto "base", |
| 1069 |
// which is a no-op |
| 1070 |
let output = work_dir.run_jj(["rebase", "-b", "c", "-o", "base"]); |
| 1071 |
insta::assert_snapshot!(output, @r" |
| 1072 |
------- stderr ------- |
| 1073 |
Skipped rebase of 3 commits that were already in place. |
| 1074 |
Nothing changed. |
| 1075 |
[EOF] |
| 1076 |
"); |
| 1077 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1078 |
@ c: b |
| 1079 |
○ b: base a |
| 1080 |
├─╮ |
| 1081 |
│ ○ a: base |
| 1082 |
├─╯ |
| 1083 |
○ base: notroot |
| 1084 |
○ notroot |
| 1085 |
◆ |
| 1086 |
[EOF] |
| 1087 |
"); |
| 1088 |
|
| 1089 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 1090 |
let output = work_dir.run_jj(["rebase", "-b", "c", "-o", "a"]); |
| 1091 |
insta::assert_snapshot!(output, @r" |
| 1092 |
------- stderr ------- |
| 1093 |
Rebased 2 commits to destination. |
| 1094 |
Working copy (@) now at: znkkpsqq 5b285fee c | c |
| 1095 |
Parent commit (@-) : vruxwmqv 988d520d b | b |
| 1096 |
[EOF] |
| 1097 |
"); |
| 1098 |
// The commits in roots(a..c), i.e. commit "b" should be rebased onto "a", |
| 1099 |
// which means "b" loses its "base" parent |
| 1100 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1101 |
@ c: b |
| 1102 |
○ b: a |
| 1103 |
○ a: base |
| 1104 |
○ base: notroot |
| 1105 |
○ notroot |
| 1106 |
◆ |
| 1107 |
[EOF] |
| 1108 |
"); |
| 1109 |
|
| 1110 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 1111 |
// This should be a no-op |
| 1112 |
let output = work_dir.run_jj(["rebase", "-b", "a", "-o", "root()"]); |
| 1113 |
insta::assert_snapshot!(output, @r" |
| 1114 |
------- stderr ------- |
| 1115 |
Skipped rebase of 5 commits that were already in place. |
| 1116 |
Nothing changed. |
| 1117 |
[EOF] |
| 1118 |
"); |
| 1119 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1120 |
@ c: b |
| 1121 |
○ b: base a |
| 1122 |
├─╮ |
| 1123 |
│ ○ a: base |
| 1124 |
├─╯ |
| 1125 |
○ base: notroot |
| 1126 |
○ notroot |
| 1127 |
◆ |
| 1128 |
[EOF] |
| 1129 |
"); |
| 1130 |
|
| 1131 |
// ===================== rebase -r tests ================= |
| 1132 |
// ====== Reminder of the setup ========= |
| 1133 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 1134 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1135 |
@ c: b |
| 1136 |
○ b: base a |
| 1137 |
├─╮ |
| 1138 |
│ ○ a: base |
| 1139 |
├─╯ |
| 1140 |
○ base: notroot |
| 1141 |
○ notroot |
| 1142 |
◆ |
| 1143 |
[EOF] |
| 1144 |
"); |
| 1145 |
|
| 1146 |
let output = work_dir.run_jj(["rebase", "-r", "base", "-o", "root()"]); |
| 1147 |
insta::assert_snapshot!(output, @r" |
| 1148 |
------- stderr ------- |
| 1149 |
Rebased 1 commits to destination. |
| 1150 |
Rebased 3 descendant commits. |
| 1151 |
Working copy (@) now at: znkkpsqq ad772a82 c | c |
| 1152 |
Parent commit (@-) : vruxwmqv 79030f30 b | b |
| 1153 |
Added 0 files, modified 0 files, removed 1 files |
| 1154 |
[EOF] |
| 1155 |
"); |
| 1156 |
// The user would expect unsimplified ancestry here. |
| 1157 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1158 |
@ c: b |
| 1159 |
○ b: notroot a |
| 1160 |
├─╮ |
| 1161 |
│ ○ a: notroot |
| 1162 |
├─╯ |
| 1163 |
○ notroot |
| 1164 |
│ ○ base |
| 1165 |
├─╯ |
| 1166 |
◆ |
| 1167 |
[EOF] |
| 1168 |
"); |
| 1169 |
|
| 1170 |
// This tests the algorithm for rebasing onto descendants. The result should |
| 1171 |
// have unsimplified ancestry. |
| 1172 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 1173 |
let output = work_dir.run_jj(["rebase", "-r", "base", "-o", "b"]); |
| 1174 |
insta::assert_snapshot!(output, @r" |
| 1175 |
------- stderr ------- |
| 1176 |
Rebased 1 commits to destination. |
| 1177 |
Rebased 3 descendant commits. |
| 1178 |
Working copy (@) now at: znkkpsqq 3cdfeb24 c | c |
| 1179 |
Parent commit (@-) : vruxwmqv d77e32e7 b | b |
| 1180 |
Added 0 files, modified 0 files, removed 1 files |
| 1181 |
[EOF] |
| 1182 |
"); |
| 1183 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1184 |
@ c: b |
| 1185 |
│ ○ base: b |
| 1186 |
├─╯ |
| 1187 |
○ b: notroot a |
| 1188 |
├─╮ |
| 1189 |
│ ○ a: notroot |
| 1190 |
├─╯ |
| 1191 |
○ notroot |
| 1192 |
◆ |
| 1193 |
[EOF] |
| 1194 |
"); |
| 1195 |
|
| 1196 |
// This tests the algorithm for rebasing onto descendants. The result should |
| 1197 |
// have unsimplified ancestry. |
| 1198 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 1199 |
let output = work_dir.run_jj(["rebase", "-r", "base", "-o", "a"]); |
| 1200 |
insta::assert_snapshot!(output, @r" |
| 1201 |
------- stderr ------- |
| 1202 |
Rebased 1 commits to destination. |
| 1203 |
Rebased 3 descendant commits. |
| 1204 |
Working copy (@) now at: znkkpsqq afc19fe0 c | c |
| 1205 |
Parent commit (@-) : vruxwmqv c319447d b | b |
| 1206 |
Added 0 files, modified 0 files, removed 1 files |
| 1207 |
[EOF] |
| 1208 |
"); |
| 1209 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1210 |
@ c: b |
| 1211 |
○ b: notroot a |
| 1212 |
├─╮ |
| 1213 |
│ │ ○ base: a |
| 1214 |
│ ├─╯ |
| 1215 |
│ ○ a: notroot |
| 1216 |
├─╯ |
| 1217 |
○ notroot |
| 1218 |
◆ |
| 1219 |
[EOF] |
| 1220 |
"); |
| 1221 |
|
| 1222 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 1223 |
// ====== Reminder of the setup ========= |
| 1224 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1225 |
@ c: b |
| 1226 |
○ b: base a |
| 1227 |
├─╮ |
| 1228 |
│ ○ a: base |
| 1229 |
├─╯ |
| 1230 |
○ base: notroot |
| 1231 |
○ notroot |
| 1232 |
◆ |
| 1233 |
[EOF] |
| 1234 |
"); |
| 1235 |
|
| 1236 |
let output = work_dir.run_jj(["rebase", "-r", "a", "-o", "root()"]); |
| 1237 |
insta::assert_snapshot!(output, @r" |
| 1238 |
------- stderr ------- |
| 1239 |
Rebased 1 commits to destination. |
| 1240 |
Rebased 2 descendant commits. |
| 1241 |
Working copy (@) now at: znkkpsqq 1cb17633 c | c |
| 1242 |
Parent commit (@-) : vruxwmqv 801b1b8c b | b |
| 1243 |
Added 0 files, modified 0 files, removed 1 files |
| 1244 |
[EOF] |
| 1245 |
"); |
| 1246 |
// In this case, it is unclear whether the user would always prefer unsimplified |
| 1247 |
// ancestry (whether `b` should also be a direct child of the root commit). |
| 1248 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1249 |
@ c: b |
| 1250 |
○ b: base |
| 1251 |
○ base: notroot |
| 1252 |
○ notroot |
| 1253 |
│ ○ a |
| 1254 |
├─╯ |
| 1255 |
◆ |
| 1256 |
[EOF] |
| 1257 |
"); |
| 1258 |
|
| 1259 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 1260 |
let output = work_dir.run_jj(["rebase", "-r", "b", "-o", "root()"]); |
| 1261 |
insta::assert_snapshot!(output, @r" |
| 1262 |
------- stderr ------- |
| 1263 |
Rebased 1 commits to destination. |
| 1264 |
Rebased 1 descendant commits. |
| 1265 |
Working copy (@) now at: znkkpsqq f8853d0d c | c |
| 1266 |
Parent commit (@-) : zsuskuln 3a2d0837 base | base |
| 1267 |
Parent commit (@-) : royxmykx c7aebf99 a | a |
| 1268 |
Added 0 files, modified 0 files, removed 1 files |
| 1269 |
[EOF] |
| 1270 |
"); |
| 1271 |
// The user would expect unsimplified ancestry here. |
| 1272 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1273 |
@ c: base a |
| 1274 |
├─╮ |
| 1275 |
│ ○ a: base |
| 1276 |
├─╯ |
| 1277 |
○ base: notroot |
| 1278 |
○ notroot |
| 1279 |
│ ○ b |
| 1280 |
├─╯ |
| 1281 |
◆ |
| 1282 |
[EOF] |
| 1283 |
"); |
| 1284 |
|
| 1285 |
// This tests the algorithm for rebasing onto descendants. The result should |
| 1286 |
// have unsimplified ancestry. |
| 1287 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 1288 |
let output = work_dir.run_jj(["rebase", "-r", "b", "-o", "c"]); |
| 1289 |
insta::assert_snapshot!(output, @r" |
| 1290 |
------- stderr ------- |
| 1291 |
Rebased 1 commits to destination. |
| 1292 |
Rebased 1 descendant commits. |
| 1293 |
Working copy (@) now at: znkkpsqq 6feb5c0f c | c |
| 1294 |
Parent commit (@-) : zsuskuln 3a2d0837 base | base |
| 1295 |
Parent commit (@-) : royxmykx c7aebf99 a | a |
| 1296 |
Added 0 files, modified 0 files, removed 1 files |
| 1297 |
[EOF] |
| 1298 |
"); |
| 1299 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1300 |
○ b: c |
| 1301 |
@ c: base a |
| 1302 |
├─╮ |
| 1303 |
│ ○ a: base |
| 1304 |
├─╯ |
| 1305 |
○ base: notroot |
| 1306 |
○ notroot |
| 1307 |
◆ |
| 1308 |
[EOF] |
| 1309 |
"); |
| 1310 |
|
| 1311 |
// In this test, the commit with weird ancestry is not rebased (neither directly |
| 1312 |
// nor indirectly). |
| 1313 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 1314 |
let output = work_dir.run_jj(["rebase", "-r", "c", "-o", "a"]); |
| 1315 |
insta::assert_snapshot!(output, @r" |
| 1316 |
------- stderr ------- |
| 1317 |
Rebased 1 commits to destination. |
| 1318 |
Working copy (@) now at: znkkpsqq a0c5ea8f c | c |
| 1319 |
Parent commit (@-) : royxmykx c7aebf99 a | a |
| 1320 |
Added 0 files, modified 0 files, removed 1 files |
| 1321 |
[EOF] |
| 1322 |
"); |
| 1323 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1324 |
@ c: a |
| 1325 |
│ ○ b: base a |
| 1326 |
╭─┤ |
| 1327 |
○ │ a: base |
| 1328 |
├─╯ |
| 1329 |
○ base: notroot |
| 1330 |
○ notroot |
| 1331 |
◆ |
| 1332 |
[EOF] |
| 1333 |
"); |
| 1334 |
} |
| 1335 |
|
| 1336 |
#[test] |
| 1337 |
fn test_rebase_after() { |
| 1338 |
let test_env = TestEnvironment::default(); |
| 1339 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 1340 |
let work_dir = test_env.work_dir("repo"); |
| 1341 |
|
| 1342 |
create_commit(&work_dir, "a", &[]); |
| 1343 |
create_commit(&work_dir, "b1", &["a"]); |
| 1344 |
create_commit(&work_dir, "b2", &["b1"]); |
| 1345 |
create_commit(&work_dir, "b3", &["a"]); |
| 1346 |
create_commit(&work_dir, "b4", &["b3"]); |
| 1347 |
create_commit(&work_dir, "c", &["b2", "b4"]); |
| 1348 |
create_commit(&work_dir, "d", &["c"]); |
| 1349 |
create_commit(&work_dir, "e", &["c"]); |
| 1350 |
create_commit(&work_dir, "f", &["e"]); |
| 1351 |
// Test the setup |
| 1352 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1353 |
@ f: e |
| 1354 |
○ e: c |
| 1355 |
│ ○ d: c |
| 1356 |
├─╯ |
| 1357 |
○ c: b2 b4 |
| 1358 |
├─╮ |
| 1359 |
│ ○ b4: b3 |
| 1360 |
│ ○ b3: a |
| 1361 |
○ │ b2: b1 |
| 1362 |
○ │ b1: a |
| 1363 |
├─╯ |
| 1364 |
○ a |
| 1365 |
◆ |
| 1366 |
[EOF] |
| 1367 |
"); |
| 1368 |
let setup_opid = work_dir.current_operation_id(); |
| 1369 |
|
| 1370 |
// Rebasing a commit after its parents should be a no-op. |
| 1371 |
let output = work_dir.run_jj(["rebase", "-r", "c", "--after", "b2", "--after", "b4"]); |
| 1372 |
insta::assert_snapshot!(output, @r" |
| 1373 |
------- stderr ------- |
| 1374 |
Skipped rebase of 4 commits that were already in place. |
| 1375 |
Nothing changed. |
| 1376 |
[EOF] |
| 1377 |
"); |
| 1378 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1379 |
@ f: e |
| 1380 |
○ e: c |
| 1381 |
│ ○ d: c |
| 1382 |
├─╯ |
| 1383 |
○ c: b2 b4 |
| 1384 |
├─╮ |
| 1385 |
│ ○ b4: b3 |
| 1386 |
│ ○ b3: a |
| 1387 |
○ │ b2: b1 |
| 1388 |
○ │ b1: a |
| 1389 |
├─╯ |
| 1390 |
○ a |
| 1391 |
◆ |
| 1392 |
[EOF] |
| 1393 |
"); |
| 1394 |
|
| 1395 |
// Rebasing a commit after itself should be a no-op. |
| 1396 |
let output = work_dir.run_jj(["rebase", "-r", "c", "--after", "c"]); |
| 1397 |
insta::assert_snapshot!(output, @r" |
| 1398 |
------- stderr ------- |
| 1399 |
Skipped rebase of 4 commits that were already in place. |
| 1400 |
Nothing changed. |
| 1401 |
[EOF] |
| 1402 |
"); |
| 1403 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1404 |
@ f: e |
| 1405 |
○ e: c |
| 1406 |
│ ○ d: c |
| 1407 |
├─╯ |
| 1408 |
○ c: b2 b4 |
| 1409 |
├─╮ |
| 1410 |
│ ○ b4: b3 |
| 1411 |
│ ○ b3: a |
| 1412 |
○ │ b2: b1 |
| 1413 |
○ │ b1: a |
| 1414 |
├─╯ |
| 1415 |
○ a |
| 1416 |
◆ |
| 1417 |
[EOF] |
| 1418 |
"); |
| 1419 |
|
| 1420 |
// Rebase a commit after another commit. "c" has parents "b2" and "b4", so its |
| 1421 |
// children "d" and "e" should be rebased onto "b2" and "b4" respectively. |
| 1422 |
let output = work_dir.run_jj(["rebase", "-r", "c", "--after", "e"]); |
| 1423 |
insta::assert_snapshot!(output, @r" |
| 1424 |
------- stderr ------- |
| 1425 |
Rebased 1 commits to destination. |
| 1426 |
Rebased 3 descendant commits. |
| 1427 |
Working copy (@) now at: xznxytkn 2f59b944 f | f |
| 1428 |
Parent commit (@-) : kmkuslsw 88ddc78c c | c |
| 1429 |
[EOF] |
| 1430 |
"); |
| 1431 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1432 |
@ f: c |
| 1433 |
○ c: e |
| 1434 |
○ e: b2 b4 |
| 1435 |
├─╮ |
| 1436 |
│ │ ○ d: b2 b4 |
| 1437 |
╭─┬─╯ |
| 1438 |
│ ○ b4: b3 |
| 1439 |
│ ○ b3: a |
| 1440 |
○ │ b2: b1 |
| 1441 |
○ │ b1: a |
| 1442 |
├─╯ |
| 1443 |
○ a |
| 1444 |
◆ |
| 1445 |
[EOF] |
| 1446 |
"); |
| 1447 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 1448 |
|
| 1449 |
// Rebase a commit after a leaf commit. |
| 1450 |
let output = work_dir.run_jj(["rebase", "-r", "e", "--after", "f"]); |
| 1451 |
insta::assert_snapshot!(output, @r" |
| 1452 |
------- stderr ------- |
| 1453 |
Rebased 1 commits to destination. |
| 1454 |
Rebased 1 descendant commits. |
| 1455 |
Working copy (@) now at: xznxytkn da215ecd f | f |
| 1456 |
Parent commit (@-) : kmkuslsw ed86d82a c | c |
| 1457 |
Added 0 files, modified 0 files, removed 1 files |
| 1458 |
[EOF] |
| 1459 |
"); |
| 1460 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1461 |
○ e: f |
| 1462 |
@ f: c |
| 1463 |
│ ○ d: c |
| 1464 |
├─╯ |
| 1465 |
○ c: b2 b4 |
| 1466 |
├─╮ |
| 1467 |
│ ○ b4: b3 |
| 1468 |
│ ○ b3: a |
| 1469 |
○ │ b2: b1 |
| 1470 |
○ │ b1: a |
| 1471 |
├─╯ |
| 1472 |
○ a |
| 1473 |
◆ |
| 1474 |
[EOF] |
| 1475 |
"); |
| 1476 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 1477 |
|
| 1478 |
// Rebase a commit after a commit in a bookmark of a merge commit. |
| 1479 |
let output = work_dir.run_jj(["rebase", "-r", "f", "--after", "b1"]); |
| 1480 |
insta::assert_snapshot!(output, @r" |
| 1481 |
------- stderr ------- |
| 1482 |
Rebased 1 commits to destination. |
| 1483 |
Rebased 4 descendant commits. |
| 1484 |
Working copy (@) now at: xznxytkn 2c606e19 f | f |
| 1485 |
Parent commit (@-) : zsuskuln 62634b59 b1 | b1 |
| 1486 |
Added 0 files, modified 0 files, removed 5 files |
| 1487 |
[EOF] |
| 1488 |
"); |
| 1489 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1490 |
○ e: c |
| 1491 |
│ ○ d: c |
| 1492 |
├─╯ |
| 1493 |
○ c: b2 b4 |
| 1494 |
├─╮ |
| 1495 |
│ ○ b4: b3 |
| 1496 |
│ ○ b3: a |
| 1497 |
○ │ b2: f |
| 1498 |
@ │ f: b1 |
| 1499 |
○ │ b1: a |
| 1500 |
├─╯ |
| 1501 |
○ a |
| 1502 |
◆ |
| 1503 |
[EOF] |
| 1504 |
"); |
| 1505 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 1506 |
|
| 1507 |
// Rebase a commit after the last commit in a bookmark of a merge commit. |
| 1508 |
let output = work_dir.run_jj(["rebase", "-r", "f", "--after", "b2"]); |
| 1509 |
insta::assert_snapshot!(output, @r" |
| 1510 |
------- stderr ------- |
| 1511 |
Rebased 1 commits to destination. |
| 1512 |
Rebased 3 descendant commits. |
| 1513 |
Working copy (@) now at: xznxytkn e60a4b0c f | f |
| 1514 |
Parent commit (@-) : royxmykx 40646d19 b2 | b2 |
| 1515 |
Added 0 files, modified 0 files, removed 4 files |
| 1516 |
[EOF] |
| 1517 |
"); |
| 1518 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1519 |
○ e: c |
| 1520 |
│ ○ d: c |
| 1521 |
├─╯ |
| 1522 |
○ c: f b4 |
| 1523 |
├─╮ |
| 1524 |
│ ○ b4: b3 |
| 1525 |
│ ○ b3: a |
| 1526 |
@ │ f: b2 |
| 1527 |
○ │ b2: b1 |
| 1528 |
○ │ b1: a |
| 1529 |
├─╯ |
| 1530 |
○ a |
| 1531 |
◆ |
| 1532 |
[EOF] |
| 1533 |
"); |
| 1534 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 1535 |
|
| 1536 |
// Rebase a commit after a commit with multiple children. |
| 1537 |
// "c" has two children "d" and "e", so the rebased commit "f" will inherit the |
| 1538 |
// two children. |
| 1539 |
let output = work_dir.run_jj(["rebase", "-r", "f", "--after", "c"]); |
| 1540 |
insta::assert_snapshot!(output, @r" |
| 1541 |
------- stderr ------- |
| 1542 |
Rebased 1 commits to destination. |
| 1543 |
Rebased 2 descendant commits. |
| 1544 |
Working copy (@) now at: xznxytkn 84786555 f | f |
| 1545 |
Parent commit (@-) : kmkuslsw ed86d82a c | c |
| 1546 |
Added 0 files, modified 0 files, removed 1 files |
| 1547 |
[EOF] |
| 1548 |
"); |
| 1549 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1550 |
○ e: f |
| 1551 |
│ ○ d: f |
| 1552 |
├─╯ |
| 1553 |
@ f: c |
| 1554 |
○ c: b2 b4 |
| 1555 |
├─╮ |
| 1556 |
│ ○ b4: b3 |
| 1557 |
│ ○ b3: a |
| 1558 |
○ │ b2: b1 |
| 1559 |
○ │ b1: a |
| 1560 |
├─╯ |
| 1561 |
○ a |
| 1562 |
◆ |
| 1563 |
[EOF] |
| 1564 |
"); |
| 1565 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 1566 |
|
| 1567 |
// Rebase a commit after multiple commits. |
| 1568 |
let output = work_dir.run_jj(["rebase", "-r", "f", "--after", "e", "--after", "d"]); |
| 1569 |
insta::assert_snapshot!(output, @r" |
| 1570 |
------- stderr ------- |
| 1571 |
Rebased 1 commits to destination. |
| 1572 |
Working copy (@) now at: xznxytkn d5324bb4 f | f |
| 1573 |
Parent commit (@-) : nkmrtpmo 50d9bd5d e | e |
| 1574 |
Parent commit (@-) : lylxulpl 610f541b d | d |
| 1575 |
Added 1 files, modified 0 files, removed 0 files |
| 1576 |
[EOF] |
| 1577 |
"); |
| 1578 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1579 |
@ f: e d |
| 1580 |
├─╮ |
| 1581 |
│ ○ d: c |
| 1582 |
○ │ e: c |
| 1583 |
├─╯ |
| 1584 |
○ c: b2 b4 |
| 1585 |
├─╮ |
| 1586 |
│ ○ b4: b3 |
| 1587 |
│ ○ b3: a |
| 1588 |
○ │ b2: b1 |
| 1589 |
○ │ b1: a |
| 1590 |
├─╯ |
| 1591 |
○ a |
| 1592 |
◆ |
| 1593 |
[EOF] |
| 1594 |
"); |
| 1595 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 1596 |
|
| 1597 |
// Rebase two unrelated commits. |
| 1598 |
let output = work_dir.run_jj(["rebase", "-r", "d", "-r", "e", "--after", "a"]); |
| 1599 |
insta::assert_snapshot!(output, @r" |
| 1600 |
------- stderr ------- |
| 1601 |
Rebased 2 commits to destination. |
| 1602 |
Rebased 6 descendant commits. |
| 1603 |
Working copy (@) now at: xznxytkn 17632090 f | f |
| 1604 |
Parent commit (@-) : kmkuslsw 726c937e c | c |
| 1605 |
Added 1 files, modified 0 files, removed 0 files |
| 1606 |
[EOF] |
| 1607 |
"); |
| 1608 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1609 |
@ f: c |
| 1610 |
○ c: b2 b4 |
| 1611 |
├─╮ |
| 1612 |
│ ○ b4: b3 |
| 1613 |
│ ○ b3: d e |
| 1614 |
│ ├─╮ |
| 1615 |
○ │ │ b2: b1 |
| 1616 |
○ │ │ b1: d e |
| 1617 |
╰─┬─╮ |
| 1618 |
│ ○ e: a |
| 1619 |
○ │ d: a |
| 1620 |
├─╯ |
| 1621 |
○ a |
| 1622 |
◆ |
| 1623 |
[EOF] |
| 1624 |
"); |
| 1625 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 1626 |
|
| 1627 |
// Rebase a subgraph with merge commit and two parents, which should preserve |
| 1628 |
// the merge. |
| 1629 |
let output = work_dir.run_jj(["rebase", "-r", "b2", "-r", "b4", "-r", "c", "--after", "f"]); |
| 1630 |
insta::assert_snapshot!(output, @r" |
| 1631 |
------- stderr ------- |
| 1632 |
Rebased 3 commits to destination. |
| 1633 |
Rebased 3 descendant commits. |
| 1634 |
Working copy (@) now at: xznxytkn 991bd3ac f | f |
| 1635 |
Parent commit (@-) : nkmrtpmo f9ecf426 e | e |
| 1636 |
Added 0 files, modified 0 files, removed 3 files |
| 1637 |
[EOF] |
| 1638 |
"); |
| 1639 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1640 |
○ c: b2 b4 |
| 1641 |
├─╮ |
| 1642 |
│ ○ b4: f |
| 1643 |
○ │ b2: f |
| 1644 |
├─╯ |
| 1645 |
@ f: e |
| 1646 |
○ e: b1 b3 |
| 1647 |
├─╮ |
| 1648 |
│ │ ○ d: b1 b3 |
| 1649 |
╭─┬─╯ |
| 1650 |
│ ○ b3: a |
| 1651 |
○ │ b1: a |
| 1652 |
├─╯ |
| 1653 |
○ a |
| 1654 |
◆ |
| 1655 |
[EOF] |
| 1656 |
"); |
| 1657 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 1658 |
|
| 1659 |
// Rebase a subgraph with four commits after one of the commits itself. |
| 1660 |
let output = work_dir.run_jj(["rebase", "-r", "b1::d", "--after", "c"]); |
| 1661 |
insta::assert_snapshot!(output, @r" |
| 1662 |
------- stderr ------- |
| 1663 |
Rebased 4 commits to destination. |
| 1664 |
Rebased 2 descendant commits. |
| 1665 |
Working copy (@) now at: xznxytkn 0123019e f | f |
| 1666 |
Parent commit (@-) : nkmrtpmo 903f8aa0 e | e |
| 1667 |
Added 1 files, modified 0 files, removed 0 files |
| 1668 |
[EOF] |
| 1669 |
"); |
| 1670 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1671 |
@ f: e |
| 1672 |
○ e: d |
| 1673 |
○ d: c |
| 1674 |
○ c: b2 b4 |
| 1675 |
├─╮ |
| 1676 |
○ │ b2: b1 |
| 1677 |
○ │ b1: a b4 |
| 1678 |
├─╮ |
| 1679 |
│ ○ b4: b3 |
| 1680 |
│ ○ b3: a |
| 1681 |
├─╯ |
| 1682 |
○ a |
| 1683 |
◆ |
| 1684 |
[EOF] |
| 1685 |
"); |
| 1686 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 1687 |
|
| 1688 |
// Rebase a subgraph before the parents of one of the commits in the subgraph. |
| 1689 |
// "c" had parents "b2" and "b4", but no longer has "b4" as a parent since |
| 1690 |
// "b4" would be a descendant of "c" after the rebase. |
| 1691 |
let output = work_dir.run_jj(["rebase", "-r", "b2::d", "--after", "root()"]); |
| 1692 |
insta::assert_snapshot!(output, @r" |
| 1693 |
------- stderr ------- |
| 1694 |
Rebased 3 commits to destination. |
| 1695 |
Rebased 6 descendant commits. |
| 1696 |
Working copy (@) now at: xznxytkn fdeb070b f | f |
| 1697 |
Parent commit (@-) : nkmrtpmo f1b259b2 e | e |
| 1698 |
Added 1 files, modified 0 files, removed 0 files |
| 1699 |
[EOF] |
| 1700 |
"); |
| 1701 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1702 |
@ f: e |
| 1703 |
○ e: b1 b4 |
| 1704 |
├─╮ |
| 1705 |
│ ○ b4: b3 |
| 1706 |
│ ○ b3: a |
| 1707 |
○ │ b1: a |
| 1708 |
├─╯ |
| 1709 |
○ a: d |
| 1710 |
○ d: c |
| 1711 |
○ c: b2 |
| 1712 |
○ b2 |
| 1713 |
◆ |
| 1714 |
[EOF] |
| 1715 |
"); |
| 1716 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 1717 |
|
| 1718 |
// Rebase a subgraph with disconnected commits. Since "b2" is an ancestor of |
| 1719 |
// "e", "b2" should be a parent of "e" after the rebase. |
| 1720 |
let output = work_dir.run_jj(["rebase", "-r", "e", "-r", "b2", "--after", "d"]); |
| 1721 |
insta::assert_snapshot!(output, @r" |
| 1722 |
------- stderr ------- |
| 1723 |
Rebased 2 commits to destination. |
| 1724 |
Rebased 3 descendant commits. |
| 1725 |
Working copy (@) now at: xznxytkn c8ba9324 f | f |
| 1726 |
Parent commit (@-) : kmkuslsw 0bd3b3d1 c | c |
| 1727 |
Added 0 files, modified 0 files, removed 2 files |
| 1728 |
[EOF] |
| 1729 |
"); |
| 1730 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1731 |
@ f: c |
| 1732 |
│ ○ e: b2 |
| 1733 |
│ ○ b2: d |
| 1734 |
│ ○ d: c |
| 1735 |
├─╯ |
| 1736 |
○ c: b1 b4 |
| 1737 |
├─╮ |
| 1738 |
│ ○ b4: b3 |
| 1739 |
│ ○ b3: a |
| 1740 |
○ │ b1: a |
| 1741 |
├─╯ |
| 1742 |
○ a |
| 1743 |
◆ |
| 1744 |
[EOF] |
| 1745 |
"); |
| 1746 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 1747 |
|
| 1748 |
// `rebase -s` of commit "c" and its descendants after itself should be a no-op. |
| 1749 |
let output = work_dir.run_jj(["rebase", "-s", "c", "--after", "c"]); |
| 1750 |
insta::assert_snapshot!(output, @r" |
| 1751 |
------- stderr ------- |
| 1752 |
Skipped rebase of 4 commits that were already in place. |
| 1753 |
Nothing changed. |
| 1754 |
[EOF] |
| 1755 |
"); |
| 1756 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1757 |
@ f: e |
| 1758 |
○ e: c |
| 1759 |
│ ○ d: c |
| 1760 |
├─╯ |
| 1761 |
○ c: b2 b4 |
| 1762 |
├─╮ |
| 1763 |
│ ○ b4: b3 |
| 1764 |
│ ○ b3: a |
| 1765 |
○ │ b2: b1 |
| 1766 |
○ │ b1: a |
| 1767 |
├─╯ |
| 1768 |
○ a |
| 1769 |
◆ |
| 1770 |
[EOF] |
| 1771 |
"); |
| 1772 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 1773 |
|
| 1774 |
// `rebase -s` of a commit and its descendants after multiple commits. |
| 1775 |
let output = work_dir.run_jj(["rebase", "-s", "c", "--after", "b1", "--after", "b3"]); |
| 1776 |
insta::assert_snapshot!(output, @r" |
| 1777 |
------- stderr ------- |
| 1778 |
Rebased 4 commits to destination. |
| 1779 |
Rebased 2 descendant commits. |
| 1780 |
Working copy (@) now at: xznxytkn 9ea28699 f | f |
| 1781 |
Parent commit (@-) : nkmrtpmo 989281ba e | e |
| 1782 |
Added 0 files, modified 0 files, removed 2 files |
| 1783 |
[EOF] |
| 1784 |
"); |
| 1785 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1786 |
○ b4: d f |
| 1787 |
├─╮ |
| 1788 |
│ │ ○ b2: d f |
| 1789 |
╭─┬─╯ |
| 1790 |
│ @ f: e |
| 1791 |
│ ○ e: c |
| 1792 |
○ │ d: c |
| 1793 |
├─╯ |
| 1794 |
○ c: b1 b3 |
| 1795 |
├─╮ |
| 1796 |
│ ○ b3: a |
| 1797 |
○ │ b1: a |
| 1798 |
├─╯ |
| 1799 |
○ a |
| 1800 |
◆ |
| 1801 |
[EOF] |
| 1802 |
"); |
| 1803 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 1804 |
|
| 1805 |
// `rebase -b` of commit "b3" after "b1" moves its descendants which are not |
| 1806 |
// already descendants of "b1" (just "b3" and "b4") in between "b1" and its |
| 1807 |
// child "b2". |
| 1808 |
let output = work_dir.run_jj(["rebase", "-b", "b3", "--after", "b1"]); |
| 1809 |
insta::assert_snapshot!(output, @r" |
| 1810 |
------- stderr ------- |
| 1811 |
Rebased 6 commits to destination. |
| 1812 |
Rebased 1 descendant commits. |
| 1813 |
Working copy (@) now at: xznxytkn 63860138 f | f |
| 1814 |
Parent commit (@-) : nkmrtpmo cc7e9907 e | e |
| 1815 |
Added 0 files, modified 0 files, removed 1 files |
| 1816 |
[EOF] |
| 1817 |
"); |
| 1818 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1819 |
○ b2: d f |
| 1820 |
├─╮ |
| 1821 |
│ @ f: e |
| 1822 |
│ ○ e: c |
| 1823 |
○ │ d: c |
| 1824 |
├─╯ |
| 1825 |
○ c: b4 |
| 1826 |
○ b4: b3 |
| 1827 |
○ b3: b1 |
| 1828 |
○ b1: a |
| 1829 |
○ a |
| 1830 |
◆ |
| 1831 |
[EOF] |
| 1832 |
"); |
| 1833 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 1834 |
|
| 1835 |
// Should error if a loop will be created. |
| 1836 |
let output = work_dir.run_jj(["rebase", "-r", "e", "--after", "a", "--after", "b2"]); |
| 1837 |
insta::assert_snapshot!(output, @" |
| 1838 |
------- stderr ------- |
| 1839 |
Error: Refusing to create a loop: commit 40646d195680 would be both an ancestor and a descendant of the rebased commits |
| 1840 |
[EOF] |
| 1841 |
[exit status: 1] |
| 1842 |
"); |
| 1843 |
} |
| 1844 |
|
| 1845 |
#[test] |
| 1846 |
fn test_rebase_before() { |
| 1847 |
let test_env = TestEnvironment::default(); |
| 1848 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 1849 |
let work_dir = test_env.work_dir("repo"); |
| 1850 |
|
| 1851 |
create_commit(&work_dir, "a", &[]); |
| 1852 |
create_commit(&work_dir, "b1", &["a"]); |
| 1853 |
create_commit(&work_dir, "b2", &["b1"]); |
| 1854 |
create_commit(&work_dir, "b3", &["a"]); |
| 1855 |
create_commit(&work_dir, "b4", &["b3"]); |
| 1856 |
create_commit(&work_dir, "c", &["b2", "b4"]); |
| 1857 |
create_commit(&work_dir, "d", &["c"]); |
| 1858 |
create_commit(&work_dir, "e", &["c"]); |
| 1859 |
create_commit(&work_dir, "f", &["e"]); |
| 1860 |
// Test the setup |
| 1861 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1862 |
@ f: e |
| 1863 |
○ e: c |
| 1864 |
│ ○ d: c |
| 1865 |
├─╯ |
| 1866 |
○ c: b2 b4 |
| 1867 |
├─╮ |
| 1868 |
│ ○ b4: b3 |
| 1869 |
│ ○ b3: a |
| 1870 |
○ │ b2: b1 |
| 1871 |
○ │ b1: a |
| 1872 |
├─╯ |
| 1873 |
○ a |
| 1874 |
◆ |
| 1875 |
[EOF] |
| 1876 |
"); |
| 1877 |
let setup_opid = work_dir.current_operation_id(); |
| 1878 |
|
| 1879 |
// Rebasing a commit before its children should be a no-op. |
| 1880 |
let output = work_dir.run_jj(["rebase", "-r", "c", "--before", "d", "--before", "e"]); |
| 1881 |
insta::assert_snapshot!(output, @r" |
| 1882 |
------- stderr ------- |
| 1883 |
Skipped rebase of 4 commits that were already in place. |
| 1884 |
Nothing changed. |
| 1885 |
[EOF] |
| 1886 |
"); |
| 1887 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1888 |
@ f: e |
| 1889 |
○ e: c |
| 1890 |
│ ○ d: c |
| 1891 |
├─╯ |
| 1892 |
○ c: b2 b4 |
| 1893 |
├─╮ |
| 1894 |
│ ○ b4: b3 |
| 1895 |
│ ○ b3: a |
| 1896 |
○ │ b2: b1 |
| 1897 |
○ │ b1: a |
| 1898 |
├─╯ |
| 1899 |
○ a |
| 1900 |
◆ |
| 1901 |
[EOF] |
| 1902 |
"); |
| 1903 |
|
| 1904 |
// Rebasing a commit before itself should be a no-op. |
| 1905 |
let output = work_dir.run_jj(["rebase", "-r", "c", "--before", "c"]); |
| 1906 |
insta::assert_snapshot!(output, @r" |
| 1907 |
------- stderr ------- |
| 1908 |
Skipped rebase of 4 commits that were already in place. |
| 1909 |
Nothing changed. |
| 1910 |
[EOF] |
| 1911 |
"); |
| 1912 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1913 |
@ f: e |
| 1914 |
○ e: c |
| 1915 |
│ ○ d: c |
| 1916 |
├─╯ |
| 1917 |
○ c: b2 b4 |
| 1918 |
├─╮ |
| 1919 |
│ ○ b4: b3 |
| 1920 |
│ ○ b3: a |
| 1921 |
○ │ b2: b1 |
| 1922 |
○ │ b1: a |
| 1923 |
├─╯ |
| 1924 |
○ a |
| 1925 |
◆ |
| 1926 |
[EOF] |
| 1927 |
"); |
| 1928 |
|
| 1929 |
// Rebasing a commit before the root commit should error. |
| 1930 |
let output = work_dir.run_jj(["rebase", "-r", "c", "--before", "root()"]); |
| 1931 |
insta::assert_snapshot!(output, @" |
| 1932 |
------- stderr ------- |
| 1933 |
Error: The root commit 000000000000 is immutable |
| 1934 |
[EOF] |
| 1935 |
[exit status: 1] |
| 1936 |
"); |
| 1937 |
|
| 1938 |
// Rebase a commit before another commit. "c" has parents "b2" and "b4", so its |
| 1939 |
// children "d" and "e" should be rebased onto "b2" and "b4" respectively. |
| 1940 |
let output = work_dir.run_jj(["rebase", "-r", "c", "--before", "a"]); |
| 1941 |
insta::assert_snapshot!(output, @r" |
| 1942 |
------- stderr ------- |
| 1943 |
Rebased 1 commits to destination. |
| 1944 |
Rebased 8 descendant commits. |
| 1945 |
Working copy (@) now at: xznxytkn ff62b7d5 f | f |
| 1946 |
Parent commit (@-) : nkmrtpmo b007a305 e | e |
| 1947 |
[EOF] |
| 1948 |
"); |
| 1949 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1950 |
@ f: e |
| 1951 |
○ e: b2 b4 |
| 1952 |
├─╮ |
| 1953 |
│ │ ○ d: b2 b4 |
| 1954 |
╭─┬─╯ |
| 1955 |
│ ○ b4: b3 |
| 1956 |
│ ○ b3: a |
| 1957 |
○ │ b2: b1 |
| 1958 |
○ │ b1: a |
| 1959 |
├─╯ |
| 1960 |
○ a: c |
| 1961 |
○ c |
| 1962 |
◆ |
| 1963 |
[EOF] |
| 1964 |
"); |
| 1965 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 1966 |
|
| 1967 |
// Rebase a commit before its parent. |
| 1968 |
let output = work_dir.run_jj(["rebase", "-r", "f", "--before", "e"]); |
| 1969 |
insta::assert_snapshot!(output, @r" |
| 1970 |
------- stderr ------- |
| 1971 |
Rebased 1 commits to destination. |
| 1972 |
Rebased 1 descendant commits. |
| 1973 |
Working copy (@) now at: xznxytkn d8eb20c6 f | f |
| 1974 |
Parent commit (@-) : kmkuslsw ed86d82a c | c |
| 1975 |
Added 0 files, modified 0 files, removed 1 files |
| 1976 |
[EOF] |
| 1977 |
"); |
| 1978 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1979 |
○ e: f |
| 1980 |
@ f: c |
| 1981 |
│ ○ d: c |
| 1982 |
├─╯ |
| 1983 |
○ c: b2 b4 |
| 1984 |
├─╮ |
| 1985 |
│ ○ b4: b3 |
| 1986 |
│ ○ b3: a |
| 1987 |
○ │ b2: b1 |
| 1988 |
○ │ b1: a |
| 1989 |
├─╯ |
| 1990 |
○ a |
| 1991 |
◆ |
| 1992 |
[EOF] |
| 1993 |
"); |
| 1994 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 1995 |
|
| 1996 |
// Rebase a commit before a commit in a bookmark of a merge commit. |
| 1997 |
let output = work_dir.run_jj(["rebase", "-r", "f", "--before", "b2"]); |
| 1998 |
insta::assert_snapshot!(output, @r" |
| 1999 |
------- stderr ------- |
| 2000 |
Rebased 1 commits to destination. |
| 2001 |
Rebased 4 descendant commits. |
| 2002 |
Working copy (@) now at: xznxytkn 5fd4cd2f f | f |
| 2003 |
Parent commit (@-) : zsuskuln 62634b59 b1 | b1 |
| 2004 |
Added 0 files, modified 0 files, removed 5 files |
| 2005 |
[EOF] |
| 2006 |
"); |
| 2007 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 2008 |
○ e: c |
| 2009 |
│ ○ d: c |
| 2010 |
├─╯ |
| 2011 |
○ c: b2 b4 |
| 2012 |
├─╮ |
| 2013 |
│ ○ b4: b3 |
| 2014 |
│ ○ b3: a |
| 2015 |
○ │ b2: f |
| 2016 |
@ │ f: b1 |
| 2017 |
○ │ b1: a |
| 2018 |
├─╯ |
| 2019 |
○ a |
| 2020 |
◆ |
| 2021 |
[EOF] |
| 2022 |
"); |
| 2023 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 2024 |
|
| 2025 |
// Rebase a commit before the first commit in a bookmark of a merge commit. |
| 2026 |
let output = work_dir.run_jj(["rebase", "-r", "f", "--before", "b1"]); |
| 2027 |
insta::assert_snapshot!(output, @r" |
| 2028 |
------- stderr ------- |
| 2029 |
Rebased 1 commits to destination. |
| 2030 |
Rebased 5 descendant commits. |
| 2031 |
Working copy (@) now at: xznxytkn 4bb8afb7 f | f |
| 2032 |
Parent commit (@-) : rlvkpnrz 7d980be7 a | a |
| 2033 |
Added 0 files, modified 0 files, removed 6 files |
| 2034 |
[EOF] |
| 2035 |
"); |
| 2036 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 2037 |
○ e: c |
| 2038 |
│ ○ d: c |
| 2039 |
├─╯ |
| 2040 |
○ c: b2 b4 |
| 2041 |
├─╮ |
| 2042 |
│ ○ b4: b3 |
| 2043 |
│ ○ b3: a |
| 2044 |
○ │ b2: b1 |
| 2045 |
○ │ b1: f |
| 2046 |
@ │ f: a |
| 2047 |
├─╯ |
| 2048 |
○ a |
| 2049 |
◆ |
| 2050 |
[EOF] |
| 2051 |
"); |
| 2052 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 2053 |
|
| 2054 |
// Rebase a commit before a merge commit. "c" has two parents "b2" and "b4", so |
| 2055 |
// the rebased commit "f" will have the two commits "b2" and "b4" as its |
| 2056 |
// parents. |
| 2057 |
let output = work_dir.run_jj(["rebase", "-r", "f", "--before", "c"]); |
| 2058 |
insta::assert_snapshot!(output, @r" |
| 2059 |
------- stderr ------- |
| 2060 |
Rebased 1 commits to destination. |
| 2061 |
Rebased 3 descendant commits. |
| 2062 |
Working copy (@) now at: xznxytkn b1d5040b f | f |
| 2063 |
Parent commit (@-) : royxmykx 40646d19 b2 | b2 |
| 2064 |
Parent commit (@-) : znkkpsqq 256ac307 b4 | b4 |
| 2065 |
Added 0 files, modified 0 files, removed 2 files |
| 2066 |
[EOF] |
| 2067 |
"); |
| 2068 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 2069 |
○ e: c |
| 2070 |
│ ○ d: c |
| 2071 |
├─╯ |
| 2072 |
○ c: f |
| 2073 |
@ f: b2 b4 |
| 2074 |
├─╮ |
| 2075 |
│ ○ b4: b3 |
| 2076 |
│ ○ b3: a |
| 2077 |
○ │ b2: b1 |
| 2078 |
○ │ b1: a |
| 2079 |
├─╯ |
| 2080 |
○ a |
| 2081 |
◆ |
| 2082 |
[EOF] |
| 2083 |
"); |
| 2084 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 2085 |
|
| 2086 |
// Rebase a commit before multiple commits. |
| 2087 |
let output = work_dir.run_jj(["rebase", "-r", "b1", "--before", "d", "--before", "e"]); |
| 2088 |
insta::assert_snapshot!(output, @r" |
| 2089 |
------- stderr ------- |
| 2090 |
Rebased 1 commits to destination. |
| 2091 |
Rebased 5 descendant commits. |
| 2092 |
Working copy (@) now at: xznxytkn 9ce35fe1 f | f |
| 2093 |
Parent commit (@-) : nkmrtpmo 95558239 e | e |
| 2094 |
[EOF] |
| 2095 |
"); |
| 2096 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 2097 |
@ f: e |
| 2098 |
○ e: b1 |
| 2099 |
│ ○ d: b1 |
| 2100 |
├─╯ |
| 2101 |
○ b1: c |
| 2102 |
○ c: b2 b4 |
| 2103 |
├─╮ |
| 2104 |
│ ○ b4: b3 |
| 2105 |
│ ○ b3: a |
| 2106 |
○ │ b2: a |
| 2107 |
├─╯ |
| 2108 |
○ a |
| 2109 |
◆ |
| 2110 |
[EOF] |
| 2111 |
"); |
| 2112 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 2113 |
|
| 2114 |
// Rebase a commit before two commits in separate bookmarks to create a merge |
| 2115 |
// commit. |
| 2116 |
let output = work_dir.run_jj(["rebase", "-r", "f", "--before", "b2", "--before", "b4"]); |
| 2117 |
insta::assert_snapshot!(output, @r" |
| 2118 |
------- stderr ------- |
| 2119 |
Rebased 1 commits to destination. |
| 2120 |
Rebased 5 descendant commits. |
| 2121 |
Working copy (@) now at: xznxytkn b984057d f | f |
| 2122 |
Parent commit (@-) : zsuskuln 62634b59 b1 | b1 |
| 2123 |
Parent commit (@-) : vruxwmqv a1d9eeb3 b3 | b3 |
| 2124 |
Added 0 files, modified 0 files, removed 4 files |
| 2125 |
[EOF] |
| 2126 |
"); |
| 2127 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 2128 |
○ e: c |
| 2129 |
│ ○ d: c |
| 2130 |
├─╯ |
| 2131 |
○ c: b2 b4 |
| 2132 |
├─╮ |
| 2133 |
│ ○ b4: f |
| 2134 |
○ │ b2: f |
| 2135 |
├─╯ |
| 2136 |
@ f: b1 b3 |
| 2137 |
├─╮ |
| 2138 |
│ ○ b3: a |
| 2139 |
○ │ b1: a |
| 2140 |
├─╯ |
| 2141 |
○ a |
| 2142 |
◆ |
| 2143 |
[EOF] |
| 2144 |
"); |
| 2145 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 2146 |
|
| 2147 |
// Rebase two unrelated commits "b2" and "b4" before a single commit "a". This |
| 2148 |
// creates a merge commit "a" with the two parents "b2" and "b4". |
| 2149 |
let output = work_dir.run_jj(["rebase", "-r", "b2", "-r", "b4", "--before", "a"]); |
| 2150 |
insta::assert_snapshot!(output, @r" |
| 2151 |
------- stderr ------- |
| 2152 |
Rebased 2 commits to destination. |
| 2153 |
Rebased 7 descendant commits. |
| 2154 |
Working copy (@) now at: xznxytkn 13214a9a f | f |
| 2155 |
Parent commit (@-) : nkmrtpmo 257f541d e | e |
| 2156 |
[EOF] |
| 2157 |
"); |
| 2158 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 2159 |
@ f: e |
| 2160 |
○ e: c |
| 2161 |
│ ○ d: c |
| 2162 |
├─╯ |
| 2163 |
○ c: b1 b3 |
| 2164 |
├─╮ |
| 2165 |
│ ○ b3: a |
| 2166 |
○ │ b1: a |
| 2167 |
├─╯ |
| 2168 |
○ a: b2 b4 |
| 2169 |
├─╮ |
| 2170 |
│ ○ b4 |
| 2171 |
○ │ b2 |
| 2172 |
├─╯ |
| 2173 |
◆ |
| 2174 |
[EOF] |
| 2175 |
"); |
| 2176 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 2177 |
|
| 2178 |
// Rebase a subgraph with a merge commit and two parents. |
| 2179 |
let output = work_dir.run_jj(["rebase", "-r", "b2", "-r", "b4", "-r", "c", "--before", "e"]); |
| 2180 |
insta::assert_snapshot!(output, @r" |
| 2181 |
------- stderr ------- |
| 2182 |
Rebased 3 commits to destination. |
| 2183 |
Rebased 3 descendant commits. |
| 2184 |
Working copy (@) now at: xznxytkn 903781e1 f | f |
| 2185 |
Parent commit (@-) : nkmrtpmo 2a0542d6 e | e |
| 2186 |
[EOF] |
| 2187 |
"); |
| 2188 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 2189 |
@ f: e |
| 2190 |
○ e: c |
| 2191 |
○ c: b2 b4 |
| 2192 |
├─╮ |
| 2193 |
│ ○ b4: b1 b3 |
| 2194 |
│ ├─╮ |
| 2195 |
○ │ │ b2: b1 b3 |
| 2196 |
╰─┬─╮ |
| 2197 |
○ │ │ d: b1 b3 |
| 2198 |
╰─┬─╮ |
| 2199 |
│ ○ b3: a |
| 2200 |
○ │ b1: a |
| 2201 |
├─╯ |
| 2202 |
○ a |
| 2203 |
◆ |
| 2204 |
[EOF] |
| 2205 |
"); |
| 2206 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 2207 |
|
| 2208 |
// Rebase a subgraph with disconnected commits. Since "b1" is an ancestor of |
| 2209 |
// "e", "b1" should be a parent of "e" after the rebase. |
| 2210 |
let output = work_dir.run_jj(["rebase", "-r", "b1", "-r", "e", "--before", "a"]); |
| 2211 |
insta::assert_snapshot!(output, @r" |
| 2212 |
------- stderr ------- |
| 2213 |
Rebased 2 commits to destination. |
| 2214 |
Rebased 7 descendant commits. |
| 2215 |
Working copy (@) now at: xznxytkn 9d5abf25 f | f |
| 2216 |
Parent commit (@-) : kmkuslsw ecde78f5 c | c |
| 2217 |
[EOF] |
| 2218 |
"); |
| 2219 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 2220 |
@ f: c |
| 2221 |
│ ○ d: c |
| 2222 |
├─╯ |
| 2223 |
○ c: b2 b4 |
| 2224 |
├─╮ |
| 2225 |
│ ○ b4: b3 |
| 2226 |
│ ○ b3: a |
| 2227 |
○ │ b2: a |
| 2228 |
├─╯ |
| 2229 |
○ a: e |
| 2230 |
○ e: b1 |
| 2231 |
○ b1 |
| 2232 |
◆ |
| 2233 |
[EOF] |
| 2234 |
"); |
| 2235 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 2236 |
|
| 2237 |
// Rebase a subgraph before the parents of one of the commits in the subgraph. |
| 2238 |
// "c" had parents "b2" and "b4", but no longer has "b4" as a parent since |
| 2239 |
// "b4" would be a descendant of "c" after the rebase. |
| 2240 |
let output = work_dir.run_jj(["rebase", "-r", "b2::d", "--before", "a"]); |
| 2241 |
insta::assert_snapshot!(output, @r" |
| 2242 |
------- stderr ------- |
| 2243 |
Rebased 3 commits to destination. |
| 2244 |
Rebased 6 descendant commits. |
| 2245 |
Working copy (@) now at: xznxytkn 912af1a2 f | f |
| 2246 |
Parent commit (@-) : nkmrtpmo 4e8eabcc e | e |
| 2247 |
Added 1 files, modified 0 files, removed 0 files |
| 2248 |
[EOF] |
| 2249 |
"); |
| 2250 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 2251 |
@ f: e |
| 2252 |
○ e: b1 b4 |
| 2253 |
├─╮ |
| 2254 |
│ ○ b4: b3 |
| 2255 |
│ ○ b3: a |
| 2256 |
○ │ b1: a |
| 2257 |
├─╯ |
| 2258 |
○ a: d |
| 2259 |
○ d: c |
| 2260 |
○ c: b2 |
| 2261 |
○ b2 |
| 2262 |
◆ |
| 2263 |
[EOF] |
| 2264 |
"); |
| 2265 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 2266 |
|
| 2267 |
// Rebase a subgraph before the parents of one of the commits in the subgraph. |
| 2268 |
// "c" had parents "b2" and "b4", but no longer has "b4" as a parent since |
| 2269 |
// "b4" would be a descendant of "c" after the rebase. |
| 2270 |
let output = work_dir.run_jj(["rebase", "-r", "b2::d", "--before", "a"]); |
| 2271 |
insta::assert_snapshot!(output, @r" |
| 2272 |
------- stderr ------- |
| 2273 |
Rebased 3 commits to destination. |
| 2274 |
Rebased 6 descendant commits. |
| 2275 |
Working copy (@) now at: xznxytkn a2ed33ff f | f |
| 2276 |
Parent commit (@-) : nkmrtpmo b69d0e4b e | e |
| 2277 |
Added 1 files, modified 0 files, removed 0 files |
| 2278 |
[EOF] |
| 2279 |
"); |
| 2280 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 2281 |
@ f: e |
| 2282 |
○ e: b1 b4 |
| 2283 |
├─╮ |
| 2284 |
│ ○ b4: b3 |
| 2285 |
│ ○ b3: a |
| 2286 |
○ │ b1: a |
| 2287 |
├─╯ |
| 2288 |
○ a: d |
| 2289 |
○ d: c |
| 2290 |
○ c: b2 |
| 2291 |
○ b2 |
| 2292 |
◆ |
| 2293 |
[EOF] |
| 2294 |
"); |
| 2295 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 2296 |
|
| 2297 |
// `rebase -s` of commit "c" and its descendants before itself should be a |
| 2298 |
// no-op. |
| 2299 |
let output = work_dir.run_jj(["rebase", "-s", "c", "--before", "c"]); |
| 2300 |
insta::assert_snapshot!(output, @r" |
| 2301 |
------- stderr ------- |
| 2302 |
Skipped rebase of 4 commits that were already in place. |
| 2303 |
Nothing changed. |
| 2304 |
[EOF] |
| 2305 |
"); |
| 2306 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 2307 |
@ f: e |
| 2308 |
○ e: c |
| 2309 |
│ ○ d: c |
| 2310 |
├─╯ |
| 2311 |
○ c: b2 b4 |
| 2312 |
├─╮ |
| 2313 |
│ ○ b4: b3 |
| 2314 |
│ ○ b3: a |
| 2315 |
○ │ b2: b1 |
| 2316 |
○ │ b1: a |
| 2317 |
├─╯ |
| 2318 |
○ a |
| 2319 |
◆ |
| 2320 |
[EOF] |
| 2321 |
"); |
| 2322 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 2323 |
|
| 2324 |
// `rebase -s` of a commit and its descendants before multiple commits. |
| 2325 |
let output = work_dir.run_jj(["rebase", "-s", "c", "--before", "b2", "--before", "b4"]); |
| 2326 |
insta::assert_snapshot!(output, @r" |
| 2327 |
------- stderr ------- |
| 2328 |
Rebased 4 commits to destination. |
| 2329 |
Rebased 2 descendant commits. |
| 2330 |
Working copy (@) now at: xznxytkn 5fe09799 f | f |
| 2331 |
Parent commit (@-) : nkmrtpmo ee33f6f1 e | e |
| 2332 |
Added 0 files, modified 0 files, removed 2 files |
| 2333 |
[EOF] |
| 2334 |
"); |
| 2335 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 2336 |
○ b4: d f |
| 2337 |
├─╮ |
| 2338 |
│ │ ○ b2: d f |
| 2339 |
╭─┬─╯ |
| 2340 |
│ @ f: e |
| 2341 |
│ ○ e: c |
| 2342 |
○ │ d: c |
| 2343 |
├─╯ |
| 2344 |
○ c: b1 b3 |
| 2345 |
├─╮ |
| 2346 |
│ ○ b3: a |
| 2347 |
○ │ b1: a |
| 2348 |
├─╯ |
| 2349 |
○ a |
| 2350 |
◆ |
| 2351 |
[EOF] |
| 2352 |
"); |
| 2353 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 2354 |
|
| 2355 |
// `rebase -b` of commit "b3" before "b2" moves its descendants which are not |
| 2356 |
// already descendants of its parent "b1" (just "b3" and "b4") in between "b1" |
| 2357 |
// and its child "b2". |
| 2358 |
let output = work_dir.run_jj(["rebase", "-b", "b3", "--before", "b1"]); |
| 2359 |
insta::assert_snapshot!(output, @r" |
| 2360 |
------- stderr ------- |
| 2361 |
Skipped rebase of 2 commits that were already in place. |
| 2362 |
Rebased 4 commits to destination. |
| 2363 |
Rebased 2 descendant commits. |
| 2364 |
Working copy (@) now at: xznxytkn d1c73b11 f | f |
| 2365 |
Parent commit (@-) : nkmrtpmo 53fc68f7 e | e |
| 2366 |
Added 0 files, modified 0 files, removed 2 files |
| 2367 |
[EOF] |
| 2368 |
"); |
| 2369 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 2370 |
○ b2: b1 |
| 2371 |
○ b1: d f |
| 2372 |
├─╮ |
| 2373 |
│ @ f: e |
| 2374 |
│ ○ e: c |
| 2375 |
○ │ d: c |
| 2376 |
├─╯ |
| 2377 |
○ c: b4 |
| 2378 |
○ b4: b3 |
| 2379 |
○ b3: a |
| 2380 |
○ a |
| 2381 |
◆ |
| 2382 |
[EOF] |
| 2383 |
"); |
| 2384 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 2385 |
|
| 2386 |
// Should error if a loop will be created. |
| 2387 |
let output = work_dir.run_jj(["rebase", "-r", "e", "--before", "b2", "--before", "c"]); |
| 2388 |
insta::assert_snapshot!(output, @" |
| 2389 |
------- stderr ------- |
| 2390 |
Error: Refusing to create a loop: commit 40646d195680 would be both an ancestor and a descendant of the rebased commits |
| 2391 |
[EOF] |
| 2392 |
[exit status: 1] |
| 2393 |
"); |
| 2394 |
} |
| 2395 |
|
| 2396 |
#[test] |
| 2397 |
fn test_rebase_after_before() { |
| 2398 |
let test_env = TestEnvironment::default(); |
| 2399 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 2400 |
let work_dir = test_env.work_dir("repo"); |
| 2401 |
|
| 2402 |
create_commit(&work_dir, "x", &[]); |
| 2403 |
create_commit(&work_dir, "y", &["x"]); |
| 2404 |
create_commit(&work_dir, "z", &["y"]); |
| 2405 |
create_commit(&work_dir, "a", &[]); |
| 2406 |
create_commit(&work_dir, "b1", &["a"]); |
| 2407 |
create_commit(&work_dir, "b2", &["a"]); |
| 2408 |
create_commit(&work_dir, "c", &["b1", "b2"]); |
| 2409 |
create_commit(&work_dir, "d", &["c"]); |
| 2410 |
create_commit(&work_dir, "e", &["c"]); |
| 2411 |
create_commit(&work_dir, "f", &["e"]); |
| 2412 |
// Test the setup |
| 2413 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 2414 |
@ f: e |
| 2415 |
○ e: c |
| 2416 |
│ ○ d: c |
| 2417 |
├─╯ |
| 2418 |
○ c: b1 b2 |
| 2419 |
├─╮ |
| 2420 |
│ ○ b2: a |
| 2421 |
○ │ b1: a |
| 2422 |
├─╯ |
| 2423 |
○ a |
| 2424 |
│ ○ z: y |
| 2425 |
│ ○ y: x |
| 2426 |
│ ○ x |
| 2427 |
├─╯ |
| 2428 |
◆ |
| 2429 |
[EOF] |
| 2430 |
"); |
| 2431 |
let setup_opid = work_dir.current_operation_id(); |
| 2432 |
|
| 2433 |
// Rebase a commit after another commit and before that commit's child to |
| 2434 |
// insert directly between the two commits. |
| 2435 |
let output = work_dir.run_jj(["rebase", "-r", "d", "--after", "e", "--before", "f"]); |
| 2436 |
insta::assert_snapshot!(output, @r" |
| 2437 |
------- stderr ------- |
| 2438 |
Rebased 1 commits to destination. |
| 2439 |
Rebased 1 descendant commits. |
| 2440 |
Working copy (@) now at: nmzmmopx 321e1d40 f | f |
| 2441 |
Parent commit (@-) : nkmrtpmo 7d7b0aec d | d |
| 2442 |
Added 1 files, modified 0 files, removed 0 files |
| 2443 |
[EOF] |
| 2444 |
"); |
| 2445 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 2446 |
@ f: d |
| 2447 |
○ d: e |
| 2448 |
○ e: c |
| 2449 |
○ c: b1 b2 |
| 2450 |
├─╮ |
| 2451 |
│ ○ b2: a |
| 2452 |
○ │ b1: a |
| 2453 |
├─╯ |
| 2454 |
○ a |
| 2455 |
│ ○ z: y |
| 2456 |
│ ○ y: x |
| 2457 |
│ ○ x |
| 2458 |
├─╯ |
| 2459 |
◆ |
| 2460 |
[EOF] |
| 2461 |
"); |
| 2462 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 2463 |
|
| 2464 |
// Rebase a commit after another commit and before that commit's descendant to |
| 2465 |
// create a new merge commit. |
| 2466 |
let output = work_dir.run_jj(["rebase", "-r", "d", "--after", "a", "--before", "f"]); |
| 2467 |
insta::assert_snapshot!(output, @r" |
| 2468 |
------- stderr ------- |
| 2469 |
Rebased 1 commits to destination. |
| 2470 |
Rebased 1 descendant commits. |
| 2471 |
Working copy (@) now at: nmzmmopx a12b0ae1 f | f |
| 2472 |
Parent commit (@-) : xznxytkn d4334f29 e | e |
| 2473 |
Parent commit (@-) : nkmrtpmo a3204f2a d | d |
| 2474 |
Added 1 files, modified 0 files, removed 0 files |
| 2475 |
[EOF] |
| 2476 |
"); |
| 2477 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 2478 |
@ f: e d |
| 2479 |
├─╮ |
| 2480 |
│ ○ d: a |
| 2481 |
○ │ e: c |
| 2482 |
○ │ c: b1 b2 |
| 2483 |
├───╮ |
| 2484 |
│ │ ○ b2: a |
| 2485 |
│ ├─╯ |
| 2486 |
○ │ b1: a |
| 2487 |
├─╯ |
| 2488 |
○ a |
| 2489 |
│ ○ z: y |
| 2490 |
│ ○ y: x |
| 2491 |
│ ○ x |
| 2492 |
├─╯ |
| 2493 |
◆ |
| 2494 |
[EOF] |
| 2495 |
"); |
| 2496 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 2497 |
|
| 2498 |
// "c" has parents "b1" and "b2", so when it is rebased, its children "d" and |
| 2499 |
// "e" should have "b1" and "b2" as parents as well. "c" is then inserted in |
| 2500 |
// between "d" and "e", making "e" a merge commit with 3 parents "b1", "b2", |
| 2501 |
// and "c". |
| 2502 |
let output = work_dir.run_jj(["rebase", "-r", "c", "--after", "d", "--before", "e"]); |
| 2503 |
insta::assert_snapshot!(output, @r" |
| 2504 |
------- stderr ------- |
| 2505 |
Rebased 1 commits to destination. |
| 2506 |
Rebased 3 descendant commits. |
| 2507 |
Working copy (@) now at: nmzmmopx 97ebbe11 f | f |
| 2508 |
Parent commit (@-) : xznxytkn e53a8360 e | e |
| 2509 |
Added 1 files, modified 0 files, removed 0 files |
| 2510 |
[EOF] |
| 2511 |
"); |
| 2512 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 2513 |
@ f: e |
| 2514 |
○ e: b1 b2 c |
| 2515 |
├─┬─╮ |
| 2516 |
│ │ ○ c: d |
| 2517 |
│ │ ○ d: b1 b2 |
| 2518 |
╭─┬─╯ |
| 2519 |
│ ○ b2: a |
| 2520 |
○ │ b1: a |
| 2521 |
├─╯ |
| 2522 |
○ a |
| 2523 |
│ ○ z: y |
| 2524 |
│ ○ y: x |
| 2525 |
│ ○ x |
| 2526 |
├─╯ |
| 2527 |
◆ |
| 2528 |
[EOF] |
| 2529 |
"); |
| 2530 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 2531 |
|
| 2532 |
// Rebase multiple commits and preserve their ancestry. Apart from the heads of |
| 2533 |
// the target commits ("d" and "e"), "f" also has commits "b1" and "b2" as |
| 2534 |
// parents since its parents "d" and "e" were in the target set and were |
| 2535 |
// replaced by their closest ancestors outside the target set. |
| 2536 |
let output = work_dir.run_jj([ |
| 2537 |
"rebase", "-r", "c", "-r", "d", "-r", "e", "--after", "a", "--before", "f", |
| 2538 |
]); |
| 2539 |
insta::assert_snapshot!(output, @r" |
| 2540 |
------- stderr ------- |
| 2541 |
Rebased 3 commits to destination. |
| 2542 |
Rebased 1 descendant commits. |
| 2543 |
Working copy (@) now at: nmzmmopx 5a27aa46 f | f |
| 2544 |
Parent commit (@-) : znkkpsqq 0780cdfa b1 | b1 |
| 2545 |
Parent commit (@-) : kmkuslsw 0692c8ed b2 | b2 |
| 2546 |
Parent commit (@-) : nkmrtpmo 07028fe4 d | d |
| 2547 |
Parent commit (@-) : xznxytkn 1aa724f0 e | e |
| 2548 |
Added 1 files, modified 0 files, removed 0 files |
| 2549 |
[EOF] |
| 2550 |
"); |
| 2551 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 2552 |
@ f: b1 b2 d e |
| 2553 |
├─┬─┬─╮ |
| 2554 |
│ │ │ ○ e: c |
| 2555 |
│ │ ○ │ d: c |
| 2556 |
│ │ ├─╯ |
| 2557 |
│ │ ○ c: a |
| 2558 |
│ ○ │ b2: a |
| 2559 |
│ ├─╯ |
| 2560 |
○ │ b1: a |
| 2561 |
├─╯ |
| 2562 |
○ a |
| 2563 |
│ ○ z: y |
| 2564 |
│ ○ y: x |
| 2565 |
│ ○ x |
| 2566 |
├─╯ |
| 2567 |
◆ |
| 2568 |
[EOF] |
| 2569 |
"); |
| 2570 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 2571 |
|
| 2572 |
// `rebase -s` of a commit and its descendants. |
| 2573 |
let output = work_dir.run_jj(["rebase", "-s", "c", "--before", "b1", "--after", "b2"]); |
| 2574 |
insta::assert_snapshot!(output, @r" |
| 2575 |
------- stderr ------- |
| 2576 |
Rebased 4 commits to destination. |
| 2577 |
Rebased 1 descendant commits. |
| 2578 |
Working copy (@) now at: nmzmmopx 5b68ace7 f | f |
| 2579 |
Parent commit (@-) : xznxytkn 8bfa4c49 e | e |
| 2580 |
Added 0 files, modified 0 files, removed 1 files |
| 2581 |
[EOF] |
| 2582 |
"); |
| 2583 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 2584 |
○ b1: a d f |
| 2585 |
├─┬─╮ |
| 2586 |
│ │ @ f: e |
| 2587 |
│ │ ○ e: c |
| 2588 |
│ ○ │ d: c |
| 2589 |
│ ├─╯ |
| 2590 |
│ ○ c: b2 |
| 2591 |
│ ○ b2: a |
| 2592 |
├─╯ |
| 2593 |
○ a |
| 2594 |
│ ○ z: y |
| 2595 |
│ ○ y: x |
| 2596 |
│ ○ x |
| 2597 |
├─╯ |
| 2598 |
◆ |
| 2599 |
[EOF] |
| 2600 |
"); |
| 2601 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 2602 |
|
| 2603 |
// `rebase -b` of a commit "y" to a destination after "a" will rebase all |
| 2604 |
// commits in "roots(a..y)" and their descendants, corresponding to "x", "y" |
| 2605 |
// and "z". They will be inserted in a new branch after "a" and before "c". |
| 2606 |
let output = work_dir.run_jj(["rebase", "-b", "y", "--after", "a", "--before", "c"]); |
| 2607 |
insta::assert_snapshot!(output, @r" |
| 2608 |
------- stderr ------- |
| 2609 |
Rebased 3 commits to destination. |
| 2610 |
Rebased 4 descendant commits. |
| 2611 |
Working copy (@) now at: nmzmmopx 68713d9d f | f |
| 2612 |
Parent commit (@-) : xznxytkn d4bcbcd4 e | e |
| 2613 |
Added 3 files, modified 0 files, removed 0 files |
| 2614 |
[EOF] |
| 2615 |
"); |
| 2616 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 2617 |
@ f: e |
| 2618 |
○ e: c |
| 2619 |
│ ○ d: c |
| 2620 |
├─╯ |
| 2621 |
○ c: b1 b2 z |
| 2622 |
├─┬─╮ |
| 2623 |
│ │ ○ z: y |
| 2624 |
│ │ ○ y: x |
| 2625 |
│ │ ○ x: a |
| 2626 |
│ ○ │ b2: a |
| 2627 |
│ ├─╯ |
| 2628 |
○ │ b1: a |
| 2629 |
├─╯ |
| 2630 |
○ a |
| 2631 |
◆ |
| 2632 |
[EOF] |
| 2633 |
"); |
| 2634 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 2635 |
|
| 2636 |
// Should error if a loop will be created. |
| 2637 |
let output = work_dir.run_jj(["rebase", "-r", "e", "--after", "c", "--before", "a"]); |
| 2638 |
insta::assert_snapshot!(output, @" |
| 2639 |
------- stderr ------- |
| 2640 |
Error: Refusing to create a loop: commit 0c9da0df7f7c would be both an ancestor and a descendant of the rebased commits |
| 2641 |
[EOF] |
| 2642 |
[exit status: 1] |
| 2643 |
"); |
| 2644 |
} |
| 2645 |
|
| 2646 |
#[test] |
| 2647 |
fn test_rebase_skip_emptied() { |
| 2648 |
let test_env = TestEnvironment::default(); |
| 2649 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 2650 |
let work_dir = test_env.work_dir("repo"); |
| 2651 |
|
| 2652 |
create_commit(&work_dir, "a", &[]); |
| 2653 |
create_commit(&work_dir, "b", &["a"]); |
| 2654 |
work_dir |
| 2655 |
.run_jj(["new", "a", "-m", "will become empty"]) |
| 2656 |
.success(); |
| 2657 |
work_dir.run_jj(["restore", "--from=b"]).success(); |
| 2658 |
work_dir.run_jj(["new", "-m", "already empty"]).success(); |
| 2659 |
work_dir |
| 2660 |
.run_jj(["new", "-m", "also already empty"]) |
| 2661 |
.success(); |
| 2662 |
let setup_opid = work_dir.current_operation_id(); |
| 2663 |
|
| 2664 |
// Test the setup |
| 2665 |
insta::assert_snapshot!(work_dir.run_jj(["log", "-T", "description"]), @" |
| 2666 |
@ also already empty |
| 2667 |
○ already empty |
| 2668 |
○ will become empty |
| 2669 |
│ ○ b |
| 2670 |
├─╯ |
| 2671 |
○ a |
| 2672 |
◆ |
| 2673 |
[EOF] |
| 2674 |
"); |
| 2675 |
|
| 2676 |
let output = work_dir.run_jj(["rebase", "-d=b", "--skip-emptied"]); |
| 2677 |
insta::assert_snapshot!(output, @r" |
| 2678 |
------- stderr ------- |
| 2679 |
Rebased 2 commits to destination. |
| 2680 |
Abandoned 1 newly emptied commits. |
| 2681 |
Working copy (@) now at: yostqsxw 6b46781e (empty) also already empty |
| 2682 |
Parent commit (@-) : vruxwmqv 4861a0a8 (empty) already empty |
| 2683 |
[EOF] |
| 2684 |
"); |
| 2685 |
|
| 2686 |
// The parent commit became empty and was dropped, but the already empty commits |
| 2687 |
// were kept |
| 2688 |
insta::assert_snapshot!(work_dir.run_jj(["log", "-T", "description"]), @" |
| 2689 |
@ also already empty |
| 2690 |
○ already empty |
| 2691 |
○ b |
| 2692 |
○ a |
| 2693 |
◆ |
| 2694 |
[EOF] |
| 2695 |
"); |
| 2696 |
|
| 2697 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 2698 |
// Test the setup |
| 2699 |
insta::assert_snapshot!(work_dir.run_jj(["log", "-T", "description"]), @" |
| 2700 |
@ also already empty |
| 2701 |
○ already empty |
| 2702 |
○ will become empty |
| 2703 |
│ ○ b |
| 2704 |
├─╯ |
| 2705 |
○ a |
| 2706 |
◆ |
| 2707 |
[EOF] |
| 2708 |
"); |
| 2709 |
|
| 2710 |
let output = work_dir.run_jj([ |
| 2711 |
"rebase", |
| 2712 |
"-r=subject('will become empty')", |
| 2713 |
"-d=b", |
| 2714 |
"--skip-emptied", |
| 2715 |
]); |
| 2716 |
insta::assert_snapshot!(output, @r" |
| 2717 |
------- stderr ------- |
| 2718 |
Rebased 2 descendant commits. |
| 2719 |
Abandoned 1 newly emptied commits. |
| 2720 |
Working copy (@) now at: yostqsxw bbfc2a27 (empty) also already empty |
| 2721 |
Parent commit (@-) : vruxwmqv 1b8c46b3 (empty) already empty |
| 2722 |
Added 0 files, modified 0 files, removed 1 files |
| 2723 |
[EOF] |
| 2724 |
"); |
| 2725 |
|
| 2726 |
// Rebasing a single commit which becomes empty abandons that commit, whilst its |
| 2727 |
// already empty descendants were kept |
| 2728 |
insta::assert_snapshot!(work_dir.run_jj(["log", "-T", "description"]), @" |
| 2729 |
@ also already empty |
| 2730 |
○ already empty |
| 2731 |
│ ○ b |
| 2732 |
├─╯ |
| 2733 |
○ a |
| 2734 |
◆ |
| 2735 |
[EOF] |
| 2736 |
"); |
| 2737 |
} |
| 2738 |
|
| 2739 |
#[test] |
| 2740 |
fn test_rebase_skip_emptied_descendants() { |
| 2741 |
let test_env = TestEnvironment::default(); |
| 2742 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 2743 |
let work_dir = test_env.work_dir("repo"); |
| 2744 |
|
| 2745 |
create_commit(&work_dir, "a", &[]); |
| 2746 |
create_commit(&work_dir, "b", &["a"]); |
| 2747 |
work_dir |
| 2748 |
.run_jj(["new", "a", "-m", "c (will become empty)"]) |
| 2749 |
.success(); |
| 2750 |
work_dir.run_jj(["restore", "--from=b"]).success(); |
| 2751 |
work_dir |
| 2752 |
.run_jj(["bookmark", "create", "-r@", "c"]) |
| 2753 |
.success(); |
| 2754 |
work_dir.run_jj(["new", "-m", "already empty"]).success(); |
| 2755 |
work_dir |
| 2756 |
.run_jj(["new", "-m", "also already empty"]) |
| 2757 |
.success(); |
| 2758 |
|
| 2759 |
// Test the setup |
| 2760 |
insta::assert_snapshot!(work_dir.run_jj(["log", "-T", "description"]), @" |
| 2761 |
@ also already empty |
| 2762 |
○ already empty |
| 2763 |
○ c (will become empty) |
| 2764 |
│ ○ b |
| 2765 |
├─╯ |
| 2766 |
○ a |
| 2767 |
◆ |
| 2768 |
[EOF] |
| 2769 |
"); |
| 2770 |
|
| 2771 |
let output = work_dir.run_jj(["rebase", "-r", "b", "--before", "c", "--skip-emptied"]); |
| 2772 |
insta::assert_snapshot!(output, @r" |
| 2773 |
------- stderr ------- |
| 2774 |
Skipped rebase of 1 commits that were already in place. |
| 2775 |
Rebased 3 descendant commits. |
| 2776 |
Working copy (@) now at: znkkpsqq 6d024ab4 (empty) also already empty |
| 2777 |
Parent commit (@-) : yostqsxw bb87e185 (empty) already empty |
| 2778 |
[EOF] |
| 2779 |
"); |
| 2780 |
|
| 2781 |
// Commits not in the rebase target set should not be abandoned even if they |
| 2782 |
// were emptied. |
| 2783 |
insta::assert_snapshot!(work_dir.run_jj(["log", "-T", "description"]), @" |
| 2784 |
@ also already empty |
| 2785 |
○ already empty |
| 2786 |
○ c (will become empty) |
| 2787 |
○ b |
| 2788 |
○ a |
| 2789 |
◆ |
| 2790 |
[EOF] |
| 2791 |
"); |
| 2792 |
} |
| 2793 |
|
| 2794 |
#[test] |
| 2795 |
fn test_rebase_skip_if_on_destination() { |
| 2796 |
let test_env = TestEnvironment::default(); |
| 2797 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 2798 |
let work_dir = test_env.work_dir("repo"); |
| 2799 |
|
| 2800 |
create_commit(&work_dir, "a", &[]); |
| 2801 |
create_commit(&work_dir, "b1", &["a"]); |
| 2802 |
create_commit(&work_dir, "b2", &["a"]); |
| 2803 |
create_commit(&work_dir, "c", &["b1", "b2"]); |
| 2804 |
create_commit(&work_dir, "d", &["c"]); |
| 2805 |
create_commit(&work_dir, "e", &["c"]); |
| 2806 |
create_commit(&work_dir, "f", &["e"]); |
| 2807 |
// Test the setup |
| 2808 |
insta::assert_snapshot!(get_long_log_output(&work_dir), @" |
| 2809 |
@ f lylxulpl cf8edc20: e |
| 2810 |
○ e kmkuslsw 65f1083b: c |
| 2811 |
│ ○ d znkkpsqq f91a8202: c |
| 2812 |
├─╯ |
| 2813 |
○ c vruxwmqv 86997ac2: b1 b2 |
| 2814 |
├─╮ |
| 2815 |
│ ○ b2 royxmykx 1d9f22d8: a |
| 2816 |
○ │ b1 zsuskuln 62634b59: a |
| 2817 |
├─╯ |
| 2818 |
○ a rlvkpnrz 7d980be7 |
| 2819 |
◆ zzzzzzzz 00000000 |
| 2820 |
[EOF] |
| 2821 |
"); |
| 2822 |
|
| 2823 |
// Skip rebase with -b |
| 2824 |
let output = work_dir.run_jj(["rebase", "-b", "d", "-o", "a"]); |
| 2825 |
insta::assert_snapshot!(output, @r" |
| 2826 |
------- stderr ------- |
| 2827 |
Skipped rebase of 6 commits that were already in place. |
| 2828 |
Nothing changed. |
| 2829 |
[EOF] |
| 2830 |
"); |
| 2831 |
insta::assert_snapshot!(get_long_log_output(&work_dir), @" |
| 2832 |
@ f lylxulpl cf8edc20: e |
| 2833 |
○ e kmkuslsw 65f1083b: c |
| 2834 |
│ ○ d znkkpsqq f91a8202: c |
| 2835 |
├─╯ |
| 2836 |
○ c vruxwmqv 86997ac2: b1 b2 |
| 2837 |
├─╮ |
| 2838 |
│ ○ b2 royxmykx 1d9f22d8: a |
| 2839 |
○ │ b1 zsuskuln 62634b59: a |
| 2840 |
├─╯ |
| 2841 |
○ a rlvkpnrz 7d980be7 |
| 2842 |
◆ zzzzzzzz 00000000 |
| 2843 |
[EOF] |
| 2844 |
"); |
| 2845 |
|
| 2846 |
// Skip rebase with -s |
| 2847 |
let output = work_dir.run_jj(["rebase", "-s", "c", "-o", "b1", "-o", "b2"]); |
| 2848 |
insta::assert_snapshot!(output, @r" |
| 2849 |
------- stderr ------- |
| 2850 |
Skipped rebase of 4 commits that were already in place. |
| 2851 |
Nothing changed. |
| 2852 |
[EOF] |
| 2853 |
"); |
| 2854 |
insta::assert_snapshot!(get_long_log_output(&work_dir), @" |
| 2855 |
@ f lylxulpl cf8edc20: e |
| 2856 |
○ e kmkuslsw 65f1083b: c |
| 2857 |
│ ○ d znkkpsqq f91a8202: c |
| 2858 |
├─╯ |
| 2859 |
○ c vruxwmqv 86997ac2: b1 b2 |
| 2860 |
├─╮ |
| 2861 |
│ ○ b2 royxmykx 1d9f22d8: a |
| 2862 |
○ │ b1 zsuskuln 62634b59: a |
| 2863 |
├─╯ |
| 2864 |
○ a rlvkpnrz 7d980be7 |
| 2865 |
◆ zzzzzzzz 00000000 |
| 2866 |
[EOF] |
| 2867 |
"); |
| 2868 |
|
| 2869 |
// Skip rebase with -r since commit has no children |
| 2870 |
let output = work_dir.run_jj(["rebase", "-r", "d", "-o", "c"]); |
| 2871 |
insta::assert_snapshot!(output, @r" |
| 2872 |
------- stderr ------- |
| 2873 |
Skipped rebase of 1 commits that were already in place. |
| 2874 |
Nothing changed. |
| 2875 |
[EOF] |
| 2876 |
"); |
| 2877 |
insta::assert_snapshot!(get_long_log_output(&work_dir), @" |
| 2878 |
@ f lylxulpl cf8edc20: e |
| 2879 |
○ e kmkuslsw 65f1083b: c |
| 2880 |
│ ○ d znkkpsqq f91a8202: c |
| 2881 |
├─╯ |
| 2882 |
○ c vruxwmqv 86997ac2: b1 b2 |
| 2883 |
├─╮ |
| 2884 |
│ ○ b2 royxmykx 1d9f22d8: a |
| 2885 |
○ │ b1 zsuskuln 62634b59: a |
| 2886 |
├─╯ |
| 2887 |
○ a rlvkpnrz 7d980be7 |
| 2888 |
◆ zzzzzzzz 00000000 |
| 2889 |
[EOF] |
| 2890 |
"); |
| 2891 |
|
| 2892 |
// Skip rebase of commit, but rebases children onto destination with -r |
| 2893 |
let output = work_dir.run_jj(["rebase", "-r", "e", "-o", "c"]); |
| 2894 |
insta::assert_snapshot!(output, @r" |
| 2895 |
------- stderr ------- |
| 2896 |
Skipped rebase of 1 commits that were already in place. |
| 2897 |
Rebased 1 descendant commits. |
| 2898 |
Working copy (@) now at: lylxulpl f2015644 f | f |
| 2899 |
Parent commit (@-) : vruxwmqv 86997ac2 c | c |
| 2900 |
Added 0 files, modified 0 files, removed 1 files |
| 2901 |
[EOF] |
| 2902 |
"); |
| 2903 |
insta::assert_snapshot!(get_long_log_output(&work_dir), @" |
| 2904 |
@ f lylxulpl f2015644: c |
| 2905 |
│ ○ e kmkuslsw 65f1083b: c |
| 2906 |
├─╯ |
| 2907 |
│ ○ d znkkpsqq f91a8202: c |
| 2908 |
├─╯ |
| 2909 |
○ c vruxwmqv 86997ac2: b1 b2 |
| 2910 |
├─╮ |
| 2911 |
│ ○ b2 royxmykx 1d9f22d8: a |
| 2912 |
○ │ b1 zsuskuln 62634b59: a |
| 2913 |
├─╯ |
| 2914 |
○ a rlvkpnrz 7d980be7 |
| 2915 |
◆ zzzzzzzz 00000000 |
| 2916 |
[EOF] |
| 2917 |
"); |
| 2918 |
} |
| 2919 |
|
| 2920 |
#[test] |
| 2921 |
fn test_rebase_skip_duplicate_divergent() { |
| 2922 |
let test_env = TestEnvironment::default(); |
| 2923 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 2924 |
let work_dir = test_env.work_dir("repo"); |
| 2925 |
|
| 2926 |
// Set up commit graph with divergent changes |
| 2927 |
create_commit_with_files(&work_dir, "a", &[], &[("file1", "initial\n")]); |
| 2928 |
create_commit_with_files(&work_dir, "b2", &["a"], &[("file1", "initial\nb\n")]); |
| 2929 |
create_commit_with_files(&work_dir, "c", &["a"], &[("file2", "c\n")]); |
| 2930 |
work_dir.run_jj(["rebase", "-r", "b2", "-o", "c"]).success(); |
| 2931 |
work_dir |
| 2932 |
.run_jj(["bookmark", "create", "b1", "-r", "at_operation(@-, b2)"]) |
| 2933 |
.success(); |
| 2934 |
create_commit_with_files(&work_dir, "d", &["b1"], &[("file3", "d\n")]); |
| 2935 |
|
| 2936 |
// Test the setup (commit B is duplicated) |
| 2937 |
insta::assert_snapshot!(get_long_log_output(&work_dir), @" |
| 2938 |
@ d znkkpsqq ecbe1d2f: b1 |
| 2939 |
○ b1 zsuskuln 48bf33ab: a |
| 2940 |
│ ○ b2 zsuskuln 3f194323: c |
| 2941 |
│ ○ c royxmykx 0fdb9e5a: a |
| 2942 |
├─╯ |
| 2943 |
○ a rlvkpnrz 08789390 |
| 2944 |
◆ zzzzzzzz 00000000 |
| 2945 |
[EOF] |
| 2946 |
"); |
| 2947 |
let setup_opid = work_dir.current_operation_id(); |
| 2948 |
|
| 2949 |
// By default, rebase should skip the duplicate of commit B |
| 2950 |
insta::assert_snapshot!(work_dir.run_jj(["rebase", "-r", "c::", "-o", "d"]), @r" |
| 2951 |
------- stderr ------- |
| 2952 |
Abandoned 1 divergent commits that were already present in the destination: |
| 2953 |
zsuskuln/0 3f194323 b2 | (divergent) b2 |
| 2954 |
Rebased 1 commits to destination. |
| 2955 |
[EOF] |
| 2956 |
"); |
| 2957 |
insta::assert_snapshot!(get_long_log_output(&work_dir), @" |
| 2958 |
○ b2 c royxmykx 56740329: d |
| 2959 |
@ d znkkpsqq ecbe1d2f: b1 |
| 2960 |
○ b1 zsuskuln 48bf33ab: a |
| 2961 |
○ a rlvkpnrz 08789390 |
| 2962 |
◆ zzzzzzzz 00000000 |
| 2963 |
[EOF] |
| 2964 |
"); |
| 2965 |
|
| 2966 |
// Rebasing should work even if the root of the target set is abandoned |
| 2967 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 2968 |
insta::assert_snapshot!(work_dir.run_jj(["rebase", "-s", "b1", "-o", "b2"]), @r" |
| 2969 |
------- stderr ------- |
| 2970 |
Abandoned 1 divergent commits that were already present in the destination: |
| 2971 |
zsuskuln/1 48bf33ab b1 | (divergent) b2 |
| 2972 |
Rebased 1 commits to destination. |
| 2973 |
Working copy (@) now at: znkkpsqq 81e83d0f d | d |
| 2974 |
Parent commit (@-) : zsuskuln 3f194323 b1 b2 | b2 |
| 2975 |
Added 1 files, modified 0 files, removed 0 files |
| 2976 |
[EOF] |
| 2977 |
"); |
| 2978 |
// BUG: "d" should be on top of "b2", but it wasn't rebased |
| 2979 |
insta::assert_snapshot!(get_long_log_output(&work_dir), @" |
| 2980 |
@ d znkkpsqq 81e83d0f: b1 b2 |
| 2981 |
○ b1 b2 zsuskuln 3f194323: c |
| 2982 |
○ c royxmykx 0fdb9e5a: a |
| 2983 |
○ a rlvkpnrz 08789390 |
| 2984 |
◆ zzzzzzzz 00000000 |
| 2985 |
[EOF] |
| 2986 |
"); |
| 2987 |
|
| 2988 |
// Rebase with "--keep-divergent" shouldn't skip any duplicates |
| 2989 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 2990 |
insta::assert_snapshot!(work_dir.run_jj(["rebase", "-s", "c", "-o", "d", "--keep-divergent"]), @r" |
| 2991 |
------- stderr ------- |
| 2992 |
Rebased 2 commits to destination. |
| 2993 |
[EOF] |
| 2994 |
"); |
| 2995 |
insta::assert_snapshot!(get_long_log_output(&work_dir), @" |
| 2996 |
○ b2 zsuskuln f8e418c5: c |
| 2997 |
○ c royxmykx e232ead1: d |
| 2998 |
@ d znkkpsqq ecbe1d2f: b1 |
| 2999 |
○ b1 zsuskuln 48bf33ab: a |
| 3000 |
○ a rlvkpnrz 08789390 |
| 3001 |
◆ zzzzzzzz 00000000 |
| 3002 |
[EOF] |
| 3003 |
"); |
| 3004 |
} |
| 3005 |
|
| 3006 |
#[test] |
| 3007 |
fn test_rebase_simplify_parents() { |
| 3008 |
let test_env = TestEnvironment::default(); |
| 3009 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 3010 |
let work_dir = test_env.work_dir("repo"); |
| 3011 |
|
| 3012 |
create_commit(&work_dir, "a", &[]); |
| 3013 |
create_commit(&work_dir, "a1", &["a"]); |
| 3014 |
create_commit(&work_dir, "a2", &["a1"]); |
| 3015 |
create_commit(&work_dir, "a3", &["a2", "a1"]); |
| 3016 |
create_commit(&work_dir, "b", &[]); |
| 3017 |
insta::assert_snapshot!(get_long_log_output(&work_dir), @" |
| 3018 |
@ b znkkpsqq 3df16d78 |
| 3019 |
│ ○ a3 vruxwmqv cf72a356: a2 a1 |
| 3020 |
│ ├─╮ |
| 3021 |
│ ○ │ a2 royxmykx 1f35d069: a1 |
| 3022 |
│ ├─╯ |
| 3023 |
│ ○ a1 zsuskuln dce85039: a |
| 3024 |
│ ○ a rlvkpnrz 7d980be7 |
| 3025 |
├─╯ |
| 3026 |
◆ zzzzzzzz 00000000 |
| 3027 |
[EOF] |
| 3028 |
"); |
| 3029 |
let setup_opid = work_dir.current_operation_id(); |
| 3030 |
|
| 3031 |
// without --simplify-parents, should transplant the whole tree structure |
| 3032 |
work_dir.run_jj(["rebase", "-s", "a", "-o", "b"]).success(); |
| 3033 |
insta::assert_snapshot!(get_long_log_output(&work_dir), @" |
| 3034 |
○ a3 vruxwmqv b15b79bb: a2 a1 |
| 3035 |
├─╮ |
| 3036 |
○ │ a2 royxmykx 06a5cde7: a1 |
| 3037 |
├─╯ |
| 3038 |
○ a1 zsuskuln 16af6bbe: a |
| 3039 |
○ a rlvkpnrz 69d157bb: b |
| 3040 |
@ b znkkpsqq 3df16d78 |
| 3041 |
◆ zzzzzzzz 00000000 |
| 3042 |
[EOF] |
| 3043 |
"); |
| 3044 |
|
| 3045 |
// with --simplify-parents, should drop the redundant a2 parent on a3 |
| 3046 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 3047 |
work_dir |
| 3048 |
.run_jj(["rebase", "-s", "a", "-o", "b", "--simplify-parents"]) |
| 3049 |
.success(); |
| 3050 |
insta::assert_snapshot!(get_long_log_output(&work_dir), @" |
| 3051 |
○ a3 vruxwmqv 867b901e: a2 |
| 3052 |
○ a2 royxmykx ecaa9fe7: a1 |
| 3053 |
○ a1 zsuskuln 88fc1ed4: a |
| 3054 |
○ a rlvkpnrz c23ea181: b |
| 3055 |
@ b znkkpsqq 3df16d78 |
| 3056 |
◆ zzzzzzzz 00000000 |
| 3057 |
[EOF] |
| 3058 |
"); |
| 3059 |
|
| 3060 |
// but, does not apply to autorebased commits |
| 3061 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 3062 |
work_dir |
| 3063 |
.run_jj(["rebase", "-r", "a", "-o", "b", "--simplify-parents"]) |
| 3064 |
.success(); |
| 3065 |
insta::assert_snapshot!(get_long_log_output(&work_dir), @" |
| 3066 |
○ a rlvkpnrz 0e4898d1: b |
| 3067 |
@ b znkkpsqq 3df16d78 |
| 3068 |
│ ○ a3 vruxwmqv 92c40092: a2 a1 |
| 3069 |
│ ├─╮ |
| 3070 |
│ ○ │ a2 royxmykx 4bed9069: a1 |
| 3071 |
│ ├─╯ |
| 3072 |
│ ○ a1 zsuskuln 98a31b4f |
| 3073 |
├─╯ |
| 3074 |
◆ zzzzzzzz 00000000 |
| 3075 |
[EOF] |
| 3076 |
"); |
| 3077 |
} |
| 3078 |
|
| 3079 |
#[must_use] |
| 3080 |
fn get_log_output(work_dir: &TestWorkDir) -> CommandOutput { |
| 3081 |
let template = "bookmarks ++ surround(': ', '', parents.map(|c| c.bookmarks()))"; |
| 3082 |
work_dir.run_jj(["log", "-T", template]) |
| 3083 |
} |
| 3084 |
|
| 3085 |
#[must_use] |
| 3086 |
fn get_long_log_output(work_dir: &TestWorkDir) -> CommandOutput { |
| 3087 |
let template = "bookmarks ++ ' ' ++ change_id.shortest(8) ++ ' ' ++ commit_id.shortest(8) \ |
| 3088 |
++ surround(': ', '', parents.map(|c| c.bookmarks()))"; |
| 3089 |
work_dir.run_jj(["log", "-T", template]) |
| 3090 |
} |