just playing with tangled
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
15use crate::common::TestEnvironment;
16
17#[test]
18fn test_status_merge() {
19 let test_env = TestEnvironment::default();
20 test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
21 let repo_path = test_env.env_root().join("repo");
22
23 std::fs::write(repo_path.join("file"), "base").unwrap();
24 test_env.jj_cmd_ok(&repo_path, &["new", "-m=left"]);
25 test_env.jj_cmd_ok(&repo_path, &["branch", "create", "left"]);
26 test_env.jj_cmd_ok(&repo_path, &["new", "@-", "-m=right"]);
27 std::fs::write(repo_path.join("file"), "right").unwrap();
28 test_env.jj_cmd_ok(&repo_path, &["new", "left", "@"]);
29
30 // The output should mention each parent, and the diff should be empty (compared
31 // to the auto-merged parents)
32 let stdout = test_env.jj_cmd_success(&repo_path, &["status"]);
33 insta::assert_snapshot!(stdout, @r###"
34 The working copy is clean
35 Working copy : mzvwutvl c965365c (empty) (no description set)
36 Parent commit: rlvkpnrz 9ae48ddb left | (empty) left
37 Parent commit: zsuskuln 29b991e9 right
38 "###);
39}
40
41// See https://github.com/martinvonz/jj/issues/2051.
42#[test]
43fn test_status_ignored_gitignore() {
44 let test_env = TestEnvironment::default();
45 test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
46 let repo_path = test_env.env_root().join("repo");
47
48 std::fs::create_dir(repo_path.join("untracked")).unwrap();
49 std::fs::write(repo_path.join("untracked").join("inside_untracked"), "test").unwrap();
50 std::fs::write(
51 repo_path.join("untracked").join(".gitignore"),
52 "!inside_untracked\n",
53 )
54 .unwrap();
55 std::fs::write(repo_path.join(".gitignore"), "untracked/\n!dummy\n").unwrap();
56
57 let stdout = test_env.jj_cmd_success(&repo_path, &["status"]);
58 insta::assert_snapshot!(stdout, @r###"
59 Working copy changes:
60 A .gitignore
61 Working copy : qpvuntsm 88a40909 (no description set)
62 Parent commit: zzzzzzzz 00000000 (empty) (no description set)
63 "###);
64}
65
66#[test]
67fn test_status_filtered() {
68 let test_env = TestEnvironment::default();
69 test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
70 let repo_path = test_env.env_root().join("repo");
71
72 std::fs::write(repo_path.join("file_1"), "file_1").unwrap();
73 std::fs::write(repo_path.join("file_2"), "file_2").unwrap();
74
75 // The output filtered to file_1 should not list the addition of file_2.
76 let stdout = test_env.jj_cmd_success(&repo_path, &["status", "file_1"]);
77 insta::assert_snapshot!(stdout, @r###"
78 Working copy changes:
79 A file_1
80 Working copy : qpvuntsm abcaaacd (no description set)
81 Parent commit: zzzzzzzz 00000000 (empty) (no description set)
82 "###);
83}
84
85// See <https://github.com/martinvonz/jj/issues/3108>
86#[test]
87fn test_status_display_rebase_instructions() {
88 let test_env = TestEnvironment::default();
89 test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);
90
91 let repo_path = test_env.env_root().join("repo");
92 let conflicted_path = repo_path.join("conflicted.txt");
93
94 // PARENT: Write the initial file
95 std::fs::write(&conflicted_path, "initial contents").unwrap();
96 test_env.jj_cmd_ok(&repo_path, &["describe", "--message", "Initial contents"]);
97
98 // CHILD1: New commit on top of <PARENT>
99 test_env.jj_cmd_ok(
100 &repo_path,
101 &["new", "--message", "First part of conflicting change"],
102 );
103 std::fs::write(&conflicted_path, "Child 1").unwrap();
104
105 // CHILD2: New commit also on top of <PARENT>
106 test_env.jj_cmd_ok(
107 &repo_path,
108 &[
109 "new",
110 "--message",
111 "Second part of conflicting change",
112 "@-",
113 ],
114 );
115 std::fs::write(&conflicted_path, "Child 2").unwrap();
116
117 // CONFLICT: New commit that is conflicted by merging <CHILD1> and <CHILD2>
118 test_env.jj_cmd_ok(&repo_path, &["new", "--message", "boom", "all:(@-)+"]);
119 // Adding more descendants to ensure we correctly find the root ancestors with
120 // conflicts, not just the parents.
121 test_env.jj_cmd_ok(&repo_path, &["new", "--message", "boom-cont"]);
122 test_env.jj_cmd_ok(&repo_path, &["new", "--message", "boom-cont-2"]);
123
124 let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-r", "::@"]);
125
126 insta::assert_snapshot!(stdout, @r###"
127 @ yqosqzyt test.user@example.com 2001-02-03 08:05:13 93e9928b conflict
128 │ (empty) boom-cont-2
129 ◉ royxmykx test.user@example.com 2001-02-03 08:05:12 ac5398e8 conflict
130 │ (empty) boom-cont
131 ◉ mzvwutvl test.user@example.com 2001-02-03 08:05:11 be6032ca conflict
132 ├─╮ (empty) boom
133 │ ◉ kkmpptxz test.user@example.com 2001-02-03 08:05:10 55ce6709
134 │ │ First part of conflicting change
135 ◉ │ zsuskuln test.user@example.com 2001-02-03 08:05:11 ba5f8773
136 ├─╯ Second part of conflicting change
137 ◉ qpvuntsm test.user@example.com 2001-02-03 08:05:08 98e0dcf8
138 │ Initial contents
139 ◉ zzzzzzzz root() 00000000
140 "###);
141
142 let stdout = test_env.jj_cmd_success(&repo_path, &["status"]);
143
144 insta::assert_snapshot!(stdout, @r###"
145 The working copy is clean
146 There are unresolved conflicts at these paths:
147 conflicted.txt 2-sided conflict
148 Working copy : yqosqzyt 93e9928b (conflict) (empty) boom-cont-2
149 Parent commit: royxmykx ac5398e8 (conflict) (empty) boom-cont
150 To resolve the conflicts, start by updating to the first one:
151 jj new mzvwutvlkqwt
152 Then use `jj resolve`, or edit the conflict markers in the file directly.
153 Once the conflicts are resolved, you may want inspect the result with `jj diff`.
154 Then run `jj squash` to move the resolution into the conflicted commit.
155 "###);
156}