| 1 |
// Copyright 2023 The Jujutsu Authors |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// https://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
use indoc::indoc; |
| 16 |
use regex::Regex; |
| 17 |
use testutils::TestResult; |
| 18 |
|
| 19 |
use crate::common::TestEnvironment; |
| 20 |
|
| 21 |
#[test] |
| 22 |
fn test_snapshot_large_file() { |
| 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 |
// test a small file using raw-integer-literal syntax, which is interpreted |
| 28 |
// in bytes |
| 29 |
test_env.add_config(r#"snapshot.max-new-file-size = 10"#); |
| 30 |
work_dir.write_file("empty", ""); |
| 31 |
work_dir.write_file("large", "a lot of text"); |
| 32 |
let output = work_dir.run_jj(["file", "list"]); |
| 33 |
insta::assert_snapshot!(output, @" |
| 34 |
empty |
| 35 |
[EOF] |
| 36 |
------- stderr ------- |
| 37 |
Warning: Refused to snapshot some files: |
| 38 |
large: 13.0B (13 bytes); the maximum size allowed is 10.0B (10 bytes) |
| 39 |
Hint: This is to prevent large files from being added by accident. To fix this: |
| 40 |
* Add the file(s) to `.gitignore` |
| 41 |
* Run `jj config set --repo snapshot.max-new-file-size 13` |
| 42 |
This will increase the maximum file size allowed for new files, in this repository only. |
| 43 |
* Run `jj --config snapshot.max-new-file-size=13 status` |
| 44 |
This will increase the maximum file size allowed for new files, for this command only. |
| 45 |
[EOF] |
| 46 |
"); |
| 47 |
|
| 48 |
// test with a larger file using 'KB' human-readable syntax |
| 49 |
test_env.add_config(r#"snapshot.max-new-file-size = "10KB""#); |
| 50 |
let big_string = vec![0; 1024 * 11]; |
| 51 |
work_dir.write_file("large", &big_string); |
| 52 |
let output = work_dir.run_jj(["file", "list"]); |
| 53 |
insta::assert_snapshot!(output, @" |
| 54 |
empty |
| 55 |
[EOF] |
| 56 |
------- stderr ------- |
| 57 |
Warning: Refused to snapshot some files: |
| 58 |
large: 11.0KiB (11264 bytes); the maximum size allowed is 10.0KiB (10240 bytes) |
| 59 |
Hint: This is to prevent large files from being added by accident. To fix this: |
| 60 |
* Add the file(s) to `.gitignore` |
| 61 |
* Run `jj config set --repo snapshot.max-new-file-size 11264` |
| 62 |
This will increase the maximum file size allowed for new files, in this repository only. |
| 63 |
* Run `jj --config snapshot.max-new-file-size=11264 status` |
| 64 |
This will increase the maximum file size allowed for new files, for this command only. |
| 65 |
[EOF] |
| 66 |
"); |
| 67 |
|
| 68 |
// test with file track for hint formatting, both files should appear in |
| 69 |
// warnings even though they were snapshotted separately |
| 70 |
work_dir.write_file("large 2", big_string); |
| 71 |
let output = work_dir.run_jj([ |
| 72 |
"file", |
| 73 |
"--config=snapshot.auto-track='large'", |
| 74 |
"track", |
| 75 |
"large 2", |
| 76 |
]); |
| 77 |
insta::assert_snapshot!(output, @" |
| 78 |
------- stderr ------- |
| 79 |
Warning: Refused to snapshot some files: |
| 80 |
large: 11.0KiB (11264 bytes); the maximum size allowed is 10.0KiB (10240 bytes) |
| 81 |
large 2: 11.0KiB (11264 bytes); the maximum size allowed is 10.0KiB (10240 bytes) |
| 82 |
Hint: This is to prevent large files from being added by accident. To fix this: |
| 83 |
* Add the file(s) to `.gitignore` |
| 84 |
* Run `jj config set --repo snapshot.max-new-file-size 11264` |
| 85 |
This will increase the maximum file size allowed for new files, in this repository only. |
| 86 |
* Run `jj --config snapshot.max-new-file-size=11264 file track large 'large 2'` |
| 87 |
This will increase the maximum file size allowed for new files, for this command only. |
| 88 |
* Run `jj file track --include-ignored large 'large 2'` |
| 89 |
This will track the file(s) regardless of size. |
| 90 |
[EOF] |
| 91 |
"); |
| 92 |
|
| 93 |
// test invalid configuration |
| 94 |
let output = work_dir.run_jj(["file", "list", "--config=snapshot.max-new-file-size=[]"]); |
| 95 |
insta::assert_snapshot!(output, @" |
| 96 |
------- stderr ------- |
| 97 |
Config error: Invalid type or value for snapshot.max-new-file-size |
| 98 |
Caused by: Expected a positive integer or a string in '<number><unit>' form |
| 99 |
For help, see https://docs.jj-vcs.dev/latest/config/ or use `jj help -k config`. |
| 100 |
[EOF] |
| 101 |
[exit status: 1] |
| 102 |
"); |
| 103 |
|
| 104 |
// No error if we disable auto-tracking of the path |
| 105 |
let output = work_dir.run_jj(["file", "list", "--config=snapshot.auto-track='none()'"]); |
| 106 |
insta::assert_snapshot!(output, @" |
| 107 |
empty |
| 108 |
[EOF] |
| 109 |
"); |
| 110 |
|
| 111 |
// max-new-file-size=0 means no limit |
| 112 |
let output = work_dir.run_jj(["file", "list", "--config=snapshot.max-new-file-size=0"]); |
| 113 |
insta::assert_snapshot!(output, @" |
| 114 |
empty |
| 115 |
large |
| 116 |
large 2 |
| 117 |
[EOF] |
| 118 |
"); |
| 119 |
} |
| 120 |
|
| 121 |
#[test] |
| 122 |
fn test_snapshot_large_file_restore() { |
| 123 |
let test_env = TestEnvironment::default(); |
| 124 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 125 |
let work_dir = test_env.work_dir("repo"); |
| 126 |
test_env.add_config("snapshot.max-new-file-size = 10"); |
| 127 |
|
| 128 |
work_dir.run_jj(["describe", "-mcommitted"]).success(); |
| 129 |
work_dir.write_file("file", "small"); |
| 130 |
|
| 131 |
// Write a large file in the working copy, restore it from a commit. The |
| 132 |
// working-copy content shouldn't be overwritten. |
| 133 |
work_dir.run_jj(["new", "root()"]).success(); |
| 134 |
work_dir.write_file("file", "a lot of text"); |
| 135 |
let output = work_dir.run_jj(["restore", "--from=subject(committed)"]); |
| 136 |
insta::assert_snapshot!(output, @" |
| 137 |
------- stderr ------- |
| 138 |
Warning: Refused to snapshot some files: |
| 139 |
file: 13.0B (13 bytes); the maximum size allowed is 10.0B (10 bytes) |
| 140 |
Hint: This is to prevent large files from being added by accident. To fix this: |
| 141 |
* Add the file(s) to `.gitignore` |
| 142 |
* Run `jj config set --repo snapshot.max-new-file-size 13` |
| 143 |
This will increase the maximum file size allowed for new files, in this repository only. |
| 144 |
* Run `jj --config snapshot.max-new-file-size=13 status` |
| 145 |
This will increase the maximum file size allowed for new files, for this command only. |
| 146 |
Working copy (@) now at: kkmpptxz 119f5156 (no description set) |
| 147 |
Parent commit (@-) : zzzzzzzz 00000000 (empty) (no description set) |
| 148 |
Added 1 files, modified 0 files, removed 0 files |
| 149 |
Warning: 1 of those updates were skipped because there were conflicting changes in the working copy. |
| 150 |
Hint: Inspect the changes compared to the intended target with `jj diff --from 119f5156d330`. |
| 151 |
Discard the conflicting changes with `jj restore --from 119f5156d330`. |
| 152 |
[EOF] |
| 153 |
"); |
| 154 |
insta::assert_snapshot!(work_dir.read_file("file"), @"a lot of text"); |
| 155 |
|
| 156 |
// However, the next command will snapshot the large file because it is now |
| 157 |
// tracked. TODO: Should we remember the untracked state? |
| 158 |
let output = work_dir.run_jj(["status"]); |
| 159 |
insta::assert_snapshot!(output, @" |
| 160 |
Working copy changes: |
| 161 |
A file |
| 162 |
Working copy (@) : kkmpptxz 09eba65e (no description set) |
| 163 |
Parent commit (@-): zzzzzzzz 00000000 (empty) (no description set) |
| 164 |
[EOF] |
| 165 |
"); |
| 166 |
} |
| 167 |
|
| 168 |
#[test] |
| 169 |
fn test_materialize_and_snapshot_different_conflict_markers() -> TestResult { |
| 170 |
let test_env = TestEnvironment::default(); |
| 171 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 172 |
let work_dir = test_env.work_dir("repo"); |
| 173 |
|
| 174 |
// Configure to use Git-style conflict markers |
| 175 |
test_env.add_config(r#"ui.conflict-marker-style = "git""#); |
| 176 |
|
| 177 |
// Create a conflict in the working copy |
| 178 |
work_dir.write_file( |
| 179 |
"file", |
| 180 |
indoc! {" |
| 181 |
line 1 |
| 182 |
line 2 |
| 183 |
line 3 |
| 184 |
"}, |
| 185 |
); |
| 186 |
work_dir.run_jj(["commit", "-m", "base"]).success(); |
| 187 |
work_dir.write_file( |
| 188 |
"file", |
| 189 |
indoc! {" |
| 190 |
line 1 |
| 191 |
line 2 - a |
| 192 |
line 3 |
| 193 |
"}, |
| 194 |
); |
| 195 |
work_dir.run_jj(["commit", "-m", "side-a"]).success(); |
| 196 |
work_dir |
| 197 |
.run_jj(["new", "subject(base)", "-m", "side-b"]) |
| 198 |
.success(); |
| 199 |
work_dir.write_file( |
| 200 |
"file", |
| 201 |
indoc! {" |
| 202 |
line 1 |
| 203 |
line 2 - b |
| 204 |
line 3 - b |
| 205 |
"}, |
| 206 |
); |
| 207 |
work_dir |
| 208 |
.run_jj(["new", "subject(side-a)", "subject(side-b)"]) |
| 209 |
.success(); |
| 210 |
|
| 211 |
// File should have Git-style conflict markers |
| 212 |
insta::assert_snapshot!(work_dir.read_file("file"), @r#" |
| 213 |
line 1 |
| 214 |
<<<<<<< rlvkpnrz df1cdd77 "side-a" |
| 215 |
line 2 - a |
| 216 |
line 3 |
| 217 |
||||||| qpvuntsm 2205b3ac "base" |
| 218 |
line 2 |
| 219 |
line 3 |
| 220 |
======= |
| 221 |
line 2 - b |
| 222 |
line 3 - b |
| 223 |
>>>>>>> zsuskuln 68dcce1b "side-b" |
| 224 |
"#); |
| 225 |
|
| 226 |
// Configure to use JJ-style "snapshot" conflict markers |
| 227 |
test_env.add_config(r#"ui.conflict-marker-style = "snapshot""#); |
| 228 |
|
| 229 |
// Update the conflict, still using Git-style conflict markers |
| 230 |
work_dir.write_file( |
| 231 |
"file", |
| 232 |
indoc! {" |
| 233 |
line 1 |
| 234 |
<<<<<<< |
| 235 |
line 2 - a |
| 236 |
line 3 - a |
| 237 |
||||||| |
| 238 |
line 2 |
| 239 |
line 3 |
| 240 |
======= |
| 241 |
line 2 - b |
| 242 |
line 3 - b |
| 243 |
>>>>>>> |
| 244 |
"}, |
| 245 |
); |
| 246 |
|
| 247 |
// Git-style markers should be parsed, then rendered with new config |
| 248 |
insta::assert_snapshot!(work_dir.run_jj(["diff", "--git"]), @r#" |
| 249 |
diff --git a/file b/file |
| 250 |
--- a/file |
| 251 |
+++ b/file |
| 252 |
@@ -2,7 +2,7 @@ |
| 253 |
<<<<<<< conflict 1 of 1 |
| 254 |
+++++++ rlvkpnrz df1cdd77 "side-a" |
| 255 |
line 2 - a |
| 256 |
-line 3 |
| 257 |
+line 3 - a |
| 258 |
------- qpvuntsm 2205b3ac "base" |
| 259 |
line 2 |
| 260 |
line 3 |
| 261 |
[EOF] |
| 262 |
"#); |
| 263 |
Ok(()) |
| 264 |
} |
| 265 |
|
| 266 |
#[test] |
| 267 |
fn test_snapshot_invalid_ignore_pattern() { |
| 268 |
let test_env = TestEnvironment::default(); |
| 269 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 270 |
let work_dir = test_env.work_dir("repo"); |
| 271 |
|
| 272 |
// Test invalid pattern in .gitignore |
| 273 |
work_dir.write_file(".gitignore", " []\n"); |
| 274 |
insta::assert_snapshot!(work_dir.run_jj(["st"]), @" |
| 275 |
Working copy changes: |
| 276 |
A .gitignore |
| 277 |
Working copy (@) : qpvuntsm c9cf4826 (no description set) |
| 278 |
Parent commit (@-): zzzzzzzz 00000000 (empty) (no description set) |
| 279 |
[EOF] |
| 280 |
"); |
| 281 |
|
| 282 |
// Test invalid UTF-8 in .gitignore |
| 283 |
work_dir.write_file(".gitignore", b"\xff\n"); |
| 284 |
insta::assert_snapshot!(work_dir.run_jj(["st"]), @" |
| 285 |
Working copy changes: |
| 286 |
A .gitignore |
| 287 |
Working copy (@) : qpvuntsm 15f3d11a (no description set) |
| 288 |
Parent commit (@-): zzzzzzzz 00000000 (empty) (no description set) |
| 289 |
[EOF] |
| 290 |
"); |
| 291 |
} |
| 292 |
|
| 293 |
#[cfg(unix)] |
| 294 |
#[test] |
| 295 |
fn test_snapshot_non_utf8_path() { |
| 296 |
use std::ffi::OsStr; |
| 297 |
use std::os::unix::ffi::OsStrExt as _; |
| 298 |
|
| 299 |
let test_env = TestEnvironment::default(); |
| 300 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 301 |
let work_dir = test_env.work_dir("repo"); |
| 302 |
|
| 303 |
if testutils::check_strict_utf8_fs(work_dir.root()) { |
| 304 |
eprintln!( |
| 305 |
"Skipping test \"test_snapshot_non_utf8_path\" due to strict UTF-8 filesystem for \ |
| 306 |
path {:?}", |
| 307 |
work_dir.root() |
| 308 |
); |
| 309 |
return; |
| 310 |
} |
| 311 |
|
| 312 |
std::fs::write(work_dir.root().join(OsStr::from_bytes(b"file\xe0")), "").unwrap(); |
| 313 |
std::fs::create_dir(work_dir.root().join(OsStr::from_bytes(b"dir\xe0"))).unwrap(); |
| 314 |
work_dir.write_file("file", ""); |
| 315 |
|
| 316 |
// The paths that can't be represented as RepoPaths are skipped, and the |
| 317 |
// snapshot succeeds. |
| 318 |
insta::assert_snapshot!(work_dir.run_jj(["st"]), @r#" |
| 319 |
Working copy changes: |
| 320 |
A file |
| 321 |
Working copy (@) : qpvuntsm 3dcf981e (no description set) |
| 322 |
Parent commit (@-): zzzzzzzz 00000000 (empty) (no description set) |
| 323 |
[EOF] |
| 324 |
------- stderr ------- |
| 325 |
Warning: Skipped some paths because they are not valid UTF-8: |
| 326 |
.: "dir\xE0" |
| 327 |
.: "file\xE0" |
| 328 |
[EOF] |
| 329 |
"#); |
| 330 |
|
| 331 |
// .gitignore doesn't apply because we can't build a RepoPath to match |
| 332 |
// against, so the paths are still reported. |
| 333 |
work_dir.write_file(".gitignore", b"dir\xe0\nfile\xe0\n"); |
| 334 |
insta::assert_snapshot!(work_dir.run_jj(["st"]), @r#" |
| 335 |
Working copy changes: |
| 336 |
A .gitignore |
| 337 |
A file |
| 338 |
Working copy (@) : qpvuntsm 0fbe2679 (no description set) |
| 339 |
Parent commit (@-): zzzzzzzz 00000000 (empty) (no description set) |
| 340 |
[EOF] |
| 341 |
------- stderr ------- |
| 342 |
Warning: Skipped some paths because they are not valid UTF-8: |
| 343 |
.: "dir\xE0" |
| 344 |
.: "file\xE0" |
| 345 |
[EOF] |
| 346 |
"#); |
| 347 |
} |
| 348 |
|
| 349 |
#[test] |
| 350 |
fn test_conflict_marker_length_stored_in_working_copy() -> TestResult { |
| 351 |
let test_env = TestEnvironment::default(); |
| 352 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 353 |
let work_dir = test_env.work_dir("repo"); |
| 354 |
|
| 355 |
// Create a conflict in the working copy with long markers on one side |
| 356 |
work_dir.write_file( |
| 357 |
"file", |
| 358 |
indoc! {" |
| 359 |
line 1 |
| 360 |
line 2 |
| 361 |
line 3 |
| 362 |
"}, |
| 363 |
); |
| 364 |
work_dir.run_jj(["commit", "-m", "base"]).success(); |
| 365 |
work_dir.write_file( |
| 366 |
"file", |
| 367 |
indoc! {" |
| 368 |
line 1 |
| 369 |
line 2 - left |
| 370 |
line 3 - left |
| 371 |
"}, |
| 372 |
); |
| 373 |
work_dir.run_jj(["commit", "-m", "side-a"]).success(); |
| 374 |
work_dir |
| 375 |
.run_jj(["new", "subject(base)", "-m", "side-b"]) |
| 376 |
.success(); |
| 377 |
work_dir.write_file( |
| 378 |
"file", |
| 379 |
indoc! {" |
| 380 |
line 1 |
| 381 |
======= fake marker |
| 382 |
line 2 - right |
| 383 |
======= fake marker |
| 384 |
line 3 |
| 385 |
"}, |
| 386 |
); |
| 387 |
work_dir |
| 388 |
.run_jj(["new", "subject(side-a)", "subject(side-b)"]) |
| 389 |
.success(); |
| 390 |
|
| 391 |
// File should be materialized with long conflict markers |
| 392 |
insta::assert_snapshot!(work_dir.read_file("file"), @r#" |
| 393 |
line 1 |
| 394 |
<<<<<<<<<<< conflict 1 of 1 |
| 395 |
%%%%%%%%%%% diff from: qpvuntsm 2205b3ac "base" |
| 396 |
\\\\\\\\\\\ to: rlvkpnrz ccf9527c "side-a" |
| 397 |
-line 2 |
| 398 |
-line 3 |
| 399 |
+line 2 - left |
| 400 |
+line 3 - left |
| 401 |
+++++++++++ zsuskuln d7acaf48 "side-b" |
| 402 |
======= fake marker |
| 403 |
line 2 - right |
| 404 |
======= fake marker |
| 405 |
line 3 |
| 406 |
>>>>>>>>>>> conflict 1 of 1 ends |
| 407 |
"#); |
| 408 |
|
| 409 |
// The timestamps in the `jj debug local-working-copy` output change, so we want |
| 410 |
// to remove them before asserting the snapshot |
| 411 |
let timestamp_regex = Regex::new(r"\b\d{10,}\b")?; |
| 412 |
let redact_output = |output: String| { |
| 413 |
let output = timestamp_regex.replace_all(&output, "<timestamp>"); |
| 414 |
output.into_owned() |
| 415 |
}; |
| 416 |
|
| 417 |
// Working copy should contain conflict marker length |
| 418 |
let output = work_dir.run_jj(["debug", "local-working-copy"]); |
| 419 |
insta::assert_snapshot!(output.normalize_stdout_with(redact_output), @r#" |
| 420 |
Current operation: OperationId("ee791f2181026a056ad383d14dbc749ba44e24fedfd39418954871b83d754929147b951bde1fbcca6a8460932e53a6d7ea739bf054ec0bf03607b9370173d6e5") |
| 421 |
Current tree: MergedTree { tree_ids: Conflicted([TreeId("381273b50cf73f8c81b3f1502ee89e9bbd6c1518"), TreeId("771f3d31c4588ea40a8864b2a981749888e596c2"), TreeId("f56b8223da0dab22b03b8323ced4946329aeb4e0")]), labels: Labeled(["rlvkpnrz ccf9527c \"side-a\"", "qpvuntsm 2205b3ac \"base\"", "zsuskuln d7acaf48 \"side-b\""]), .. } |
| 422 |
Normal { exec_bit: ExecBit(false) } 313 <timestamp> Some(MaterializedConflictData { conflict_marker_len: 11 }) "file" |
| 423 |
[EOF] |
| 424 |
"#); |
| 425 |
|
| 426 |
// Update the conflict with more fake markers, and it should still parse |
| 427 |
// correctly (the markers should be ignored) |
| 428 |
work_dir.write_file( |
| 429 |
"file", |
| 430 |
indoc! {" |
| 431 |
line 1 |
| 432 |
<<<<<<<<<<< conflict 1 of 1 |
| 433 |
%%%%%%%%%%% diff from base to side #1 |
| 434 |
-line 2 |
| 435 |
-line 3 |
| 436 |
+line 2 - left |
| 437 |
+line 3 - left |
| 438 |
+++++++++++ side #2 |
| 439 |
<<<<<<< fake marker |
| 440 |
||||||| fake marker |
| 441 |
line 2 - right |
| 442 |
======= fake marker |
| 443 |
line 3 |
| 444 |
>>>>>>> fake marker |
| 445 |
>>>>>>>>>>> conflict 1 of 1 ends |
| 446 |
"}, |
| 447 |
); |
| 448 |
|
| 449 |
// The file should still be conflicted, and the new content should be saved |
| 450 |
let output = work_dir.run_jj(["st"]); |
| 451 |
insta::assert_snapshot!(output, @" |
| 452 |
Working copy changes: |
| 453 |
M file |
| 454 |
Working copy (@) : mzvwutvl d31c99cf (conflict) (no description set) |
| 455 |
Parent commit (@-): rlvkpnrz ccf9527c side-a |
| 456 |
Parent commit (@-): zsuskuln d7acaf48 side-b |
| 457 |
Warning: There are unresolved conflicts at these paths: |
| 458 |
file 2-sided conflict |
| 459 |
[EOF] |
| 460 |
"); |
| 461 |
insta::assert_snapshot!(work_dir.run_jj(["diff", "--git"]), @r#" |
| 462 |
diff --git a/file b/file |
| 463 |
--- a/file |
| 464 |
+++ b/file |
| 465 |
@@ -7,8 +7,10 @@ |
| 466 |
+line 2 - left |
| 467 |
+line 3 - left |
| 468 |
+++++++++++ zsuskuln d7acaf48 "side-b" |
| 469 |
-======= fake marker |
| 470 |
+<<<<<<< fake marker |
| 471 |
+||||||| fake marker |
| 472 |
line 2 - right |
| 473 |
======= fake marker |
| 474 |
line 3 |
| 475 |
+>>>>>>> fake marker |
| 476 |
>>>>>>>>>>> conflict 1 of 1 ends |
| 477 |
[EOF] |
| 478 |
"#); |
| 479 |
|
| 480 |
// Working copy should still contain conflict marker length |
| 481 |
let output = work_dir.run_jj(["debug", "local-working-copy"]); |
| 482 |
insta::assert_snapshot!(output.normalize_stdout_with(redact_output), @r#" |
| 483 |
Current operation: OperationId("b196f038bbd8cf84508417da8e974874b52202bc98abca08725e946a7a9ea9e011aeddda805c565f49a1e07e43524161caa56fa438de662aba8a6349b5a44be1") |
| 484 |
Current tree: MergedTree { tree_ids: Conflicted([TreeId("381273b50cf73f8c81b3f1502ee89e9bbd6c1518"), TreeId("771f3d31c4588ea40a8864b2a981749888e596c2"), TreeId("3329c18c95f7b7a55c278c2259e9c4ce711fae59")]), labels: Labeled(["rlvkpnrz ccf9527c \"side-a\"", "qpvuntsm 2205b3ac \"base\"", "zsuskuln d7acaf48 \"side-b\""]), .. } |
| 485 |
Normal { exec_bit: ExecBit(false) } 274 <timestamp> Some(MaterializedConflictData { conflict_marker_len: 11 }) "file" |
| 486 |
[EOF] |
| 487 |
"#); |
| 488 |
|
| 489 |
// Resolve the conflict |
| 490 |
work_dir.write_file( |
| 491 |
"file", |
| 492 |
indoc! {" |
| 493 |
line 1 |
| 494 |
<<<<<<< fake marker |
| 495 |
||||||| fake marker |
| 496 |
line 2 - left |
| 497 |
line 2 - right |
| 498 |
======= fake marker |
| 499 |
line 3 - left |
| 500 |
>>>>>>> fake marker |
| 501 |
"}, |
| 502 |
); |
| 503 |
|
| 504 |
let output = work_dir.run_jj(["st"]); |
| 505 |
insta::assert_snapshot!(output, @" |
| 506 |
Working copy changes: |
| 507 |
M file |
| 508 |
Working copy (@) : mzvwutvl 469d479f (no description set) |
| 509 |
Parent commit (@-): rlvkpnrz ccf9527c side-a |
| 510 |
Parent commit (@-): zsuskuln d7acaf48 side-b |
| 511 |
[EOF] |
| 512 |
"); |
| 513 |
|
| 514 |
// When the file is resolved, the conflict marker length is removed from the |
| 515 |
// working copy |
| 516 |
let output = work_dir.run_jj(["debug", "local-working-copy"]); |
| 517 |
insta::assert_snapshot!(output.normalize_stdout_with(redact_output), @r#" |
| 518 |
Current operation: OperationId("65b561ae4667b8b9db3f3d6cb2f6bccd087f17b008ba87b976266e641efdab4f12193407e4f6f8bd76b02eff767a6c173ef53e2c0217be389b05779170a257b6") |
| 519 |
Current tree: MergedTree { tree_ids: Resolved(TreeId("6120567b3cb2472d549753ed3e4b84183d52a650")), labels: Unlabeled, .. } |
| 520 |
Normal { exec_bit: ExecBit(false) } 130 <timestamp> None "file" |
| 521 |
[EOF] |
| 522 |
"#); |
| 523 |
Ok(()) |
| 524 |
} |
| 525 |
|
| 526 |
#[test] |
| 527 |
fn test_submodule_ignored() { |
| 528 |
let test_env = TestEnvironment::default(); |
| 529 |
|
| 530 |
test_env |
| 531 |
.run_jj_in(".", ["git", "init", "--colocate", "submodule"]) |
| 532 |
.success(); |
| 533 |
let submodule_dir = test_env.work_dir("submodule"); |
| 534 |
submodule_dir.write_file("sub", "sub"); |
| 535 |
submodule_dir |
| 536 |
.run_jj(["commit", "-m", "Submodule commit"]) |
| 537 |
.success(); |
| 538 |
|
| 539 |
test_env |
| 540 |
.run_jj_in(".", ["git", "init", "--colocate", "repo"]) |
| 541 |
.success(); |
| 542 |
let work_dir = test_env.work_dir("repo"); |
| 543 |
|
| 544 |
// There's no particular reason to run this with jj util exec, it's just that |
| 545 |
// the infra makes it easier to run this way. |
| 546 |
let output = work_dir.run_jj([ |
| 547 |
"util", |
| 548 |
"exec", |
| 549 |
"--", |
| 550 |
"git", |
| 551 |
"-c", |
| 552 |
// Git normally doesn't allow file:// in submodules. |
| 553 |
"protocol.file.allow=always", |
| 554 |
"submodule", |
| 555 |
"add", |
| 556 |
&format!("{}/submodule", test_env.env_root().display()), |
| 557 |
"sub", |
| 558 |
]); |
| 559 |
insta::assert_snapshot!(output, @" |
| 560 |
------- stderr ------- |
| 561 |
Cloning into '$TEST_ENV/repo/sub'... |
| 562 |
done. |
| 563 |
[EOF] |
| 564 |
"); |
| 565 |
// Use git to commit since jj won't play nice with the submodule. |
| 566 |
work_dir |
| 567 |
.run_jj([ |
| 568 |
"util", |
| 569 |
"exec", |
| 570 |
"--", |
| 571 |
"git", |
| 572 |
"-c", |
| 573 |
"[email protected]", |
| 574 |
"-c", |
| 575 |
"user.name=Test user", |
| 576 |
"commit", |
| 577 |
"-m", |
| 578 |
"Add submodule", |
| 579 |
]) |
| 580 |
.success(); |
| 581 |
|
| 582 |
// This should be empty. We shouldn't track the submodule itself. |
| 583 |
let output = work_dir.run_jj(["diff", "--summary"]); |
| 584 |
insta::assert_snapshot!(output, @r#" |
| 585 |
------- stderr ------- |
| 586 |
ignoring git submodule at "sub" |
| 587 |
Done importing changes from the underlying Git repo. |
| 588 |
[EOF] |
| 589 |
"#); |
| 590 |
|
| 591 |
// Switch to a historical commit before the submodule was checked in. |
| 592 |
work_dir.run_jj(["prev"]).success(); |
| 593 |
// jj new (or equivalently prev) should always leave you with an empty working |
| 594 |
// copy. |
| 595 |
let output = work_dir.run_jj(["diff", "--summary"]); |
| 596 |
insta::assert_snapshot!(output, @""); |
| 597 |
} |
| 598 |
|
| 599 |
#[test] |
| 600 |
fn test_snapshot_jjconflict_trees() -> TestResult { |
| 601 |
let test_env = TestEnvironment::default(); |
| 602 |
test_env |
| 603 |
.run_jj_in(".", ["git", "init", "repo", "--colocate"]) |
| 604 |
.success(); |
| 605 |
let work_dir = test_env.work_dir("repo"); |
| 606 |
|
| 607 |
// Create a conflict in the working copy |
| 608 |
work_dir.write_file( |
| 609 |
"file", |
| 610 |
indoc! {" |
| 611 |
line 1 |
| 612 |
line 2 |
| 613 |
line 3 |
| 614 |
"}, |
| 615 |
); |
| 616 |
work_dir.run_jj(["new", "-m", "side-a"]).success(); |
| 617 |
work_dir.write_file( |
| 618 |
"file", |
| 619 |
indoc! {" |
| 620 |
line 1 |
| 621 |
line 2 - left |
| 622 |
line 3 - left |
| 623 |
"}, |
| 624 |
); |
| 625 |
work_dir |
| 626 |
.run_jj(["new", "subject(side-a)-", "-m", "side-b"]) |
| 627 |
.success(); |
| 628 |
work_dir.write_file( |
| 629 |
"file", |
| 630 |
indoc! {" |
| 631 |
line 1 |
| 632 |
line 2 - right |
| 633 |
line 3 |
| 634 |
"}, |
| 635 |
); |
| 636 |
work_dir.run_jj(["new"]).success(); |
| 637 |
work_dir |
| 638 |
.run_jj(["rebase", "-s", "subject(side-b)", "-o", "subject(side-a)"]) |
| 639 |
.success(); |
| 640 |
|
| 641 |
// Run `git reset --hard HEAD` to simulate checking out the branch with Git. |
| 642 |
let output = std::process::Command::new("git") |
| 643 |
.current_dir(work_dir.root()) |
| 644 |
.args(["reset", "--hard", "HEAD"]) |
| 645 |
.output()?; |
| 646 |
assert!(output.status.success()); |
| 647 |
|
| 648 |
// We should see a warning regarding '.jjconflict' trees being checked out. |
| 649 |
let output = work_dir.run_jj(["st"]); |
| 650 |
insta::assert_snapshot!(output.to_string().replace('\\', "/"), @r" |
| 651 |
Working copy changes: |
| 652 |
A .jjconflict-base-0/file |
| 653 |
A .jjconflict-side-0/file |
| 654 |
A .jjconflict-side-1/file |
| 655 |
A JJ-CONFLICT-README |
| 656 |
M file |
| 657 |
Working copy (@) : zsuskuln 2681a418 (no description set) |
| 658 |
Parent commit (@-): kkmpptxz aadeb8eb (conflict) side-b |
| 659 |
Hint: Conflict in parent commit has been resolved in working copy. |
| 660 |
[EOF] |
| 661 |
------- stderr ------- |
| 662 |
Warning: The working copy contains '.jjconflict' files. These files are used by `jj` internally and should not be present in the working copy. |
| 663 |
Hint: You may have used a regular `git` command to check out a conflicted commit. |
| 664 |
Hint: You can use `jj abandon` to discard the working copy changes. |
| 665 |
[EOF] |
| 666 |
"); |
| 667 |
Ok(()) |
| 668 |
} |