Debian Codegraph @

cli/tests/test_status_command.rs

raw
1 // Copyright 2022 The Jujutsu Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 use crate::common::TestEnvironment;
16 use crate::common::create_commit_with_files;
17
18 #[test]
19 fn test_status_copies() {
20 let test_env = TestEnvironment::default();
21 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
22 let work_dir = test_env.work_dir("repo");
23
24 work_dir.write_file("copy-source", "copy1\ncopy2\ncopy3\n");
25 work_dir.write_file("rename-source", "rename");
26 work_dir.run_jj(["new"]).success();
27 work_dir.write_file("copy-source", "copy1\ncopy2\ncopy3\nsource\n");
28 work_dir.write_file("copy-target", "copy1\ncopy2\ncopy3\ntarget\n");
29 work_dir.remove_file("rename-source");
30 work_dir.write_file("rename-target", "rename");
31
32 let output = work_dir.run_jj(["status"]);
33 insta::assert_snapshot!(output, @"
34 Working copy changes:
35 M copy-source
36 C {copy-source => copy-target}
37 R {rename-source => rename-target}
38 Working copy (@) : rlvkpnrz c2fce842 (no description set)
39 Parent commit (@-): qpvuntsm ebf799bc (no description set)
40 [EOF]
41 ");
42 }
43
44 #[test]
45 fn test_status_merge() {
46 let test_env = TestEnvironment::default();
47 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
48 let work_dir = test_env.work_dir("repo");
49
50 work_dir.write_file("file", "base");
51 work_dir.run_jj(["new", "-m=left"]).success();
52 work_dir
53 .run_jj(["bookmark", "create", "-r@", "left"])
54 .success();
55 work_dir.run_jj(["new", "@-", "-m=right"]).success();
56 work_dir.write_file("file", "right");
57 work_dir.run_jj(["new", "left", "@"]).success();
58
59 // The output should mention each parent, and the diff should be empty (compared
60 // to the auto-merged parents)
61 let output = work_dir.run_jj(["status"]);
62 insta::assert_snapshot!(output, @"
63 The working copy has no changes.
64 Working copy (@) : mzvwutvl f62dad77 (empty) (no description set)
65 Parent commit (@-): rlvkpnrz a007d87b left | (empty) left
66 Parent commit (@-): zsuskuln e6ad1952 right
67 [EOF]
68 ");
69 }
70
71 // See https://github.com/jj-vcs/jj/issues/2051.
72 #[test]
73 fn test_status_ignored_gitignore() {
74 let test_env = TestEnvironment::default();
75 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
76 let work_dir = test_env.work_dir("repo");
77
78 let untracked_dir = work_dir.create_dir("untracked");
79 untracked_dir.write_file("inside_untracked", "test");
80 untracked_dir.write_file(".gitignore", "!inside_untracked\n");
81 work_dir.write_file(".gitignore", "untracked/\n!dummy\n");
82
83 let output = work_dir.run_jj(["status"]);
84 insta::assert_snapshot!(output, @"
85 Working copy changes:
86 A .gitignore
87 Working copy (@) : qpvuntsm 32bad97e (no description set)
88 Parent commit (@-): zzzzzzzz 00000000 (empty) (no description set)
89 [EOF]
90 ");
91 }
92
93 #[test]
94 fn test_status_filtered() {
95 let test_env = TestEnvironment::default();
96 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
97 let work_dir = test_env.work_dir("repo");
98
99 work_dir.write_file("file_1", "file_1");
100 work_dir.write_file("file_2", "file_2");
101
102 // The output filtered to file_1 should not list the addition of file_2.
103 let output = work_dir.run_jj(["status", "file_1"]);
104 insta::assert_snapshot!(output, @"
105 Working copy changes:
106 A file_1
107 Working copy (@) : qpvuntsm 2f169edb (no description set)
108 Parent commit (@-): zzzzzzzz 00000000 (empty) (no description set)
109 [EOF]
110 ");
111
112 // The diff summary should preserve ANSI color codes instead of sanitizing them.
113 let output = work_dir.run_jj(["status", "file_1", "--color=always"]);
114 insta::assert_snapshot!(output, @"
115 Working copy changes:
116 A file_1
117 Working copy (@) : qpvuntsm 2f169edb (no description set)
118 Parent commit (@-): zzzzzzzz 00000000 (empty) (no description set)
119 [EOF]
120 ");
121
122 // The output filtered to a non-existent file should display a warning.
123 let output = work_dir.run_jj(["status", "nonexistent"]);
124 insta::assert_snapshot!(output, @"
125 Working copy (@) : qpvuntsm 2f169edb (no description set)
126 Parent commit (@-): zzzzzzzz 00000000 (empty) (no description set)
127 [EOF]
128 ------- stderr -------
129 Warning: No matching entries for paths: nonexistent
130 [EOF]
131 ");
132
133 // The output filtered to file_1 should not print an empty changes header
134 // when only file_2 changed.
135 work_dir.run_jj(["new"]).success();
136 work_dir.write_file("file_2", "updated");
137
138 let output = work_dir.run_jj(["status", "file_1"]);
139 insta::assert_snapshot!(output, @"
140 Working copy (@) : mzvwutvl d977fd8e (no description set)
141 Parent commit (@-): qpvuntsm 2f169edb (no description set)
142 [EOF]
143 ");
144
145 // The output filtered to file_1 and a non-existent file should display
146 // only the warning.
147 let output = work_dir.run_jj(["status", "file_1", "nonexistent"]);
148 insta::assert_snapshot!(output, @"
149 Working copy (@) : mzvwutvl d977fd8e (no description set)
150 Parent commit (@-): qpvuntsm 2f169edb (no description set)
151 [EOF]
152 ------- stderr -------
153 Warning: No matching entries for paths: nonexistent
154 [EOF]
155 ");
156
157 // The output filtered to a non-existent file in a clean working copy should
158 // report no changes and display a warning.
159 work_dir.run_jj(["new"]).success();
160
161 let output = work_dir.run_jj(["status", "nonexistent"]);
162 insta::assert_snapshot!(output, @"
163 The working copy has no changes.
164 Working copy (@) : vruxwmqv bc1fcb38 (empty) (no description set)
165 Parent commit (@-): mzvwutvl d977fd8e (no description set)
166 [EOF]
167 ------- stderr -------
168 Warning: No matching entries for paths: nonexistent
169 [EOF]
170 ");
171 }
172
173 #[test]
174 fn test_status_conflicted_bookmarks() {
175 // create conflicted local bookmark
176 let test_env = TestEnvironment::default();
177 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
178 let work_dir = test_env.work_dir("repo");
179 work_dir
180 .run_jj(["bookmark", "create", "local_bookmark"])
181 .success();
182 work_dir.run_jj(["describe", "-m=a"]).success();
183 work_dir
184 .run_jj(["describe", "-m=b", "--at-op=@-"])
185 .success();
186
187 let output = work_dir.run_jj(["status"]);
188 insta::assert_snapshot!(output, @"
189 The working copy has no changes.
190 Working copy (@) : qpvuntsm/1 99025a24 local_bookmark?? | (divergent) (empty) a
191 Parent commit (@-): zzzzzzzz 00000000 (empty) (no description set)
192 Warning: These bookmarks have conflicts:
193 local_bookmark
194 Hint: Use `jj bookmark list` to see details. Use `jj bookmark set <name> -r <rev>` to resolve.
195 [EOF]
196 ------- stderr -------
197 Concurrent modification detected, resolving automatically.
198 [EOF]
199 ");
200
201 // create remote
202 test_env
203 .run_jj_in(".", ["git", "init", "origin", "--colocate"])
204 .success();
205 let origin_dir = test_env.work_dir("origin");
206 let origin_git_repo_path = origin_dir.root().join(".git");
207 origin_dir
208 .run_jj(["bookmark", "create", "remote_bookmark"])
209 .success();
210 origin_dir.run_jj(["git", "export"]).success();
211
212 // fetch remote bookmark with empty changes
213 work_dir
214 .run_jj([
215 "git",
216 "remote",
217 "add",
218 "origin",
219 origin_git_repo_path.to_str().unwrap(),
220 ])
221 .success();
222 work_dir.run_jj(["git", "fetch"]).success();
223
224 // update remote
225 origin_dir.write_file("file.txt", "");
226 origin_dir.run_jj(["git", "export"]).success();
227
228 // create conflicted remote bookmark
229 work_dir.run_jj(["git", "fetch", "--at-op", "@-"]).success();
230 let output = work_dir.run_jj(["status"]);
231 insta::assert_snapshot!(output, @"
232 The working copy has no changes.
233 Working copy (@) : qpvuntsm/1 99025a24 local_bookmark?? | (divergent) (empty) a
234 Parent commit (@-): zzzzzzzz 00000000 (empty) (no description set)
235 Warning: These bookmarks have conflicts:
236 local_bookmark
237 Hint: Use `jj bookmark list` to see details. Use `jj bookmark set <name> -r <rev>` to resolve.
238 Warning: These remote bookmarks have conflicts:
239 remote_bookmark@origin
240 Hint: Use `jj bookmark list` to see details. Resolve by fetching an updated bookmark from the remote.
241 [EOF]
242 ------- stderr -------
243 Concurrent modification detected, resolving automatically.
244 [EOF]
245 ");
246 }
247
248 // See <https://github.com/jj-vcs/jj/issues/3108>
249 // See <https://github.com/jj-vcs/jj/issues/4147>
250 #[test]
251 fn test_status_display_relevant_working_commit_conflict_hints() {
252 let test_env = TestEnvironment::default();
253 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
254
255 let work_dir = test_env.work_dir("repo");
256 // PARENT: Write the initial file
257 work_dir.write_file("conflicted1.txt", "initial contents");
258 work_dir.write_file("conflicted2.txt", "initial contents");
259 work_dir
260 .run_jj(["describe", "--message", "Initial contents"])
261 .success();
262
263 // CHILD1: New commit on top of <PARENT>
264 work_dir
265 .run_jj(["new", "--message", "First part of conflicting change"])
266 .success();
267 work_dir.write_file("conflicted1.txt", "Child 1");
268 work_dir.write_file("conflicted2.txt", "Child 1");
269
270 // CHILD2: New commit also on top of <PARENT>
271 work_dir
272 .run_jj([
273 "new",
274 "--message",
275 "Second part of conflicting change",
276 "@-",
277 ])
278 .success();
279 work_dir.write_file("conflicted1.txt", "Child 2");
280 work_dir.write_file("conflicted2.txt", "Child 2");
281
282 // CONFLICT: New commit that is conflicted by merging <CHILD1> and <CHILD2>
283 work_dir
284 .run_jj(["new", "--message", "boom", "(@-)+"])
285 .success();
286 // Adding more descendants to ensure we correctly find the root ancestors with
287 // conflicts, not just the parents.
288 work_dir.run_jj(["new", "--message", "boom-cont"]).success();
289 work_dir
290 .run_jj(["new", "--message", "boom-cont-2"])
291 .success();
292
293 let output = work_dir.run_jj(["log", "-r", "::"]);
294
295 insta::assert_snapshot!(output, @"
296 @ yqosqzyt [email protected] 2001-02-03 08:05:13 06b8a9dd (conflict)
297 │ (empty) boom-cont-2
298 × royxmykx [email protected] 2001-02-03 08:05:12 fc966143 (conflict)
299 │ (empty) boom-cont
300 × mzvwutvl [email protected] 2001-02-03 08:05:11 7bc77be4 (conflict)
301 ├─╮ (empty) boom
302 │ ○ kkmpptxz [email protected] 2001-02-03 08:05:10 7bb1724e
303 │ │ First part of conflicting change
304 ○ │ zsuskuln [email protected] 2001-02-03 08:05:11 263e2eb6
305 ├─╯ Second part of conflicting change
306 ○ qpvuntsm [email protected] 2001-02-03 08:05:08 8b2bca65
307 │ Initial contents
308 ◆ zzzzzzzz root() 00000000
309 [EOF]
310 ");
311
312 let output = work_dir.run_jj(["status"]);
313 insta::assert_snapshot!(output, @"
314 The working copy has no changes.
315 Working copy (@) : yqosqzyt 06b8a9dd (conflict) (empty) boom-cont-2
316 Parent commit (@-): royxmykx fc966143 (conflict) (empty) boom-cont
317 Warning: There are unresolved conflicts at these paths:
318 conflicted1.txt 2-sided conflict
319 conflicted2.txt 2-sided conflict
320 Hint: To resolve the conflicts, start by creating a commit on top of
321 the first conflicted commit:
322 jj new mzvwutvl
323 Then use `jj resolve`, or edit the conflict markers in the file directly.
324 Once the conflicts are resolved, you can inspect the result with `jj diff`.
325 Then run `jj squash` to move the resolution into the conflicted commit.
326 [EOF]
327 ");
328
329 // Can filter by paths for conflicts.
330 let output = work_dir.run_jj(["status", "conflicted1.txt"]);
331 insta::assert_snapshot!(output, @"
332 The working copy has no changes.
333 Working copy (@) : yqosqzyt 06b8a9dd (conflict) (empty) boom-cont-2
334 Parent commit (@-): royxmykx fc966143 (conflict) (empty) boom-cont
335 Warning: There are unresolved conflicts at these paths:
336 conflicted1.txt 2-sided conflict
337 Hint: To resolve the conflicts, start by creating a commit on top of
338 the first conflicted commit:
339 jj new mzvwutvl
340 Then use `jj resolve`, or edit the conflict markers in the file directly.
341 Once the conflicts are resolved, you can inspect the result with `jj diff`.
342 Then run `jj squash` to move the resolution into the conflicted commit.
343 [EOF]
344 ");
345
346 let output = work_dir.run_jj(["status", "--color=always"]);
347 insta::assert_snapshot!(output, @"
348 The working copy has no changes.
349 Working copy (@) : yqosqzyt 06b8a9dd (conflict) (empty) boom-cont-2
350 Parent commit (@-): royxmykx fc966143 (conflict) (empty) boom-cont
351 Warning: There are unresolved conflicts at these paths:
352 conflicted1.txt 2-sided conflict
353 conflicted2.txt 2-sided conflict
354 Hint: To resolve the conflicts, start by creating a commit on top of
355 the first conflicted commit:
356  jj new mzvwutvl
357 Then use `jj resolve`, or edit the conflict markers in the file directly.
358 Once the conflicts are resolved, you can inspect the result with `jj diff`.
359 Then run `jj squash` to move the resolution into the conflicted commit.
360 [EOF]
361 ");
362
363 let output = work_dir.run_jj(["status", "--config=hints.resolving-conflicts=false"]);
364 insta::assert_snapshot!(output, @"
365 The working copy has no changes.
366 Working copy (@) : yqosqzyt 06b8a9dd (conflict) (empty) boom-cont-2
367 Parent commit (@-): royxmykx fc966143 (conflict) (empty) boom-cont
368 Warning: There are unresolved conflicts at these paths:
369 conflicted1.txt 2-sided conflict
370 conflicted2.txt 2-sided conflict
371 [EOF]
372 ");
373
374 // Resolve conflict
375 work_dir.run_jj(["new", "--message", "fixed 1"]).success();
376 work_dir.write_file("conflicted1.txt", "first commit to fix conflict");
377 work_dir.write_file("conflicted2.txt", "first commit to fix conflict");
378
379 // Add one more commit atop the commit that resolves the conflict.
380 work_dir.run_jj(["new", "--message", "fixed 2"]).success();
381 work_dir.write_file("conflicted1.txt", "edit not conflict");
382 work_dir.write_file("conflicted2.txt", "edit not conflict");
383
384 // wc is now conflict free, parent is also conflict free
385 let output = work_dir.run_jj(["log", "-r", "::"]);
386
387 insta::assert_snapshot!(output, @"
388 @ lylxulpl [email protected] 2001-02-03 08:05:21 cb6faf76
389 │ fixed 2
390 ○ wqnwkozp [email protected] 2001-02-03 08:05:20 4ecf4b33
391 │ fixed 1
392 × yqosqzyt [email protected] 2001-02-03 08:05:13 06b8a9dd (conflict)
393 │ (empty) boom-cont-2
394 × royxmykx [email protected] 2001-02-03 08:05:12 fc966143 (conflict)
395 │ (empty) boom-cont
396 × mzvwutvl [email protected] 2001-02-03 08:05:11 7bc77be4 (conflict)
397 ├─╮ (empty) boom
398 │ ○ kkmpptxz [email protected] 2001-02-03 08:05:10 7bb1724e
399 │ │ First part of conflicting change
400 ○ │ zsuskuln [email protected] 2001-02-03 08:05:11 263e2eb6
401 ├─╯ Second part of conflicting change
402 ○ qpvuntsm [email protected] 2001-02-03 08:05:08 8b2bca65
403 │ Initial contents
404 ◆ zzzzzzzz root() 00000000
405 [EOF]
406 ");
407
408 let output = work_dir.run_jj(["status"]);
409
410 insta::assert_snapshot!(output, @"
411 Working copy changes:
412 M conflicted1.txt
413 M conflicted2.txt
414 Working copy (@) : lylxulpl cb6faf76 fixed 2
415 Parent commit (@-): wqnwkozp 4ecf4b33 fixed 1
416 [EOF]
417 ");
418
419 // Step back one.
420 // wc is still conflict free, parent has a conflict.
421 work_dir.run_jj(["edit", "@-"]).success();
422 let output = work_dir.run_jj(["log", "-r", "::"]);
423
424 insta::assert_snapshot!(output, @"
425 ○ lylxulpl [email protected] 2001-02-03 08:05:21 cb6faf76
426 │ fixed 2
427 @ wqnwkozp [email protected] 2001-02-03 08:05:20 4ecf4b33
428 │ fixed 1
429 × yqosqzyt [email protected] 2001-02-03 08:05:13 06b8a9dd (conflict)
430 │ (empty) boom-cont-2
431 × royxmykx [email protected] 2001-02-03 08:05:12 fc966143 (conflict)
432 │ (empty) boom-cont
433 × mzvwutvl [email protected] 2001-02-03 08:05:11 7bc77be4 (conflict)
434 ├─╮ (empty) boom
435 │ ○ kkmpptxz [email protected] 2001-02-03 08:05:10 7bb1724e
436 │ │ First part of conflicting change
437 ○ │ zsuskuln [email protected] 2001-02-03 08:05:11 263e2eb6
438 ├─╯ Second part of conflicting change
439 ○ qpvuntsm [email protected] 2001-02-03 08:05:08 8b2bca65
440 │ Initial contents
441 ◆ zzzzzzzz root() 00000000
442 [EOF]
443 ");
444
445 let output = work_dir.run_jj(["status"]);
446
447 insta::assert_snapshot!(output, @r"
448 Working copy changes:
449 M conflicted1.txt
450 M conflicted2.txt
451 Working copy (@) : wqnwkozp 4ecf4b33 fixed 1
452 Parent commit (@-): yqosqzyt 06b8a9dd (conflict) (empty) boom-cont-2
453 Hint: Conflict in parent commit has been resolved in working copy.
454 [EOF]
455 ");
456
457 // Step back to all the way to `root()+` so that wc has no conflict, even though
458 // there is a conflict later in the tree. So that we can confirm
459 // our hinting logic doesn't get confused.
460 work_dir.run_jj(["edit", "root()+"]).success();
461 let output = work_dir.run_jj(["log", "-r", "::"]);
462
463 insta::assert_snapshot!(output, @"
464 ○ lylxulpl [email protected] 2001-02-03 08:05:21 cb6faf76
465 │ fixed 2
466 ○ wqnwkozp [email protected] 2001-02-03 08:05:20 4ecf4b33
467 │ fixed 1
468 × yqosqzyt [email protected] 2001-02-03 08:05:13 06b8a9dd (conflict)
469 │ (empty) boom-cont-2
470 × royxmykx [email protected] 2001-02-03 08:05:12 fc966143 (conflict)
471 │ (empty) boom-cont
472 × mzvwutvl [email protected] 2001-02-03 08:05:11 7bc77be4 (conflict)
473 ├─╮ (empty) boom
474 │ ○ kkmpptxz [email protected] 2001-02-03 08:05:10 7bb1724e
475 │ │ First part of conflicting change
476 ○ │ zsuskuln [email protected] 2001-02-03 08:05:11 263e2eb6
477 ├─╯ Second part of conflicting change
478 @ qpvuntsm [email protected] 2001-02-03 08:05:08 8b2bca65
479 │ Initial contents
480 ◆ zzzzzzzz root() 00000000
481 [EOF]
482 ");
483
484 let output = work_dir.run_jj(["status"]);
485
486 insta::assert_snapshot!(output, @"
487 Working copy changes:
488 A conflicted1.txt
489 A conflicted2.txt
490 Working copy (@) : qpvuntsm 8b2bca65 Initial contents
491 Parent commit (@-): zzzzzzzz 00000000 (empty) (no description set)
492 [EOF]
493 ");
494 }
495
496 #[test]
497 fn test_status_simplify_conflict_sides() {
498 let test_env = TestEnvironment::default();
499 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
500 let work_dir = test_env.work_dir("repo");
501
502 // Creates a 4-sided conflict, with fileA and fileB having different conflicts:
503 // fileA: A - B + C - B + B - B + B
504 // fileB: A - A + A - A + B - C + D
505 create_commit_with_files(
506 &work_dir,
507 "base",
508 &[],
509 &[("fileA", "base\n"), ("fileB", "base\n")],
510 );
511 create_commit_with_files(&work_dir, "a1", &["base"], &[("fileA", "1\n")]);
512 create_commit_with_files(&work_dir, "a2", &["base"], &[("fileA", "2\n")]);
513 create_commit_with_files(&work_dir, "b1", &["base"], &[("fileB", "1\n")]);
514 create_commit_with_files(&work_dir, "b2", &["base"], &[("fileB", "2\n")]);
515 create_commit_with_files(&work_dir, "conflictA", &["a1", "a2"], &[]);
516 create_commit_with_files(&work_dir, "conflictB", &["b1", "b2"], &[]);
517 create_commit_with_files(&work_dir, "conflict", &["conflictA", "conflictB"], &[]);
518
519 insta::assert_snapshot!(work_dir.run_jj(["status"]),
520 @"
521 The working copy has no changes.
522 Working copy (@) : nkmrtpmo ae2d1b1f conflict | (conflict) (empty) conflict
523 Parent commit (@-): kmkuslsw fb05b298 conflictA | (conflict) (empty) conflictA
524 Parent commit (@-): lylxulpl c680c6d6 conflictB | (conflict) (empty) conflictB
525 Warning: There are unresolved conflicts at these paths:
526 fileA 2-sided conflict
527 fileB 2-sided conflict
528 Hint: To resolve the conflicts, start by creating a commit on top of
529 one of the first conflicted commits:
530 jj new lylxulpl
531 jj new kmkuslsw
532 Then use `jj resolve`, or edit the conflict markers in the file directly.
533 Once the conflicts are resolved, you can inspect the result with `jj diff`.
534 Then run `jj squash` to move the resolution into the conflicted commit.
535 [EOF]
536 ");
537 }
538
539 #[test]
540 fn test_status_untracked_files() {
541 let test_env = TestEnvironment::default();
542 test_env.add_config(r#"snapshot.auto-track = "none()""#);
543
544 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
545 let work_dir = test_env.work_dir("repo");
546
547 work_dir.write_file("always-untracked-file", "...");
548 work_dir.write_file("initially-untracked-file", "...");
549 let sub_dir = work_dir.create_dir("sub");
550 sub_dir.write_file("always-untracked", "...");
551 sub_dir.write_file("initially-untracked", "...");
552
553 let output = work_dir.run_jj(["status"]);
554 insta::assert_snapshot!(output.normalize_backslash(), @"
555 Untracked paths:
556 ? always-untracked-file
557 ? initially-untracked-file
558 ? sub/
559 Working copy (@) : qpvuntsm e8849ae1 (empty) (no description set)
560 Parent commit (@-): zzzzzzzz 00000000 (empty) (no description set)
561 [EOF]
562 ");
563
564 work_dir
565 .run_jj([
566 "file",
567 "track",
568 "initially-untracked-file",
569 "sub/initially-untracked",
570 ])
571 .success();
572
573 let output = work_dir.run_jj(["status"]);
574 insta::assert_snapshot!(output.normalize_backslash(), @"
575 Working copy changes:
576 A initially-untracked-file
577 A sub/initially-untracked
578 Untracked paths:
579 ? always-untracked-file
580 ? sub/always-untracked
581 Working copy (@) : qpvuntsm b8c1286d (no description set)
582 Parent commit (@-): zzzzzzzz 00000000 (empty) (no description set)
583 [EOF]
584 ");
585
586 work_dir.run_jj(["new"]).success();
587
588 let output = work_dir.run_jj(["status"]);
589 insta::assert_snapshot!(output.normalize_backslash(), @"
590 Untracked paths:
591 ? always-untracked-file
592 ? sub/always-untracked
593 Working copy (@) : mzvwutvl daa133b8 (empty) (no description set)
594 Parent commit (@-): qpvuntsm b8c1286d (no description set)
595 [EOF]
596 ");
597
598 work_dir
599 .run_jj([
600 "file",
601 "untrack",
602 "initially-untracked-file",
603 "sub/initially-untracked",
604 ])
605 .success();
606 let output = work_dir.run_jj(["status"]);
607 insta::assert_snapshot!(output.normalize_backslash(), @"
608 Working copy changes:
609 D initially-untracked-file
610 D sub/initially-untracked
611 Untracked paths:
612 ? always-untracked-file
613 ? initially-untracked-file
614 ? sub/
615 Working copy (@) : mzvwutvl 240f261a (no description set)
616 Parent commit (@-): qpvuntsm b8c1286d (no description set)
617 [EOF]
618 ");
619
620 work_dir.run_jj(["new"]).success();
621
622 let output = work_dir.run_jj(["status"]);
623 insta::assert_snapshot!(output.normalize_backslash(), @"
624 Untracked paths:
625 ? always-untracked-file
626 ? initially-untracked-file
627 ? sub/
628 Working copy (@) : yostqsxw 50beac0d (empty) (no description set)
629 Parent commit (@-): mzvwutvl 240f261a (no description set)
630 [EOF]
631 ");
632
633 let output = work_dir.dir("sub").run_jj(["status"]);
634 insta::assert_snapshot!(output.normalize_backslash(), @"
635 Untracked paths:
636 ? ../always-untracked-file
637 ? ../initially-untracked-file
638 ? ./
639 Working copy (@) : yostqsxw 50beac0d (empty) (no description set)
640 Parent commit (@-): mzvwutvl 240f261a (no description set)
641 [EOF]
642 ");
643 }
644
645 #[test]
646 fn test_status_filtered_untracked() {
647 let test_env = TestEnvironment::default();
648 test_env.add_config(r#"snapshot.auto-track = "none()""#);
649 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
650 let work_dir = test_env.work_dir("repo");
651
652 work_dir.write_file("file_a", "...");
653 work_dir.write_file("file_b", "...");
654 let dir = work_dir.create_dir("dir");
655 dir.write_file("file_c", "...");
656
657 // Filter to file_a: only file_a shown as untracked
658 let output = work_dir.run_jj(["status", "file_a"]);
659 insta::assert_snapshot!(output, @"
660 Untracked paths:
661 ? file_a
662 Working copy (@) : qpvuntsm e8849ae1 (empty) (no description set)
663 Parent commit (@-): zzzzzzzz 00000000 (empty) (no description set)
664 [EOF]
665 ------- stderr -------
666 Warning: No matching entries for paths: file_a
667 [EOF]
668 ");
669
670 // Filter to dir: collapsed directory shown
671 let output = work_dir.run_jj(["status", "dir"]);
672 insta::assert_snapshot!(output.normalize_backslash(), @"
673 Untracked paths:
674 ? dir/
675 Working copy (@) : qpvuntsm e8849ae1 (empty) (no description set)
676 Parent commit (@-): zzzzzzzz 00000000 (empty) (no description set)
677 [EOF]
678 ------- stderr -------
679 Warning: No matching entries for paths: dir
680 [EOF]
681 ");
682
683 // Filter to nonexistent: no matching untracked paths, but unrelated
684 // untracked changes still make the working copy dirty.
685 let output = work_dir.run_jj(["status", "nonexistent"]);
686 insta::assert_snapshot!(output, @"
687 Working copy (@) : qpvuntsm e8849ae1 (empty) (no description set)
688 Parent commit (@-): zzzzzzzz 00000000 (empty) (no description set)
689 [EOF]
690 ------- stderr -------
691 Warning: No matching entries for paths: nonexistent
692 [EOF]
693 ");
694 }
695
696 #[test]
697 fn test_status_no_working_copy() {
698 let test_env = TestEnvironment::default();
699 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
700 let work_dir = test_env.work_dir("repo");
701 work_dir.run_jj(["workspace", "forget"]).success();
702
703 insta::assert_snapshot!(work_dir.run_jj(["status"]), @r"
704 No working copy.
705 [EOF]
706 ");
707 }