| 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 test_case::test_case; |
| 16 |
|
| 17 |
use crate::common::TestEnvironment; |
| 18 |
use crate::common::create_commit; |
| 19 |
|
| 20 |
#[test] |
| 21 |
fn test_simplify_parents_no_commits() { |
| 22 |
let test_env = TestEnvironment::default(); |
| 23 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 24 |
let work_dir = test_env.work_dir("repo"); |
| 25 |
|
| 26 |
let output = work_dir.run_jj(["simplify-parents", "-r", "root() ~ root()"]); |
| 27 |
insta::assert_snapshot!(output, @" |
| 28 |
------- stderr ------- |
| 29 |
Nothing changed. |
| 30 |
[EOF] |
| 31 |
"); |
| 32 |
} |
| 33 |
|
| 34 |
#[test] |
| 35 |
fn test_simplify_parents_immutable() { |
| 36 |
let test_env = TestEnvironment::default(); |
| 37 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 38 |
let work_dir = test_env.work_dir("repo"); |
| 39 |
|
| 40 |
let output = work_dir.run_jj(["simplify-parents", "-r", "root()"]); |
| 41 |
insta::assert_snapshot!(output, @" |
| 42 |
------- stderr ------- |
| 43 |
Error: The root commit 000000000000 is immutable |
| 44 |
[EOF] |
| 45 |
[exit status: 1] |
| 46 |
"); |
| 47 |
} |
| 48 |
|
| 49 |
#[test] |
| 50 |
fn test_simplify_parents_no_change() { |
| 51 |
let test_env = TestEnvironment::default(); |
| 52 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 53 |
let work_dir = test_env.work_dir("repo"); |
| 54 |
|
| 55 |
create_commit(&work_dir, "a", &["root()"]); |
| 56 |
create_commit(&work_dir, "b", &["a"]); |
| 57 |
let output = work_dir.run_jj(["log", "-r", "all()", "-T", "description"]); |
| 58 |
insta::assert_snapshot!(output, @" |
| 59 |
@ b |
| 60 |
○ a |
| 61 |
◆ |
| 62 |
[EOF] |
| 63 |
"); |
| 64 |
|
| 65 |
let output = work_dir.run_jj(["simplify-parents", "-s", "@-"]); |
| 66 |
insta::assert_snapshot!(output, @" |
| 67 |
------- stderr ------- |
| 68 |
Nothing changed. |
| 69 |
[EOF] |
| 70 |
"); |
| 71 |
|
| 72 |
let output = work_dir.run_jj(["log", "-r", "all()", "-T", "description"]); |
| 73 |
insta::assert_snapshot!(output, @" |
| 74 |
@ b |
| 75 |
○ a |
| 76 |
◆ |
| 77 |
[EOF] |
| 78 |
"); |
| 79 |
} |
| 80 |
|
| 81 |
#[test] |
| 82 |
fn test_simplify_parents_no_change_diamond() { |
| 83 |
let test_env = TestEnvironment::default(); |
| 84 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 85 |
let work_dir = test_env.work_dir("repo"); |
| 86 |
|
| 87 |
create_commit(&work_dir, "a", &["root()"]); |
| 88 |
create_commit(&work_dir, "b", &["a"]); |
| 89 |
create_commit(&work_dir, "c", &["a"]); |
| 90 |
create_commit(&work_dir, "d", &["b", "c"]); |
| 91 |
let output = work_dir.run_jj(["log", "-r", "all()", "-T", "description"]); |
| 92 |
insta::assert_snapshot!(output, @" |
| 93 |
@ d |
| 94 |
├─╮ |
| 95 |
│ ○ c |
| 96 |
○ │ b |
| 97 |
├─╯ |
| 98 |
○ a |
| 99 |
◆ |
| 100 |
[EOF] |
| 101 |
"); |
| 102 |
|
| 103 |
let output = work_dir.run_jj(["simplify-parents", "-r", "all() ~ root()"]); |
| 104 |
insta::assert_snapshot!(output, @" |
| 105 |
------- stderr ------- |
| 106 |
Nothing changed. |
| 107 |
[EOF] |
| 108 |
"); |
| 109 |
|
| 110 |
let output = work_dir.run_jj(["log", "-r", "all()", "-T", "description"]); |
| 111 |
insta::assert_snapshot!(output, @" |
| 112 |
@ d |
| 113 |
├─╮ |
| 114 |
│ ○ c |
| 115 |
○ │ b |
| 116 |
├─╯ |
| 117 |
○ a |
| 118 |
◆ |
| 119 |
[EOF] |
| 120 |
"); |
| 121 |
} |
| 122 |
|
| 123 |
#[test_case(&["simplify-parents", "-r", "@", "-r", "@-"] ; "revisions")] |
| 124 |
#[test_case(&["simplify-parents", "-s", "@-"] ; "sources")] |
| 125 |
fn test_simplify_parents_redundant_parent(args: &[&str]) { |
| 126 |
let test_env = TestEnvironment::default(); |
| 127 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 128 |
let work_dir = test_env.work_dir("repo"); |
| 129 |
|
| 130 |
create_commit(&work_dir, "a", &["root()"]); |
| 131 |
create_commit(&work_dir, "b", &["a"]); |
| 132 |
create_commit(&work_dir, "c", &["a", "b"]); |
| 133 |
let output = work_dir.run_jj(["log", "-r", "all()", "-T", "description"]); |
| 134 |
insta::allow_duplicates! { |
| 135 |
insta::assert_snapshot!(output, @" |
| 136 |
@ c |
| 137 |
├─╮ |
| 138 |
│ ○ b |
| 139 |
├─╯ |
| 140 |
○ a |
| 141 |
◆ |
| 142 |
[EOF] |
| 143 |
"); |
| 144 |
} |
| 145 |
let output = work_dir.run_jj(args); |
| 146 |
insta::allow_duplicates! { |
| 147 |
insta::assert_snapshot!(output, @r" |
| 148 |
------- stderr ------- |
| 149 |
Removed 1 edges from 1 out of 3 commits. |
| 150 |
Working copy (@) now at: royxmykx 265f0407 c | c |
| 151 |
Parent commit (@-) : zsuskuln 123b4d91 b | b |
| 152 |
[EOF] |
| 153 |
"); |
| 154 |
} |
| 155 |
|
| 156 |
let output = work_dir.run_jj(["log", "-r", "all()", "-T", "description"]); |
| 157 |
insta::allow_duplicates! { |
| 158 |
insta::assert_snapshot!(output, @" |
| 159 |
@ c |
| 160 |
○ b |
| 161 |
○ a |
| 162 |
◆ |
| 163 |
[EOF] |
| 164 |
"); |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
#[test] |
| 169 |
fn test_simplify_parents_multiple_redundant_parents() { |
| 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 |
create_commit(&work_dir, "a", &["root()"]); |
| 175 |
create_commit(&work_dir, "b", &["a"]); |
| 176 |
create_commit(&work_dir, "c", &["a", "b"]); |
| 177 |
create_commit(&work_dir, "d", &["c"]); |
| 178 |
create_commit(&work_dir, "e", &["d"]); |
| 179 |
create_commit(&work_dir, "f", &["d", "e"]); |
| 180 |
let output = work_dir.run_jj(["log", "-r", "all()", "-T", "description"]); |
| 181 |
insta::assert_snapshot!(output, @" |
| 182 |
@ f |
| 183 |
├─╮ |
| 184 |
│ ○ e |
| 185 |
├─╯ |
| 186 |
○ d |
| 187 |
○ c |
| 188 |
├─╮ |
| 189 |
│ ○ b |
| 190 |
├─╯ |
| 191 |
○ a |
| 192 |
◆ |
| 193 |
[EOF] |
| 194 |
"); |
| 195 |
let setup_opid = work_dir.current_operation_id(); |
| 196 |
|
| 197 |
// Test with `-r`. |
| 198 |
let output = work_dir.run_jj(["simplify-parents", "-r", "c", "-r", "f"]); |
| 199 |
insta::assert_snapshot!(output, @r" |
| 200 |
------- stderr ------- |
| 201 |
Removed 2 edges from 2 out of 2 commits. |
| 202 |
Rebased 2 descendant commits. |
| 203 |
Working copy (@) now at: kmkuslsw 5ad764e9 f | f |
| 204 |
Parent commit (@-) : znkkpsqq 9102487c e | e |
| 205 |
[EOF] |
| 206 |
"); |
| 207 |
|
| 208 |
let output = work_dir.run_jj(["log", "-r", "all()", "-T", "description"]); |
| 209 |
insta::assert_snapshot!(output, @" |
| 210 |
@ f |
| 211 |
○ e |
| 212 |
○ d |
| 213 |
○ c |
| 214 |
○ b |
| 215 |
○ a |
| 216 |
◆ |
| 217 |
[EOF] |
| 218 |
"); |
| 219 |
|
| 220 |
// Test with `-s`. |
| 221 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 222 |
let output = work_dir.run_jj(["simplify-parents", "-s", "c"]); |
| 223 |
insta::assert_snapshot!(output, @r" |
| 224 |
------- stderr ------- |
| 225 |
Removed 2 edges from 2 out of 4 commits. |
| 226 |
Rebased 2 descendant commits. |
| 227 |
Working copy (@) now at: kmkuslsw 2b2c1c63 f | f |
| 228 |
Parent commit (@-) : znkkpsqq 9142e3bb e | e |
| 229 |
[EOF] |
| 230 |
"); |
| 231 |
|
| 232 |
let output = work_dir.run_jj(["log", "-r", "all()", "-T", "description"]); |
| 233 |
insta::assert_snapshot!(output, @" |
| 234 |
@ f |
| 235 |
○ e |
| 236 |
○ d |
| 237 |
○ c |
| 238 |
○ b |
| 239 |
○ a |
| 240 |
◆ |
| 241 |
[EOF] |
| 242 |
"); |
| 243 |
} |
| 244 |
|
| 245 |
#[test] |
| 246 |
fn test_simplify_parents_no_args() { |
| 247 |
let test_env = TestEnvironment::default(); |
| 248 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 249 |
let work_dir = test_env.work_dir("repo"); |
| 250 |
|
| 251 |
create_commit(&work_dir, "a", &["root()"]); |
| 252 |
create_commit(&work_dir, "b", &["a"]); |
| 253 |
create_commit(&work_dir, "c", &["a", "b"]); |
| 254 |
create_commit(&work_dir, "d", &["c"]); |
| 255 |
create_commit(&work_dir, "e", &["d"]); |
| 256 |
create_commit(&work_dir, "f", &["d", "e"]); |
| 257 |
let output = work_dir.run_jj(["log", "-r", "all()", "-T", "description"]); |
| 258 |
insta::assert_snapshot!(output, @" |
| 259 |
@ f |
| 260 |
├─╮ |
| 261 |
│ ○ e |
| 262 |
├─╯ |
| 263 |
○ d |
| 264 |
○ c |
| 265 |
├─╮ |
| 266 |
│ ○ b |
| 267 |
├─╯ |
| 268 |
○ a |
| 269 |
◆ |
| 270 |
[EOF] |
| 271 |
"); |
| 272 |
let setup_opid = work_dir.current_operation_id(); |
| 273 |
|
| 274 |
let output = work_dir.run_jj(["simplify-parents"]); |
| 275 |
insta::assert_snapshot!(output, @r" |
| 276 |
------- stderr ------- |
| 277 |
Removed 2 edges from 2 out of 6 commits. |
| 278 |
Rebased 2 descendant commits. |
| 279 |
Working copy (@) now at: kmkuslsw 5ad764e9 f | f |
| 280 |
Parent commit (@-) : znkkpsqq 9102487c e | e |
| 281 |
[EOF] |
| 282 |
"); |
| 283 |
|
| 284 |
let output = work_dir.run_jj(["log", "-r", "all()", "-T", "description"]); |
| 285 |
insta::assert_snapshot!(output, @" |
| 286 |
@ f |
| 287 |
○ e |
| 288 |
○ d |
| 289 |
○ c |
| 290 |
○ b |
| 291 |
○ a |
| 292 |
◆ |
| 293 |
[EOF] |
| 294 |
"); |
| 295 |
|
| 296 |
// Test with custom `revsets.simplify-parents`. |
| 297 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 298 |
test_env.add_config(r#"revsets.simplify-parents = "d::""#); |
| 299 |
let output = work_dir.run_jj(["simplify-parents"]); |
| 300 |
insta::assert_snapshot!(output, @r" |
| 301 |
------- stderr ------- |
| 302 |
Removed 1 edges from 1 out of 3 commits. |
| 303 |
Working copy (@) now at: kmkuslsw 1180d0f5 f | f |
| 304 |
Parent commit (@-) : znkkpsqq 009aef72 e | e |
| 305 |
[EOF] |
| 306 |
"); |
| 307 |
|
| 308 |
let output = work_dir.run_jj(["log", "-r", "all()", "-T", "description"]); |
| 309 |
insta::assert_snapshot!(output, @" |
| 310 |
@ f |
| 311 |
○ e |
| 312 |
○ d |
| 313 |
○ c |
| 314 |
├─╮ |
| 315 |
│ ○ b |
| 316 |
├─╯ |
| 317 |
○ a |
| 318 |
◆ |
| 319 |
[EOF] |
| 320 |
"); |
| 321 |
} |