| 1 |
// Copyright 2024 The Jujutsu Authors |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// https://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
use testutils::TestResult; |
| 16 |
|
| 17 |
use crate::common::CommandOutput; |
| 18 |
use crate::common::TestEnvironment; |
| 19 |
use crate::common::TestWorkDir; |
| 20 |
|
| 21 |
#[test] |
| 22 |
fn test_absorb_simple() { |
| 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 |
work_dir.run_jj(["describe", "-m0"]).success(); |
| 28 |
work_dir.write_file("file1", ""); |
| 29 |
|
| 30 |
work_dir.run_jj(["new", "-m1"]).success(); |
| 31 |
work_dir.write_file("file1", "1a\n1b\n"); |
| 32 |
|
| 33 |
work_dir.run_jj(["new", "-m2"]).success(); |
| 34 |
work_dir.write_file("file1", "1a\n1b\n2a\n2b\n"); |
| 35 |
|
| 36 |
// Empty commit |
| 37 |
work_dir.run_jj(["new"]).success(); |
| 38 |
let output = work_dir.run_jj(["absorb"]); |
| 39 |
insta::assert_snapshot!(output, @" |
| 40 |
------- stderr ------- |
| 41 |
Nothing changed. |
| 42 |
[EOF] |
| 43 |
"); |
| 44 |
|
| 45 |
// Insert first and last lines |
| 46 |
work_dir.write_file("file1", "1X\n1a\n1b\n2a\n2b\n2Z\n"); |
| 47 |
let output = work_dir.run_jj(["absorb"]); |
| 48 |
insta::assert_snapshot!(output, @" |
| 49 |
------- stderr ------- |
| 50 |
Absorbed changes into 2 revisions: |
| 51 |
zsuskuln 95568809 2 |
| 52 |
kkmpptxz bd7d4016 1 |
| 53 |
Working copy (@) now at: yqosqzyt 977269ac (empty) (no description set) |
| 54 |
Parent commit (@-) : zsuskuln 95568809 2 |
| 55 |
[EOF] |
| 56 |
"); |
| 57 |
|
| 58 |
// Modify middle line in hunk |
| 59 |
work_dir.write_file("file1", "1X\n1A\n1b\n2a\n2b\n2Z\n"); |
| 60 |
let output = work_dir.run_jj(["absorb"]); |
| 61 |
insta::assert_snapshot!(output, @r" |
| 62 |
------- stderr ------- |
| 63 |
Absorbed changes into 1 revisions: |
| 64 |
kkmpptxz 5810eb0f 1 |
| 65 |
Rebased 1 descendant commits. |
| 66 |
Working copy (@) now at: vruxwmqv 48c7d8fa (empty) (no description set) |
| 67 |
Parent commit (@-) : zsuskuln 8edd60a2 2 |
| 68 |
[EOF] |
| 69 |
"); |
| 70 |
|
| 71 |
// Remove middle line from hunk |
| 72 |
work_dir.write_file("file1", "1X\n1A\n1b\n2a\n2Z\n"); |
| 73 |
let output = work_dir.run_jj(["absorb"]); |
| 74 |
insta::assert_snapshot!(output, @" |
| 75 |
------- stderr ------- |
| 76 |
Absorbed changes into 1 revisions: |
| 77 |
zsuskuln dd109863 2 |
| 78 |
Working copy (@) now at: yostqsxw 7482f74b (empty) (no description set) |
| 79 |
Parent commit (@-) : zsuskuln dd109863 2 |
| 80 |
[EOF] |
| 81 |
"); |
| 82 |
|
| 83 |
// Insert ambiguous line in between |
| 84 |
work_dir.write_file("file1", "1X\n1A\n1b\nY\n2a\n2Z\n"); |
| 85 |
let output = work_dir.run_jj(["absorb"]); |
| 86 |
insta::assert_snapshot!(output, @" |
| 87 |
------- stderr ------- |
| 88 |
Nothing changed. |
| 89 |
[EOF] |
| 90 |
"); |
| 91 |
|
| 92 |
insta::assert_snapshot!(get_diffs(&work_dir, "mutable()"), @" |
| 93 |
@ yostqsxw bde51bc9 (no description set) |
| 94 |
│ diff --git a/file1 b/file1 |
| 95 |
│ index 8653ca354d..88eb438902 100644 |
| 96 |
│ --- a/file1 |
| 97 |
│ +++ b/file1 |
| 98 |
│ @@ -1,5 +1,6 @@ |
| 99 |
│ 1X |
| 100 |
│ 1A |
| 101 |
│ 1b |
| 102 |
│ +Y |
| 103 |
│ 2a |
| 104 |
│ 2Z |
| 105 |
○ zsuskuln dd109863 2 |
| 106 |
│ diff --git a/file1 b/file1 |
| 107 |
│ index ed237b5112..8653ca354d 100644 |
| 108 |
│ --- a/file1 |
| 109 |
│ +++ b/file1 |
| 110 |
│ @@ -1,3 +1,5 @@ |
| 111 |
│ 1X |
| 112 |
│ 1A |
| 113 |
│ 1b |
| 114 |
│ +2a |
| 115 |
│ +2Z |
| 116 |
○ kkmpptxz 5810eb0f 1 |
| 117 |
│ diff --git a/file1 b/file1 |
| 118 |
│ index e69de29bb2..ed237b5112 100644 |
| 119 |
│ --- a/file1 |
| 120 |
│ +++ b/file1 |
| 121 |
│ @@ -0,0 +1,3 @@ |
| 122 |
│ +1X |
| 123 |
│ +1A |
| 124 |
│ +1b |
| 125 |
○ qpvuntsm 6a446874 0 |
| 126 |
│ diff --git a/file1 b/file1 |
| 127 |
~ new file mode 100644 |
| 128 |
index 0000000000..e69de29bb2 |
| 129 |
[EOF] |
| 130 |
"); |
| 131 |
insta::assert_snapshot!(get_evolog(&work_dir, "subject(1)"), @" |
| 132 |
○ kkmpptxz 5810eb0f 1 |
| 133 |
├─╮ |
| 134 |
│ ○ yqosqzyt/0 39b42898 (hidden) (no description set) |
| 135 |
│ ○ yqosqzyt/1 977269ac (hidden) (empty) (no description set) |
| 136 |
○ kkmpptxz/1 bd7d4016 (hidden) 1 |
| 137 |
├─╮ |
| 138 |
│ ○ mzvwutvl/0 0b307741 (hidden) (no description set) |
| 139 |
│ ○ mzvwutvl/1 f2709b4e (hidden) (empty) (no description set) |
| 140 |
○ kkmpptxz/2 1553c5e8 (hidden) 1 |
| 141 |
○ kkmpptxz/3 eb943711 (hidden) (empty) 1 |
| 142 |
[EOF] |
| 143 |
"); |
| 144 |
insta::assert_snapshot!(get_evolog(&work_dir, "subject(2)"), @" |
| 145 |
○ zsuskuln dd109863 2 |
| 146 |
├─╮ |
| 147 |
│ ○ vruxwmqv/0 761492a8 (hidden) (no description set) |
| 148 |
│ ○ vruxwmqv/1 48c7d8fa (hidden) (empty) (no description set) |
| 149 |
○ zsuskuln/1 8edd60a2 (hidden) 2 |
| 150 |
○ zsuskuln/2 95568809 (hidden) 2 |
| 151 |
├─╮ |
| 152 |
│ ○ mzvwutvl/0 0b307741 (hidden) (no description set) |
| 153 |
│ ○ mzvwutvl/1 f2709b4e (hidden) (empty) (no description set) |
| 154 |
○ zsuskuln/3 36fad385 (hidden) 2 |
| 155 |
○ zsuskuln/4 561fbce9 (hidden) (empty) 2 |
| 156 |
[EOF] |
| 157 |
"); |
| 158 |
} |
| 159 |
|
| 160 |
#[test] |
| 161 |
fn test_absorb_replace_single_line_hunk() { |
| 162 |
let test_env = TestEnvironment::default(); |
| 163 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 164 |
let work_dir = test_env.work_dir("repo"); |
| 165 |
|
| 166 |
work_dir.run_jj(["describe", "-m1"]).success(); |
| 167 |
work_dir.write_file("file1", "1a\n"); |
| 168 |
|
| 169 |
work_dir.run_jj(["new", "-m2"]).success(); |
| 170 |
work_dir.write_file("file1", "2a\n1a\n2b\n"); |
| 171 |
|
| 172 |
// Replace single-line hunk, which produces a conflict right now. If our |
| 173 |
// merge logic were based on interleaved delta, the hunk would be applied |
| 174 |
// cleanly. |
| 175 |
work_dir.run_jj(["new"]).success(); |
| 176 |
work_dir.write_file("file1", "2a\n1A\n2b\n"); |
| 177 |
let output = work_dir.run_jj(["absorb"]); |
| 178 |
insta::assert_snapshot!(output, @r" |
| 179 |
------- stderr ------- |
| 180 |
Absorbed changes into 1 revisions: |
| 181 |
qpvuntsm 125fba68 (conflict) 1 |
| 182 |
Rebased 1 descendant commits. |
| 183 |
Working copy (@) now at: mzvwutvl deeb043a (empty) (no description set) |
| 184 |
Parent commit (@-) : kkmpptxz 732472fb 2 |
| 185 |
New conflicts appeared in 1 commits: |
| 186 |
qpvuntsm 125fba68 (conflict) 1 |
| 187 |
Hint: To resolve the conflicts, start by creating a commit on top of |
| 188 |
the conflicted commit: |
| 189 |
jj new qpvuntsm |
| 190 |
Then use `jj resolve`, or edit the conflict markers in the file directly. |
| 191 |
Once the conflicts are resolved, you can inspect the result with `jj diff`. |
| 192 |
Then run `jj squash` to move the resolution into the conflicted commit. |
| 193 |
[EOF] |
| 194 |
"); |
| 195 |
|
| 196 |
insta::assert_snapshot!(get_diffs(&work_dir, "mutable()"), @r#" |
| 197 |
@ mzvwutvl deeb043a (empty) (no description set) |
| 198 |
○ kkmpptxz 732472fb 2 |
| 199 |
│ diff --git a/file1 b/file1 |
| 200 |
│ index 0000000000..2f87e8e465 100644 |
| 201 |
│ --- a/file1 |
| 202 |
│ +++ b/file1 |
| 203 |
│ @@ -1,11 +1,3 @@ |
| 204 |
│ -<<<<<<< conflict 1 of 1 |
| 205 |
│ -%%%%%%% diff from: kkmpptxz 9d700628 "2" (parents of absorbed revision) |
| 206 |
│ -\\\\\\\ to: qpvuntsm aa6cb9bc "1" (absorb destination) |
| 207 |
│ --2a |
| 208 |
│ - 1a |
| 209 |
│ --2b |
| 210 |
│ -+++++++ absorbed changes (from zsuskuln 5d926f12) |
| 211 |
│ 2a |
| 212 |
│ 1A |
| 213 |
│ 2b |
| 214 |
│ ->>>>>>> conflict 1 of 1 ends |
| 215 |
× qpvuntsm 125fba68 (conflict) 1 |
| 216 |
│ diff --git a/file1 b/file1 |
| 217 |
~ new file mode 100644 |
| 218 |
index 0000000000..0000000000 |
| 219 |
--- /dev/null |
| 220 |
+++ b/file1 |
| 221 |
@@ -0,0 +1,11 @@ |
| 222 |
+<<<<<<< conflict 1 of 1 |
| 223 |
+%%%%%%% diff from: kkmpptxz 9d700628 "2" (parents of absorbed revision) |
| 224 |
+\\\\\\\ to: qpvuntsm aa6cb9bc "1" (absorb destination) |
| 225 |
+-2a |
| 226 |
+ 1a |
| 227 |
+-2b |
| 228 |
++++++++ absorbed changes (from zsuskuln 5d926f12) |
| 229 |
+2a |
| 230 |
+1A |
| 231 |
+2b |
| 232 |
+>>>>>>> conflict 1 of 1 ends |
| 233 |
[EOF] |
| 234 |
"#); |
| 235 |
} |
| 236 |
|
| 237 |
#[test] |
| 238 |
fn test_absorb_merge() { |
| 239 |
let test_env = TestEnvironment::default(); |
| 240 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 241 |
let work_dir = test_env.work_dir("repo"); |
| 242 |
|
| 243 |
work_dir.run_jj(["describe", "-m0"]).success(); |
| 244 |
work_dir.write_file("file1", "0a\n"); |
| 245 |
|
| 246 |
work_dir.run_jj(["new", "-m1"]).success(); |
| 247 |
work_dir.write_file("file1", "1a\n1b\n0a\n"); |
| 248 |
|
| 249 |
work_dir.run_jj(["new", "-m2", "subject(0)"]).success(); |
| 250 |
work_dir.write_file("file1", "0a\n2a\n2b\n"); |
| 251 |
|
| 252 |
let output = work_dir.run_jj(["new", "-m3", "subject(1)", "subject(2)"]); |
| 253 |
insta::assert_snapshot!(output, @" |
| 254 |
------- stderr ------- |
| 255 |
Working copy (@) now at: mzvwutvl 42875bf7 (empty) 3 |
| 256 |
Parent commit (@-) : kkmpptxz 9c66f62f 1 |
| 257 |
Parent commit (@-) : zsuskuln 6a3dcbcf 2 |
| 258 |
Added 0 files, modified 1 files, removed 0 files |
| 259 |
[EOF] |
| 260 |
"); |
| 261 |
|
| 262 |
// Modify first and last lines, absorb from merge |
| 263 |
work_dir.write_file("file1", "1A\n1b\n0a\n2a\n2B\n"); |
| 264 |
let output = work_dir.run_jj(["absorb"]); |
| 265 |
insta::assert_snapshot!(output, @r" |
| 266 |
------- stderr ------- |
| 267 |
Absorbed changes into 2 revisions: |
| 268 |
zsuskuln a6fde7ea 2 |
| 269 |
kkmpptxz 00ecc958 1 |
| 270 |
Rebased 1 descendant commits. |
| 271 |
Working copy (@) now at: mzvwutvl 30499858 (empty) 3 |
| 272 |
Parent commit (@-) : kkmpptxz 00ecc958 1 |
| 273 |
Parent commit (@-) : zsuskuln a6fde7ea 2 |
| 274 |
[EOF] |
| 275 |
"); |
| 276 |
|
| 277 |
// Add hunk to merge revision |
| 278 |
work_dir.write_file("file2", "3a\n"); |
| 279 |
|
| 280 |
// Absorb into merge |
| 281 |
work_dir.run_jj(["new"]).success(); |
| 282 |
work_dir.write_file("file2", "3A\n"); |
| 283 |
let output = work_dir.run_jj(["absorb"]); |
| 284 |
insta::assert_snapshot!(output, @" |
| 285 |
------- stderr ------- |
| 286 |
Absorbed changes into 1 revisions: |
| 287 |
mzvwutvl faf778a4 3 |
| 288 |
Working copy (@) now at: vruxwmqv cec519a1 (empty) (no description set) |
| 289 |
Parent commit (@-) : mzvwutvl faf778a4 3 |
| 290 |
[EOF] |
| 291 |
"); |
| 292 |
|
| 293 |
insta::assert_snapshot!(get_diffs(&work_dir, "mutable()"), @" |
| 294 |
@ vruxwmqv cec519a1 (empty) (no description set) |
| 295 |
○ mzvwutvl faf778a4 3 |
| 296 |
├─╮ diff --git a/file2 b/file2 |
| 297 |
│ │ new file mode 100644 |
| 298 |
│ │ index 0000000000..44442d2d7b |
| 299 |
│ │ --- /dev/null |
| 300 |
│ │ +++ b/file2 |
| 301 |
│ │ @@ -0,0 +1,1 @@ |
| 302 |
│ │ +3A |
| 303 |
│ ○ zsuskuln a6fde7ea 2 |
| 304 |
│ │ diff --git a/file1 b/file1 |
| 305 |
│ │ index eb6e8821f1..4907935b9f 100644 |
| 306 |
│ │ --- a/file1 |
| 307 |
│ │ +++ b/file1 |
| 308 |
│ │ @@ -1,1 +1,3 @@ |
| 309 |
│ │ 0a |
| 310 |
│ │ +2a |
| 311 |
│ │ +2B |
| 312 |
○ │ kkmpptxz 00ecc958 1 |
| 313 |
├─╯ diff --git a/file1 b/file1 |
| 314 |
│ index eb6e8821f1..902dd8ef13 100644 |
| 315 |
│ --- a/file1 |
| 316 |
│ +++ b/file1 |
| 317 |
│ @@ -1,1 +1,3 @@ |
| 318 |
│ +1A |
| 319 |
│ +1b |
| 320 |
│ 0a |
| 321 |
○ qpvuntsm d4f07be5 0 |
| 322 |
│ diff --git a/file1 b/file1 |
| 323 |
~ new file mode 100644 |
| 324 |
index 0000000000..eb6e8821f1 |
| 325 |
--- /dev/null |
| 326 |
+++ b/file1 |
| 327 |
@@ -0,0 +1,1 @@ |
| 328 |
+0a |
| 329 |
[EOF] |
| 330 |
"); |
| 331 |
} |
| 332 |
|
| 333 |
#[test] |
| 334 |
fn test_absorb_discardable_merge_with_descendant() { |
| 335 |
let test_env = TestEnvironment::default(); |
| 336 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 337 |
let work_dir = test_env.work_dir("repo"); |
| 338 |
|
| 339 |
work_dir.run_jj(["describe", "-m0"]).success(); |
| 340 |
work_dir.write_file("file1", "0a\n"); |
| 341 |
|
| 342 |
work_dir.run_jj(["new", "-m1"]).success(); |
| 343 |
work_dir.write_file("file1", "1a\n1b\n0a\n"); |
| 344 |
|
| 345 |
work_dir.run_jj(["new", "-m2", "subject(0)"]).success(); |
| 346 |
work_dir.write_file("file1", "0a\n2a\n2b\n"); |
| 347 |
|
| 348 |
let output = work_dir.run_jj(["new", "subject(1)", "subject(2)"]); |
| 349 |
insta::assert_snapshot!(output, @" |
| 350 |
------- stderr ------- |
| 351 |
Working copy (@) now at: mzvwutvl ad00b91a (empty) (no description set) |
| 352 |
Parent commit (@-) : kkmpptxz 9c66f62f 1 |
| 353 |
Parent commit (@-) : zsuskuln 6a3dcbcf 2 |
| 354 |
Added 0 files, modified 1 files, removed 0 files |
| 355 |
[EOF] |
| 356 |
"); |
| 357 |
|
| 358 |
// Modify first and last lines in the merge commit |
| 359 |
work_dir.write_file("file1", "1A\n1b\n0a\n2a\n2B\n"); |
| 360 |
// Add new commit on top |
| 361 |
work_dir.run_jj(["new", "-m3"]).success(); |
| 362 |
work_dir.write_file("file2", "3a\n"); |
| 363 |
// Then absorb the merge commit |
| 364 |
let output = work_dir.run_jj(["absorb", "--from=@-"]); |
| 365 |
insta::assert_snapshot!(output, @r" |
| 366 |
------- stderr ------- |
| 367 |
Absorbed changes into 2 revisions: |
| 368 |
zsuskuln a6cd8e87 2 |
| 369 |
kkmpptxz 98b7d214 1 |
| 370 |
Rebased 1 descendant commits. |
| 371 |
Working copy (@) now at: royxmykx df946e9b 3 |
| 372 |
Parent commit (@-) : kkmpptxz 98b7d214 1 |
| 373 |
Parent commit (@-) : zsuskuln a6cd8e87 2 |
| 374 |
[EOF] |
| 375 |
"); |
| 376 |
|
| 377 |
insta::assert_snapshot!(get_diffs(&work_dir, "mutable()"), @" |
| 378 |
@ royxmykx df946e9b 3 |
| 379 |
├─╮ diff --git a/file2 b/file2 |
| 380 |
│ │ new file mode 100644 |
| 381 |
│ │ index 0000000000..31cd755d20 |
| 382 |
│ │ --- /dev/null |
| 383 |
│ │ +++ b/file2 |
| 384 |
│ │ @@ -0,0 +1,1 @@ |
| 385 |
│ │ +3a |
| 386 |
│ ○ zsuskuln a6cd8e87 2 |
| 387 |
│ │ diff --git a/file1 b/file1 |
| 388 |
│ │ index eb6e8821f1..4907935b9f 100644 |
| 389 |
│ │ --- a/file1 |
| 390 |
│ │ +++ b/file1 |
| 391 |
│ │ @@ -1,1 +1,3 @@ |
| 392 |
│ │ 0a |
| 393 |
│ │ +2a |
| 394 |
│ │ +2B |
| 395 |
○ │ kkmpptxz 98b7d214 1 |
| 396 |
├─╯ diff --git a/file1 b/file1 |
| 397 |
│ index eb6e8821f1..902dd8ef13 100644 |
| 398 |
│ --- a/file1 |
| 399 |
│ +++ b/file1 |
| 400 |
│ @@ -1,1 +1,3 @@ |
| 401 |
│ +1A |
| 402 |
│ +1b |
| 403 |
│ 0a |
| 404 |
○ qpvuntsm d4f07be5 0 |
| 405 |
│ diff --git a/file1 b/file1 |
| 406 |
~ new file mode 100644 |
| 407 |
index 0000000000..eb6e8821f1 |
| 408 |
--- /dev/null |
| 409 |
+++ b/file1 |
| 410 |
@@ -0,0 +1,1 @@ |
| 411 |
+0a |
| 412 |
[EOF] |
| 413 |
"); |
| 414 |
} |
| 415 |
|
| 416 |
#[test] |
| 417 |
fn test_absorb_conflict() { |
| 418 |
let test_env = TestEnvironment::default(); |
| 419 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 420 |
let work_dir = test_env.work_dir("repo"); |
| 421 |
|
| 422 |
work_dir.run_jj(["describe", "-m1"]).success(); |
| 423 |
work_dir.write_file("file1", "1a\n1b\n"); |
| 424 |
|
| 425 |
work_dir.run_jj(["new", "root()"]).success(); |
| 426 |
work_dir.write_file("file1", "2a\n2b\n"); |
| 427 |
let output = work_dir.run_jj(["rebase", "-r@", "-dsubject(1)"]); |
| 428 |
insta::assert_snapshot!(output, @r" |
| 429 |
------- stderr ------- |
| 430 |
Rebased 1 commits to destination. |
| 431 |
Working copy (@) now at: kkmpptxz 628e2b00 (conflict) (no description set) |
| 432 |
Parent commit (@-) : qpvuntsm e35bcaff 1 |
| 433 |
Added 0 files, modified 1 files, removed 0 files |
| 434 |
Warning: There are unresolved conflicts at these paths: |
| 435 |
file1 2-sided conflict |
| 436 |
New conflicts appeared in 1 commits: |
| 437 |
kkmpptxz 628e2b00 (conflict) (no description set) |
| 438 |
Hint: To resolve the conflicts, start by creating a commit on top of |
| 439 |
the conflicted commit: |
| 440 |
jj new kkmpptxz |
| 441 |
Then use `jj resolve`, or edit the conflict markers in the file directly. |
| 442 |
Once the conflicts are resolved, you can inspect the result with `jj diff`. |
| 443 |
Then run `jj squash` to move the resolution into the conflicted commit. |
| 444 |
[EOF] |
| 445 |
"); |
| 446 |
|
| 447 |
let conflict_content = work_dir.read_file("file1"); |
| 448 |
insta::assert_snapshot!(conflict_content, @r#" |
| 449 |
<<<<<<< conflict 1 of 1 |
| 450 |
%%%%%%% diff from: zzzzzzzz 00000000 (parents of rebased revision) |
| 451 |
\\\\\\\ to: qpvuntsm e35bcaff "1" (rebase destination) |
| 452 |
+1a |
| 453 |
+1b |
| 454 |
+++++++ kkmpptxz e05db987 (rebased revision) |
| 455 |
2a |
| 456 |
2b |
| 457 |
>>>>>>> conflict 1 of 1 ends |
| 458 |
"#); |
| 459 |
|
| 460 |
// Cannot absorb from conflict |
| 461 |
let output = work_dir.run_jj(["absorb"]); |
| 462 |
insta::assert_snapshot!(output, @" |
| 463 |
------- stderr ------- |
| 464 |
Warning: Skipping file1: Is a conflict |
| 465 |
Nothing changed. |
| 466 |
[EOF] |
| 467 |
"); |
| 468 |
|
| 469 |
// Cannot absorb from resolved conflict |
| 470 |
work_dir.run_jj(["new"]).success(); |
| 471 |
work_dir.write_file("file1", "1A\n1b\n2a\n2B\n"); |
| 472 |
let output = work_dir.run_jj(["absorb"]); |
| 473 |
insta::assert_snapshot!(output, @" |
| 474 |
------- stderr ------- |
| 475 |
Warning: Skipping file1: Is a conflict |
| 476 |
Nothing changed. |
| 477 |
[EOF] |
| 478 |
"); |
| 479 |
} |
| 480 |
|
| 481 |
#[test] |
| 482 |
fn test_absorb_deleted_file() { |
| 483 |
let test_env = TestEnvironment::default(); |
| 484 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 485 |
let work_dir = test_env.work_dir("repo"); |
| 486 |
|
| 487 |
work_dir.run_jj(["describe", "-m1"]).success(); |
| 488 |
work_dir.write_file("file1", "1a\n"); |
| 489 |
work_dir.write_file("file2", "1a\n"); |
| 490 |
work_dir.write_file("file3", ""); |
| 491 |
|
| 492 |
work_dir.run_jj(["new"]).success(); |
| 493 |
work_dir.remove_file("file1"); |
| 494 |
work_dir.write_file("file2", ""); // emptied |
| 495 |
work_dir.remove_file("file3"); // no content change |
| 496 |
|
| 497 |
// Since the destinations are chosen based on content diffs, file3 cannot be |
| 498 |
// absorbed. |
| 499 |
let output = work_dir.run_jj(["absorb"]); |
| 500 |
insta::assert_snapshot!(output, @r" |
| 501 |
------- stderr ------- |
| 502 |
Absorbed changes into 1 revisions: |
| 503 |
qpvuntsm 38af7fd3 1 |
| 504 |
Rebased 1 descendant commits. |
| 505 |
Working copy (@) now at: kkmpptxz efd883f6 (no description set) |
| 506 |
Parent commit (@-) : qpvuntsm 38af7fd3 1 |
| 507 |
Remaining changes: |
| 508 |
D file3 |
| 509 |
[EOF] |
| 510 |
"); |
| 511 |
|
| 512 |
insta::assert_snapshot!(get_diffs(&work_dir, "mutable()"), @" |
| 513 |
@ kkmpptxz efd883f6 (no description set) |
| 514 |
│ diff --git a/file3 b/file3 |
| 515 |
│ deleted file mode 100644 |
| 516 |
│ index e69de29bb2..0000000000 |
| 517 |
○ qpvuntsm 38af7fd3 1 |
| 518 |
│ diff --git a/file2 b/file2 |
| 519 |
~ new file mode 100644 |
| 520 |
index 0000000000..e69de29bb2 |
| 521 |
diff --git a/file3 b/file3 |
| 522 |
new file mode 100644 |
| 523 |
index 0000000000..e69de29bb2 |
| 524 |
[EOF] |
| 525 |
"); |
| 526 |
} |
| 527 |
|
| 528 |
#[test] |
| 529 |
fn test_absorb_deleted_file_with_multiple_hunks() { |
| 530 |
let test_env = TestEnvironment::default(); |
| 531 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 532 |
let work_dir = test_env.work_dir("repo"); |
| 533 |
|
| 534 |
work_dir.run_jj(["describe", "-m1"]).success(); |
| 535 |
work_dir.write_file("file1", "1a\n1b\n"); |
| 536 |
work_dir.write_file("file2", "1a\n"); |
| 537 |
|
| 538 |
work_dir.run_jj(["new", "-m2"]).success(); |
| 539 |
work_dir.write_file("file1", "1a\n"); |
| 540 |
work_dir.write_file("file2", "1a\n1b\n"); |
| 541 |
|
| 542 |
// These changes produce conflicts because |
| 543 |
// - for file1, "1a\n" is deleted from the commit 1, |
| 544 |
// - for file2, two consecutive hunks are deleted. |
| 545 |
// |
| 546 |
// Since file2 change is split to two separate hunks, the file deletion |
| 547 |
// cannot be propagated. If we implement merging based on interleaved delta, |
| 548 |
// the file2 change will apply cleanly. The file1 change might be split into |
| 549 |
// "1a\n" deletion at the commit 1 and file deletion at the commit 2, but |
| 550 |
// I'm not sure if that's intuitive. |
| 551 |
work_dir.run_jj(["new"]).success(); |
| 552 |
work_dir.remove_file("file1"); |
| 553 |
work_dir.remove_file("file2"); |
| 554 |
let output = work_dir.run_jj(["absorb"]); |
| 555 |
insta::assert_snapshot!(output, @r" |
| 556 |
------- stderr ------- |
| 557 |
Absorbed changes into 2 revisions: |
| 558 |
kkmpptxz 3e1b2472 (conflict) 2 |
| 559 |
qpvuntsm c49bcdd3 (conflict) 1 |
| 560 |
Rebased 1 descendant commits. |
| 561 |
Working copy (@) now at: zsuskuln 9376eb56 (no description set) |
| 562 |
Parent commit (@-) : kkmpptxz 3e1b2472 (conflict) 2 |
| 563 |
New conflicts appeared in 2 commits: |
| 564 |
kkmpptxz 3e1b2472 (conflict) 2 |
| 565 |
qpvuntsm c49bcdd3 (conflict) 1 |
| 566 |
Hint: To resolve the conflicts, start by creating a commit on top of |
| 567 |
the first conflicted commit: |
| 568 |
jj new qpvuntsm |
| 569 |
Then use `jj resolve`, or edit the conflict markers in the file directly. |
| 570 |
Once the conflicts are resolved, you can inspect the result with `jj diff`. |
| 571 |
Then run `jj squash` to move the resolution into the conflicted commit. |
| 572 |
Remaining changes: |
| 573 |
D file2 |
| 574 |
[EOF] |
| 575 |
"); |
| 576 |
|
| 577 |
insta::assert_snapshot!(get_diffs(&work_dir, "mutable()"), @r#" |
| 578 |
@ zsuskuln 9376eb56 (no description set) |
| 579 |
│ diff --git a/file2 b/file2 |
| 580 |
│ deleted file mode 100644 |
| 581 |
│ index 0000000000..0000000000 |
| 582 |
│ --- a/file2 |
| 583 |
│ +++ /dev/null |
| 584 |
│ @@ -1,8 +0,0 @@ |
| 585 |
│ -<<<<<<< conflict 1 of 1 |
| 586 |
│ -%%%%%%% diff from: kkmpptxz 33662096 "2" (parents of absorbed revision) |
| 587 |
│ -\\\\\\\ to: kkmpptxz 33662096 "2" (absorb destination) |
| 588 |
│ --1a |
| 589 |
│ - 1b |
| 590 |
│ -+++++++ absorbed changes (from zsuskuln d6492c8f) |
| 591 |
│ -1a |
| 592 |
│ ->>>>>>> conflict 1 of 1 ends |
| 593 |
× kkmpptxz 3e1b2472 (conflict) 2 |
| 594 |
│ diff --git a/file1 b/file1 |
| 595 |
│ deleted file mode 100644 |
| 596 |
│ index 0000000000..0000000000 |
| 597 |
│ --- a/file1 |
| 598 |
│ +++ /dev/null |
| 599 |
│ @@ -1,7 +0,0 @@ |
| 600 |
│ -<<<<<<< conflict 1 of 1 |
| 601 |
│ -%%%%%%% diff from: kkmpptxz 33662096 "2" (parents of absorbed revision) |
| 602 |
│ -\\\\\\\ to: qpvuntsm 66b2ce5b "1" (absorb destination) |
| 603 |
│ - 1a |
| 604 |
│ -+1b |
| 605 |
│ -+++++++ absorbed changes (from zsuskuln d6492c8f) |
| 606 |
│ ->>>>>>> conflict 1 of 1 ends |
| 607 |
│ diff --git a/file2 b/file2 |
| 608 |
│ --- a/file2 |
| 609 |
│ +++ b/file2 |
| 610 |
│ @@ -1,8 +1,8 @@ |
| 611 |
│ <<<<<<< conflict 1 of 1 |
| 612 |
│ %%%%%%% diff from: kkmpptxz 33662096 "2" (parents of absorbed revision) |
| 613 |
│ -\\\\\\\ to: qpvuntsm 66b2ce5b "1" (absorb destination) |
| 614 |
│ - 1a |
| 615 |
│ --1b |
| 616 |
│ +\\\\\\\ to: kkmpptxz 33662096 "2" (absorb destination) |
| 617 |
│ +-1a |
| 618 |
│ + 1b |
| 619 |
│ +++++++ absorbed changes (from zsuskuln d6492c8f) |
| 620 |
│ -1b |
| 621 |
│ +1a |
| 622 |
│ >>>>>>> conflict 1 of 1 ends |
| 623 |
× qpvuntsm c49bcdd3 (conflict) 1 |
| 624 |
│ diff --git a/file1 b/file1 |
| 625 |
~ new file mode 100644 |
| 626 |
index 0000000000..0000000000 |
| 627 |
--- /dev/null |
| 628 |
+++ b/file1 |
| 629 |
@@ -0,0 +1,7 @@ |
| 630 |
+<<<<<<< conflict 1 of 1 |
| 631 |
+%%%%%%% diff from: kkmpptxz 33662096 "2" (parents of absorbed revision) |
| 632 |
+\\\\\\\ to: qpvuntsm 66b2ce5b "1" (absorb destination) |
| 633 |
+ 1a |
| 634 |
++1b |
| 635 |
++++++++ absorbed changes (from zsuskuln d6492c8f) |
| 636 |
+>>>>>>> conflict 1 of 1 ends |
| 637 |
diff --git a/file2 b/file2 |
| 638 |
new file mode 100644 |
| 639 |
index 0000000000..0000000000 |
| 640 |
--- /dev/null |
| 641 |
+++ b/file2 |
| 642 |
@@ -0,0 +1,8 @@ |
| 643 |
+<<<<<<< conflict 1 of 1 |
| 644 |
+%%%%%%% diff from: kkmpptxz 33662096 "2" (parents of absorbed revision) |
| 645 |
+\\\\\\\ to: qpvuntsm 66b2ce5b "1" (absorb destination) |
| 646 |
+ 1a |
| 647 |
+-1b |
| 648 |
++++++++ absorbed changes (from zsuskuln d6492c8f) |
| 649 |
+1b |
| 650 |
+>>>>>>> conflict 1 of 1 ends |
| 651 |
[EOF] |
| 652 |
"#); |
| 653 |
} |
| 654 |
|
| 655 |
#[test] |
| 656 |
fn test_absorb_file_mode() { |
| 657 |
let test_env = TestEnvironment::default(); |
| 658 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 659 |
let work_dir = test_env.work_dir("repo"); |
| 660 |
|
| 661 |
work_dir.run_jj(["describe", "-m1"]).success(); |
| 662 |
work_dir.write_file("file1", "1a\n"); |
| 663 |
work_dir.run_jj(["file", "chmod", "x", "file1"]).success(); |
| 664 |
|
| 665 |
// Modify content and mode |
| 666 |
work_dir.run_jj(["new"]).success(); |
| 667 |
work_dir.write_file("file1", "1A\n"); |
| 668 |
work_dir.run_jj(["file", "chmod", "n", "file1"]).success(); |
| 669 |
|
| 670 |
// Mode change shouldn't be absorbed |
| 671 |
let output = work_dir.run_jj(["absorb"]); |
| 672 |
insta::assert_snapshot!(output, @r" |
| 673 |
------- stderr ------- |
| 674 |
Absorbed changes into 1 revisions: |
| 675 |
qpvuntsm 2a0c7f1d 1 |
| 676 |
Rebased 1 descendant commits. |
| 677 |
Working copy (@) now at: zsuskuln 8ca9761d (no description set) |
| 678 |
Parent commit (@-) : qpvuntsm 2a0c7f1d 1 |
| 679 |
Remaining changes: |
| 680 |
M file1 |
| 681 |
[EOF] |
| 682 |
"); |
| 683 |
|
| 684 |
insta::assert_snapshot!(get_diffs(&work_dir, "mutable()"), @" |
| 685 |
@ zsuskuln 8ca9761d (no description set) |
| 686 |
│ diff --git a/file1 b/file1 |
| 687 |
│ old mode 100755 |
| 688 |
│ new mode 100644 |
| 689 |
○ qpvuntsm 2a0c7f1d 1 |
| 690 |
│ diff --git a/file1 b/file1 |
| 691 |
~ new file mode 100755 |
| 692 |
index 0000000000..268de3f3ec |
| 693 |
--- /dev/null |
| 694 |
+++ b/file1 |
| 695 |
@@ -0,0 +1,1 @@ |
| 696 |
+1A |
| 697 |
[EOF] |
| 698 |
"); |
| 699 |
} |
| 700 |
|
| 701 |
#[test] |
| 702 |
fn test_absorb_from_into() { |
| 703 |
let test_env = TestEnvironment::default(); |
| 704 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 705 |
let work_dir = test_env.work_dir("repo"); |
| 706 |
|
| 707 |
work_dir.run_jj(["new", "-m1"]).success(); |
| 708 |
work_dir.write_file("file1", "1a\n1b\n1c\n"); |
| 709 |
|
| 710 |
work_dir.run_jj(["new", "-m2"]).success(); |
| 711 |
work_dir.write_file("file1", "1a\n2a\n1b\n1c\n2b\n"); |
| 712 |
|
| 713 |
// Line "X" and "Z" have unambiguous adjacent line within the destinations |
| 714 |
// range. Line "Y" doesn't have such line. |
| 715 |
work_dir.run_jj(["new"]).success(); |
| 716 |
work_dir.write_file("file1", "1a\nX\n2a\n1b\nY\n1c\n2b\nZ\n"); |
| 717 |
let output = work_dir.run_jj(["absorb", "--into=@-"]); |
| 718 |
insta::assert_snapshot!(output, @r" |
| 719 |
------- stderr ------- |
| 720 |
Absorbed changes into 1 revisions: |
| 721 |
kkmpptxz cae507ef 2 |
| 722 |
Rebased 1 descendant commits. |
| 723 |
Working copy (@) now at: zsuskuln f02fd9ea (no description set) |
| 724 |
Parent commit (@-) : kkmpptxz cae507ef 2 |
| 725 |
Remaining changes: |
| 726 |
M file1 |
| 727 |
[EOF] |
| 728 |
"); |
| 729 |
|
| 730 |
insta::assert_snapshot!(get_diffs(&work_dir, "@-::"), @" |
| 731 |
@ zsuskuln f02fd9ea (no description set) |
| 732 |
│ diff --git a/file1 b/file1 |
| 733 |
│ index faf62af049..c2d0b12547 100644 |
| 734 |
│ --- a/file1 |
| 735 |
│ +++ b/file1 |
| 736 |
│ @@ -2,6 +2,7 @@ |
| 737 |
│ X |
| 738 |
│ 2a |
| 739 |
│ 1b |
| 740 |
│ +Y |
| 741 |
│ 1c |
| 742 |
│ 2b |
| 743 |
│ Z |
| 744 |
○ kkmpptxz cae507ef 2 |
| 745 |
│ diff --git a/file1 b/file1 |
| 746 |
~ index 352e9b3794..faf62af049 100644 |
| 747 |
--- a/file1 |
| 748 |
+++ b/file1 |
| 749 |
@@ -1,3 +1,7 @@ |
| 750 |
1a |
| 751 |
+X |
| 752 |
+2a |
| 753 |
1b |
| 754 |
1c |
| 755 |
+2b |
| 756 |
+Z |
| 757 |
[EOF] |
| 758 |
"); |
| 759 |
|
| 760 |
// Absorb all lines from the working-copy parent. An empty commit won't be |
| 761 |
// discarded because "absorb" isn't a command to squash commit descriptions. |
| 762 |
let output = work_dir.run_jj(["absorb", "--from=@-"]); |
| 763 |
insta::assert_snapshot!(output, @r" |
| 764 |
------- stderr ------- |
| 765 |
Absorbed changes into 1 revisions: |
| 766 |
rlvkpnrz ddaed33d 1 |
| 767 |
Rebased 2 descendant commits. |
| 768 |
Working copy (@) now at: zsuskuln 3652e5e5 (no description set) |
| 769 |
Parent commit (@-) : kkmpptxz 7f4339e7 (empty) 2 |
| 770 |
[EOF] |
| 771 |
"); |
| 772 |
|
| 773 |
insta::assert_snapshot!(get_diffs(&work_dir, "mutable()"), @" |
| 774 |
@ zsuskuln 3652e5e5 (no description set) |
| 775 |
│ diff --git a/file1 b/file1 |
| 776 |
│ index faf62af049..c2d0b12547 100644 |
| 777 |
│ --- a/file1 |
| 778 |
│ +++ b/file1 |
| 779 |
│ @@ -2,6 +2,7 @@ |
| 780 |
│ X |
| 781 |
│ 2a |
| 782 |
│ 1b |
| 783 |
│ +Y |
| 784 |
│ 1c |
| 785 |
│ 2b |
| 786 |
│ Z |
| 787 |
○ kkmpptxz 7f4339e7 (empty) 2 |
| 788 |
○ rlvkpnrz ddaed33d 1 |
| 789 |
│ diff --git a/file1 b/file1 |
| 790 |
│ new file mode 100644 |
| 791 |
│ index 0000000000..faf62af049 |
| 792 |
│ --- /dev/null |
| 793 |
│ +++ b/file1 |
| 794 |
│ @@ -0,0 +1,7 @@ |
| 795 |
│ +1a |
| 796 |
│ +X |
| 797 |
│ +2a |
| 798 |
│ +1b |
| 799 |
│ +1c |
| 800 |
│ +2b |
| 801 |
│ +Z |
| 802 |
○ qpvuntsm e8849ae1 (empty) (no description set) |
| 803 |
│ |
| 804 |
~ |
| 805 |
[EOF] |
| 806 |
"); |
| 807 |
} |
| 808 |
|
| 809 |
#[test] |
| 810 |
fn test_absorb_paths() { |
| 811 |
let test_env = TestEnvironment::default(); |
| 812 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 813 |
let work_dir = test_env.work_dir("repo"); |
| 814 |
|
| 815 |
work_dir.run_jj(["describe", "-m1"]).success(); |
| 816 |
work_dir.write_file("file1", "1a\n"); |
| 817 |
work_dir.write_file("file2", "1a\n"); |
| 818 |
|
| 819 |
// Modify both files |
| 820 |
work_dir.run_jj(["new"]).success(); |
| 821 |
work_dir.write_file("file1", "1A\n"); |
| 822 |
work_dir.write_file("file2", "1A\n"); |
| 823 |
|
| 824 |
let output = work_dir.run_jj(["absorb", "nonexistent"]); |
| 825 |
insta::assert_snapshot!(output, @" |
| 826 |
------- stderr ------- |
| 827 |
Warning: No matching entries for paths: nonexistent |
| 828 |
Nothing changed. |
| 829 |
[EOF] |
| 830 |
"); |
| 831 |
|
| 832 |
let output = work_dir.run_jj(["absorb", "file1"]); |
| 833 |
insta::assert_snapshot!(output, @r" |
| 834 |
------- stderr ------- |
| 835 |
Absorbed changes into 1 revisions: |
| 836 |
qpvuntsm ca07fabe 1 |
| 837 |
Rebased 1 descendant commits. |
| 838 |
Working copy (@) now at: kkmpptxz 4d80ada8 (no description set) |
| 839 |
Parent commit (@-) : qpvuntsm ca07fabe 1 |
| 840 |
Remaining changes: |
| 841 |
M file2 |
| 842 |
[EOF] |
| 843 |
"); |
| 844 |
|
| 845 |
insta::assert_snapshot!(get_diffs(&work_dir, "mutable()"), @" |
| 846 |
@ kkmpptxz 4d80ada8 (no description set) |
| 847 |
│ diff --git a/file2 b/file2 |
| 848 |
│ index a8994dc188..268de3f3ec 100644 |
| 849 |
│ --- a/file2 |
| 850 |
│ +++ b/file2 |
| 851 |
│ @@ -1,1 +1,1 @@ |
| 852 |
│ -1a |
| 853 |
│ +1A |
| 854 |
○ qpvuntsm ca07fabe 1 |
| 855 |
│ diff --git a/file1 b/file1 |
| 856 |
~ new file mode 100644 |
| 857 |
index 0000000000..268de3f3ec |
| 858 |
--- /dev/null |
| 859 |
+++ b/file1 |
| 860 |
@@ -0,0 +1,1 @@ |
| 861 |
+1A |
| 862 |
diff --git a/file2 b/file2 |
| 863 |
new file mode 100644 |
| 864 |
index 0000000000..a8994dc188 |
| 865 |
--- /dev/null |
| 866 |
+++ b/file2 |
| 867 |
@@ -0,0 +1,1 @@ |
| 868 |
+1a |
| 869 |
[EOF] |
| 870 |
"); |
| 871 |
} |
| 872 |
|
| 873 |
#[test] |
| 874 |
fn test_absorb_immutable() { |
| 875 |
let test_env = TestEnvironment::default(); |
| 876 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 877 |
let work_dir = test_env.work_dir("repo"); |
| 878 |
test_env.add_config("revset-aliases.'immutable_heads()' = 'present(main)'"); |
| 879 |
|
| 880 |
work_dir.run_jj(["describe", "-m1"]).success(); |
| 881 |
work_dir.write_file("file1", "1a\n1b\n"); |
| 882 |
|
| 883 |
work_dir.run_jj(["new", "-m2"]).success(); |
| 884 |
work_dir |
| 885 |
.run_jj(["bookmark", "set", "-r@-", "main"]) |
| 886 |
.success(); |
| 887 |
work_dir.write_file("file1", "1a\n1b\n2a\n2b\n"); |
| 888 |
|
| 889 |
work_dir.run_jj(["new"]).success(); |
| 890 |
work_dir.write_file("file1", "1A\n1b\n2a\n2B\n"); |
| 891 |
|
| 892 |
// Immutable revisions are excluded by default |
| 893 |
let output = work_dir.run_jj(["absorb"]); |
| 894 |
insta::assert_snapshot!(output, @r" |
| 895 |
------- stderr ------- |
| 896 |
Absorbed changes into 1 revisions: |
| 897 |
kkmpptxz e68cc3e2 2 |
| 898 |
Rebased 1 descendant commits. |
| 899 |
Working copy (@) now at: mzvwutvl 88443af7 (no description set) |
| 900 |
Parent commit (@-) : kkmpptxz e68cc3e2 2 |
| 901 |
Remaining changes: |
| 902 |
M file1 |
| 903 |
[EOF] |
| 904 |
"); |
| 905 |
|
| 906 |
// Immutable revisions shouldn't be rewritten |
| 907 |
let output = work_dir.run_jj(["absorb", "--into=all()"]); |
| 908 |
insta::assert_snapshot!(output, @r#" |
| 909 |
------- stderr ------- |
| 910 |
Error: Commit e35bcaffcb55 is immutable |
| 911 |
Hint: Could not modify commit: qpvuntsm e35bcaff main | 1 |
| 912 |
Hint: Immutable commits are used to protect shared history. |
| 913 |
Hint: For more information, see: |
| 914 |
- https://docs.jj-vcs.dev/latest/config/#set-of-immutable-commits |
| 915 |
- `jj help -k config`, "Set of immutable commits" |
| 916 |
Hint: This operation would rewrite 1 immutable commits. |
| 917 |
[EOF] |
| 918 |
[exit status: 1] |
| 919 |
"#); |
| 920 |
|
| 921 |
insta::assert_snapshot!(get_diffs(&work_dir, ".."), @" |
| 922 |
@ mzvwutvl 88443af7 (no description set) |
| 923 |
│ diff --git a/file1 b/file1 |
| 924 |
│ index 75e4047831..428796ca20 100644 |
| 925 |
│ --- a/file1 |
| 926 |
│ +++ b/file1 |
| 927 |
│ @@ -1,4 +1,4 @@ |
| 928 |
│ -1a |
| 929 |
│ +1A |
| 930 |
│ 1b |
| 931 |
│ 2a |
| 932 |
│ 2B |
| 933 |
○ kkmpptxz e68cc3e2 2 |
| 934 |
│ diff --git a/file1 b/file1 |
| 935 |
│ index 8c5268f893..75e4047831 100644 |
| 936 |
│ --- a/file1 |
| 937 |
│ +++ b/file1 |
| 938 |
│ @@ -1,2 +1,4 @@ |
| 939 |
│ 1a |
| 940 |
│ 1b |
| 941 |
│ +2a |
| 942 |
│ +2B |
| 943 |
◆ qpvuntsm e35bcaff 1 |
| 944 |
│ diff --git a/file1 b/file1 |
| 945 |
~ new file mode 100644 |
| 946 |
index 0000000000..8c5268f893 |
| 947 |
--- /dev/null |
| 948 |
+++ b/file1 |
| 949 |
@@ -0,0 +1,2 @@ |
| 950 |
+1a |
| 951 |
+1b |
| 952 |
[EOF] |
| 953 |
"); |
| 954 |
} |
| 955 |
|
| 956 |
#[test] |
| 957 |
fn test_absorb_interactive() -> TestResult { |
| 958 |
let mut test_env = TestEnvironment::default(); |
| 959 |
let edit_script = test_env.set_up_fake_diff_editor(); |
| 960 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 961 |
let work_dir = test_env.work_dir("repo"); |
| 962 |
|
| 963 |
work_dir.run_jj(["describe", "-m0"]).success(); |
| 964 |
work_dir.write_file("file1", ""); |
| 965 |
|
| 966 |
work_dir.run_jj(["new", "-m1"]).success(); |
| 967 |
work_dir.write_file("file1", "1a\n1b\n"); |
| 968 |
|
| 969 |
work_dir.run_jj(["new", "-m2"]).success(); |
| 970 |
work_dir.write_file("file1", "1a\n1b\n2a\n2b\n"); |
| 971 |
|
| 972 |
// Working copy with changes to lines from both ancestors. |
| 973 |
work_dir.run_jj(["new"]).success(); |
| 974 |
work_dir.write_file("file1", "1X\n1b\n2Y\n2b\n"); |
| 975 |
// Snapshot the changes so they are part of the source commit when we capture |
| 976 |
// the op id (otherwise op restore would land on an empty @). |
| 977 |
work_dir.run_jj(["util", "snapshot"]).success(); |
| 978 |
let setup_opid = work_dir.current_operation_id(); |
| 979 |
|
| 980 |
// If we don't make any changes in the diff-editor, all selected changes are |
| 981 |
// considered for absorption (and distributed by the usual annotation logic). |
| 982 |
std::fs::write(&edit_script, "dump JJ-INSTRUCTIONS instrs")?; |
| 983 |
let output = work_dir.run_jj(["absorb", "-i"]); |
| 984 |
insta::assert_snapshot!(output, @" |
| 985 |
------- stderr ------- |
| 986 |
Absorbed changes into 2 revisions: |
| 987 |
zsuskuln e1082c87 2 |
| 988 |
kkmpptxz db75688c 1 |
| 989 |
Working copy (@) now at: yqosqzyt 9959af44 (empty) (no description set) |
| 990 |
Parent commit (@-) : zsuskuln e1082c87 2 |
| 991 |
[EOF] |
| 992 |
"); |
| 993 |
|
| 994 |
let instrs = std::fs::read_to_string(test_env.env_root().join("instrs"))?; |
| 995 |
insta::assert_snapshot!(instrs, @" |
| 996 |
You are selecting changes from: mzvwutvl 97027697 (no description set) to be considered for |
| 997 |
absorption into ancestors. |
| 998 |
|
| 999 |
The left side of the diff shows the parent commit. The right side |
| 1000 |
initially shows the contents of the commit you're absorbing from. |
| 1001 |
|
| 1002 |
Adjust the right side until the diff shows the changes you want to |
| 1003 |
absorb. Selected hunks will be considered for assignment to the |
| 1004 |
closest ancestor where the corresponding lines were last modified |
| 1005 |
(using annotation). Any hunks that cannot be absorbed unambiguously |
| 1006 |
remain in the source commit. |
| 1007 |
"); |
| 1008 |
|
| 1009 |
// Can absorb only some changes in interactive mode (pick hunks that target |
| 1010 |
// only the "1" commit). |
| 1011 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 1012 |
// The right side written here has only the change to the lines from commit 1. |
| 1013 |
std::fs::write(&edit_script, "write file1\n1X\n1b\n2a\n2b\n")?; |
| 1014 |
let output = work_dir.run_jj(["absorb", "-i"]); |
| 1015 |
insta::assert_snapshot!(output, @" |
| 1016 |
------- stderr ------- |
| 1017 |
Absorbed changes into 1 revisions: |
| 1018 |
kkmpptxz 1478a2b5 1 |
| 1019 |
Rebased 2 descendant commits. |
| 1020 |
Working copy (@) now at: mzvwutvl 1c71fcb1 (no description set) |
| 1021 |
Parent commit (@-) : zsuskuln f718fb8c 2 |
| 1022 |
Remaining changes: |
| 1023 |
M file1 |
| 1024 |
[EOF] |
| 1025 |
"); |
| 1026 |
insta::assert_snapshot!(get_diffs(&work_dir, "mutable()"), @" |
| 1027 |
@ mzvwutvl 1c71fcb1 (no description set) |
| 1028 |
│ diff --git a/file1 b/file1 |
| 1029 |
│ index 69f126596d..90ee77ff42 100644 |
| 1030 |
│ --- a/file1 |
| 1031 |
│ +++ b/file1 |
| 1032 |
│ @@ -1,4 +1,4 @@ |
| 1033 |
│ 1X |
| 1034 |
│ 1b |
| 1035 |
│ -2a |
| 1036 |
│ +2Y |
| 1037 |
│ 2b |
| 1038 |
○ zsuskuln f718fb8c 2 |
| 1039 |
│ diff --git a/file1 b/file1 |
| 1040 |
│ index 63451a887b..69f126596d 100644 |
| 1041 |
│ --- a/file1 |
| 1042 |
│ +++ b/file1 |
| 1043 |
│ @@ -1,2 +1,4 @@ |
| 1044 |
│ 1X |
| 1045 |
│ 1b |
| 1046 |
│ +2a |
| 1047 |
│ +2b |
| 1048 |
○ kkmpptxz 1478a2b5 1 |
| 1049 |
│ diff --git a/file1 b/file1 |
| 1050 |
│ index e69de29bb2..63451a887b 100644 |
| 1051 |
│ --- a/file1 |
| 1052 |
│ +++ b/file1 |
| 1053 |
│ @@ -0,0 +1,2 @@ |
| 1054 |
│ +1X |
| 1055 |
│ +1b |
| 1056 |
○ qpvuntsm 6a446874 0 |
| 1057 |
│ diff --git a/file1 b/file1 |
| 1058 |
~ new file mode 100644 |
| 1059 |
index 0000000000..e69de29bb2 |
| 1060 |
[EOF] |
| 1061 |
"); |
| 1062 |
|
| 1063 |
// Selected hunks that can't be absorbed and unselected changes are left in |
| 1064 |
// the source commit. |
| 1065 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 1066 |
work_dir.write_file("file1", "1X\n1B\n2A\n2b\n"); |
| 1067 |
work_dir.run_jj(["util", "snapshot"]).success(); |
| 1068 |
std::fs::write(&edit_script, "write file1\n1a\n1B\n2A\n2b\n")?; |
| 1069 |
let output = work_dir.run_jj(["absorb", "-i"]); |
| 1070 |
insta::assert_snapshot!(output, @" |
| 1071 |
------- stderr ------- |
| 1072 |
Nothing changed. |
| 1073 |
[EOF] |
| 1074 |
"); |
| 1075 |
insta::assert_snapshot!(get_diffs(&work_dir, "mutable()"), @" |
| 1076 |
@ mzvwutvl 8ea686ec (no description set) |
| 1077 |
│ diff --git a/file1 b/file1 |
| 1078 |
│ index 3de64a0b0c..c7ae2125d4 100644 |
| 1079 |
│ --- a/file1 |
| 1080 |
│ +++ b/file1 |
| 1081 |
│ @@ -1,4 +1,4 @@ |
| 1082 |
│ -1a |
| 1083 |
│ -1b |
| 1084 |
│ -2a |
| 1085 |
│ +1X |
| 1086 |
│ +1B |
| 1087 |
│ +2A |
| 1088 |
│ 2b |
| 1089 |
○ zsuskuln 36fad385 2 |
| 1090 |
│ diff --git a/file1 b/file1 |
| 1091 |
│ index 8c5268f893..3de64a0b0c 100644 |
| 1092 |
│ --- a/file1 |
| 1093 |
│ +++ b/file1 |
| 1094 |
│ @@ -1,2 +1,4 @@ |
| 1095 |
│ 1a |
| 1096 |
│ 1b |
| 1097 |
│ +2a |
| 1098 |
│ +2b |
| 1099 |
○ kkmpptxz 1553c5e8 1 |
| 1100 |
│ diff --git a/file1 b/file1 |
| 1101 |
│ index e69de29bb2..8c5268f893 100644 |
| 1102 |
│ --- a/file1 |
| 1103 |
│ +++ b/file1 |
| 1104 |
│ @@ -0,0 +1,2 @@ |
| 1105 |
│ +1a |
| 1106 |
│ +1b |
| 1107 |
○ qpvuntsm 6a446874 0 |
| 1108 |
│ diff --git a/file1 b/file1 |
| 1109 |
~ new file mode 100644 |
| 1110 |
index 0000000000..e69de29bb2 |
| 1111 |
[EOF] |
| 1112 |
"); |
| 1113 |
|
| 1114 |
// Error if no changes selected in interactive mode |
| 1115 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 1116 |
std::fs::write(&edit_script, "reset file1")?; |
| 1117 |
let output = work_dir.run_jj(["absorb", "-i"]); |
| 1118 |
insta::assert_snapshot!(output, @" |
| 1119 |
------- stderr ------- |
| 1120 |
Error: No changes selected |
| 1121 |
[EOF] |
| 1122 |
[exit status: 1] |
| 1123 |
"); |
| 1124 |
Ok(()) |
| 1125 |
} |
| 1126 |
|
| 1127 |
#[must_use] |
| 1128 |
fn get_diffs(work_dir: &TestWorkDir, revision: &str) -> CommandOutput { |
| 1129 |
let template = r#"format_commit_summary_with_refs(self, "") ++ "\n""#; |
| 1130 |
work_dir.run_jj(["log", "-r", revision, "-T", template, "--git"]) |
| 1131 |
} |
| 1132 |
|
| 1133 |
#[must_use] |
| 1134 |
fn get_evolog(work_dir: &TestWorkDir, revision: &str) -> CommandOutput { |
| 1135 |
let template = r#"format_commit_summary_with_refs(commit, "") ++ "\n""#; |
| 1136 |
work_dir.run_jj(["evolog", "-r", revision, "-T", template]) |
| 1137 |
} |