| 1 |
// Copyright 2026 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 |
use testutils::TestResult; |
| 17 |
|
| 18 |
use crate::common::CommandOutput; |
| 19 |
use crate::common::TestEnvironment; |
| 20 |
use crate::common::TestWorkDir; |
| 21 |
use crate::common::create_commit_with_files; |
| 22 |
use crate::common::force_interactive; |
| 23 |
|
| 24 |
// `jj converge` must runs successfully when there are no divergent changes and |
| 25 |
// prints a message to stderr. |
| 26 |
#[test] |
| 27 |
fn test_converge_no_divergence() { |
| 28 |
let test_env = TestEnvironment::default(); |
| 29 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 30 |
let work_dir = test_env.work_dir("repo"); |
| 31 |
|
| 32 |
// Set up commit graph (without divergent changes) |
| 33 |
create_commit_with_files(&work_dir, "a", &[], &[("file1", "a")]); |
| 34 |
create_commit_with_files(&work_dir, "b", &["a"], &[("file2", "b")]); |
| 35 |
create_commit_with_files(&work_dir, "c", &["a"], &[("file3", "c")]); |
| 36 |
|
| 37 |
// Test the setup |
| 38 |
insta::assert_snapshot!(get_long_log_output(&work_dir), @r" |
| 39 |
@ c royxmykx 78dcec21 - description: c |
| 40 |
│ ○ b zsuskuln 056564da - description: b |
| 41 |
├─╯ |
| 42 |
○ a rlvkpnrz 3b93fc14 - description: a |
| 43 |
◆ zzzzzzzz 00000000 |
| 44 |
[EOF] |
| 45 |
"); |
| 46 |
|
| 47 |
// Run `jj converge` command and check the output. |
| 48 |
let output = work_dir.run_jj(["converge"]).success(); |
| 49 |
insta::assert_snapshot!(output, @r" |
| 50 |
------- stderr ------- |
| 51 |
No divergent changes found. |
| 52 |
[EOF] |
| 53 |
"); |
| 54 |
} |
| 55 |
|
| 56 |
// A simple `jj converge` scenario where there is a single divergent change with |
| 57 |
// two visible commits. In this setup no user input is required. |
| 58 |
#[test] |
| 59 |
fn test_converge_simple() { |
| 60 |
let test_env = TestEnvironment::default(); |
| 61 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 62 |
let work_dir = test_env.work_dir("repo"); |
| 63 |
|
| 64 |
// Set up commit graph with one divergent change (with two visible commits). |
| 65 |
create_commit_with_files(&work_dir, "a", &[], &[("file1", "1")]); |
| 66 |
create_commit_with_files(&work_dir, "b2", &["a"], &[("file2", "2")]); |
| 67 |
create_commit_with_files(&work_dir, "c", &["a"], &[("file3", "3")]); |
| 68 |
work_dir.run_jj(["rebase", "-r", "b2", "-o", "c"]).success(); |
| 69 |
work_dir |
| 70 |
.run_jj(["bookmark", "create", "b1", "-r", "at_operation(@-, b2)"]) |
| 71 |
.success(); |
| 72 |
create_commit_with_files(&work_dir, "d", &["b1"], &[("file4", "4")]); |
| 73 |
|
| 74 |
// Test the setup: look at the commit graph, commit B is duplicated |
| 75 |
insta::assert_snapshot!(get_long_log_output(&work_dir), @r" |
| 76 |
@ d znkkpsqq bf5126ef - description: d |
| 77 |
○ b1 zsuskuln/1 59a77004 - description: b2 |
| 78 |
│ ○ b2 zsuskuln/0 2c2bd25d - description: b2 |
| 79 |
│ ○ c royxmykx 4343fc61 - description: c |
| 80 |
├─╯ |
| 81 |
○ a rlvkpnrz e9a731d9 - description: a |
| 82 |
◆ zzzzzzzz 00000000 |
| 83 |
[EOF] |
| 84 |
"); |
| 85 |
|
| 86 |
// Test the setup: look at the evolog |
| 87 |
insta::assert_snapshot!(get_evolog(&work_dir, "b2"), @r" |
| 88 |
○ zsuskuln/0 2c2bd25d (divergent) b2 |
| 89 |
○ zsuskuln/1 59a77004 (divergent) b2 |
| 90 |
○ zsuskuln/2 b2852eb2 (hidden) (empty) b2 |
| 91 |
[EOF] |
| 92 |
"); |
| 93 |
|
| 94 |
// Run `jj converge` command and check the output. In this case no user input is |
| 95 |
// needed. |
| 96 |
let output = work_dir.run_jj(["converge"]).success(); |
| 97 |
insta::assert_snapshot!(output, @r" |
| 98 |
------- stderr ------- |
| 99 |
Found 1 divergent change(s) in the specified revset: |
| 100 |
- Change: zsuskulnrvyr with 2 commits: |
| 101 |
zsuskuln/0 2c2bd25d b2 | (divergent) b2 |
| 102 |
zsuskuln/1 59a77004 b1 | (divergent) b2 |
| 103 |
|
| 104 |
Attempting to converge change zsuskulnrvyr... |
| 105 |
|
| 106 |
Successfully converged change: created commit 6b1ce5bc4cbe. |
| 107 |
Rebased 1 descendants |
| 108 |
Working copy (@) now at: znkkpsqq 696cf5e0 d | d |
| 109 |
Parent commit (@-) : zsuskuln 6b1ce5bc b1 b2 | b2 |
| 110 |
Added 1 files, modified 0 files, removed 0 files |
| 111 |
[EOF] |
| 112 |
"); |
| 113 |
|
| 114 |
// Verify the commit graph after converge |
| 115 |
insta::assert_snapshot!(get_long_log_output(&work_dir), @r" |
| 116 |
@ d znkkpsqq 696cf5e0 - description: d |
| 117 |
○ b1 b2 zsuskuln 6b1ce5bc - description: b2 |
| 118 |
○ c royxmykx 4343fc61 - description: c |
| 119 |
○ a rlvkpnrz e9a731d9 - description: a |
| 120 |
◆ zzzzzzzz 00000000 |
| 121 |
[EOF] |
| 122 |
"); |
| 123 |
|
| 124 |
// Verify the evolution history after converge |
| 125 |
insta::assert_snapshot!(get_evolog(&work_dir, "b2"), @r" |
| 126 |
○ zsuskuln 6b1ce5bc b2 |
| 127 |
├─╮ |
| 128 |
○ │ zsuskuln/1 2c2bd25d (hidden) b2 |
| 129 |
├─╯ |
| 130 |
○ zsuskuln/2 59a77004 (hidden) b2 |
| 131 |
○ zsuskuln/3 b2852eb2 (hidden) (empty) b2 |
| 132 |
[EOF] |
| 133 |
"); |
| 134 |
} |
| 135 |
|
| 136 |
// When there are multiple divergent changes, the command must prompt the user |
| 137 |
// to select one of them. When running in non-interactive mode (jj converge |
| 138 |
// --no-interactive) this is not possible. |
| 139 |
#[test] |
| 140 |
fn test_converge_two_divergent_changes_in_non_interactive_mode() { |
| 141 |
let test_env = TestEnvironment::default(); |
| 142 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 143 |
let work_dir = test_env.work_dir("repo"); |
| 144 |
|
| 145 |
// Set up: first create a base commit |
| 146 |
create_commit_with_files(&work_dir, "a", &[], &[("file1", "1")]); |
| 147 |
|
| 148 |
// Set up: create commit graph with two divergent changes |
| 149 |
// First divergent change: |
| 150 |
create_commit_with_files(&work_dir, "b2", &["a"], &[("file2", "2")]); |
| 151 |
create_commit_with_files(&work_dir, "c", &["a"], &[("file3", "3")]); |
| 152 |
work_dir.run_jj(["rebase", "-r", "b2", "-o", "c"]).success(); |
| 153 |
work_dir |
| 154 |
.run_jj(["bookmark", "create", "b1", "-r", "at_operation(@-, b2)"]) |
| 155 |
.success(); |
| 156 |
create_commit_with_files(&work_dir, "d", &["b1"], &[("file4", "4")]); |
| 157 |
|
| 158 |
// Second divergent change: |
| 159 |
create_commit_with_files(&work_dir, "e2", &["a"], &[("file5", "5")]); |
| 160 |
create_commit_with_files(&work_dir, "f", &["a"], &[("file6", "6")]); |
| 161 |
work_dir.run_jj(["rebase", "-r", "e2", "-o", "f"]).success(); |
| 162 |
work_dir |
| 163 |
.run_jj(["bookmark", "create", "e1", "-r", "at_operation(@-, e2)"]) |
| 164 |
.success(); |
| 165 |
create_commit_with_files(&work_dir, "g", &["e1"], &[("file7", "7")]); |
| 166 |
|
| 167 |
// Test the setup: look at the commit graph (commit B is duplicated and commit E |
| 168 |
// is duplicated) |
| 169 |
insta::assert_snapshot!(get_long_log_output(&work_dir), @r" |
| 170 |
@ g xznxytkn 46658cae - description: g |
| 171 |
○ e1 kmkuslsw/1 15962bae - description: e2 |
| 172 |
│ ○ e2 kmkuslsw/0 b54f15d8 - description: e2 |
| 173 |
│ ○ f lylxulpl d50e2761 - description: f |
| 174 |
├─╯ |
| 175 |
│ ○ b2 zsuskuln/0 2c2bd25d - description: b2 |
| 176 |
│ ○ c royxmykx 4343fc61 - description: c |
| 177 |
├─╯ |
| 178 |
│ ○ d znkkpsqq bf5126ef - description: d |
| 179 |
│ ○ b1 zsuskuln/1 59a77004 - description: b2 |
| 180 |
├─╯ |
| 181 |
○ a rlvkpnrz e9a731d9 - description: a |
| 182 |
◆ zzzzzzzz 00000000 |
| 183 |
[EOF] |
| 184 |
"); |
| 185 |
|
| 186 |
// Pass --non-interactive to jj converge command. |
| 187 |
let output = |
| 188 |
work_dir.run_jj_with(|cmd| force_interactive(cmd).args(["converge", "--no-interactive"])); |
| 189 |
insta::assert_snapshot!(output, @r" |
| 190 |
------- stderr ------- |
| 191 |
Found 2 divergent change(s) in the specified revset: |
| 192 |
- Change: zsuskulnrvyr with 2 commits: |
| 193 |
zsuskuln/0 2c2bd25d b2 | (divergent) b2 |
| 194 |
zsuskuln/1 59a77004 b1 | (divergent) b2 |
| 195 |
|
| 196 |
- Change: kmkuslswpqwq with 2 commits: |
| 197 |
kmkuslsw/0 b54f15d8 e2 | (divergent) e2 |
| 198 |
kmkuslsw/1 15962bae e1 | (divergent) e2 |
| 199 |
|
| 200 |
Error: Cannot automatically choose which change to converge |
| 201 |
Hint: Run `jj converge` in interactive mode, or specify a revset that resolves to only one change ID |
| 202 |
[EOF] |
| 203 |
[exit status: 1] |
| 204 |
"); |
| 205 |
|
| 206 |
// Note: in the test environment jj commands run in non-interactive (quiet) mode |
| 207 |
// by default, so the following also fails but for a different reason: it |
| 208 |
// cannot prompt the user |
| 209 |
let output = work_dir.run_jj(["converge"]); |
| 210 |
insta::assert_snapshot!(output, @r" |
| 211 |
------- stderr ------- |
| 212 |
Found 2 divergent change(s) in the specified revset: |
| 213 |
- Change: zsuskulnrvyr with 2 commits: |
| 214 |
zsuskuln/0 2c2bd25d b2 | (divergent) b2 |
| 215 |
zsuskuln/1 59a77004 b1 | (divergent) b2 |
| 216 |
|
| 217 |
- Change: kmkuslswpqwq with 2 commits: |
| 218 |
kmkuslsw/0 b54f15d8 e2 | (divergent) e2 |
| 219 |
kmkuslsw/1 15962bae e1 | (divergent) e2 |
| 220 |
|
| 221 |
Choose which change to converge (jj converge only converges one change at a time): |
| 222 |
1: zsuskulnrvyr |
| 223 |
2: kmkuslswpqwq |
| 224 |
q: abort |
| 225 |
Error: Cannot prompt for input since the output is not connected to a terminal |
| 226 |
[EOF] |
| 227 |
[exit status: 1] |
| 228 |
"); |
| 229 |
|
| 230 |
// Note: the invocation also fails if stdin is not connected to a terminal |
| 231 |
let output = work_dir.run_jj_with(|cmd| force_interactive(cmd).args(["converge"])); |
| 232 |
insta::assert_snapshot!(output, @r" |
| 233 |
------- stderr ------- |
| 234 |
Found 2 divergent change(s) in the specified revset: |
| 235 |
- Change: zsuskulnrvyr with 2 commits: |
| 236 |
zsuskuln/0 2c2bd25d b2 | (divergent) b2 |
| 237 |
zsuskuln/1 59a77004 b1 | (divergent) b2 |
| 238 |
|
| 239 |
- Change: kmkuslswpqwq with 2 commits: |
| 240 |
kmkuslsw/0 b54f15d8 e2 | (divergent) e2 |
| 241 |
kmkuslsw/1 15962bae e1 | (divergent) e2 |
| 242 |
|
| 243 |
Choose which change to converge (jj converge only converges one change at a time): |
| 244 |
1: zsuskulnrvyr |
| 245 |
2: kmkuslswpqwq |
| 246 |
q: abort |
| 247 |
Enter the index of the change to converge: Error: Prompt canceled by EOF |
| 248 |
[EOF] |
| 249 |
[exit status: 1] |
| 250 |
"); |
| 251 |
} |
| 252 |
|
| 253 |
// This tests scenarios where there are two divergent changes. The command |
| 254 |
// prompts the user to choose which change to converge. |
| 255 |
#[test] |
| 256 |
fn test_converge_two_divergent_changes() { |
| 257 |
let test_env = TestEnvironment::default(); |
| 258 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 259 |
let work_dir = test_env.work_dir("repo"); |
| 260 |
|
| 261 |
// Set up: first create a base commit |
| 262 |
create_commit_with_files(&work_dir, "a", &[], &[("file1", "1")]); |
| 263 |
|
| 264 |
// Set up: create commit graph with two divergent changes |
| 265 |
// First divergent change: |
| 266 |
create_commit_with_files(&work_dir, "b2", &["a"], &[("file2", "2")]); |
| 267 |
create_commit_with_files(&work_dir, "c", &["a"], &[("file3", "3")]); |
| 268 |
work_dir.run_jj(["rebase", "-r", "b2", "-o", "c"]).success(); |
| 269 |
work_dir |
| 270 |
.run_jj(["bookmark", "create", "b1", "-r", "at_operation(@-, b2)"]) |
| 271 |
.success(); |
| 272 |
create_commit_with_files(&work_dir, "d", &["b1"], &[("file4", "4")]); |
| 273 |
|
| 274 |
// Second divergent change: |
| 275 |
create_commit_with_files(&work_dir, "e2", &["a"], &[("file5", "5")]); |
| 276 |
create_commit_with_files(&work_dir, "f", &["a"], &[("file6", "6")]); |
| 277 |
work_dir.run_jj(["rebase", "-r", "e2", "-o", "f"]).success(); |
| 278 |
work_dir |
| 279 |
.run_jj(["bookmark", "create", "e1", "-r", "at_operation(@-, e2)"]) |
| 280 |
.success(); |
| 281 |
create_commit_with_files(&work_dir, "g", &["e1"], &[("file7", "7")]); |
| 282 |
|
| 283 |
// Test the setup: look at the commit graph (commit B is duplicated and commit E |
| 284 |
// is duplicated) |
| 285 |
insta::assert_snapshot!(get_long_log_output(&work_dir), @r" |
| 286 |
@ g xznxytkn 46658cae - description: g |
| 287 |
○ e1 kmkuslsw/1 15962bae - description: e2 |
| 288 |
│ ○ e2 kmkuslsw/0 b54f15d8 - description: e2 |
| 289 |
│ ○ f lylxulpl d50e2761 - description: f |
| 290 |
├─╯ |
| 291 |
│ ○ b2 zsuskuln/0 2c2bd25d - description: b2 |
| 292 |
│ ○ c royxmykx 4343fc61 - description: c |
| 293 |
├─╯ |
| 294 |
│ ○ d znkkpsqq bf5126ef - description: d |
| 295 |
│ ○ b1 zsuskuln/1 59a77004 - description: b2 |
| 296 |
├─╯ |
| 297 |
○ a rlvkpnrz e9a731d9 - description: a |
| 298 |
◆ zzzzzzzz 00000000 |
| 299 |
[EOF] |
| 300 |
"); |
| 301 |
|
| 302 |
// Test the setup: look at the evolog |
| 303 |
insta::assert_snapshot!(get_evolog(&work_dir, "b2"), @r" |
| 304 |
○ zsuskuln/0 2c2bd25d (divergent) b2 |
| 305 |
○ zsuskuln/1 59a77004 (divergent) b2 |
| 306 |
○ zsuskuln/2 b2852eb2 (hidden) (empty) b2 |
| 307 |
[EOF] |
| 308 |
"); |
| 309 |
|
| 310 |
// Test the setup: look at the evolog |
| 311 |
insta::assert_snapshot!(get_evolog(&work_dir, "e2"), @r" |
| 312 |
○ kmkuslsw/0 b54f15d8 (divergent) e2 |
| 313 |
○ kmkuslsw/1 15962bae (divergent) e2 |
| 314 |
○ kmkuslsw/2 843de29d (hidden) (empty) e2 |
| 315 |
[EOF] |
| 316 |
"); |
| 317 |
|
| 318 |
// If the user chooses to abort the converge operation nothing changes. |
| 319 |
let output = work_dir |
| 320 |
.run_jj_with(|cmd| force_interactive(cmd).args(["converge"]).write_stdin("q\n")) |
| 321 |
.success(); |
| 322 |
|
| 323 |
insta::assert_snapshot!(output, @r" |
| 324 |
------- stderr ------- |
| 325 |
Found 2 divergent change(s) in the specified revset: |
| 326 |
- Change: zsuskulnrvyr with 2 commits: |
| 327 |
zsuskuln/0 2c2bd25d b2 | (divergent) b2 |
| 328 |
zsuskuln/1 59a77004 b1 | (divergent) b2 |
| 329 |
|
| 330 |
- Change: kmkuslswpqwq with 2 commits: |
| 331 |
kmkuslsw/0 b54f15d8 e2 | (divergent) e2 |
| 332 |
kmkuslsw/1 15962bae e1 | (divergent) e2 |
| 333 |
|
| 334 |
Choose which change to converge (jj converge only converges one change at a time): |
| 335 |
1: zsuskulnrvyr |
| 336 |
2: kmkuslswpqwq |
| 337 |
q: abort |
| 338 |
Enter the index of the change to converge: |
| 339 |
|
| 340 |
Aborting... nothing changed. |
| 341 |
[EOF] |
| 342 |
"); |
| 343 |
|
| 344 |
// Run the command again, this time the user chooses the first divergent change. |
| 345 |
// This invocation succeeds to automatically converge that change. A hint is |
| 346 |
// printed to inform the user that there is still one divergent change |
| 347 |
// remaining. |
| 348 |
let output = work_dir |
| 349 |
.run_jj_with(|cmd| force_interactive(cmd).args(["converge"]).write_stdin("1\n")) |
| 350 |
.success(); |
| 351 |
|
| 352 |
insta::assert_snapshot!(output, @r" |
| 353 |
------- stderr ------- |
| 354 |
Found 2 divergent change(s) in the specified revset: |
| 355 |
- Change: zsuskulnrvyr with 2 commits: |
| 356 |
zsuskuln/0 2c2bd25d b2 | (divergent) b2 |
| 357 |
zsuskuln/1 59a77004 b1 | (divergent) b2 |
| 358 |
|
| 359 |
- Change: kmkuslswpqwq with 2 commits: |
| 360 |
kmkuslsw/0 b54f15d8 e2 | (divergent) e2 |
| 361 |
kmkuslsw/1 15962bae e1 | (divergent) e2 |
| 362 |
|
| 363 |
Choose which change to converge (jj converge only converges one change at a time): |
| 364 |
1: zsuskulnrvyr |
| 365 |
2: kmkuslswpqwq |
| 366 |
q: abort |
| 367 |
Enter the index of the change to converge: |
| 368 |
|
| 369 |
Attempting to converge change zsuskulnrvyr... |
| 370 |
|
| 371 |
Successfully converged change: created commit ba447f020ee6. |
| 372 |
Rebased 1 descendants |
| 373 |
Hint: There are still 1 divergent changes remaining in the specified revset, you can run this command again to converge another one. |
| 374 |
[EOF] |
| 375 |
"); |
| 376 |
|
| 377 |
// Verify the commit graph after converging the first divergent change |
| 378 |
insta::assert_snapshot!(get_long_log_output(&work_dir), @r" |
| 379 |
@ g xznxytkn 46658cae - description: g |
| 380 |
○ e1 kmkuslsw/1 15962bae - description: e2 |
| 381 |
│ ○ e2 kmkuslsw/0 b54f15d8 - description: e2 |
| 382 |
│ ○ f lylxulpl d50e2761 - description: f |
| 383 |
├─╯ |
| 384 |
│ ○ d znkkpsqq b30d892b - description: d |
| 385 |
│ ○ b1 b2 zsuskuln ba447f02 - description: b2 |
| 386 |
│ ○ c royxmykx 4343fc61 - description: c |
| 387 |
├─╯ |
| 388 |
○ a rlvkpnrz e9a731d9 - description: a |
| 389 |
◆ zzzzzzzz 00000000 |
| 390 |
[EOF] |
| 391 |
"); |
| 392 |
|
| 393 |
// Verify the evolution history after converging the first divergent change |
| 394 |
insta::assert_snapshot!(get_evolog(&work_dir, "b2"), @r" |
| 395 |
○ zsuskuln ba447f02 b2 |
| 396 |
├─╮ |
| 397 |
○ │ zsuskuln/1 2c2bd25d (hidden) b2 |
| 398 |
├─╯ |
| 399 |
○ zsuskuln/2 59a77004 (hidden) b2 |
| 400 |
○ zsuskuln/3 b2852eb2 (hidden) (empty) b2 |
| 401 |
[EOF] |
| 402 |
"); |
| 403 |
|
| 404 |
// Run converge a second time to converge the other divergent change |
| 405 |
let output = work_dir.run_jj(["converge"]).success(); |
| 406 |
insta::assert_snapshot!(output, @r" |
| 407 |
------- stderr ------- |
| 408 |
Found 1 divergent change(s) in the specified revset: |
| 409 |
- Change: kmkuslswpqwq with 2 commits: |
| 410 |
kmkuslsw/0 b54f15d8 e2 | (divergent) e2 |
| 411 |
kmkuslsw/1 15962bae e1 | (divergent) e2 |
| 412 |
|
| 413 |
Attempting to converge change kmkuslswpqwq... |
| 414 |
|
| 415 |
Successfully converged change: created commit 3f08d00a88c4. |
| 416 |
Rebased 1 descendants |
| 417 |
Working copy (@) now at: xznxytkn f9fd4e7e g | g |
| 418 |
Parent commit (@-) : kmkuslsw 3f08d00a e1 e2 | e2 |
| 419 |
Added 1 files, modified 0 files, removed 0 files |
| 420 |
[EOF] |
| 421 |
"); |
| 422 |
|
| 423 |
// Verify the commit graph after converging the second divergent change |
| 424 |
insta::assert_snapshot!(get_long_log_output(&work_dir), @r" |
| 425 |
@ g xznxytkn f9fd4e7e - description: g |
| 426 |
○ e1 e2 kmkuslsw 3f08d00a - description: e2 |
| 427 |
○ f lylxulpl d50e2761 - description: f |
| 428 |
│ ○ d znkkpsqq b30d892b - description: d |
| 429 |
│ ○ b1 b2 zsuskuln ba447f02 - description: b2 |
| 430 |
│ ○ c royxmykx 4343fc61 - description: c |
| 431 |
├─╯ |
| 432 |
○ a rlvkpnrz e9a731d9 - description: a |
| 433 |
◆ zzzzzzzz 00000000 |
| 434 |
[EOF] |
| 435 |
"); |
| 436 |
|
| 437 |
// Verify the evolution history after converging the second divergent change |
| 438 |
insta::assert_snapshot!(get_evolog(&work_dir, "e2"), @r" |
| 439 |
○ kmkuslsw 3f08d00a e2 |
| 440 |
├─╮ |
| 441 |
○ │ kmkuslsw/1 b54f15d8 (hidden) e2 |
| 442 |
├─╯ |
| 443 |
○ kmkuslsw/2 15962bae (hidden) e2 |
| 444 |
○ kmkuslsw/3 843de29d (hidden) (empty) e2 |
| 445 |
[EOF] |
| 446 |
"); |
| 447 |
|
| 448 |
// There are no more divergent changes now |
| 449 |
let output = work_dir.run_jj(["converge"]).success(); |
| 450 |
insta::assert_snapshot!(output, @r" |
| 451 |
------- stderr ------- |
| 452 |
No divergent changes found. |
| 453 |
[EOF] |
| 454 |
"); |
| 455 |
} |
| 456 |
|
| 457 |
// This tests scenarios where the user specifies revisions to converge. More |
| 458 |
// precisely, the user specifies a revset that is used as the search space for |
| 459 |
// divergent commits. |
| 460 |
#[test] |
| 461 |
fn test_converge_simple_with_revisions_arg() { |
| 462 |
let test_env = TestEnvironment::default(); |
| 463 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 464 |
let work_dir = test_env.work_dir("repo"); |
| 465 |
|
| 466 |
// Set up commit graph with divergent changes |
| 467 |
create_commit_with_files(&work_dir, "a", &[], &[("file1", "1")]); |
| 468 |
create_commit_with_files(&work_dir, "b2", &["a"], &[("file2", "2")]); |
| 469 |
create_commit_with_files(&work_dir, "c", &["a"], &[("file3", "3")]); |
| 470 |
work_dir.run_jj(["rebase", "-r", "b2", "-o", "c"]).success(); |
| 471 |
work_dir |
| 472 |
.run_jj(["bookmark", "create", "b1", "-r", "at_operation(@-, b2)"]) |
| 473 |
.success(); |
| 474 |
create_commit_with_files(&work_dir, "d", &["b1"], &[("file4", "4")]); |
| 475 |
|
| 476 |
// Test the setup (commit B is duplicated) |
| 477 |
insta::assert_snapshot!(get_long_log_output(&work_dir), @r" |
| 478 |
@ d znkkpsqq bf5126ef - description: d |
| 479 |
○ b1 zsuskuln/1 59a77004 - description: b2 |
| 480 |
│ ○ b2 zsuskuln/0 2c2bd25d - description: b2 |
| 481 |
│ ○ c royxmykx 4343fc61 - description: c |
| 482 |
├─╯ |
| 483 |
○ a rlvkpnrz e9a731d9 - description: a |
| 484 |
◆ zzzzzzzz 00000000 |
| 485 |
[EOF] |
| 486 |
"); |
| 487 |
|
| 488 |
insta::assert_snapshot!(get_evolog(&work_dir, "b2"), @r" |
| 489 |
○ zsuskuln/0 2c2bd25d (divergent) b2 |
| 490 |
○ zsuskuln/1 59a77004 (divergent) b2 |
| 491 |
○ zsuskuln/2 b2852eb2 (hidden) (empty) b2 |
| 492 |
[EOF] |
| 493 |
"); |
| 494 |
|
| 495 |
// `-r a::d` resolves to {a, b1, d}. b1 IS a divergent commit, but in that |
| 496 |
// revset there are no other commits with that change-id, so by design the |
| 497 |
// command does nothing (we could change that in the future). |
| 498 |
let output = work_dir.run_jj(["converge", "-r", "a::d"]).success(); |
| 499 |
insta::assert_snapshot!(output, @r" |
| 500 |
------- stderr ------- |
| 501 |
No divergence found among the specified revisions. |
| 502 |
[EOF] |
| 503 |
"); |
| 504 |
|
| 505 |
// `-r a::` resolves to {a, b1, b2, c, d}. Now the command "sees" two commits |
| 506 |
// with the same change-id and converges them. |
| 507 |
let output = work_dir.run_jj(["converge", "-r", "a::"]).success(); |
| 508 |
insta::assert_snapshot!(output, @r" |
| 509 |
------- stderr ------- |
| 510 |
Found 1 divergent change(s) in the specified revset: |
| 511 |
- Change: zsuskulnrvyr with 2 commits: |
| 512 |
zsuskuln/0 2c2bd25d b2 | (divergent) b2 |
| 513 |
zsuskuln/1 59a77004 b1 | (divergent) b2 |
| 514 |
|
| 515 |
Attempting to converge change zsuskulnrvyr... |
| 516 |
|
| 517 |
Successfully converged change: created commit 5b9d32498e06. |
| 518 |
Rebased 1 descendants |
| 519 |
Working copy (@) now at: znkkpsqq 4080edbe d | d |
| 520 |
Parent commit (@-) : zsuskuln 5b9d3249 b1 b2 | b2 |
| 521 |
Added 1 files, modified 0 files, removed 0 files |
| 522 |
[EOF] |
| 523 |
"); |
| 524 |
|
| 525 |
// Verify the commit graph after converge |
| 526 |
insta::assert_snapshot!(get_long_log_output(&work_dir), @r" |
| 527 |
@ d znkkpsqq 4080edbe - description: d |
| 528 |
○ b1 b2 zsuskuln 5b9d3249 - description: b2 |
| 529 |
○ c royxmykx 4343fc61 - description: c |
| 530 |
○ a rlvkpnrz e9a731d9 - description: a |
| 531 |
◆ zzzzzzzz 00000000 |
| 532 |
[EOF] |
| 533 |
"); |
| 534 |
|
| 535 |
// Verify the evolution history after converge |
| 536 |
insta::assert_snapshot!(get_evolog(&work_dir, "b2"), @r" |
| 537 |
○ zsuskuln 5b9d3249 b2 |
| 538 |
├─╮ |
| 539 |
○ │ zsuskuln/1 2c2bd25d (hidden) b2 |
| 540 |
├─╯ |
| 541 |
○ zsuskuln/2 59a77004 (hidden) b2 |
| 542 |
○ zsuskuln/3 b2852eb2 (hidden) (empty) b2 |
| 543 |
[EOF] |
| 544 |
"); |
| 545 |
} |
| 546 |
|
| 547 |
// This tests scenarios where the user specifies revisions to converge. More |
| 548 |
// precisely, the user specifies a revset that is used as the search space for |
| 549 |
// divergent commits. This is a variation of |
| 550 |
// test_converge_simple_with_revisions_arg: in that test there was a single |
| 551 |
// divergent change, here there are two. |
| 552 |
#[test] |
| 553 |
fn test_converge_simple_with_revisions_arg_and_two_divergent_changes() { |
| 554 |
let test_env = TestEnvironment::default(); |
| 555 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 556 |
let work_dir = test_env.work_dir("repo"); |
| 557 |
|
| 558 |
// Set up: first create a base commit |
| 559 |
create_commit_with_files(&work_dir, "a", &[], &[("file1", "1")]); |
| 560 |
|
| 561 |
// Set up: create commit graph with two divergent changes |
| 562 |
// First divergent change: |
| 563 |
create_commit_with_files(&work_dir, "b2", &["a"], &[("file2", "2")]); |
| 564 |
create_commit_with_files(&work_dir, "c", &["a"], &[("file3", "3")]); |
| 565 |
work_dir.run_jj(["rebase", "-r", "b2", "-o", "c"]).success(); |
| 566 |
work_dir |
| 567 |
.run_jj(["bookmark", "create", "b1", "-r", "at_operation(@-, b2)"]) |
| 568 |
.success(); |
| 569 |
create_commit_with_files(&work_dir, "d", &["b1"], &[("file4", "4")]); |
| 570 |
|
| 571 |
// Second divergent change: |
| 572 |
create_commit_with_files(&work_dir, "e3", &["a"], &[("file5", "5")]); |
| 573 |
create_commit_with_files(&work_dir, "f", &["a"], &[("file6", "6")]); |
| 574 |
work_dir.run_jj(["rebase", "-r", "e3", "-o", "f"]).success(); |
| 575 |
work_dir |
| 576 |
.run_jj(["bookmark", "create", "e2", "-r", "at_operation(@-, e3)"]) |
| 577 |
.success(); |
| 578 |
work_dir |
| 579 |
.run_jj(["describe", "-r", "e2", "-m", "blah blah blah"]) |
| 580 |
.success(); |
| 581 |
work_dir |
| 582 |
.run_jj(["bookmark", "create", "e1", "-r", "at_operation(@-, e2)"]) |
| 583 |
.success(); |
| 584 |
create_commit_with_files(&work_dir, "g", &["e2"], &[("file7", "7")]); |
| 585 |
|
| 586 |
// Test the setup: look at the commit graph (commit B is duplicated and commit E |
| 587 |
// is duplicated) |
| 588 |
insta::assert_snapshot!(get_long_log_output(&work_dir), @r" |
| 589 |
@ g nmzmmopx 7e4fac7e - description: g |
| 590 |
○ e2 kmkuslsw/0 c8976369 - description: blah blah blah |
| 591 |
│ ○ e3 kmkuslsw/1 d34ec64c - description: e3 |
| 592 |
│ ○ f lylxulpl d50e2761 - description: f |
| 593 |
├─╯ |
| 594 |
│ ○ e1 kmkuslsw/2 faebbd68 - description: e3 |
| 595 |
├─╯ |
| 596 |
│ ○ b2 zsuskuln/0 2c2bd25d - description: b2 |
| 597 |
│ ○ c royxmykx 4343fc61 - description: c |
| 598 |
├─╯ |
| 599 |
│ ○ d znkkpsqq bf5126ef - description: d |
| 600 |
│ ○ b1 zsuskuln/1 59a77004 - description: b2 |
| 601 |
├─╯ |
| 602 |
○ a rlvkpnrz e9a731d9 - description: a |
| 603 |
◆ zzzzzzzz 00000000 |
| 604 |
[EOF] |
| 605 |
"); |
| 606 |
|
| 607 |
// Test the setup: look at the evolog |
| 608 |
insta::assert_snapshot!(get_evolog(&work_dir, "b2"), @r" |
| 609 |
○ zsuskuln/0 2c2bd25d (divergent) b2 |
| 610 |
○ zsuskuln/1 59a77004 (divergent) b2 |
| 611 |
○ zsuskuln/2 b2852eb2 (hidden) (empty) b2 |
| 612 |
[EOF] |
| 613 |
"); |
| 614 |
|
| 615 |
// Test the setup: look at the evolog |
| 616 |
insta::assert_snapshot!(get_evolog(&work_dir, "e3"), @r" |
| 617 |
○ kmkuslsw/1 d34ec64c (divergent) e3 |
| 618 |
○ kmkuslsw/2 faebbd68 (divergent) e3 |
| 619 |
○ kmkuslsw/3 8f5eb314 (hidden) (empty) e3 |
| 620 |
[EOF] |
| 621 |
"); |
| 622 |
|
| 623 |
// `-r a::d` resolves to {a, b1, d}. b1 IS a divergent commit, but in that |
| 624 |
// revset there are no other commits with that change-id, so by design the |
| 625 |
// command does nothing (we could change that in the future). |
| 626 |
let output = work_dir.run_jj(["converge", "-r", "a::d"]).success(); |
| 627 |
insta::assert_snapshot!(output, @r" |
| 628 |
------- stderr ------- |
| 629 |
No divergence found among the specified revisions. |
| 630 |
[EOF] |
| 631 |
"); |
| 632 |
|
| 633 |
// `-r a::` does resolve to both divergent changes. In this test we simulate the |
| 634 |
// user aborts at the prompt. |
| 635 |
let output = work_dir |
| 636 |
.run_jj_with(|cmd| { |
| 637 |
force_interactive(cmd) |
| 638 |
.args(["converge", "-r", "a::"]) |
| 639 |
.write_stdin("q\n") |
| 640 |
}) |
| 641 |
.success(); |
| 642 |
insta::assert_snapshot!(output, @r" |
| 643 |
------- stderr ------- |
| 644 |
Found 2 divergent change(s) in the specified revset: |
| 645 |
- Change: zsuskulnrvyr with 2 commits: |
| 646 |
zsuskuln/0 2c2bd25d b2 | (divergent) b2 |
| 647 |
zsuskuln/1 59a77004 b1 | (divergent) b2 |
| 648 |
|
| 649 |
- Change: kmkuslswpqwq with 3 commits: |
| 650 |
kmkuslsw/0 c8976369 e2 | (divergent) blah blah blah |
| 651 |
kmkuslsw/1 d34ec64c e3 | (divergent) e3 |
| 652 |
kmkuslsw/2 faebbd68 e1 | (divergent) e3 |
| 653 |
|
| 654 |
Choose which change to converge (jj converge only converges one change at a time): |
| 655 |
1: zsuskulnrvyr |
| 656 |
2: kmkuslswpqwq |
| 657 |
q: abort |
| 658 |
Enter the index of the change to converge: |
| 659 |
|
| 660 |
Aborting... nothing changed. |
| 661 |
[EOF] |
| 662 |
"); |
| 663 |
|
| 664 |
// `-r b1|e3` resolve to those two commits. Both ARE divergent commits, but in |
| 665 |
// the search space there are no other commits with either change-id so the |
| 666 |
// command does nothing. |
| 667 |
let output = work_dir |
| 668 |
.run_jj_with(|cmd| { |
| 669 |
force_interactive(cmd) |
| 670 |
.args(["converge", "-r", "b1|e3"]) |
| 671 |
.write_stdin("q\n") |
| 672 |
}) |
| 673 |
.success(); |
| 674 |
insta::assert_snapshot!(output, @r" |
| 675 |
------- stderr ------- |
| 676 |
No divergence found among the specified revisions. |
| 677 |
[EOF] |
| 678 |
"); |
| 679 |
|
| 680 |
// Specifying `-r b1|b2` resolves to that divergent change and only that one. |
| 681 |
// There should not be any prompt. |
| 682 |
let output = work_dir |
| 683 |
.run_jj_with(|cmd| { |
| 684 |
force_interactive(cmd) |
| 685 |
.args(["converge", "-r", "b1|b2"]) |
| 686 |
.write_stdin("q\n") |
| 687 |
}) |
| 688 |
.success(); |
| 689 |
insta::assert_snapshot!(output, @r" |
| 690 |
------- stderr ------- |
| 691 |
Found 1 divergent change(s) in the specified revset: |
| 692 |
- Change: zsuskulnrvyr with 2 commits: |
| 693 |
zsuskuln/0 2c2bd25d b2 | (divergent) b2 |
| 694 |
zsuskuln/1 59a77004 b1 | (divergent) b2 |
| 695 |
|
| 696 |
Attempting to converge change zsuskulnrvyr... |
| 697 |
|
| 698 |
Successfully converged change: created commit 32d4597c081c. |
| 699 |
Rebased 1 descendants |
| 700 |
[EOF] |
| 701 |
"); |
| 702 |
|
| 703 |
// Look at the resulting commit graph |
| 704 |
insta::assert_snapshot!(get_long_log_output(&work_dir), @r" |
| 705 |
@ g nmzmmopx 7e4fac7e - description: g |
| 706 |
○ e2 kmkuslsw/0 c8976369 - description: blah blah blah |
| 707 |
│ ○ e3 kmkuslsw/1 d34ec64c - description: e3 |
| 708 |
│ ○ f lylxulpl d50e2761 - description: f |
| 709 |
├─╯ |
| 710 |
│ ○ e1 kmkuslsw/2 faebbd68 - description: e3 |
| 711 |
├─╯ |
| 712 |
│ ○ d znkkpsqq 5aecbdd4 - description: d |
| 713 |
│ ○ b1 b2 zsuskuln 32d4597c - description: b2 |
| 714 |
│ ○ c royxmykx 4343fc61 - description: c |
| 715 |
├─╯ |
| 716 |
○ a rlvkpnrz e9a731d9 - description: a |
| 717 |
◆ zzzzzzzz 00000000 |
| 718 |
[EOF] |
| 719 |
"); |
| 720 |
|
| 721 |
// Verify the evolution history after converge |
| 722 |
insta::assert_snapshot!(get_evolog(&work_dir, "b2"), @r" |
| 723 |
○ zsuskuln 32d4597c b2 |
| 724 |
├─╮ |
| 725 |
○ │ zsuskuln/1 2c2bd25d (hidden) b2 |
| 726 |
├─╯ |
| 727 |
○ zsuskuln/2 59a77004 (hidden) b2 |
| 728 |
○ zsuskuln/3 b2852eb2 (hidden) (empty) b2 |
| 729 |
[EOF] |
| 730 |
"); |
| 731 |
|
| 732 |
// Lets undo the previous converge operation to try a different scenario. |
| 733 |
work_dir.run_jj(["undo"]).success(); |
| 734 |
|
| 735 |
// The next invocation shows that specifying `-r e1|e3` converges those two |
| 736 |
// divergent commits, but leaves e1 around (by design). |
| 737 |
let output = work_dir |
| 738 |
.run_jj_with(|cmd| { |
| 739 |
force_interactive(cmd) |
| 740 |
.args(["converge", "-r", "e1|e3"]) |
| 741 |
.write_stdin("q\n") |
| 742 |
}) |
| 743 |
.success(); |
| 744 |
insta::assert_snapshot!(output, @r" |
| 745 |
------- stderr ------- |
| 746 |
Found 1 divergent change(s) in the specified revset: |
| 747 |
- Change: kmkuslswpqwq with 2 commits: |
| 748 |
kmkuslsw/1 d34ec64c e3 | (divergent) e3 |
| 749 |
kmkuslsw/2 faebbd68 e1 | (divergent) e3 |
| 750 |
|
| 751 |
Attempting to converge change kmkuslswpqwq... |
| 752 |
|
| 753 |
Successfully converged change: created commit b5ce73ed2a0d. |
| 754 |
[EOF] |
| 755 |
"); |
| 756 |
|
| 757 |
// Look at the resulting commit graph |
| 758 |
insta::assert_snapshot!(get_long_log_output(&work_dir), @r" |
| 759 |
@ g nmzmmopx 7e4fac7e - description: g |
| 760 |
○ e2 kmkuslsw/1 c8976369 - description: blah blah blah |
| 761 |
│ ○ e1 e3 kmkuslsw/0 b5ce73ed - description: e3 |
| 762 |
│ ○ f lylxulpl d50e2761 - description: f |
| 763 |
├─╯ |
| 764 |
│ ○ b2 zsuskuln/1 2c2bd25d - description: b2 |
| 765 |
│ ○ c royxmykx 4343fc61 - description: c |
| 766 |
├─╯ |
| 767 |
│ ○ d znkkpsqq bf5126ef - description: d |
| 768 |
│ ○ b1 zsuskuln/2 59a77004 - description: b2 |
| 769 |
├─╯ |
| 770 |
○ a rlvkpnrz e9a731d9 - description: a |
| 771 |
◆ zzzzzzzz 00000000 |
| 772 |
[EOF] |
| 773 |
"); |
| 774 |
|
| 775 |
// Verify the evolution history after converge |
| 776 |
insta::assert_snapshot!(get_evolog(&work_dir, "e3"), @r" |
| 777 |
○ kmkuslsw/0 b5ce73ed (divergent) e3 |
| 778 |
├─╮ |
| 779 |
○ │ kmkuslsw/2 d34ec64c (hidden) e3 |
| 780 |
├─╯ |
| 781 |
○ kmkuslsw/3 faebbd68 (hidden) e3 |
| 782 |
○ kmkuslsw/4 8f5eb314 (hidden) (empty) e3 |
| 783 |
[EOF] |
| 784 |
"); |
| 785 |
} |
| 786 |
|
| 787 |
// In this scenario there are two divergent commits. One side changed the |
| 788 |
// description, the other side was rebased. In such simple cases `jj converge` |
| 789 |
// should be able to automatically combine the new description with the new |
| 790 |
// parents. |
| 791 |
#[test] |
| 792 |
fn test_converge_one_side_rebased_one_side_description_changed() { |
| 793 |
let test_env = TestEnvironment::default(); |
| 794 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 795 |
let work_dir = test_env.work_dir("repo"); |
| 796 |
|
| 797 |
// Set up commit graph with divergent changes |
| 798 |
create_commit_with_files(&work_dir, "a", &[], &[("file1", "1")]); |
| 799 |
create_commit_with_files(&work_dir, "b2", &["a"], &[("file2", "2")]); |
| 800 |
create_commit_with_files(&work_dir, "c", &["a"], &[("file3", "3")]); |
| 801 |
work_dir.run_jj(["rebase", "-r", "b2", "-o", "c"]).success(); |
| 802 |
work_dir |
| 803 |
.run_jj(["bookmark", "create", "b1", "-r", "at_operation(@-, b2)"]) |
| 804 |
.success(); |
| 805 |
work_dir |
| 806 |
.run_jj(["describe", "-r", "b1", "-m", "blah blah blah"]) |
| 807 |
.success(); |
| 808 |
create_commit_with_files(&work_dir, "d", &["b1"], &[("file4", "4")]); |
| 809 |
|
| 810 |
// Test the setup (commit B is duplicated) |
| 811 |
insta::assert_snapshot!(get_long_log_output(&work_dir), @r" |
| 812 |
@ d kpqxywon 16d29671 - description: d |
| 813 |
○ b1 zsuskuln/0 d471c689 - description: blah blah blah |
| 814 |
│ ○ b2 zsuskuln/1 2c2bd25d - description: b2 |
| 815 |
│ ○ c royxmykx 4343fc61 - description: c |
| 816 |
├─╯ |
| 817 |
○ a rlvkpnrz e9a731d9 - description: a |
| 818 |
◆ zzzzzzzz 00000000 |
| 819 |
[EOF] |
| 820 |
"); |
| 821 |
|
| 822 |
insta::assert_snapshot!(get_evolog(&work_dir, "b2"), @r" |
| 823 |
○ zsuskuln/1 2c2bd25d (divergent) b2 |
| 824 |
○ zsuskuln/2 59a77004 (hidden) b2 |
| 825 |
○ zsuskuln/3 b2852eb2 (hidden) (empty) b2 |
| 826 |
[EOF] |
| 827 |
"); |
| 828 |
|
| 829 |
let output = work_dir.run_jj(["converge"]).success(); |
| 830 |
insta::assert_snapshot!(output, @r" |
| 831 |
------- stderr ------- |
| 832 |
Found 1 divergent change(s) in the specified revset: |
| 833 |
- Change: zsuskulnrvyr with 2 commits: |
| 834 |
zsuskuln/0 d471c689 b1 | (divergent) blah blah blah |
| 835 |
zsuskuln/1 2c2bd25d b2 | (divergent) b2 |
| 836 |
|
| 837 |
Attempting to converge change zsuskulnrvyr... |
| 838 |
|
| 839 |
Successfully converged change: created commit 65226e3f7378. |
| 840 |
Rebased 1 descendants |
| 841 |
Working copy (@) now at: kpqxywon 405941e7 d | d |
| 842 |
Parent commit (@-) : zsuskuln 65226e3f b1 b2 | blah blah blah |
| 843 |
Added 1 files, modified 0 files, removed 0 files |
| 844 |
[EOF] |
| 845 |
"); |
| 846 |
|
| 847 |
// Verify the commit graph after converge |
| 848 |
insta::assert_snapshot!(get_long_log_output(&work_dir), @r" |
| 849 |
@ d kpqxywon 405941e7 - description: d |
| 850 |
○ b1 b2 zsuskuln 65226e3f - description: blah blah blah |
| 851 |
○ c royxmykx 4343fc61 - description: c |
| 852 |
○ a rlvkpnrz e9a731d9 - description: a |
| 853 |
◆ zzzzzzzz 00000000 |
| 854 |
[EOF] |
| 855 |
"); |
| 856 |
|
| 857 |
// Verify the evolution history after converge |
| 858 |
insta::assert_snapshot!(get_evolog(&work_dir, "b2"), @r" |
| 859 |
○ zsuskuln 65226e3f blah blah blah |
| 860 |
├─╮ |
| 861 |
│ ○ zsuskuln/2 2c2bd25d (hidden) b2 |
| 862 |
○ │ zsuskuln/1 d471c689 (hidden) blah blah blah |
| 863 |
├─╯ |
| 864 |
○ zsuskuln/3 59a77004 (hidden) b2 |
| 865 |
○ zsuskuln/4 b2852eb2 (hidden) (empty) b2 |
| 866 |
[EOF] |
| 867 |
"); |
| 868 |
} |
| 869 |
|
| 870 |
#[test_case(false; "dont_invoke_text_editor")] |
| 871 |
#[test_case(true; "invoke_text_editor")] |
| 872 |
fn test_converge_description_changed_inconsistently(invoke_text_editor: bool) -> TestResult { |
| 873 |
let mut test_env = TestEnvironment::default(); |
| 874 |
let edit_script = test_env.set_up_fake_editor(); |
| 875 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 876 |
let work_dir = test_env.work_dir("repo"); |
| 877 |
|
| 878 |
// Set up commit graph with divergent changes |
| 879 |
create_commit_with_files(&work_dir, "a", &[], &[("file1", "1")]); |
| 880 |
create_commit_with_files(&work_dir, "b2", &["a"], &[("file2", "2")]); |
| 881 |
work_dir |
| 882 |
.run_jj(["describe", "-r", "b2", "-m", "foo"]) |
| 883 |
.success(); |
| 884 |
work_dir |
| 885 |
.run_jj(["bookmark", "create", "b1", "-r", "at_operation(@-, b2)"]) |
| 886 |
.success(); |
| 887 |
work_dir |
| 888 |
.run_jj(["describe", "-r", "b1", "-m", "bar"]) |
| 889 |
.success(); |
| 890 |
create_commit_with_files(&work_dir, "d", &["b1"], &[("file3", "3")]); |
| 891 |
|
| 892 |
// Test the setup (commit B is duplicated) |
| 893 |
insta::assert_snapshot!(get_long_log_output(&work_dir), @r" |
| 894 |
@ d yostqsxw a906f67a - description: d |
| 895 |
○ b1 zsuskuln/0 0ec69b7a - description: bar |
| 896 |
│ ○ b2 zsuskuln/1 08117b18 - description: foo |
| 897 |
├─╯ |
| 898 |
○ a rlvkpnrz e9a731d9 - description: a |
| 899 |
◆ zzzzzzzz 00000000 |
| 900 |
[EOF] |
| 901 |
"); |
| 902 |
|
| 903 |
insta::assert_snapshot!(get_evolog(&work_dir, "b2"), @r" |
| 904 |
○ zsuskuln/1 08117b18 (divergent) foo |
| 905 |
○ zsuskuln/2 59a77004 (hidden) b2 |
| 906 |
○ zsuskuln/3 b2852eb2 (hidden) (empty) b2 |
| 907 |
[EOF] |
| 908 |
"); |
| 909 |
|
| 910 |
// First check behavior in non-interactive mode. |
| 911 |
let output = |
| 912 |
work_dir.run_jj_with(|cmd| force_interactive(cmd).args(["converge", "--no-interactive"])); |
| 913 |
insta::assert_snapshot!(output, @r" |
| 914 |
------- stderr ------- |
| 915 |
Found 1 divergent change(s) in the specified revset: |
| 916 |
- Change: zsuskulnrvyr with 2 commits: |
| 917 |
zsuskuln/0 0ec69b7a b1 | (divergent) bar |
| 918 |
zsuskuln/1 08117b18 b2 | (divergent) foo |
| 919 |
|
| 920 |
Attempting to converge change zsuskulnrvyr... |
| 921 |
|
| 922 |
Could not determine which description to use. |
| 923 |
Error: Could not converge change |
| 924 |
[EOF] |
| 925 |
[exit status: 1] |
| 926 |
"); |
| 927 |
|
| 928 |
// Now check behavior in interactive mode. |
| 929 |
if invoke_text_editor { |
| 930 |
std::fs::write( |
| 931 |
&edit_script, |
| 932 |
["dump editor0", "write\nmy-merged-description"].join("\0"), |
| 933 |
)?; |
| 934 |
let output = work_dir |
| 935 |
.run_jj_with(|cmd| force_interactive(cmd).args(["converge"]).write_stdin("y\n")) |
| 936 |
.success(); |
| 937 |
insta::assert_snapshot!( |
| 938 |
std::fs::read_to_string(test_env.env_root().join("editor0"))?, @r#" |
| 939 |
<<<<<<< conflict 1 of 1 |
| 940 |
%%%%%%% diff from: zsuskuln 59a77004 "b2" |
| 941 |
\\\\\\\ to: zsuskuln 0ec69b7a "bar" |
| 942 |
-b2 |
| 943 |
+bar |
| 944 |
+++++++ zsuskuln 08117b18 "foo" |
| 945 |
foo |
| 946 |
>>>>>>> conflict 1 of 1 ends |
| 947 |
"#); |
| 948 |
insta::assert_snapshot!(output.stdout.normalized(), @""); |
| 949 |
insta::assert_snapshot!(output.stderr.normalized(), @r" |
| 950 |
Found 1 divergent change(s) in the specified revset: |
| 951 |
- Change: zsuskulnrvyr with 2 commits: |
| 952 |
zsuskuln/0 0ec69b7a b1 | (divergent) bar |
| 953 |
zsuskuln/1 08117b18 b2 | (divergent) foo |
| 954 |
|
| 955 |
Attempting to converge change zsuskulnrvyr... |
| 956 |
|
| 957 |
There are divergent descriptions. You can choose to merge them now in a |
| 958 |
text editor, or skip merging and use the conflicted description (with |
| 959 |
conflict markers). Do you want to merge them now? (Yn): |
| 960 |
|
| 961 |
Successfully converged change: created commit a393891bef3b. |
| 962 |
Rebased 1 descendants |
| 963 |
Working copy (@) now at: yostqsxw a9dd817f d | d |
| 964 |
Parent commit (@-) : zsuskuln a393891b b1 b2 | my-merged-description |
| 965 |
"); |
| 966 |
|
| 967 |
// Verify the commit graph after converge |
| 968 |
insta::assert_snapshot!(get_long_log_output(&work_dir), @r" |
| 969 |
@ d yostqsxw a9dd817f - description: d |
| 970 |
○ b1 b2 zsuskuln a393891b - description: my-merged-des... |
| 971 |
○ a rlvkpnrz e9a731d9 - description: a |
| 972 |
◆ zzzzzzzz 00000000 |
| 973 |
[EOF] |
| 974 |
"); |
| 975 |
|
| 976 |
// Verify the evolution history after converge |
| 977 |
insta::assert_snapshot!(get_evolog(&work_dir, "b2"), @r" |
| 978 |
○ zsuskuln a393891b my-merged-description |
| 979 |
├─╮ |
| 980 |
│ ○ zsuskuln/2 08117b18 (hidden) foo |
| 981 |
○ │ zsuskuln/1 0ec69b7a (hidden) bar |
| 982 |
├─╯ |
| 983 |
○ zsuskuln/3 59a77004 (hidden) b2 |
| 984 |
○ zsuskuln/4 b2852eb2 (hidden) (empty) b2 |
| 985 |
[EOF] |
| 986 |
"); |
| 987 |
} else { |
| 988 |
let output = work_dir |
| 989 |
.run_jj_with(|cmd| force_interactive(cmd).args(["converge"]).write_stdin("n\n")) |
| 990 |
.success(); |
| 991 |
insta::assert_snapshot!(output, @r" |
| 992 |
------- stderr ------- |
| 993 |
Found 1 divergent change(s) in the specified revset: |
| 994 |
- Change: zsuskulnrvyr with 2 commits: |
| 995 |
zsuskuln/0 0ec69b7a b1 | (divergent) bar |
| 996 |
zsuskuln/1 08117b18 b2 | (divergent) foo |
| 997 |
|
| 998 |
Attempting to converge change zsuskulnrvyr... |
| 999 |
|
| 1000 |
There are divergent descriptions. You can choose to merge them now in a |
| 1001 |
text editor, or skip merging and use the conflicted description (with |
| 1002 |
conflict markers). Do you want to merge them now? (Yn): |
| 1003 |
|
| 1004 |
Successfully converged change: created commit 6fdb1551f127. |
| 1005 |
Rebased 1 descendants |
| 1006 |
Working copy (@) now at: yostqsxw 6b108e95 d | d |
| 1007 |
Parent commit (@-) : zsuskuln 6fdb1551 b1 b2 | <<<<<<< conflict 1 of 1 |
| 1008 |
[EOF] |
| 1009 |
"); |
| 1010 |
|
| 1011 |
// Verify the commit graph after converge |
| 1012 |
insta::assert_snapshot!(get_long_log_output(&work_dir), @r" |
| 1013 |
@ d yostqsxw 6b108e95 - description: d |
| 1014 |
○ b1 b2 zsuskuln 6fdb1551 - description: <<<<<<< confl... |
| 1015 |
○ a rlvkpnrz e9a731d9 - description: a |
| 1016 |
◆ zzzzzzzz 00000000 |
| 1017 |
[EOF] |
| 1018 |
"); |
| 1019 |
|
| 1020 |
// Verify the evolution history after converge |
| 1021 |
insta::assert_snapshot!(get_evolog(&work_dir, "b2"), @r" |
| 1022 |
○ zsuskuln 6fdb1551 <<<<<<< conflict 1 of 1 |
| 1023 |
├─╮ |
| 1024 |
│ ○ zsuskuln/2 08117b18 (hidden) foo |
| 1025 |
○ │ zsuskuln/1 0ec69b7a (hidden) bar |
| 1026 |
├─╯ |
| 1027 |
○ zsuskuln/3 59a77004 (hidden) b2 |
| 1028 |
○ zsuskuln/4 b2852eb2 (hidden) (empty) b2 |
| 1029 |
[EOF] |
| 1030 |
"); |
| 1031 |
|
| 1032 |
// Verify the description after converge (it should have conflict markers) |
| 1033 |
let output = work_dir.run_jj(["log", "-T", "description", "-r", "b1", "--no-graph"]); |
| 1034 |
insta::assert_snapshot!(output, @r#" |
| 1035 |
<<<<<<< conflict 1 of 1 |
| 1036 |
%%%%%%% diff from: zsuskuln 59a77004 "b2" |
| 1037 |
\\\\\\\ to: zsuskuln 0ec69b7a "bar" |
| 1038 |
-b2 |
| 1039 |
+bar |
| 1040 |
+++++++ zsuskuln 08117b18 "foo" |
| 1041 |
foo |
| 1042 |
>>>>>>> conflict 1 of 1 ends |
| 1043 |
[EOF] |
| 1044 |
"#); |
| 1045 |
} |
| 1046 |
Ok(()) |
| 1047 |
} |
| 1048 |
|
| 1049 |
// In this scenario there are two divergent commits. Each side rebased their |
| 1050 |
// common predecessor on top of different parents. In this case `jj converge` |
| 1051 |
// cannot automatically determine which parents to use, so it should prompt the |
| 1052 |
// user. |
| 1053 |
#[test] |
| 1054 |
fn test_converge_with_inconsistent_parents() { |
| 1055 |
let test_env = TestEnvironment::default(); |
| 1056 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 1057 |
let work_dir = test_env.work_dir("repo"); |
| 1058 |
|
| 1059 |
// Set up commit graph with divergent changes |
| 1060 |
create_commit_with_files(&work_dir, "a", &[], &[("file1", "1")]); |
| 1061 |
create_commit_with_files(&work_dir, "b", &[], &[("file2", "2")]); |
| 1062 |
create_commit_with_files(&work_dir, "c", &[], &[("file3", "3")]); |
| 1063 |
create_commit_with_files(&work_dir, "d2", &["a"], &[("file4", "4")]); |
| 1064 |
work_dir.run_jj(["rebase", "-r", "d2", "-o", "b"]).success(); |
| 1065 |
work_dir |
| 1066 |
.run_jj(["bookmark", "create", "d1", "-r", "at_operation(@-, d2)"]) |
| 1067 |
.success(); |
| 1068 |
work_dir.run_jj(["rebase", "-r", "d1", "-o", "c"]).success(); |
| 1069 |
|
| 1070 |
// Test the setup (commit D is duplicated) |
| 1071 |
insta::assert_snapshot!(get_long_log_output(&work_dir), @r" |
| 1072 |
@ d2 vruxwmqv/1 c3de3020 - description: d2 |
| 1073 |
○ b zsuskuln 38bded60 - description: b |
| 1074 |
│ ○ d1 vruxwmqv/0 4bcd1134 - description: d2 |
| 1075 |
│ ○ c royxmykx b616a3ce - description: c |
| 1076 |
├─╯ |
| 1077 |
│ ○ a rlvkpnrz e9a731d9 - description: a |
| 1078 |
├─╯ |
| 1079 |
◆ zzzzzzzz 00000000 |
| 1080 |
[EOF] |
| 1081 |
"); |
| 1082 |
|
| 1083 |
insta::assert_snapshot!(get_evolog(&work_dir, "d1"), @r" |
| 1084 |
○ vruxwmqv/0 4bcd1134 (divergent) d2 |
| 1085 |
○ vruxwmqv/2 459038a5 (hidden) d2 |
| 1086 |
○ vruxwmqv/3 b31c58cf (hidden) (empty) d2 |
| 1087 |
[EOF] |
| 1088 |
"); |
| 1089 |
|
| 1090 |
insta::assert_snapshot!(get_evolog(&work_dir, "d2"), @r" |
| 1091 |
@ vruxwmqv/1 c3de3020 (divergent) d2 |
| 1092 |
○ vruxwmqv/2 459038a5 (hidden) d2 |
| 1093 |
○ vruxwmqv/3 b31c58cf (hidden) (empty) d2 |
| 1094 |
[EOF] |
| 1095 |
"); |
| 1096 |
|
| 1097 |
// First check behavior in non-interactive mode. The command cannot determine |
| 1098 |
// which parents to use, so it should fail. |
| 1099 |
let output = |
| 1100 |
work_dir.run_jj_with(|cmd| force_interactive(cmd).args(["converge", "--no-interactive"])); |
| 1101 |
insta::assert_snapshot!(output, @r" |
| 1102 |
------- stderr ------- |
| 1103 |
Found 1 divergent change(s) in the specified revset: |
| 1104 |
- Change: vruxwmqvtpmx with 2 commits: |
| 1105 |
vruxwmqv/0 4bcd1134 d1 | (divergent) d2 |
| 1106 |
vruxwmqv/1 c3de3020 d2 | (divergent) d2 |
| 1107 |
|
| 1108 |
Attempting to converge change vruxwmqvtpmx... |
| 1109 |
|
| 1110 |
Could not determine which parents to use. |
| 1111 |
Error: Could not converge change |
| 1112 |
[EOF] |
| 1113 |
[exit status: 1] |
| 1114 |
"); |
| 1115 |
|
| 1116 |
// Run the command again, but this time choose to abort at the prompt. |
| 1117 |
let output = |
| 1118 |
work_dir.run_jj_with(|cmd| force_interactive(cmd).args(["converge"]).write_stdin("q\n")); |
| 1119 |
insta::assert_snapshot!(output, @r" |
| 1120 |
------- stderr ------- |
| 1121 |
Found 1 divergent change(s) in the specified revset: |
| 1122 |
- Change: vruxwmqvtpmx with 2 commits: |
| 1123 |
vruxwmqv/0 4bcd1134 d1 | (divergent) d2 |
| 1124 |
vruxwmqv/1 c3de3020 d2 | (divergent) d2 |
| 1125 |
|
| 1126 |
Attempting to converge change vruxwmqvtpmx... |
| 1127 |
|
| 1128 |
Could not determine automatically which parents to use |
| 1129 |
1: 4bcd1134ba57: |
| 1130 |
Parent: royxmykx b616a3ce c | c |
| 1131 |
2: c3de3020707a: |
| 1132 |
Parent: zsuskuln 38bded60 b | b |
| 1133 |
q: abort |
| 1134 |
Enter the index of one of the divergent commits whose parent(s) will be the parents of the solution: |
| 1135 |
|
| 1136 |
Error: Aborting... nothing changed. |
| 1137 |
[EOF] |
| 1138 |
[exit status: 1] |
| 1139 |
"); |
| 1140 |
|
| 1141 |
// Run the command one more time, this time the user chooses parents. |
| 1142 |
let output = |
| 1143 |
work_dir.run_jj_with(|cmd| force_interactive(cmd).args(["converge"]).write_stdin("2\n")); |
| 1144 |
insta::assert_snapshot!(output, @r" |
| 1145 |
------- stderr ------- |
| 1146 |
Found 1 divergent change(s) in the specified revset: |
| 1147 |
- Change: vruxwmqvtpmx with 2 commits: |
| 1148 |
vruxwmqv/0 4bcd1134 d1 | (divergent) d2 |
| 1149 |
vruxwmqv/1 c3de3020 d2 | (divergent) d2 |
| 1150 |
|
| 1151 |
Attempting to converge change vruxwmqvtpmx... |
| 1152 |
|
| 1153 |
Could not determine automatically which parents to use |
| 1154 |
1: 4bcd1134ba57: |
| 1155 |
Parent: royxmykx b616a3ce c | c |
| 1156 |
2: c3de3020707a: |
| 1157 |
Parent: zsuskuln 38bded60 b | b |
| 1158 |
q: abort |
| 1159 |
Enter the index of one of the divergent commits whose parent(s) will be the parents of the solution: |
| 1160 |
|
| 1161 |
Successfully converged change: created commit 5a4258f7aa61. |
| 1162 |
Working copy (@) now at: vruxwmqv 5a4258f7 d1 d2 | d2 |
| 1163 |
Parent commit (@-) : zsuskuln 38bded60 b | b |
| 1164 |
[EOF] |
| 1165 |
"); |
| 1166 |
|
| 1167 |
// Verify the commit graph after converge |
| 1168 |
insta::assert_snapshot!(get_long_log_output(&work_dir), @r" |
| 1169 |
@ d1 d2 vruxwmqv 5a4258f7 - description: d2 |
| 1170 |
○ b zsuskuln 38bded60 - description: b |
| 1171 |
│ ○ c royxmykx b616a3ce - description: c |
| 1172 |
├─╯ |
| 1173 |
│ ○ a rlvkpnrz e9a731d9 - description: a |
| 1174 |
├─╯ |
| 1175 |
◆ zzzzzzzz 00000000 |
| 1176 |
[EOF] |
| 1177 |
"); |
| 1178 |
|
| 1179 |
// Verify the evolution history after converge |
| 1180 |
insta::assert_snapshot!(get_evolog(&work_dir, "d2"), @r" |
| 1181 |
@ vruxwmqv 5a4258f7 d2 |
| 1182 |
├─╮ |
| 1183 |
│ ○ vruxwmqv/2 c3de3020 (hidden) d2 |
| 1184 |
○ │ vruxwmqv/1 4bcd1134 (hidden) d2 |
| 1185 |
├─╯ |
| 1186 |
○ vruxwmqv/3 459038a5 (hidden) d2 |
| 1187 |
○ vruxwmqv/4 b31c58cf (hidden) (empty) d2 |
| 1188 |
[EOF] |
| 1189 |
"); |
| 1190 |
} |
| 1191 |
|
| 1192 |
// It is possible that a divergent commit is a child of another divergent commit |
| 1193 |
// (with the same change-id or a different one). Consider the case where both |
| 1194 |
// parent and child have the same change-id. When converging that change-id the |
| 1195 |
// algorithm --or the user-- must choose the parent commit(s) of the solution. |
| 1196 |
// To be concrete, say commit A is the parent of commit B, both with the same |
| 1197 |
// change-id. |
| 1198 |
// |
| 1199 |
// Whether automatically or by user choice, `jj converge` is (currently) |
| 1200 |
// designed such that the parent(s) of the solution is the parent(s) of one of |
| 1201 |
// the divergent commits. BUT `jj converge` is "smart" and only considers |
| 1202 |
// divergent commits that are not descendants of other divergent commits during |
| 1203 |
// this parent selection process. Please see the implementation for more |
| 1204 |
// details. |
| 1205 |
// |
| 1206 |
// This test is to ensure that the above behavior is correct. |
| 1207 |
#[test] |
| 1208 |
fn test_converge_one_divergent_commit_is_a_descendant_of_another_divergent_commit() -> TestResult { |
| 1209 |
let mut test_env = TestEnvironment::default(); |
| 1210 |
let edit_script = test_env.set_up_fake_editor(); |
| 1211 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 1212 |
let work_dir = test_env.work_dir("repo"); |
| 1213 |
|
| 1214 |
// Start by setting description to "message 1", then simulate two concurrent |
| 1215 |
// operations, one changing the description to "message 2" and the other |
| 1216 |
// changing it to "message 3" (--at-op=@- is what allows us to pretend these two |
| 1217 |
// operations happen concurrently). At this point we have two divergent commits. |
| 1218 |
// Then we set up bookmarks b2 and b3 to point to the commits. Finally we rebase |
| 1219 |
// b2 onto b3. This sets the stage for this test's scenario. |
| 1220 |
work_dir.run_jj(["describe", "-m", "message 1"]).success(); |
| 1221 |
work_dir.run_jj(["describe", "-m", "message 2"]).success(); |
| 1222 |
work_dir |
| 1223 |
.run_jj(["describe", "-m", "message 3", "--at-op", "@-"]) |
| 1224 |
.success(); |
| 1225 |
work_dir |
| 1226 |
.run_jj([ |
| 1227 |
"bookmark", |
| 1228 |
"create", |
| 1229 |
"-r", |
| 1230 |
"description('message 2*')", |
| 1231 |
"b2", |
| 1232 |
]) |
| 1233 |
.success(); |
| 1234 |
work_dir |
| 1235 |
.run_jj([ |
| 1236 |
"bookmark", |
| 1237 |
"create", |
| 1238 |
"-r", |
| 1239 |
"description('message 3*')", |
| 1240 |
"b3", |
| 1241 |
]) |
| 1242 |
.success(); |
| 1243 |
work_dir |
| 1244 |
.run_jj(["rebase", "-r", "b2", "-d", "b3", "--keep-divergent"]) |
| 1245 |
.success(); |
| 1246 |
|
| 1247 |
// Test the setup: look at the operation log. |
| 1248 |
insta::assert_snapshot!(get_op_log_output(&work_dir), @r" |
| 1249 |
@ rebase commit 59df0df7968367d456d4438cc68ebe6a316ef8ce |
| 1250 |
│ args: jj rebase -r b2 -d b3 --keep-divergent |
| 1251 |
○ create bookmark b3 pointing to commit 4734557e78fe9ccdb827e03e71602c685bfe8b53 |
| 1252 |
│ args: jj bookmark create -r 'description(\'message 3*\')' b3 |
| 1253 |
○ create bookmark b2 pointing to commit 59df0df7968367d456d4438cc68ebe6a316ef8ce |
| 1254 |
│ args: jj bookmark create -r 'description(\'message 2*\')' b2 |
| 1255 |
○ reconcile divergent operations |
| 1256 |
├─╮ args: jj bookmark create -r 'description(\'message 2*\')' b2 |
| 1257 |
○ │ describe commit a289638d100c5af526559dfafb99f062631771c4 |
| 1258 |
│ │ args: jj describe -m 'message 2' |
| 1259 |
│ ○ describe commit a289638d100c5af526559dfafb99f062631771c4 |
| 1260 |
├─╯ args: jj describe -m 'message 3' --at-op @- |
| 1261 |
○ describe commit e8849ae12c709f2321908879bc724fdb2ab8a781 |
| 1262 |
│ args: jj describe -m 'message 1' |
| 1263 |
○ add workspace 'default' |
| 1264 |
○ |
| 1265 |
[EOF] |
| 1266 |
"); |
| 1267 |
|
| 1268 |
// Test the setup: look at the commit graph (commit B is duplicated and commit E |
| 1269 |
// is duplicated) |
| 1270 |
insta::assert_snapshot!(get_long_log_output(&work_dir), @r" |
| 1271 |
@ b2 qpvuntsm/0 cca75b59 - description: message 2 |
| 1272 |
○ b3 qpvuntsm/1 4734557e - description: message 3 |
| 1273 |
◆ zzzzzzzz 00000000 |
| 1274 |
[EOF] |
| 1275 |
"); |
| 1276 |
|
| 1277 |
// Test the setup: look at the evolog |
| 1278 |
insta::assert_snapshot!(get_evolog(&work_dir, "b2"), @r" |
| 1279 |
@ qpvuntsm/0 cca75b59 (divergent) (empty) message 2 |
| 1280 |
○ qpvuntsm/2 59df0df7 (hidden) (empty) message 2 |
| 1281 |
○ qpvuntsm/3 a289638d (hidden) (empty) message 1 |
| 1282 |
○ qpvuntsm/4 e8849ae1 (hidden) (empty) (no description set) |
| 1283 |
[EOF] |
| 1284 |
"); |
| 1285 |
|
| 1286 |
// Test the setup: look at the evolog |
| 1287 |
insta::assert_snapshot!(get_evolog(&work_dir, "b3"), @r" |
| 1288 |
○ qpvuntsm/1 4734557e (divergent) (empty) message 3 |
| 1289 |
○ qpvuntsm/3 a289638d (hidden) (empty) message 1 |
| 1290 |
○ qpvuntsm/4 e8849ae1 (hidden) (empty) (no description set) |
| 1291 |
[EOF] |
| 1292 |
"); |
| 1293 |
|
| 1294 |
// Run `jj converge` command and check the output. In this case the user must |
| 1295 |
// merge the descriptions in a text editor. However, the parents are chosen |
| 1296 |
// automatically (b2 is ignored because it is a descendant of b3). |
| 1297 |
std::fs::write( |
| 1298 |
&edit_script, |
| 1299 |
["dump editor0", "write\nmy-merged-description"].join("\0"), |
| 1300 |
)?; |
| 1301 |
let output = work_dir |
| 1302 |
.run_jj_with(|cmd| force_interactive(cmd).args(["converge"]).write_stdin("y\n")) |
| 1303 |
.success(); |
| 1304 |
insta::assert_snapshot!( |
| 1305 |
std::fs::read_to_string(test_env.env_root().join("editor0"))?, @r#" |
| 1306 |
<<<<<<< conflict 1 of 1 |
| 1307 |
%%%%%%% diff from: qpvuntsm a289638d "message 1" |
| 1308 |
\\\\\\\ to: qpvuntsm cca75b59 "message 2" |
| 1309 |
-message 1 |
| 1310 |
+message 2 |
| 1311 |
+++++++ qpvuntsm 4734557e "message 3" |
| 1312 |
message 3 |
| 1313 |
>>>>>>> conflict 1 of 1 ends |
| 1314 |
"#); |
| 1315 |
insta::assert_snapshot!(output.stdout.normalized(), @""); |
| 1316 |
insta::assert_snapshot!(output.stderr.normalized(), @r" |
| 1317 |
Found 1 divergent change(s) in the specified revset: |
| 1318 |
- Change: qpvuntsmwlqt with 2 commits: |
| 1319 |
qpvuntsm/0 cca75b59 b2 | (divergent) (empty) message 2 |
| 1320 |
qpvuntsm/1 4734557e b3 | (divergent) (empty) message 3 |
| 1321 |
|
| 1322 |
Attempting to converge change qpvuntsmwlqt... |
| 1323 |
|
| 1324 |
There are divergent descriptions. You can choose to merge them now in a |
| 1325 |
text editor, or skip merging and use the conflicted description (with |
| 1326 |
conflict markers). Do you want to merge them now? (Yn): |
| 1327 |
|
| 1328 |
Successfully converged change: created commit ae6fe4a3240c. |
| 1329 |
Working copy (@) now at: qpvuntsm ae6fe4a3 b2 b3 | (empty) my-merged-description |
| 1330 |
Parent commit (@-) : zzzzzzzz 00000000 (empty) (no description set) |
| 1331 |
"); |
| 1332 |
|
| 1333 |
// Verify the commit graph after converge |
| 1334 |
insta::assert_snapshot!(get_long_log_output(&work_dir), @r" |
| 1335 |
@ b2 b3 qpvuntsm ae6fe4a3 - description: my-merged-des... |
| 1336 |
◆ zzzzzzzz 00000000 |
| 1337 |
[EOF] |
| 1338 |
"); |
| 1339 |
|
| 1340 |
// Verify the operation log after converge |
| 1341 |
insta::assert_snapshot!(get_op_log_output(&work_dir), @r" |
| 1342 |
@ converge qpvuntsmwlqt with 2 predecessors |
| 1343 |
│ args: jj converge |
| 1344 |
○ rebase commit 59df0df7968367d456d4438cc68ebe6a316ef8ce |
| 1345 |
│ args: jj rebase -r b2 -d b3 --keep-divergent |
| 1346 |
○ create bookmark b3 pointing to commit 4734557e78fe9ccdb827e03e71602c685bfe8b53 |
| 1347 |
│ args: jj bookmark create -r 'description(\'message 3*\')' b3 |
| 1348 |
○ create bookmark b2 pointing to commit 59df0df7968367d456d4438cc68ebe6a316ef8ce |
| 1349 |
│ args: jj bookmark create -r 'description(\'message 2*\')' b2 |
| 1350 |
○ reconcile divergent operations |
| 1351 |
├─╮ args: jj bookmark create -r 'description(\'message 2*\')' b2 |
| 1352 |
○ │ describe commit a289638d100c5af526559dfafb99f062631771c4 |
| 1353 |
│ │ args: jj describe -m 'message 2' |
| 1354 |
│ ○ describe commit a289638d100c5af526559dfafb99f062631771c4 |
| 1355 |
├─╯ args: jj describe -m 'message 3' --at-op @- |
| 1356 |
○ describe commit e8849ae12c709f2321908879bc724fdb2ab8a781 |
| 1357 |
│ args: jj describe -m 'message 1' |
| 1358 |
○ add workspace 'default' |
| 1359 |
○ |
| 1360 |
[EOF] |
| 1361 |
"); |
| 1362 |
|
| 1363 |
// Verify the evolution history after converge |
| 1364 |
insta::assert_snapshot!(get_evolog(&work_dir, "b2"), @r" |
| 1365 |
@ qpvuntsm ae6fe4a3 (empty) my-merged-description |
| 1366 |
├─╮ |
| 1367 |
│ ○ qpvuntsm/2 4734557e (hidden) (empty) message 3 |
| 1368 |
○ │ qpvuntsm/1 cca75b59 (hidden) (empty) message 2 |
| 1369 |
○ │ qpvuntsm/3 59df0df7 (hidden) (empty) message 2 |
| 1370 |
├─╯ |
| 1371 |
○ qpvuntsm/4 a289638d (hidden) (empty) message 1 |
| 1372 |
○ qpvuntsm/5 e8849ae1 (hidden) (empty) (no description set) |
| 1373 |
[EOF] |
| 1374 |
"); |
| 1375 |
|
| 1376 |
Ok(()) |
| 1377 |
} |
| 1378 |
|
| 1379 |
// Similar to |
| 1380 |
// test_converge_one_divergent_commit_is_a_descendant_of_another_divergent_commit, |
| 1381 |
// but with a few variations: |
| 1382 |
// * There is an related commit "in between" the two divergent commits |
| 1383 |
// * There are other unrelated commits |
| 1384 |
#[test] |
| 1385 |
fn test_converge_two_divergent_commits_with_unrelated_commit_in_between() -> TestResult { |
| 1386 |
let mut test_env = TestEnvironment::default(); |
| 1387 |
let edit_script = test_env.set_up_fake_editor(); |
| 1388 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 1389 |
let work_dir = test_env.work_dir("repo"); |
| 1390 |
|
| 1391 |
// Start by setting description to "message 1", then simulate two concurrent |
| 1392 |
// operations, one changing the description to "message 2" and the other |
| 1393 |
// changing it to "message 3" (--at-op=@- is what allows us to pretend these two |
| 1394 |
// operations happen concurrently). At this point we have two divergent commits. |
| 1395 |
// Then we set up bookmarks b2 and b3 to point to the commits. After that we |
| 1396 |
// create foo as a child of b3, then we rebase b2 onto foo. This sets the |
| 1397 |
// stage for this test's scenario. We create two other commits (bar and baz) |
| 1398 |
// to observe how descendants are rebased. |
| 1399 |
work_dir.run_jj(["describe", "-m", "message 1"]).success(); |
| 1400 |
work_dir.run_jj(["describe", "-m", "message 2"]).success(); |
| 1401 |
work_dir |
| 1402 |
.run_jj(["describe", "-m", "message 3", "--at-op", "@-"]) |
| 1403 |
.success(); |
| 1404 |
work_dir |
| 1405 |
.run_jj([ |
| 1406 |
"bookmark", |
| 1407 |
"create", |
| 1408 |
"-r", |
| 1409 |
"description('message 2*')", |
| 1410 |
"b2", |
| 1411 |
]) |
| 1412 |
.success(); |
| 1413 |
work_dir |
| 1414 |
.run_jj([ |
| 1415 |
"bookmark", |
| 1416 |
"create", |
| 1417 |
"-r", |
| 1418 |
"description('message 3*')", |
| 1419 |
"b3", |
| 1420 |
]) |
| 1421 |
.success(); |
| 1422 |
work_dir.run_jj(["new", "-r", "b3", "-m", "foo"]).success(); |
| 1423 |
work_dir |
| 1424 |
.run_jj(["rebase", "-r", "b2", "-d", "@", "--keep-divergent"]) |
| 1425 |
.success(); |
| 1426 |
work_dir.run_jj(["new", "-r", "b2", "-m", "bar"]).success(); |
| 1427 |
work_dir.run_jj(["new", "-r", "b3", "-m", "baz"]).success(); |
| 1428 |
|
| 1429 |
// Test the setup: look at the operation log. |
| 1430 |
insta::assert_snapshot!(get_op_log_output(&work_dir), @r" |
| 1431 |
@ new empty commit |
| 1432 |
│ args: jj new -r b3 -m baz |
| 1433 |
○ new empty commit |
| 1434 |
│ args: jj new -r b2 -m bar |
| 1435 |
○ rebase commit 59df0df7968367d456d4438cc68ebe6a316ef8ce |
| 1436 |
│ args: jj rebase -r b2 -d @ --keep-divergent |
| 1437 |
○ new empty commit |
| 1438 |
│ args: jj new -r b3 -m foo |
| 1439 |
○ create bookmark b3 pointing to commit 4734557e78fe9ccdb827e03e71602c685bfe8b53 |
| 1440 |
│ args: jj bookmark create -r 'description(\'message 3*\')' b3 |
| 1441 |
○ create bookmark b2 pointing to commit 59df0df7968367d456d4438cc68ebe6a316ef8ce |
| 1442 |
│ args: jj bookmark create -r 'description(\'message 2*\')' b2 |
| 1443 |
○ reconcile divergent operations |
| 1444 |
├─╮ args: jj bookmark create -r 'description(\'message 2*\')' b2 |
| 1445 |
○ │ describe commit a289638d100c5af526559dfafb99f062631771c4 |
| 1446 |
│ │ args: jj describe -m 'message 2' |
| 1447 |
│ ○ describe commit a289638d100c5af526559dfafb99f062631771c4 |
| 1448 |
├─╯ args: jj describe -m 'message 3' --at-op @- |
| 1449 |
○ describe commit e8849ae12c709f2321908879bc724fdb2ab8a781 |
| 1450 |
│ args: jj describe -m 'message 1' |
| 1451 |
○ add workspace 'default' |
| 1452 |
○ |
| 1453 |
[EOF] |
| 1454 |
"); |
| 1455 |
|
| 1456 |
// Test the setup: look at the commit graph (commit B is duplicated and commit E |
| 1457 |
// is duplicated) |
| 1458 |
insta::assert_snapshot!(get_long_log_output(&work_dir), @r" |
| 1459 |
@ znkkpsqq aac9c864 - description: baz |
| 1460 |
│ ○ yostqsxw 38a29791 - description: bar |
| 1461 |
│ ○ b2 qpvuntsm/0 2a258b0d - description: message 2 |
| 1462 |
│ ○ yqosqzyt f658f253 - description: foo |
| 1463 |
├─╯ |
| 1464 |
○ b3 qpvuntsm/1 4734557e - description: message 3 |
| 1465 |
◆ zzzzzzzz 00000000 |
| 1466 |
[EOF] |
| 1467 |
"); |
| 1468 |
|
| 1469 |
// Test the setup: look at the evolog |
| 1470 |
insta::assert_snapshot!(get_evolog(&work_dir, "b2"), @r" |
| 1471 |
○ qpvuntsm/0 2a258b0d (divergent) (empty) message 2 |
| 1472 |
○ qpvuntsm/2 59df0df7 (hidden) (empty) message 2 |
| 1473 |
○ qpvuntsm/3 a289638d (hidden) (empty) message 1 |
| 1474 |
○ qpvuntsm/4 e8849ae1 (hidden) (empty) (no description set) |
| 1475 |
[EOF] |
| 1476 |
"); |
| 1477 |
|
| 1478 |
// Test the setup: look at the evolog |
| 1479 |
insta::assert_snapshot!(get_evolog(&work_dir, "b3"), @r" |
| 1480 |
○ qpvuntsm/1 4734557e (divergent) (empty) message 3 |
| 1481 |
○ qpvuntsm/3 a289638d (hidden) (empty) message 1 |
| 1482 |
○ qpvuntsm/4 e8849ae1 (hidden) (empty) (no description set) |
| 1483 |
[EOF] |
| 1484 |
"); |
| 1485 |
|
| 1486 |
// Run `jj converge` command and check the output. In this case the user must |
| 1487 |
// merge the descriptions in a text editor. However, the parents are chosen |
| 1488 |
// automatically (b2 is ignored because it is a descendant of b3). |
| 1489 |
std::fs::write( |
| 1490 |
&edit_script, |
| 1491 |
["dump editor0", "write\nmy-merged-description"].join("\0"), |
| 1492 |
)?; |
| 1493 |
let output = work_dir |
| 1494 |
.run_jj_with(|cmd| force_interactive(cmd).args(["converge"]).write_stdin("y\n")) |
| 1495 |
.success(); |
| 1496 |
insta::assert_snapshot!( |
| 1497 |
std::fs::read_to_string(test_env.env_root().join("editor0"))?, @r#" |
| 1498 |
<<<<<<< conflict 1 of 1 |
| 1499 |
%%%%%%% diff from: qpvuntsm a289638d "message 1" |
| 1500 |
\\\\\\\ to: qpvuntsm 2a258b0d "message 2" |
| 1501 |
-message 1 |
| 1502 |
+message 2 |
| 1503 |
+++++++ qpvuntsm 4734557e "message 3" |
| 1504 |
message 3 |
| 1505 |
>>>>>>> conflict 1 of 1 ends |
| 1506 |
"#); |
| 1507 |
insta::assert_snapshot!(output.stdout.normalized(), @""); |
| 1508 |
insta::assert_snapshot!(output.stderr.normalized(), @r" |
| 1509 |
Found 1 divergent change(s) in the specified revset: |
| 1510 |
- Change: qpvuntsmwlqt with 2 commits: |
| 1511 |
qpvuntsm/0 2a258b0d b2 | (divergent) (empty) message 2 |
| 1512 |
qpvuntsm/1 4734557e b3 | (divergent) (empty) message 3 |
| 1513 |
|
| 1514 |
Attempting to converge change qpvuntsmwlqt... |
| 1515 |
|
| 1516 |
There are divergent descriptions. You can choose to merge them now in a |
| 1517 |
text editor, or skip merging and use the conflicted description (with |
| 1518 |
conflict markers). Do you want to merge them now? (Yn): |
| 1519 |
|
| 1520 |
Successfully converged change: created commit 605808281071. |
| 1521 |
Rebased 3 descendants |
| 1522 |
Working copy (@) now at: znkkpsqq 3ea044e0 (empty) baz |
| 1523 |
Parent commit (@-) : qpvuntsm 60580828 b2 b3 | (empty) my-merged-description |
| 1524 |
"); |
| 1525 |
|
| 1526 |
insta::assert_snapshot!(work_dir.run_jj(["op", "show"]).success(), @r" |
| 1527 |
23ae9388893c [email protected] default@ 2001-02-03 04:05:21.000 +07:00 - 2001-02-03 04:05:21.000 +07:00 |
| 1528 |
converge qpvuntsmwlqt with 2 predecessors |
| 1529 |
args: jj converge |
| 1530 |
|
| 1531 |
Changed commits: |
| 1532 |
○ + znkkpsqq 3ea044e0 (empty) baz |
| 1533 |
│ - znkkpsqq/1 aac9c864 (hidden) (empty) baz |
| 1534 |
│ ○ + yostqsxw a4dd040e (empty) bar |
| 1535 |
├─╯ - yostqsxw/1 38a29791 (hidden) (empty) bar |
| 1536 |
│ ○ + yqosqzyt e85707a5 (empty) foo |
| 1537 |
├─╯ - yqosqzyt/1 f658f253 (hidden) (empty) foo |
| 1538 |
○ + qpvuntsm 60580828 b2 b3 | (empty) my-merged-description |
| 1539 |
- qpvuntsm/1 2a258b0d (hidden) (empty) message 2 |
| 1540 |
- qpvuntsm/2 4734557e (hidden) (empty) message 3 |
| 1541 |
|
| 1542 |
Changed working copy default@: |
| 1543 |
+ znkkpsqq 3ea044e0 (empty) baz |
| 1544 |
- znkkpsqq/1 aac9c864 (hidden) (empty) baz |
| 1545 |
|
| 1546 |
Changed local bookmarks: |
| 1547 |
b2: |
| 1548 |
+ qpvuntsm 60580828 b2 b3 | (empty) my-merged-description |
| 1549 |
- qpvuntsm/1 2a258b0d (hidden) (empty) message 2 |
| 1550 |
b3: |
| 1551 |
+ qpvuntsm 60580828 b2 b3 | (empty) my-merged-description |
| 1552 |
- qpvuntsm/2 4734557e (hidden) (empty) message 3 |
| 1553 |
[EOF] |
| 1554 |
"); |
| 1555 |
|
| 1556 |
// Verify the commit graph after converge; notice the commit that was |
| 1557 |
// "sandwiched" between b2 and b3 (foo) is now a child of the solution commit. |
| 1558 |
insta::assert_snapshot!(get_long_log_output(&work_dir), @r" |
| 1559 |
@ znkkpsqq 3ea044e0 - description: baz |
| 1560 |
│ ○ yostqsxw a4dd040e - description: bar |
| 1561 |
├─╯ |
| 1562 |
│ ○ yqosqzyt e85707a5 - description: foo |
| 1563 |
├─╯ |
| 1564 |
○ b2 b3 qpvuntsm 60580828 - description: my-merged-des... |
| 1565 |
◆ zzzzzzzz 00000000 |
| 1566 |
[EOF] |
| 1567 |
"); |
| 1568 |
|
| 1569 |
// Verify the operation log after converge |
| 1570 |
insta::assert_snapshot!(get_op_log_output(&work_dir), @r" |
| 1571 |
@ converge qpvuntsmwlqt with 2 predecessors |
| 1572 |
│ args: jj converge |
| 1573 |
○ new empty commit |
| 1574 |
│ args: jj new -r b3 -m baz |
| 1575 |
○ new empty commit |
| 1576 |
│ args: jj new -r b2 -m bar |
| 1577 |
○ rebase commit 59df0df7968367d456d4438cc68ebe6a316ef8ce |
| 1578 |
│ args: jj rebase -r b2 -d @ --keep-divergent |
| 1579 |
○ new empty commit |
| 1580 |
│ args: jj new -r b3 -m foo |
| 1581 |
○ create bookmark b3 pointing to commit 4734557e78fe9ccdb827e03e71602c685bfe8b53 |
| 1582 |
│ args: jj bookmark create -r 'description(\'message 3*\')' b3 |
| 1583 |
○ create bookmark b2 pointing to commit 59df0df7968367d456d4438cc68ebe6a316ef8ce |
| 1584 |
│ args: jj bookmark create -r 'description(\'message 2*\')' b2 |
| 1585 |
○ reconcile divergent operations |
| 1586 |
├─╮ args: jj bookmark create -r 'description(\'message 2*\')' b2 |
| 1587 |
○ │ describe commit a289638d100c5af526559dfafb99f062631771c4 |
| 1588 |
│ │ args: jj describe -m 'message 2' |
| 1589 |
│ ○ describe commit a289638d100c5af526559dfafb99f062631771c4 |
| 1590 |
├─╯ args: jj describe -m 'message 3' --at-op @- |
| 1591 |
○ describe commit e8849ae12c709f2321908879bc724fdb2ab8a781 |
| 1592 |
│ args: jj describe -m 'message 1' |
| 1593 |
○ add workspace 'default' |
| 1594 |
○ |
| 1595 |
[EOF] |
| 1596 |
"); |
| 1597 |
|
| 1598 |
// Verify the evolution history after converge |
| 1599 |
insta::assert_snapshot!(get_evolog(&work_dir, "b2"), @r" |
| 1600 |
○ qpvuntsm 60580828 (empty) my-merged-description |
| 1601 |
├─╮ |
| 1602 |
│ ○ qpvuntsm/2 4734557e (hidden) (empty) message 3 |
| 1603 |
○ │ qpvuntsm/1 2a258b0d (hidden) (empty) message 2 |
| 1604 |
○ │ qpvuntsm/3 59df0df7 (hidden) (empty) message 2 |
| 1605 |
├─╯ |
| 1606 |
○ qpvuntsm/4 a289638d (hidden) (empty) message 1 |
| 1607 |
○ qpvuntsm/5 e8849ae1 (hidden) (empty) (no description set) |
| 1608 |
[EOF] |
| 1609 |
"); |
| 1610 |
|
| 1611 |
Ok(()) |
| 1612 |
} |
| 1613 |
|
| 1614 |
#[must_use] |
| 1615 |
fn get_long_log_output(work_dir: &TestWorkDir) -> CommandOutput { |
| 1616 |
let template = "bookmarks ++ ' ' ++ format_short_change_id_with_change_offset(self) ++ ' ' \ |
| 1617 |
++ commit_id.shortest(8) ++ surround(' - description: ', '', truncate_end(16, \ |
| 1618 |
description.first_line(), '...'))"; |
| 1619 |
work_dir.run_jj(["log", "-T", template]) |
| 1620 |
} |
| 1621 |
|
| 1622 |
#[must_use] |
| 1623 |
fn get_op_log_output(work_dir: &TestWorkDir) -> CommandOutput { |
| 1624 |
work_dir.run_jj(["op", "log", "-T", "description ++ '\n' ++ attributes"]) |
| 1625 |
} |
| 1626 |
|
| 1627 |
#[must_use] |
| 1628 |
fn get_evolog<S: AsRef<str>>(work_dir: &TestWorkDir, revision: S) -> CommandOutput { |
| 1629 |
let template = "format_commit_summary_with_refs(commit, '')"; |
| 1630 |
work_dir.run_jj(["evolog", "-r", revision.as_ref(), "-T", template]) |
| 1631 |
} |