Debian Codegraph @

cli/tests/test_repo_change_report.rs

raw
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 crate::common::TestEnvironment;
16
17 #[test]
18 fn test_report_conflicts() {
19 let test_env = TestEnvironment::default();
20 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
21 let work_dir = test_env.work_dir("repo");
22
23 work_dir.write_file("file", "A\n");
24 work_dir.run_jj(["commit", "-m=A"]).success();
25 work_dir.write_file("file", "B\n");
26 work_dir.run_jj(["commit", "-m=B"]).success();
27 work_dir.write_file("file", "C\n");
28 work_dir.run_jj(["commit", "-m=C"]).success();
29
30 let output = work_dir.run_jj(["rebase", "-s=subject(B)", "-d=root()"]);
31 insta::assert_snapshot!(output, @r"
32 ------- stderr -------
33 Rebased 3 commits to destination.
34 Working copy (@) now at: zsuskuln 0e8936d7 (conflict) (empty) (no description set)
35 Parent commit (@-) : kkmpptxz 435d6ea3 (conflict) C
36 Added 0 files, modified 1 files, removed 0 files
37 Warning: There are unresolved conflicts at these paths:
38 file 2-sided conflict including 1 deletion
39 New conflicts appeared in 2 commits:
40 kkmpptxz 435d6ea3 (conflict) C
41 rlvkpnrz d7d0e1b4 (conflict) B
42 Hint: To resolve the conflicts, start by creating a commit on top of
43 the first conflicted commit:
44 jj new rlvkpnrz
45 Then use `jj resolve`, or edit the conflict markers in the file directly.
46 Once the conflicts are resolved, you can inspect the result with `jj diff`.
47 Then run `jj squash` to move the resolution into the conflicted commit.
48 [EOF]
49 ");
50
51 let output = work_dir.run_jj(["rebase", "-d=subject(A)"]);
52 insta::assert_snapshot!(output, @r"
53 ------- stderr -------
54 Rebased 3 commits to destination.
55 Working copy (@) now at: zsuskuln bad741db (empty) (no description set)
56 Parent commit (@-) : kkmpptxz cec3d034 C
57 Added 0 files, modified 1 files, removed 0 files
58 Existing conflicts were resolved or abandoned from 2 commits.
59 [EOF]
60 ");
61
62 // Can get hint about multiple root commits
63 let output = work_dir.run_jj(["rebase", "-r=subject(B)", "-d=root()"]);
64 insta::assert_snapshot!(output, @r"
65 ------- stderr -------
66 Rebased 1 commits to destination.
67 Rebased 2 descendant commits.
68 Working copy (@) now at: zsuskuln da4348d9 (conflict) (empty) (no description set)
69 Parent commit (@-) : kkmpptxz 79a1eb93 (conflict) C
70 Added 0 files, modified 1 files, removed 0 files
71 Warning: There are unresolved conflicts at these paths:
72 file 2-sided conflict
73 New conflicts appeared in 2 commits:
74 kkmpptxz 79a1eb93 (conflict) C
75 rlvkpnrz 894d709e (conflict) B
76 Hint: To resolve the conflicts, start by creating a commit on top of
77 one of the first conflicted commits:
78 jj new kkmpptxz
79 jj new rlvkpnrz
80 Then use `jj resolve`, or edit the conflict markers in the file directly.
81 Once the conflicts are resolved, you can inspect the result with `jj diff`.
82 Then run `jj squash` to move the resolution into the conflicted commit.
83 [EOF]
84 ");
85
86 // Resolve one of the conflicts by (mostly) following the instructions
87 let output = work_dir.run_jj(["new", "rlvkpnrzqnoo"]);
88 insta::assert_snapshot!(output, @"
89 ------- stderr -------
90 Working copy (@) now at: vruxwmqv 94208127 (conflict) (empty) (no description set)
91 Parent commit (@-) : rlvkpnrz 894d709e (conflict) B
92 Added 0 files, modified 1 files, removed 0 files
93 Warning: There are unresolved conflicts at these paths:
94 file 2-sided conflict including 1 deletion
95 [EOF]
96 ");
97 work_dir.write_file("file", "resolved\n");
98 let output = work_dir.run_jj(["squash"]);
99 insta::assert_snapshot!(output, @r"
100 ------- stderr -------
101 Working copy (@) now at: yostqsxw 350a6e50 (empty) (no description set)
102 Parent commit (@-) : rlvkpnrz 1aa1004b B
103 Existing conflicts were resolved or abandoned from 1 commits.
104 [EOF]
105 ");
106 }
107
108 #[test]
109 fn test_report_conflicts_with_divergent_commits() {
110 let test_env = TestEnvironment::default();
111 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
112 let work_dir = test_env.work_dir("repo");
113
114 work_dir.run_jj(["describe", "-m=A"]).success();
115 work_dir.write_file("file", "A\n");
116 work_dir.run_jj(["new", "-m=B"]).success();
117 work_dir.write_file("file", "B\n");
118 work_dir.run_jj(["new", "-m=C"]).success();
119 work_dir.write_file("file", "C\n");
120 work_dir.run_jj(["describe", "-m=C2"]).success();
121 work_dir
122 .run_jj(["describe", "-m=C3", "--at-op=@-"])
123 .success();
124
125 let output = work_dir.run_jj(["rebase", "-s=subject(B)", "-d=root()"]);
126 insta::assert_snapshot!(output, @r"
127 ------- stderr -------
128 Concurrent modification detected, resolving automatically.
129 Rebased 3 commits to destination.
130 Working copy (@) now at: zsuskuln/1 f3e2e0a2 (divergent) (conflict) C2
131 Parent commit (@-) : kkmpptxz c6237d2f (conflict) B
132 Added 0 files, modified 1 files, removed 0 files
133 Warning: There are unresolved conflicts at these paths:
134 file 2-sided conflict including 1 deletion
135 New conflicts appeared in 3 commits:
136 zsuskuln/0 9432879f (divergent) (conflict) C3
137 zsuskuln/1 f3e2e0a2 (divergent) (conflict) C2
138 kkmpptxz c6237d2f (conflict) B
139 Hint: To resolve the conflicts, start by creating a commit on top of
140 the first conflicted commit:
141 jj new kkmpptxz
142 Then use `jj resolve`, or edit the conflict markers in the file directly.
143 Once the conflicts are resolved, you can inspect the result with `jj diff`.
144 Then run `jj squash` to move the resolution into the conflicted commit.
145 [EOF]
146 ");
147
148 let output = work_dir.run_jj(["rebase", "-d=subject(A)"]);
149 insta::assert_snapshot!(output, @r"
150 ------- stderr -------
151 Rebased 3 commits to destination.
152 Working copy (@) now at: zsuskuln/1 27ef05d9 (divergent) C2
153 Parent commit (@-) : kkmpptxz 9039ed49 B
154 Added 0 files, modified 1 files, removed 0 files
155 Existing conflicts were resolved or abandoned from 3 commits.
156 [EOF]
157 ");
158
159 // Same thing when rebasing the divergent commits one at a time
160 let output = work_dir.run_jj(["rebase", "-s=subject(C2)", "-d=root()"]);
161 insta::assert_snapshot!(output, @r"
162 ------- stderr -------
163 Rebased 1 commits to destination.
164 Working copy (@) now at: zsuskuln/0 aa95f2b1 (divergent) (conflict) C2
165 Parent commit (@-) : zzzzzzzz 00000000 (empty) (no description set)
166 Added 0 files, modified 1 files, removed 0 files
167 Warning: There are unresolved conflicts at these paths:
168 file 2-sided conflict including 1 deletion
169 New conflicts appeared in 1 commits:
170 zsuskuln/0 aa95f2b1 (divergent) (conflict) C2
171 Hint: To resolve the conflicts, start by creating a commit on top of
172 the conflicted commit:
173 jj new zsuskuln/0
174 Then use `jj resolve`, or edit the conflict markers in the file directly.
175 Once the conflicts are resolved, you can inspect the result with `jj diff`.
176 Then run `jj squash` to move the resolution into the conflicted commit.
177 [EOF]
178 ");
179
180 let output = work_dir.run_jj(["rebase", "-s=subject(C3)", "-d=root()"]);
181 insta::assert_snapshot!(output, @r"
182 ------- stderr -------
183 Rebased 1 commits to destination.
184 New conflicts appeared in 1 commits:
185 zsuskuln/0 733a79ca (divergent) (conflict) C3
186 Hint: To resolve the conflicts, start by creating a commit on top of
187 the conflicted commit:
188 jj new zsuskuln/0
189 Then use `jj resolve`, or edit the conflict markers in the file directly.
190 Once the conflicts are resolved, you can inspect the result with `jj diff`.
191 Then run `jj squash` to move the resolution into the conflicted commit.
192 [EOF]
193 ");
194
195 let output = work_dir.run_jj(["rebase", "-s=subject(C2)", "-d=subject(B)"]);
196 insta::assert_snapshot!(output, @r"
197 ------- stderr -------
198 Rebased 1 commits to destination.
199 Working copy (@) now at: zsuskuln/0 3fcf2fd2 (divergent) C2
200 Parent commit (@-) : kkmpptxz 9039ed49 B
201 Added 0 files, modified 1 files, removed 0 files
202 Existing conflicts were resolved or abandoned from 1 commits.
203 [EOF]
204 ");
205
206 let output = work_dir.run_jj(["rebase", "-s=subject(C3)", "-d=subject(B)"]);
207 insta::assert_snapshot!(output, @r"
208 ------- stderr -------
209 Rebased 1 commits to destination.
210 Existing conflicts were resolved or abandoned from 1 commits.
211 [EOF]
212 ");
213 }
214
215 #[test]
216 fn test_report_conflicts_with_resolving_conflicts_hint_disabled() {
217 let test_env = TestEnvironment::default();
218 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
219 let work_dir = test_env.work_dir("repo");
220
221 work_dir.write_file("file", "A\n");
222 work_dir.run_jj(["commit", "-m=A"]).success();
223 work_dir.write_file("file", "B\n");
224 work_dir.run_jj(["commit", "-m=B"]).success();
225 work_dir.write_file("file", "C\n");
226 work_dir.run_jj(["commit", "-m=C"]).success();
227
228 let output = work_dir.run_jj([
229 "rebase",
230 "-s=subject(B)",
231 "-d=root()",
232 "--config=hints.resolving-conflicts=false",
233 ]);
234 insta::assert_snapshot!(output, @r"
235 ------- stderr -------
236 Rebased 3 commits to destination.
237 Working copy (@) now at: zsuskuln 0e8936d7 (conflict) (empty) (no description set)
238 Parent commit (@-) : kkmpptxz 435d6ea3 (conflict) C
239 Added 0 files, modified 1 files, removed 0 files
240 Warning: There are unresolved conflicts at these paths:
241 file 2-sided conflict including 1 deletion
242 New conflicts appeared in 2 commits:
243 kkmpptxz 435d6ea3 (conflict) C
244 rlvkpnrz d7d0e1b4 (conflict) B
245 [EOF]
246 ");
247 }