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