2022-11-26 23:57:50 +00:00
// Copyright 2022 The Jujutsu Authors
2022-04-13 13:43:54 +00:00
//
// 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 std ::path ::Path ;
use crate ::common ::TestEnvironment ;
fn create_commit ( test_env : & TestEnvironment , repo_path : & Path , name : & str , parents : & [ & str ] ) {
if parents . is_empty ( ) {
2023-10-10 11:59:18 +00:00
test_env . jj_cmd_ok ( repo_path , & [ " new " , " root() " , " -m " , name ] ) ;
2022-04-13 13:43:54 +00:00
} else {
2022-08-31 05:39:32 +00:00
let mut args = vec! [ " new " , " -m " , name ] ;
2022-04-13 13:43:54 +00:00
args . extend ( parents ) ;
2023-10-10 11:59:18 +00:00
test_env . jj_cmd_ok ( repo_path , & args ) ;
2022-04-13 13:43:54 +00:00
}
2022-11-04 04:14:41 +00:00
std ::fs ::write ( repo_path . join ( name ) , format! ( " {name} \n " ) ) . unwrap ( ) ;
2024-08-21 19:59:15 +00:00
test_env . jj_cmd_ok ( repo_path , & [ " bookmark " , " create " , name ] ) ;
2022-04-13 13:43:54 +00:00
}
#[ test ]
fn test_rebase_invalid ( ) {
let test_env = TestEnvironment ::default ( ) ;
2024-05-17 19:49:25 +00:00
test_env . jj_cmd_ok ( test_env . env_root ( ) , & [ " git " , " init " , " repo " ] ) ;
2022-04-13 13:43:54 +00:00
let repo_path = test_env . env_root ( ) . join ( " repo " ) ;
create_commit ( & test_env , & repo_path , " a " , & [ ] ) ;
create_commit ( & test_env , & repo_path , " b " , & [ " a " ] ) ;
// Missing destination
2022-11-18 20:50:39 +00:00
let stderr = test_env . jj_cmd_cli_error ( & repo_path , & [ " rebase " ] ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
2023-03-17 23:14:20 +00:00
error : the following required arguments were not provided :
2024-03-29 13:32:55 +00:00
< - - destination < DESTINATION > | - - insert - after < INSERT_AFTER > | - - insert - before < INSERT_BEFORE > >
2022-11-18 20:50:39 +00:00
2024-03-29 13:32:55 +00:00
Usage : jj rebase < - - destination < DESTINATION > | - - insert - after < INSERT_AFTER > | - - insert - before < INSERT_BEFORE > >
2022-11-18 20:50:39 +00:00
2023-03-17 23:14:20 +00:00
For more information , try ' - - help ' .
2022-11-18 20:50:39 +00:00
" ###);
2022-04-13 13:43:54 +00:00
// Both -r and -s
2022-11-18 20:50:39 +00:00
let stderr =
test_env . jj_cmd_cli_error ( & repo_path , & [ " rebase " , " -r " , " a " , " -s " , " a " , " -d " , " b " ] ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
2024-04-23 14:47:55 +00:00
error : the argument ' - - revisions < REVISIONS > ' cannot be used with ' - - source < SOURCE > '
2022-11-18 20:50:39 +00:00
2024-03-29 13:32:55 +00:00
Usage : jj rebase - - revisions < REVISIONS > < - - destination < DESTINATION > | - - insert - after < INSERT_AFTER > | - - insert - before < INSERT_BEFORE > >
2022-11-18 20:50:39 +00:00
2023-03-17 23:14:20 +00:00
For more information , try ' - - help ' .
2022-11-18 20:50:39 +00:00
" ###);
2022-04-13 13:43:54 +00:00
2022-04-13 17:53:50 +00:00
// Both -b and -s
2022-11-18 20:50:39 +00:00
let stderr =
test_env . jj_cmd_cli_error ( & repo_path , & [ " rebase " , " -b " , " a " , " -s " , " a " , " -d " , " b " ] ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
2023-03-17 23:14:20 +00:00
error : the argument ' - - branch < BRANCH > ' cannot be used with ' - - source < SOURCE > '
2022-11-18 20:50:39 +00:00
2024-03-29 13:32:55 +00:00
Usage : jj rebase - - branch < BRANCH > < - - destination < DESTINATION > | - - insert - after < INSERT_AFTER > | - - insert - before < INSERT_BEFORE > >
2022-11-18 20:50:39 +00:00
2023-03-17 23:14:20 +00:00
For more information , try ' - - help ' .
2022-11-18 20:50:39 +00:00
" ###);
2022-04-13 17:53:50 +00:00
2024-03-29 13:32:55 +00:00
// Both -d and --after
let stderr = test_env . jj_cmd_cli_error (
& repo_path ,
& [ " rebase " , " -r " , " a " , " -d " , " b " , " --after " , " b " ] ,
) ;
insta ::assert_snapshot! ( stderr , @ r ###"
error : the argument ' - - destination < DESTINATION > ' cannot be used with ' - - insert - after < INSERT_AFTER > '
Usage : jj rebase - - revisions < REVISIONS > < - - destination < DESTINATION > | - - insert - after < INSERT_AFTER > | - - insert - before < INSERT_BEFORE > >
For more information , try ' - - help ' .
" ###);
// Both -d and --before
let stderr = test_env . jj_cmd_cli_error (
& repo_path ,
& [ " rebase " , " -r " , " a " , " -d " , " b " , " --before " , " b " ] ,
) ;
insta ::assert_snapshot! ( stderr , @ r ###"
error : the argument ' - - destination < DESTINATION > ' cannot be used with ' - - insert - before < INSERT_BEFORE > '
Usage : jj rebase - - revisions < REVISIONS > < - - destination < DESTINATION > | - - insert - after < INSERT_AFTER > | - - insert - before < INSERT_BEFORE > >
For more information , try ' - - help ' .
" ###);
2023-10-28 02:29:13 +00:00
// Rebase onto self with -r
let stderr = test_env . jj_cmd_failure ( & repo_path , & [ " rebase " , " -r " , " a " , " -d " , " a " ] ) ;
2022-04-28 23:32:18 +00:00
insta ::assert_snapshot! ( stderr , @ r ###"
2023-10-28 02:29:13 +00:00
Error : Cannot rebase 2443 ea76b0b1 onto itself
" ###);
// Rebase root with -r
let stderr = test_env . jj_cmd_failure ( & repo_path , & [ " rebase " , " -r " , " root() " , " -d " , " a " ] ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
Error : The root commit 000000000000 is immutable
2022-04-28 23:32:18 +00:00
" ###);
2022-04-13 13:43:54 +00:00
// Rebase onto descendant with -s
let stderr = test_env . jj_cmd_failure ( & repo_path , & [ " rebase " , " -s " , " a " , " -d " , " b " ] ) ;
2022-04-28 23:32:18 +00:00
insta ::assert_snapshot! ( stderr , @ r ###"
2022-12-21 04:47:10 +00:00
Error : Cannot rebase 2443 ea76b0b1 onto descendant 1394 f625cbbd
2022-04-28 23:32:18 +00:00
" ###);
2022-04-13 13:43:54 +00:00
}
2022-04-13 17:53:50 +00:00
#[ test ]
2024-08-21 19:59:15 +00:00
fn test_rebase_bookmark ( ) {
2022-04-13 17:53:50 +00:00
let test_env = TestEnvironment ::default ( ) ;
2024-05-17 19:49:25 +00:00
test_env . jj_cmd_ok ( test_env . env_root ( ) , & [ " git " , " init " , " repo " ] ) ;
2022-04-13 17:53:50 +00:00
let repo_path = test_env . env_root ( ) . join ( " repo " ) ;
create_commit ( & test_env , & repo_path , " a " , & [ ] ) ;
create_commit ( & test_env , & repo_path , " b " , & [ " a " ] ) ;
create_commit ( & test_env , & repo_path , " c " , & [ " b " ] ) ;
create_commit ( & test_env , & repo_path , " d " , & [ " b " ] ) ;
create_commit ( & test_env , & repo_path , " e " , & [ " a " ] ) ;
// Test the setup
2022-05-29 23:46:47 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ e : a
│ ○ d : b
│ │ ○ c : b
2023-02-09 02:53:47 +00:00
│ ├ ─ ╯
2024-08-17 08:03:00 +00:00
│ ○ b : a
2023-02-09 02:53:47 +00:00
├ ─ ╯
2024-07-15 22:20:10 +00:00
○ a
◆
2022-04-13 17:53:50 +00:00
" ###);
2023-10-10 11:59:18 +00:00
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -b " , " c " , " -d " , " e " ] ) ;
2023-10-10 11:07:06 +00:00
insta ::assert_snapshot! ( stdout , @ " " ) ;
2024-11-11 12:43:52 +00:00
insta ::assert_snapshot! ( stderr , @ " Rebased 3 commits onto destination " ) ;
2022-05-29 23:46:47 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
○ d : b
│ ○ c : b
2023-02-09 02:53:47 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ b : e
@ e : a
2024-07-15 22:20:10 +00:00
○ a
◆
2022-04-13 17:53:50 +00:00
" ###);
2023-02-19 03:31:48 +00:00
2024-08-21 19:59:15 +00:00
// Test rebasing multiple bookmarks at once
2023-10-10 11:59:18 +00:00
test_env . jj_cmd_ok ( & repo_path , & [ " undo " ] ) ;
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -b=e " , " -b=d " , " -d=b " ] ) ;
2023-10-10 11:07:06 +00:00
insta ::assert_snapshot! ( stdout , @ " " ) ;
2024-11-11 12:43:52 +00:00
insta ::assert_snapshot! ( stderr , @ r #"
2024-04-29 07:45:33 +00:00
Skipped rebase of 1 commits that were already in place
2024-11-11 12:43:52 +00:00
Rebased 1 commits onto destination
2023-08-08 03:11:59 +00:00
Working copy now at : znkkpsqq 9 ca2a154 e | e
Parent commit : zsuskuln 1394 f625 b | b
2023-02-19 03:31:48 +00:00
Added 1 files , modified 0 files , removed 0 files
2024-11-11 12:43:52 +00:00
" #);
2023-02-19 03:31:48 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ e : b
│ ○ d : b
2023-02-19 03:31:48 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
│ ○ c : b
2023-02-19 03:31:48 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ b : a
2024-07-15 22:20:10 +00:00
○ a
◆
2023-02-19 03:31:48 +00:00
" ###);
2023-07-25 17:17:36 +00:00
// Same test but with more than one revision per argument
2023-10-10 11:59:18 +00:00
test_env . jj_cmd_ok ( & repo_path , & [ " undo " ] ) ;
2023-07-25 17:17:36 +00:00
let stderr = test_env . jj_cmd_failure ( & repo_path , & [ " rebase " , " -b=e|d " , " -d=b " ] ) ;
2023-02-19 03:31:48 +00:00
insta ::assert_snapshot! ( stderr , @ r ###"
Error : Revset " e|d " resolved to more than one revision
Hint : The revset " e|d " resolved to these revisions :
2024-03-24 07:42:04 +00:00
znkkpsqq e52756c8 e | e
vruxwmqv 514 fa6b2 d | d
2024-03-23 06:15:58 +00:00
Hint : Prefix the expression with ' all :' to allow any number of revisions ( i . e . ' all :e | d ' ) .
2023-02-19 03:31:48 +00:00
" ###);
2023-10-10 11:59:18 +00:00
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -b=all:e|d " , " -d=b " ] ) ;
2023-10-10 11:07:06 +00:00
insta ::assert_snapshot! ( stdout , @ " " ) ;
2024-11-11 12:43:52 +00:00
insta ::assert_snapshot! ( stderr , @ r #"
2024-04-29 07:45:33 +00:00
Skipped rebase of 1 commits that were already in place
2024-11-11 12:43:52 +00:00
Rebased 1 commits onto destination
2023-08-08 03:11:59 +00:00
Working copy now at : znkkpsqq 817e3 fb0 e | e
Parent commit : zsuskuln 1394 f625 b | b
2023-02-19 03:31:48 +00:00
Added 1 files , modified 0 files , removed 0 files
2024-11-11 12:43:52 +00:00
" #);
2023-02-19 03:31:48 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ e : b
│ ○ d : b
2023-02-19 03:31:48 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
│ ○ c : b
2023-02-19 03:31:48 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ b : a
2024-07-15 22:20:10 +00:00
○ a
◆
2023-02-19 03:31:48 +00:00
" ###);
2022-04-13 17:53:50 +00:00
}
#[ test ]
2024-08-21 19:59:15 +00:00
fn test_rebase_bookmark_with_merge ( ) {
2022-04-13 17:53:50 +00:00
let test_env = TestEnvironment ::default ( ) ;
2024-05-17 19:49:25 +00:00
test_env . jj_cmd_ok ( test_env . env_root ( ) , & [ " git " , " init " , " repo " ] ) ;
2022-04-13 17:53:50 +00:00
let repo_path = test_env . env_root ( ) . join ( " repo " ) ;
create_commit ( & test_env , & repo_path , " a " , & [ ] ) ;
create_commit ( & test_env , & repo_path , " b " , & [ " a " ] ) ;
create_commit ( & test_env , & repo_path , " c " , & [ ] ) ;
create_commit ( & test_env , & repo_path , " d " , & [ " c " ] ) ;
create_commit ( & test_env , & repo_path , " e " , & [ " a " , " d " ] ) ;
// Test the setup
2022-05-29 23:46:47 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ e : a d
2023-02-09 02:53:47 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ d : c
2024-07-15 22:20:10 +00:00
│ ○ c
2024-08-17 08:03:00 +00:00
│ │ ○ b : a
2023-07-28 06:51:08 +00:00
├ ─ ─ ─ ╯
2024-07-15 22:20:10 +00:00
○ │ a
2023-02-09 02:53:47 +00:00
├ ─ ╯
2024-07-15 22:20:10 +00:00
◆
2022-04-13 17:53:50 +00:00
" ###);
2023-10-10 11:59:18 +00:00
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -b " , " d " , " -d " , " b " ] ) ;
2023-10-10 11:07:06 +00:00
insta ::assert_snapshot! ( stdout , @ " " ) ;
2024-11-11 12:43:52 +00:00
insta ::assert_snapshot! ( stderr , @ r #"
Rebased 3 commits onto destination
2024-01-29 06:49:35 +00:00
Working copy now at : znkkpsqq 5 f8a3db2 e | e
Parent commit : rlvkpnrz 2443 ea76 a | a
2023-08-08 03:11:59 +00:00
Parent commit : vruxwmqv 1677 f795 d | d
2022-04-13 17:53:50 +00:00
Added 1 files , modified 0 files , removed 0 files
2024-11-11 12:43:52 +00:00
" #);
2022-05-29 23:46:47 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ e : a d
2024-01-29 06:49:35 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ d : c
│ ○ c : b
│ ○ b : a
2024-01-29 06:49:35 +00:00
├ ─ ╯
2024-07-15 22:20:10 +00:00
○ a
◆
2022-04-13 17:53:50 +00:00
" ###);
2023-10-10 11:59:18 +00:00
test_env . jj_cmd_ok ( & repo_path , & [ " undo " ] ) ;
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -d " , " b " ] ) ;
2023-10-10 11:07:06 +00:00
insta ::assert_snapshot! ( stdout , @ " " ) ;
2024-11-11 12:43:52 +00:00
insta ::assert_snapshot! ( stderr , @ r #"
Rebased 3 commits onto destination
2024-01-29 06:49:35 +00:00
Working copy now at : znkkpsqq a331ac11 e | e
Parent commit : rlvkpnrz 2443 ea76 a | a
2023-08-08 03:11:59 +00:00
Parent commit : vruxwmqv 3 d0f3644 d | d
2022-04-13 17:53:50 +00:00
Added 1 files , modified 0 files , removed 0 files
2024-11-11 12:43:52 +00:00
" #);
2022-05-29 23:46:47 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ e : a d
2024-01-29 06:49:35 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ d : c
│ ○ c : b
│ ○ b : a
2024-01-29 06:49:35 +00:00
├ ─ ╯
2024-07-15 22:20:10 +00:00
○ a
◆
2022-04-13 17:53:50 +00:00
" ###);
}
2022-04-13 13:43:54 +00:00
#[ test ]
fn test_rebase_single_revision ( ) {
let test_env = TestEnvironment ::default ( ) ;
2024-05-17 19:49:25 +00:00
test_env . jj_cmd_ok ( test_env . env_root ( ) , & [ " git " , " init " , " repo " ] ) ;
2022-04-13 13:43:54 +00:00
let repo_path = test_env . env_root ( ) . join ( " repo " ) ;
create_commit ( & test_env , & repo_path , " a " , & [ ] ) ;
2024-04-21 15:29:09 +00:00
create_commit ( & test_env , & repo_path , " b " , & [ " a " ] ) ;
create_commit ( & test_env , & repo_path , " c " , & [ " a " ] ) ;
create_commit ( & test_env , & repo_path , " d " , & [ " b " , " c " ] ) ;
create_commit ( & test_env , & repo_path , " e " , & [ " d " ] ) ;
2022-04-13 13:43:54 +00:00
// Test the setup
2022-05-29 23:46:47 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ e : d
○ d : b c
2023-02-09 02:53:47 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ c : a
○ │ b : a
2023-02-09 02:53:47 +00:00
├ ─ ╯
2024-07-15 22:20:10 +00:00
○ a
◆
2022-04-13 13:43:54 +00:00
" ###);
2024-04-21 15:29:09 +00:00
// Descendants of the rebased commit "c" should be rebased onto parents. First
2024-04-21 15:29:09 +00:00
// we test with a non-merge commit.
2024-04-21 15:29:09 +00:00
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -r " , " c " , " -d " , " b " ] ) ;
2023-10-10 11:07:06 +00:00
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
2024-04-23 14:47:55 +00:00
Rebased 1 commits onto destination
2024-03-29 13:32:55 +00:00
Rebased 2 descendant commits
2024-04-21 15:29:09 +00:00
Working copy now at : znkkpsqq 2668 ffbe e | e
Parent commit : vruxwmqv 7 b370c85 d | d
Fix `rebase -r` of a parent of a merge commit
Previously, using `rebase -r` on the parent of a merge commit
turned it into a non-merge commit. In other words, starting
with
```
o d
|\
o | c
o | b
| o a
|/
o
```
and doing `rebase -r c -d a` resulted in
```
o d
o b
| o c
| o a
|/
o
```
where `d` is no longer a merge commit.
For reference, here's a complete test that passed before this commit (but should NOT pass; see the diff for a test that should pass):
```
#[test]
fn test_rebase_single_revision_merge_parent() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
create_commit(&test_env, &repo_path, "a", &[]);
create_commit(&test_env, &repo_path, "b", &[]);
create_commit(&test_env, &repo_path, "c", &["b"]);
create_commit(&test_env, &repo_path, "d", &["a", "c"]);
// Test the setup
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@
o d
|\
o | c
o | b
| o a
|/
o
"###);
let stdout = test_env.jj_cmd_success(&repo_path, &["rebase", "-r", "c", "-d", "a"]);
insta::assert_snapshot!(stdout, @r###"
Also rebased 2 descendant commits onto parent of rebased commit
Working copy now at: 3e176b54d680 (no description set)
Added 0 files, modified 0 files, removed 2 files
"###);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@
o d
| o c
o | b
| o a
|/
o
"###);
}
```
2022-09-11 21:23:46 +00:00
Added 0 files , modified 0 files , removed 1 files
2022-04-13 17:53:50 +00:00
" ###);
2022-05-29 23:46:47 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ e : d
○ d : b a
2024-03-29 13:32:55 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ │ ○ c : b
2024-03-29 13:32:55 +00:00
├ ─ ─ ─ ╯
2024-08-17 08:03:00 +00:00
○ │ b : a
2023-02-09 02:53:47 +00:00
├ ─ ╯
2024-07-15 22:20:10 +00:00
○ a
◆
2022-04-13 13:43:54 +00:00
" ###);
2023-10-10 11:59:18 +00:00
test_env . jj_cmd_ok ( & repo_path , & [ " undo " ] ) ;
Fix `rebase -r` of a parent of a merge commit
Previously, using `rebase -r` on the parent of a merge commit
turned it into a non-merge commit. In other words, starting
with
```
o d
|\
o | c
o | b
| o a
|/
o
```
and doing `rebase -r c -d a` resulted in
```
o d
o b
| o c
| o a
|/
o
```
where `d` is no longer a merge commit.
For reference, here's a complete test that passed before this commit (but should NOT pass; see the diff for a test that should pass):
```
#[test]
fn test_rebase_single_revision_merge_parent() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
create_commit(&test_env, &repo_path, "a", &[]);
create_commit(&test_env, &repo_path, "b", &[]);
create_commit(&test_env, &repo_path, "c", &["b"]);
create_commit(&test_env, &repo_path, "d", &["a", "c"]);
// Test the setup
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@
o d
|\
o | c
o | b
| o a
|/
o
"###);
let stdout = test_env.jj_cmd_success(&repo_path, &["rebase", "-r", "c", "-d", "a"]);
insta::assert_snapshot!(stdout, @r###"
Also rebased 2 descendant commits onto parent of rebased commit
Working copy now at: 3e176b54d680 (no description set)
Added 0 files, modified 0 files, removed 2 files
"###);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@
o d
| o c
o | b
| o a
|/
o
"###);
}
```
2022-09-11 21:23:46 +00:00
2024-04-21 15:29:09 +00:00
// Now, let's try moving the merge commit. After, both parents of "d" ("b" and
// "c") should become parents of "e".
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -r " , " d " , " -d " , " a " ] ) ;
2023-10-10 11:07:06 +00:00
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
2024-04-23 14:47:55 +00:00
Rebased 1 commits onto destination
2024-03-29 13:32:55 +00:00
Rebased 1 descendant commits
2024-04-21 15:29:09 +00:00
Working copy now at : znkkpsqq ed210c15 e | e
Parent commit : zsuskuln 1394 f625 b | b
Parent commit : royxmykx c0cb3a0b c | c
2022-04-13 17:53:50 +00:00
Added 0 files , modified 0 files , removed 1 files
" ###);
2022-05-29 23:46:47 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ e : b c
2024-03-29 13:32:55 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ c : a
○ │ b : a
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
│ ○ d : a
2023-02-09 02:53:47 +00:00
├ ─ ╯
2024-07-15 22:20:10 +00:00
○ a
◆
2022-04-13 13:43:54 +00:00
" ###);
}
Fix `rebase -r` of a parent of a merge commit
Previously, using `rebase -r` on the parent of a merge commit
turned it into a non-merge commit. In other words, starting
with
```
o d
|\
o | c
o | b
| o a
|/
o
```
and doing `rebase -r c -d a` resulted in
```
o d
o b
| o c
| o a
|/
o
```
where `d` is no longer a merge commit.
For reference, here's a complete test that passed before this commit (but should NOT pass; see the diff for a test that should pass):
```
#[test]
fn test_rebase_single_revision_merge_parent() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
create_commit(&test_env, &repo_path, "a", &[]);
create_commit(&test_env, &repo_path, "b", &[]);
create_commit(&test_env, &repo_path, "c", &["b"]);
create_commit(&test_env, &repo_path, "d", &["a", "c"]);
// Test the setup
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@
o d
|\
o | c
o | b
| o a
|/
o
"###);
let stdout = test_env.jj_cmd_success(&repo_path, &["rebase", "-r", "c", "-d", "a"]);
insta::assert_snapshot!(stdout, @r###"
Also rebased 2 descendant commits onto parent of rebased commit
Working copy now at: 3e176b54d680 (no description set)
Added 0 files, modified 0 files, removed 2 files
"###);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@
o d
| o c
o | b
| o a
|/
o
"###);
}
```
2022-09-11 21:23:46 +00:00
#[ test ]
fn test_rebase_single_revision_merge_parent ( ) {
let test_env = TestEnvironment ::default ( ) ;
2024-05-17 19:49:25 +00:00
test_env . jj_cmd_ok ( test_env . env_root ( ) , & [ " git " , " init " , " repo " ] ) ;
Fix `rebase -r` of a parent of a merge commit
Previously, using `rebase -r` on the parent of a merge commit
turned it into a non-merge commit. In other words, starting
with
```
o d
|\
o | c
o | b
| o a
|/
o
```
and doing `rebase -r c -d a` resulted in
```
o d
o b
| o c
| o a
|/
o
```
where `d` is no longer a merge commit.
For reference, here's a complete test that passed before this commit (but should NOT pass; see the diff for a test that should pass):
```
#[test]
fn test_rebase_single_revision_merge_parent() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
create_commit(&test_env, &repo_path, "a", &[]);
create_commit(&test_env, &repo_path, "b", &[]);
create_commit(&test_env, &repo_path, "c", &["b"]);
create_commit(&test_env, &repo_path, "d", &["a", "c"]);
// Test the setup
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@
o d
|\
o | c
o | b
| o a
|/
o
"###);
let stdout = test_env.jj_cmd_success(&repo_path, &["rebase", "-r", "c", "-d", "a"]);
insta::assert_snapshot!(stdout, @r###"
Also rebased 2 descendant commits onto parent of rebased commit
Working copy now at: 3e176b54d680 (no description set)
Added 0 files, modified 0 files, removed 2 files
"###);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@
o d
| o c
o | b
| o a
|/
o
"###);
}
```
2022-09-11 21:23:46 +00:00
let repo_path = test_env . env_root ( ) . join ( " repo " ) ;
create_commit ( & test_env , & repo_path , " a " , & [ ] ) ;
create_commit ( & test_env , & repo_path , " b " , & [ ] ) ;
create_commit ( & test_env , & repo_path , " c " , & [ " b " ] ) ;
create_commit ( & test_env , & repo_path , " d " , & [ " a " , " c " ] ) ;
// Test the setup
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ d : a c
2023-02-09 02:53:47 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ c : b
2024-07-15 22:20:10 +00:00
│ ○ b
○ │ a
2023-02-09 02:53:47 +00:00
├ ─ ╯
2024-07-15 22:20:10 +00:00
◆
Fix `rebase -r` of a parent of a merge commit
Previously, using `rebase -r` on the parent of a merge commit
turned it into a non-merge commit. In other words, starting
with
```
o d
|\
o | c
o | b
| o a
|/
o
```
and doing `rebase -r c -d a` resulted in
```
o d
o b
| o c
| o a
|/
o
```
where `d` is no longer a merge commit.
For reference, here's a complete test that passed before this commit (but should NOT pass; see the diff for a test that should pass):
```
#[test]
fn test_rebase_single_revision_merge_parent() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
create_commit(&test_env, &repo_path, "a", &[]);
create_commit(&test_env, &repo_path, "b", &[]);
create_commit(&test_env, &repo_path, "c", &["b"]);
create_commit(&test_env, &repo_path, "d", &["a", "c"]);
// Test the setup
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@
o d
|\
o | c
o | b
| o a
|/
o
"###);
let stdout = test_env.jj_cmd_success(&repo_path, &["rebase", "-r", "c", "-d", "a"]);
insta::assert_snapshot!(stdout, @r###"
Also rebased 2 descendant commits onto parent of rebased commit
Working copy now at: 3e176b54d680 (no description set)
Added 0 files, modified 0 files, removed 2 files
"###);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@
o d
| o c
o | b
| o a
|/
o
"###);
}
```
2022-09-11 21:23:46 +00:00
" ###);
// Descendants of the rebased commit should be rebased onto parents, and if
// the descendant is a merge commit, it shouldn't forget its other parents.
2023-10-10 11:59:18 +00:00
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -r " , " c " , " -d " , " a " ] ) ;
2023-10-10 11:07:06 +00:00
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
2024-04-23 14:47:55 +00:00
Rebased 1 commits onto destination
2024-03-29 13:32:55 +00:00
Rebased 1 descendant commits
2024-04-21 11:59:12 +00:00
Working copy now at : vruxwmqv a37531e8 d | d
2023-08-08 03:11:59 +00:00
Parent commit : rlvkpnrz 2443 ea76 a | a
2024-04-21 11:59:12 +00:00
Parent commit : zsuskuln d370aee1 b | b
Fix `rebase -r` of a parent of a merge commit
Previously, using `rebase -r` on the parent of a merge commit
turned it into a non-merge commit. In other words, starting
with
```
o d
|\
o | c
o | b
| o a
|/
o
```
and doing `rebase -r c -d a` resulted in
```
o d
o b
| o c
| o a
|/
o
```
where `d` is no longer a merge commit.
For reference, here's a complete test that passed before this commit (but should NOT pass; see the diff for a test that should pass):
```
#[test]
fn test_rebase_single_revision_merge_parent() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
create_commit(&test_env, &repo_path, "a", &[]);
create_commit(&test_env, &repo_path, "b", &[]);
create_commit(&test_env, &repo_path, "c", &["b"]);
create_commit(&test_env, &repo_path, "d", &["a", "c"]);
// Test the setup
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@
o d
|\
o | c
o | b
| o a
|/
o
"###);
let stdout = test_env.jj_cmd_success(&repo_path, &["rebase", "-r", "c", "-d", "a"]);
insta::assert_snapshot!(stdout, @r###"
Also rebased 2 descendant commits onto parent of rebased commit
Working copy now at: 3e176b54d680 (no description set)
Added 0 files, modified 0 files, removed 2 files
"###);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@
o d
| o c
o | b
| o a
|/
o
"###);
}
```
2022-09-11 21:23:46 +00:00
Added 0 files , modified 0 files , removed 1 files
" ###);
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ d : a b
2024-03-29 13:32:55 +00:00
├ ─ ╮
2024-07-15 22:20:10 +00:00
│ ○ b
2024-08-17 08:03:00 +00:00
│ │ ○ c : a
2024-03-29 13:32:55 +00:00
├ ─ ─ ─ ╯
2024-07-15 22:20:10 +00:00
○ │ a
2023-10-28 02:29:13 +00:00
├ ─ ╯
2024-07-15 22:20:10 +00:00
◆
2023-10-28 02:29:13 +00:00
" ###);
}
2024-04-23 14:47:55 +00:00
#[ test ]
fn test_rebase_multiple_revisions ( ) {
let test_env = TestEnvironment ::default ( ) ;
2024-05-17 19:49:25 +00:00
test_env . jj_cmd_ok ( test_env . env_root ( ) , & [ " git " , " init " , " repo " ] ) ;
2024-04-23 14:47:55 +00:00
let repo_path = test_env . env_root ( ) . join ( " repo " ) ;
create_commit ( & test_env , & repo_path , " a " , & [ ] ) ;
create_commit ( & test_env , & repo_path , " b " , & [ " a " ] ) ;
create_commit ( & test_env , & repo_path , " c " , & [ " b " ] ) ;
create_commit ( & test_env , & repo_path , " d " , & [ " a " ] ) ;
create_commit ( & test_env , & repo_path , " e " , & [ " d " ] ) ;
create_commit ( & test_env , & repo_path , " f " , & [ " c " , " e " ] ) ;
create_commit ( & test_env , & repo_path , " g " , & [ " f " ] ) ;
create_commit ( & test_env , & repo_path , " h " , & [ " g " ] ) ;
create_commit ( & test_env , & repo_path , " i " , & [ " f " ] ) ;
// Test the setup
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ i : f
│ ○ h : g
│ ○ g : f
2024-04-23 14:47:55 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ f : c e
2024-04-23 14:47:55 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ e : d
│ ○ d : a
○ │ c : b
○ │ b : a
2024-04-23 14:47:55 +00:00
├ ─ ╯
2024-07-15 22:20:10 +00:00
○ a
◆
2024-04-23 14:47:55 +00:00
" ###);
// Test with two non-related non-merge commits.
let ( stdout , stderr ) =
test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -r " , " c " , " -r " , " e " , " -d " , " a " ] ) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
Rebased 2 commits onto destination
2024-03-29 13:32:55 +00:00
Rebased 4 descendant commits
2024-04-23 14:47:55 +00:00
Working copy now at : xznxytkn 016685 dc i | i
Parent commit : kmkuslsw e04d3932 f | f
Added 0 files , modified 0 files , removed 2 files
" ###);
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ i : f
│ ○ h : g
│ ○ g : f
2024-04-23 14:47:55 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ f : b d
2024-03-29 13:32:55 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ d : a
○ │ b : a
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
│ ○ e : a
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
│ ○ c : a
2024-04-23 14:47:55 +00:00
├ ─ ╯
2024-07-15 22:20:10 +00:00
○ a
◆
2024-04-23 14:47:55 +00:00
" ###);
test_env . jj_cmd_ok ( & repo_path , & [ " undo " ] ) ;
// Test with two related non-merge commits. Since "b" is a parent of "c", when
// rebasing commits "b" and "c", their ancestry relationship should be
// preserved.
let ( stdout , stderr ) =
test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -r " , " b " , " -r " , " c " , " -d " , " e " ] ) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
Rebased 2 commits onto destination
2024-03-29 13:32:55 +00:00
Rebased 4 descendant commits
2024-04-23 14:47:55 +00:00
Working copy now at : xznxytkn 94538385 i | i
Parent commit : kmkuslsw dae8d293 f | f
Added 0 files , modified 0 files , removed 2 files
" ###);
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ i : f
│ ○ h : g
│ ○ g : f
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ f : a e
2024-03-29 13:32:55 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ │ ○ c : b
│ │ ○ b : e
2024-04-23 14:47:55 +00:00
│ ├ ─ ╯
2024-08-17 08:03:00 +00:00
│ ○ e : d
│ ○ d : a
2024-04-23 14:47:55 +00:00
├ ─ ╯
2024-07-15 22:20:10 +00:00
○ a
◆
2024-04-23 14:47:55 +00:00
" ###);
test_env . jj_cmd_ok ( & repo_path , & [ " undo " ] ) ;
// Test with a subgraph containing a merge commit. Since the merge commit "f"
// was extracted, its descendants which are not part of the subgraph will
// inherit its descendants which are not in the subtree ("c" and "d").
2024-04-29 19:18:03 +00:00
// "f" will retain its parent "c" since "c" is outside the target set, and not
// a descendant of any new children.
2024-04-23 14:47:55 +00:00
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -r " , " e::g " , " -d " , " a " ] ) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
Rebased 3 commits onto destination
2024-03-29 13:32:55 +00:00
Rebased 2 descendant commits
2024-04-23 14:47:55 +00:00
Working copy now at : xznxytkn 1868 ded4 i | i
Parent commit : royxmykx 7e4 fbf4f c | c
Parent commit : vruxwmqv 4 cc44fbf d | d
Added 0 files , modified 0 files , removed 2 files
" ###);
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ i : c d
2024-03-29 13:32:55 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ │ ○ h : c d
2024-03-29 13:32:55 +00:00
╭ ─ ┬ ─ ╯
2024-08-17 08:03:00 +00:00
│ ○ d : a
2024-04-29 19:18:03 +00:00
│ │ ○ g : f
│ │ ○ f : c e
╭ ─ ─ ─ ┤
│ │ ○ e : a
│ ├ ─ ╯
2024-08-17 08:03:00 +00:00
○ │ c : b
○ │ b : a
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-07-15 22:20:10 +00:00
○ a
◆
2024-04-23 14:47:55 +00:00
" ###);
test_env . jj_cmd_ok ( & repo_path , & [ " undo " ] ) ;
// Test with commits in a disconnected subgraph. The subgraph has the
// relationship d->e->f->g->h, but only "d", "f" and "h" are in the set of
// rebased commits. "d" should be a new parent of "f", and "f" should be a
2024-04-29 19:18:03 +00:00
// new parent of "h". "f" will retain its parent "c" since "c" is outside the
// target set, and not a descendant of any new children.
2024-04-23 14:47:55 +00:00
let ( stdout , stderr ) = test_env . jj_cmd_ok (
& repo_path ,
& [ " rebase " , " -r " , " d " , " -r " , " f " , " -r " , " h " , " -d " , " b " ] ,
) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
Rebased 3 commits onto destination
2024-03-29 13:32:55 +00:00
Rebased 3 descendant commits
2024-04-23 14:47:55 +00:00
Working copy now at : xznxytkn 9 cfd1635 i | i
Parent commit : royxmykx 7e4 fbf4f c | c
Parent commit : znkkpsqq ecf9a1d5 e | e
Added 0 files , modified 0 files , removed 2 files
" ###);
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ i : c e
2024-03-29 13:32:55 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ │ ○ g : c e
2024-03-29 13:32:55 +00:00
╭ ─ ┬ ─ ╯
2024-08-17 08:03:00 +00:00
│ ○ e : a
│ │ ○ h : f
2024-04-29 19:18:03 +00:00
│ │ ○ f : c d
╭ ─ ─ ─ ┤
2024-08-17 08:03:00 +00:00
│ │ ○ d : b
2024-04-29 19:18:03 +00:00
○ │ │ c : b
2024-04-23 14:47:55 +00:00
├ ─ ─ ─ ╯
2024-08-17 08:03:00 +00:00
○ │ b : a
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-07-15 22:20:10 +00:00
○ a
◆
2024-04-23 14:47:55 +00:00
" ###);
test_env . jj_cmd_ok ( & repo_path , & [ " undo " ] ) ;
// Test rebasing a subgraph onto its descendants.
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -r " , " d::e " , " -d " , " i " ] ) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
Rebased 2 commits onto destination
2024-03-29 13:32:55 +00:00
Rebased 4 descendant commits
2024-04-23 14:47:55 +00:00
Working copy now at : xznxytkn 5 d911e5c i | i
Parent commit : kmkuslsw d1bfda8c f | f
Added 0 files , modified 0 files , removed 2 files
" ###);
2024-09-21 06:01:33 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r #"
○ e : d
○ d : i
@ i : f
│ ○ h : g
│ ○ g : f
2024-04-23 14:47:55 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ f : c a
2024-04-23 14:47:55 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
○ │ c : b
○ │ b : a
2024-04-23 14:47:55 +00:00
├ ─ ╯
2024-07-15 22:20:10 +00:00
○ a
◆
2024-09-21 06:01:33 +00:00
" #);
2024-04-23 14:47:55 +00:00
}
2023-10-28 02:29:13 +00:00
#[ test ]
fn test_rebase_revision_onto_descendant ( ) {
let test_env = TestEnvironment ::default ( ) ;
2024-05-17 19:49:25 +00:00
test_env . jj_cmd_ok ( test_env . env_root ( ) , & [ " git " , " init " , " repo " ] ) ;
2023-10-28 02:29:13 +00:00
let repo_path = test_env . env_root ( ) . join ( " repo " ) ;
create_commit ( & test_env , & repo_path , " base " , & [ ] ) ;
create_commit ( & test_env , & repo_path , " a " , & [ " base " ] ) ;
create_commit ( & test_env , & repo_path , " b " , & [ " base " ] ) ;
create_commit ( & test_env , & repo_path , " merge " , & [ " b " , " a " ] ) ;
// Test the setup
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ merge : b a
2023-02-09 02:53:47 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ a : base
○ │ b : base
2023-10-28 02:29:13 +00:00
├ ─ ╯
2024-07-15 22:20:10 +00:00
○ base
◆
2023-10-28 02:29:13 +00:00
" ###);
let setup_opid = test_env . current_operation_id ( & repo_path ) ;
// Simpler example
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -r " , " base " , " -d " , " a " ] ) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
2024-04-23 14:47:55 +00:00
Rebased 1 commits onto destination
2024-03-29 13:32:55 +00:00
Rebased 3 descendant commits
2023-10-28 02:29:13 +00:00
Working copy now at : vruxwmqv bff4a4eb merge | merge
Parent commit : royxmykx c84e900d b | b
Parent commit : zsuskuln d57db87b a | a
Added 0 files , modified 0 files , removed 1 files
" ###);
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ merge : b a
2024-03-29 13:32:55 +00:00
├ ─ ╮
2024-07-15 22:20:10 +00:00
○ │ b
2024-08-17 08:03:00 +00:00
│ │ ○ base : a
2024-03-29 13:32:55 +00:00
│ ├ ─ ╯
2024-07-15 22:20:10 +00:00
│ ○ a
2023-10-28 02:29:13 +00:00
├ ─ ╯
2024-07-15 22:20:10 +00:00
◆
2023-10-28 02:29:13 +00:00
" ###);
// Now, let's rebase onto the descendant merge
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
2024-09-25 06:52:11 +00:00
insta ::assert_snapshot! ( stderr , @ r #"
2024-10-07 03:00:49 +00:00
Restored to operation : cc1a7e3419ad ( 2001 - 02 - 03 08 :05 :15 ) create bookmark merge pointing to commit b05964d109522cd06e48f1a2661e1a0f58be0984
2023-10-28 02:29:13 +00:00
Working copy now at : vruxwmqv b05964d1 merge | merge
Parent commit : royxmykx cea87a87 b | b
Parent commit : zsuskuln 2 c5b7858 a | a
Added 1 files , modified 0 files , removed 0 files
2024-09-25 06:52:11 +00:00
" #);
2023-10-28 02:29:13 +00:00
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -r " , " base " , " -d " , " merge " ] ) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
2024-04-23 14:47:55 +00:00
Rebased 1 commits onto destination
2024-03-29 13:32:55 +00:00
Rebased 3 descendant commits
2023-10-28 02:29:13 +00:00
Working copy now at : vruxwmqv 986 b7a49 merge | merge
Parent commit : royxmykx c07c677c b | b
Parent commit : zsuskuln abc90087 a | a
Added 0 files , modified 0 files , removed 1 files
" ###);
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
○ base : merge
@ merge : b a
2023-10-28 02:29:13 +00:00
├ ─ ╮
2024-07-15 22:20:10 +00:00
│ ○ a
○ │ b
2023-02-09 02:53:47 +00:00
├ ─ ╯
2024-07-15 22:20:10 +00:00
◆
Fix `rebase -r` of a parent of a merge commit
Previously, using `rebase -r` on the parent of a merge commit
turned it into a non-merge commit. In other words, starting
with
```
o d
|\
o | c
o | b
| o a
|/
o
```
and doing `rebase -r c -d a` resulted in
```
o d
o b
| o c
| o a
|/
o
```
where `d` is no longer a merge commit.
For reference, here's a complete test that passed before this commit (but should NOT pass; see the diff for a test that should pass):
```
#[test]
fn test_rebase_single_revision_merge_parent() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
create_commit(&test_env, &repo_path, "a", &[]);
create_commit(&test_env, &repo_path, "b", &[]);
create_commit(&test_env, &repo_path, "c", &["b"]);
create_commit(&test_env, &repo_path, "d", &["a", "c"]);
// Test the setup
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@
o d
|\
o | c
o | b
| o a
|/
o
"###);
let stdout = test_env.jj_cmd_success(&repo_path, &["rebase", "-r", "c", "-d", "a"]);
insta::assert_snapshot!(stdout, @r###"
Also rebased 2 descendant commits onto parent of rebased commit
Working copy now at: 3e176b54d680 (no description set)
Added 0 files, modified 0 files, removed 2 files
"###);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@
o d
| o c
o | b
| o a
|/
o
"###);
}
```
2022-09-11 21:23:46 +00:00
" ###);
2023-10-28 02:29:13 +00:00
// TODO(ilyagr): These will be good tests for `jj rebase --insert-after` and
// `--insert-before`, once those are implemented.
Fix `rebase -r` of a parent of a merge commit
Previously, using `rebase -r` on the parent of a merge commit
turned it into a non-merge commit. In other words, starting
with
```
o d
|\
o | c
o | b
| o a
|/
o
```
and doing `rebase -r c -d a` resulted in
```
o d
o b
| o c
| o a
|/
o
```
where `d` is no longer a merge commit.
For reference, here's a complete test that passed before this commit (but should NOT pass; see the diff for a test that should pass):
```
#[test]
fn test_rebase_single_revision_merge_parent() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
create_commit(&test_env, &repo_path, "a", &[]);
create_commit(&test_env, &repo_path, "b", &[]);
create_commit(&test_env, &repo_path, "c", &["b"]);
create_commit(&test_env, &repo_path, "d", &["a", "c"]);
// Test the setup
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@
o d
|\
o | c
o | b
| o a
|/
o
"###);
let stdout = test_env.jj_cmd_success(&repo_path, &["rebase", "-r", "c", "-d", "a"]);
insta::assert_snapshot!(stdout, @r###"
Also rebased 2 descendant commits onto parent of rebased commit
Working copy now at: 3e176b54d680 (no description set)
Added 0 files, modified 0 files, removed 2 files
"###);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@
o d
| o c
o | b
| o a
|/
o
"###);
}
```
2022-09-11 21:23:46 +00:00
}
2022-04-13 13:43:54 +00:00
#[ test ]
fn test_rebase_multiple_destinations ( ) {
let test_env = TestEnvironment ::default ( ) ;
2024-05-17 19:49:25 +00:00
test_env . jj_cmd_ok ( test_env . env_root ( ) , & [ " git " , " init " , " repo " ] ) ;
2022-04-13 13:43:54 +00:00
let repo_path = test_env . env_root ( ) . join ( " repo " ) ;
create_commit ( & test_env , & repo_path , " a " , & [ ] ) ;
create_commit ( & test_env , & repo_path , " b " , & [ ] ) ;
create_commit ( & test_env , & repo_path , " c " , & [ ] ) ;
// Test the setup
2022-05-29 23:46:47 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2023-02-09 02:53:47 +00:00
@ c
2024-07-15 22:20:10 +00:00
│ ○ b
2023-02-09 02:53:47 +00:00
├ ─ ╯
2024-07-15 22:20:10 +00:00
│ ○ a
2023-02-09 02:53:47 +00:00
├ ─ ╯
2024-07-15 22:20:10 +00:00
◆
2022-04-13 13:43:54 +00:00
" ###);
2023-10-10 11:59:18 +00:00
let ( stdout , stderr ) =
test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -r " , " a " , " -d " , " b " , " -d " , " c " ] ) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
2024-04-23 14:47:55 +00:00
insta ::assert_snapshot! ( stderr , @ r ###"
Rebased 1 commits onto destination
" ###);
2022-05-29 23:46:47 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
○ a : b c
2023-02-09 02:53:47 +00:00
├ ─ ╮
2023-07-28 06:51:08 +00:00
│ @ c
2024-07-15 22:20:10 +00:00
○ │ b
2023-02-09 02:53:47 +00:00
├ ─ ╯
2024-07-15 22:20:10 +00:00
◆
2022-04-13 13:43:54 +00:00
" ###);
2022-09-12 09:45:16 +00:00
2023-02-04 08:24:48 +00:00
let stderr = test_env . jj_cmd_failure ( & repo_path , & [ " rebase " , " -r " , " a " , " -d " , " b|c " ] ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
Error : Revset " b|c " resolved to more than one revision
Hint : The revset " b|c " resolved to these revisions :
2024-03-24 07:42:04 +00:00
royxmykx fe2e8e8b c | c
zsuskuln d370aee1 b | b
2024-03-23 06:15:58 +00:00
Hint : Prefix the expression with ' all :' to allow any number of revisions ( i . e . ' all :b | c ' ) .
2023-02-04 08:24:48 +00:00
" ###);
2024-04-04 21:07:39 +00:00
// try with 'all:' and succeed
2023-10-10 11:59:18 +00:00
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -r " , " a " , " -d " , " all:b|c " ] ) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
2024-04-23 14:47:55 +00:00
insta ::assert_snapshot! ( stderr , @ r ###"
Rebased 1 commits onto destination
" ###);
2023-01-31 06:32:18 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
○ a : c b
2023-02-09 02:53:47 +00:00
├ ─ ╮
2024-07-15 22:20:10 +00:00
│ ○ b
revset_graph: group commits topologically
The original idea was similar to Mercurial's "topo" sorting, but it was bad
at handling merge-heavy history. In order to render merges of topic branches
nicely, we need to prioritize branches at merge point, not at fork point.
OTOH, we do also want to place unmerged branches as close to the fork point
as possible. This commit implements the former requirement, and the latter
will be addressed by the next commit.
I think this is similar to Git's sorting logic described in the following blog
post. In our case, the in-degree walk can be dumb since topological order is
guaranteed by the index. We keep HashSet<CommitId> instead of an in-degree
integer value, which will be used in the next commit to resolve new heads as
late as possible.
https://github.blog/2022-08-30-gits-database-internals-ii-commit-history-queries/#topological-sorting
Compared to Sapling's beautify_graph(), this is lazy, and can roughly preserve
the index (or chronological) order. I tried beautify_graph() with prioritizing
the @ commit, but the result seemed too aggressively reordered. Perhaps, for
more complex history, beautify_graph() would produce a better result. For my
wip branches (~30 branches, a couple of commits per branch), this works pretty
well.
#242
2023-07-16 10:47:46 +00:00
@ │ c
2023-02-09 02:53:47 +00:00
├ ─ ╯
2024-07-15 22:20:10 +00:00
◆
2023-01-31 06:32:18 +00:00
" ###);
2023-02-04 08:24:48 +00:00
2024-04-04 21:07:39 +00:00
// undo and do it again, but with 'ui.always-allow-large-revsets'
let ( _ , _ ) = test_env . jj_cmd_ok ( & repo_path , & [ " undo " ] ) ;
let ( _ , _ ) = test_env . jj_cmd_ok (
& repo_path ,
& [
" rebase " ,
" --config-toml=ui.always-allow-large-revsets=true " ,
" -r=a " ,
" -d=b|c " ,
] ,
) ;
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
○ a : c b
2024-04-04 21:07:39 +00:00
├ ─ ╮
2024-07-15 22:20:10 +00:00
│ ○ b
2024-04-04 21:07:39 +00:00
@ │ c
├ ─ ╯
2024-07-15 22:20:10 +00:00
◆
2024-04-04 21:07:39 +00:00
" ###);
2023-02-04 08:24:48 +00:00
let stderr = test_env . jj_cmd_failure ( & repo_path , & [ " rebase " , " -r " , " a " , " -d " , " b " , " -d " , " b " ] ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
2023-02-04 05:33:17 +00:00
Error : More than one revset resolved to revision d370aee184ba
2023-02-04 08:24:48 +00:00
" ###);
2023-07-25 16:07:03 +00:00
// Same error with 'all:' if there is overlap.
2023-07-25 17:17:36 +00:00
let stderr = test_env . jj_cmd_failure (
2023-01-31 06:32:18 +00:00
& repo_path ,
2023-07-25 16:07:03 +00:00
& [ " rebase " , " -r " , " a " , " -d " , " all:b|c " , " -d " , " b " ] ,
2023-01-31 06:32:18 +00:00
) ;
2023-07-25 17:17:36 +00:00
insta ::assert_snapshot! ( stderr , @ r ###"
Error : More than one revset resolved to revision d370aee184ba
2023-01-31 06:32:18 +00:00
" ###);
2023-09-03 03:47:23 +00:00
let stderr = test_env . jj_cmd_failure (
& repo_path ,
& [ " rebase " , " -r " , " a " , " -d " , " b " , " -d " , " root() " ] ,
) ;
2022-11-18 20:50:39 +00:00
insta ::assert_snapshot! ( stderr , @ r ###"
2024-03-30 07:29:10 +00:00
Error : The Git backend does not support creating merge commits with the root commit as one of the parents .
2022-11-18 20:50:39 +00:00
" ###);
2022-04-13 13:43:54 +00:00
}
#[ test ]
fn test_rebase_with_descendants ( ) {
let test_env = TestEnvironment ::default ( ) ;
2024-05-17 19:49:25 +00:00
test_env . jj_cmd_ok ( test_env . env_root ( ) , & [ " git " , " init " , " repo " ] ) ;
2022-04-13 13:43:54 +00:00
let repo_path = test_env . env_root ( ) . join ( " repo " ) ;
create_commit ( & test_env , & repo_path , " a " , & [ ] ) ;
create_commit ( & test_env , & repo_path , " b " , & [ ] ) ;
create_commit ( & test_env , & repo_path , " c " , & [ " a " , " b " ] ) ;
create_commit ( & test_env , & repo_path , " d " , & [ " c " ] ) ;
// Test the setup
2022-05-29 23:46:47 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ d : c
○ c : a b
2023-02-09 02:53:47 +00:00
├ ─ ╮
2024-07-15 22:20:10 +00:00
│ ○ b
○ │ a
2023-02-09 02:53:47 +00:00
├ ─ ╯
2024-07-15 22:20:10 +00:00
◆
2022-04-13 13:43:54 +00:00
" ###);
2023-10-10 11:59:18 +00:00
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -s " , " b " , " -d " , " a " ] ) ;
2023-10-10 11:07:06 +00:00
insta ::assert_snapshot! ( stdout , @ " " ) ;
2024-11-11 12:43:52 +00:00
insta ::assert_snapshot! ( stderr , @ r #"
Rebased 3 commits onto destination
2024-01-29 06:49:35 +00:00
Working copy now at : vruxwmqv 705832 bd d | d
Parent commit : royxmykx 57 c7246a c | c
2024-11-11 12:43:52 +00:00
" #);
2022-05-29 23:46:47 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ d : c
○ c : a b
2024-01-29 06:49:35 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ b : a
2024-01-29 06:49:35 +00:00
├ ─ ╯
2024-07-15 22:20:10 +00:00
○ a
◆
2022-04-13 13:43:54 +00:00
" ###);
2023-02-19 03:31:48 +00:00
// Rebase several subtrees at once.
2023-10-10 11:59:18 +00:00
test_env . jj_cmd_ok ( & repo_path , & [ " undo " ] ) ;
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -s=c " , " -s=d " , " -d=a " ] ) ;
2023-10-10 11:07:06 +00:00
insta ::assert_snapshot! ( stdout , @ " " ) ;
2024-11-11 12:43:52 +00:00
insta ::assert_snapshot! ( stderr , @ r #"
Rebased 2 commits onto destination
2023-08-08 03:11:59 +00:00
Working copy now at : vruxwmqv 92 c2bc9a d | d
Parent commit : rlvkpnrz 2443 ea76 a | a
2023-02-19 03:31:48 +00:00
Added 0 files , modified 0 files , removed 2 files
2024-11-11 12:43:52 +00:00
" #);
2023-02-19 03:31:48 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ d : a
│ ○ c : a
2023-02-19 03:31:48 +00:00
├ ─ ╯
2024-07-15 22:20:10 +00:00
○ a
│ ○ b
2023-02-19 03:31:48 +00:00
├ ─ ╯
2024-07-15 22:20:10 +00:00
◆
2023-02-19 03:31:48 +00:00
" ###);
2023-10-10 11:59:18 +00:00
test_env . jj_cmd_ok ( & repo_path , & [ " undo " ] ) ;
2023-02-19 03:31:48 +00:00
// Reminder of the setup
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ d : c
○ c : a b
2023-02-19 03:31:48 +00:00
├ ─ ╮
2024-07-15 22:20:10 +00:00
│ ○ b
○ │ a
2023-02-19 03:31:48 +00:00
├ ─ ╯
2024-07-15 22:20:10 +00:00
◆
2023-02-19 03:31:48 +00:00
" ###);
// `d` was a descendant of `b`, and both are moved to be direct descendants of
// `a`. `c` remains a descendant of `b`.
2023-10-10 11:59:18 +00:00
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -s=b " , " -s=d " , " -d=a " ] ) ;
2023-10-10 11:07:06 +00:00
insta ::assert_snapshot! ( stdout , @ " " ) ;
2024-11-11 12:43:52 +00:00
insta ::assert_snapshot! ( stderr , @ r #"
Rebased 3 commits onto destination
2023-08-08 03:11:59 +00:00
Working copy now at : vruxwmqv f1e71cb7 d | d
Parent commit : rlvkpnrz 2443 ea76 a | a
2023-02-19 03:31:48 +00:00
Added 0 files , modified 0 files , removed 2 files
2024-11-11 12:43:52 +00:00
" #);
2024-09-21 06:01:33 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r #"
2024-04-30 11:27:24 +00:00
@ d : a
│ ○ c : a b
╭ ─ ┤
2024-08-17 08:03:00 +00:00
│ ○ b : a
2024-01-29 06:49:35 +00:00
├ ─ ╯
2024-07-15 22:20:10 +00:00
○ a
◆
2024-09-21 06:01:33 +00:00
" #);
2023-02-19 03:31:48 +00:00
2023-07-25 17:17:36 +00:00
// Same test as above, but with multiple commits per argument
2023-10-10 11:59:18 +00:00
test_env . jj_cmd_ok ( & repo_path , & [ " undo " ] ) ;
2023-07-25 17:17:36 +00:00
let stderr = test_env . jj_cmd_failure ( & repo_path , & [ " rebase " , " -s=b|d " , " -d=a " ] ) ;
2023-02-19 03:31:48 +00:00
insta ::assert_snapshot! ( stderr , @ r ###"
Error : Revset " b|d " resolved to more than one revision
Hint : The revset " b|d " resolved to these revisions :
2024-03-24 07:42:04 +00:00
vruxwmqv df54a9fd d | d
zsuskuln d370aee1 b | b
2024-03-23 06:15:58 +00:00
Hint : Prefix the expression with ' all :' to allow any number of revisions ( i . e . ' all :b | d ' ) .
2023-02-19 03:31:48 +00:00
" ###);
2023-10-10 11:59:18 +00:00
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -s=all:b|d " , " -d=a " ] ) ;
2023-10-10 11:07:06 +00:00
insta ::assert_snapshot! ( stdout , @ " " ) ;
2024-11-11 12:43:52 +00:00
insta ::assert_snapshot! ( stderr , @ r #"
Rebased 3 commits onto destination
2023-08-08 03:11:59 +00:00
Working copy now at : vruxwmqv d17539f7 d | d
Parent commit : rlvkpnrz 2443 ea76 a | a
2023-02-19 03:31:48 +00:00
Added 0 files , modified 0 files , removed 2 files
2024-11-11 12:43:52 +00:00
" #);
2024-09-21 06:01:33 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r #"
2024-04-30 11:27:24 +00:00
@ d : a
│ ○ c : a b
╭ ─ ┤
2024-08-17 08:03:00 +00:00
│ ○ b : a
2024-01-29 06:49:35 +00:00
├ ─ ╯
2024-07-15 22:20:10 +00:00
○ a
◆
2024-09-21 06:01:33 +00:00
" #);
2022-04-13 13:43:54 +00:00
}
2022-05-29 23:46:47 +00:00
2024-03-17 13:44:20 +00:00
#[ test ]
fn test_rebase_error_revision_does_not_exist ( ) {
let test_env = TestEnvironment ::default ( ) ;
2024-05-17 19:49:25 +00:00
test_env . jj_cmd_ok ( test_env . env_root ( ) , & [ " git " , " init " , " repo " ] ) ;
2024-03-17 13:44:20 +00:00
let repo_path = test_env . env_root ( ) . join ( " repo " ) ;
test_env . jj_cmd_ok ( & repo_path , & [ " describe " , " -m " , " one " ] ) ;
2024-08-21 19:59:15 +00:00
test_env . jj_cmd_ok ( & repo_path , & [ " bookmark " , " create " , " b-one " ] ) ;
2024-03-17 13:44:20 +00:00
test_env . jj_cmd_ok ( & repo_path , & [ " new " , " -r " , " @- " , " -m " , " two " ] ) ;
let stderr = test_env . jj_cmd_failure ( & repo_path , & [ " rebase " , " -b " , " b-one " , " -d " , " this " ] ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
Error : Revision " this " doesn ' t exist
" ###);
let stderr = test_env . jj_cmd_failure ( & repo_path , & [ " rebase " , " -b " , " this " , " -d " , " b-one " ] ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
Error : Revision " this " doesn ' t exist
" ###);
}
2023-11-26 06:56:29 +00:00
// This behavior illustrates https://github.com/martinvonz/jj/issues/2600
#[ test ]
fn test_rebase_with_child_and_descendant_bug_2600 ( ) {
let test_env = TestEnvironment ::default ( ) ;
2024-05-17 19:49:25 +00:00
test_env . jj_cmd_ok ( test_env . env_root ( ) , & [ " git " , " init " , " repo " ] ) ;
2023-11-26 06:56:29 +00:00
let repo_path = test_env . env_root ( ) . join ( " repo " ) ;
2024-04-21 15:29:09 +00:00
create_commit ( & test_env , & repo_path , " notroot " , & [ ] ) ;
create_commit ( & test_env , & repo_path , " base " , & [ " notroot " ] ) ;
2023-11-26 06:56:29 +00:00
create_commit ( & test_env , & repo_path , " a " , & [ " base " ] ) ;
create_commit ( & test_env , & repo_path , " b " , & [ " base " , " a " ] ) ;
create_commit ( & test_env , & repo_path , " c " , & [ " b " ] ) ;
let setup_opid = test_env . current_operation_id ( & repo_path ) ;
// Test the setup
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ c : b
○ b : base a
2023-11-26 06:56:29 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ a : base
2023-11-26 06:56:29 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ base : notroot
2024-07-15 22:20:10 +00:00
○ notroot
◆
2023-11-26 06:56:29 +00:00
" ###);
2023-11-28 23:37:55 +00:00
// ===================== rebase -s tests =================
let ( stdout , stderr ) =
2024-04-21 15:29:09 +00:00
test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -s " , " base " , " -d " , " notroot " ] ) ;
2023-11-28 23:37:55 +00:00
insta ::assert_snapshot! ( stdout , @ " " ) ;
2024-03-25 11:46:10 +00:00
// This should be a no-op
2023-11-28 23:37:55 +00:00
insta ::assert_snapshot! ( stderr , @ r ###"
2024-04-30 11:27:24 +00:00
Skipped rebase of 4 commits that were already in place
Nothing changed .
2023-11-28 23:37:55 +00:00
" ###);
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ c : b
○ b : base a
2024-01-29 06:49:35 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ a : base
2024-01-29 06:49:35 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ base : notroot
2024-07-15 22:20:10 +00:00
○ notroot
◆
2023-11-28 23:37:55 +00:00
" ###);
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -s " , " a " , " -d " , " base " ] ) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
2024-03-25 11:46:10 +00:00
// This should be a no-op
2023-11-28 23:37:55 +00:00
insta ::assert_snapshot! ( stderr , @ r ###"
2024-04-30 11:27:24 +00:00
Skipped rebase of 3 commits that were already in place
Nothing changed .
2023-11-28 23:37:55 +00:00
" ###);
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ c : b
○ b : base a
2024-01-29 06:49:35 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ a : base
2024-01-29 06:49:35 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ base : notroot
2024-07-15 22:20:10 +00:00
○ notroot
◆
2023-11-28 23:37:55 +00:00
" ###);
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -s " , " a " , " -d " , " root() " ] ) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
2024-11-11 12:43:52 +00:00
insta ::assert_snapshot! ( stderr , @ r #"
Rebased 3 commits onto destination
2024-04-21 15:29:09 +00:00
Working copy now at : znkkpsqq cf8ecff5 c | c
Parent commit : vruxwmqv 24e1 a270 b | b
2024-11-11 12:43:52 +00:00
" #);
2024-01-29 06:49:35 +00:00
// Commit "a" should be rebased onto the root commit. Commit "b" should have
// "base" and "a" as parents as before.
2023-11-28 23:37:55 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ c : b
○ b : base a
2023-11-28 23:37:55 +00:00
├ ─ ╮
2024-07-15 22:20:10 +00:00
│ ○ a
2024-08-17 08:03:00 +00:00
○ │ base : notroot
2024-07-15 22:20:10 +00:00
○ │ notroot
2023-11-28 23:37:55 +00:00
├ ─ ╯
2024-07-15 22:20:10 +00:00
◆
2023-11-28 23:37:55 +00:00
" ###);
// ===================== rebase -b tests =================
// ====== Reminder of the setup =========
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ c : b
○ b : base a
2023-11-28 23:37:55 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ a : base
2023-11-28 23:37:55 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ base : notroot
2024-07-15 22:20:10 +00:00
○ notroot
◆
2023-11-28 23:37:55 +00:00
" ###);
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -b " , " c " , " -d " , " base " ] ) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
2024-01-29 06:49:35 +00:00
// The commits in roots(base..c), i.e. commit "a" should be rebased onto "base",
// which is a no-op
2024-03-25 11:46:10 +00:00
insta ::assert_snapshot! ( stderr , @ r ###"
2024-04-30 11:27:24 +00:00
Skipped rebase of 3 commits that were already in place
Nothing changed .
2024-03-25 11:46:10 +00:00
" ###);
2023-11-28 23:37:55 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ c : b
○ b : base a
2024-01-29 06:49:35 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ a : base
2024-01-29 06:49:35 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ base : notroot
2024-07-15 22:20:10 +00:00
○ notroot
◆
2023-11-28 23:37:55 +00:00
" ###);
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -b " , " c " , " -d " , " a " ] ) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
2024-11-11 12:43:52 +00:00
insta ::assert_snapshot! ( stderr , @ r #"
Rebased 2 commits onto destination
2024-04-21 15:29:09 +00:00
Working copy now at : znkkpsqq 76914 dcc c | c
Parent commit : vruxwmqv f73f03c7 b | b
2024-11-11 12:43:52 +00:00
" #);
2024-01-29 06:49:35 +00:00
// The commits in roots(a..c), i.e. commit "b" should be rebased onto "a",
// which means "b" loses its "base" parent
2023-11-28 23:37:55 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ c : b
○ b : a
○ a : base
○ base : notroot
2024-07-15 22:20:10 +00:00
○ notroot
◆
2023-11-28 23:37:55 +00:00
" ###);
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -b " , " a " , " -d " , " root() " ] ) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
2024-03-25 11:46:10 +00:00
// This should be a no-op
2023-11-28 23:37:55 +00:00
insta ::assert_snapshot! ( stderr , @ r ###"
2024-04-30 11:27:24 +00:00
Skipped rebase of 5 commits that were already in place
Nothing changed .
2023-11-28 23:37:55 +00:00
" ###);
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ c : b
○ b : base a
2024-01-29 06:49:35 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ a : base
2024-01-29 06:49:35 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ base : notroot
2024-07-15 22:20:10 +00:00
○ notroot
◆
2023-11-28 23:37:55 +00:00
" ###);
// ===================== rebase -r tests =================
// ====== Reminder of the setup =========
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ c : b
○ b : base a
2023-11-28 23:37:55 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ a : base
2023-11-28 23:37:55 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ base : notroot
2024-07-15 22:20:10 +00:00
○ notroot
◆
2023-11-28 23:37:55 +00:00
" ###);
2023-11-26 06:56:29 +00:00
let ( stdout , stderr ) =
test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -r " , " base " , " -d " , " root() " ] ) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
2024-04-23 14:47:55 +00:00
Rebased 1 commits onto destination
2024-03-29 13:32:55 +00:00
Rebased 3 descendant commits
2024-04-21 15:29:09 +00:00
Working copy now at : znkkpsqq 45371 aaf c | c
Parent commit : vruxwmqv c0a76bf4 b | b
2023-11-26 06:56:29 +00:00
Added 0 files , modified 0 files , removed 1 files
" ###);
// The user would expect unsimplified ancestry here.
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ c : b
○ b : notroot a
2024-03-29 13:32:55 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ a : notroot
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-07-15 22:20:10 +00:00
○ notroot
│ ○ base
2023-11-26 06:56:29 +00:00
├ ─ ╯
2024-07-15 22:20:10 +00:00
◆
2023-11-26 06:56:29 +00:00
" ###);
2024-04-21 15:29:09 +00:00
// This tests the algorithm for rebasing onto descendants. The result should
// have unsimplified ancestry.
2023-11-26 06:56:29 +00:00
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
2024-04-21 11:59:12 +00:00
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -r " , " base " , " -d " , " b " ] ) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
2024-04-23 14:47:55 +00:00
Rebased 1 commits onto destination
2024-03-29 13:32:55 +00:00
Rebased 3 descendant commits
2024-04-21 15:29:09 +00:00
Working copy now at : znkkpsqq e28fa972 c | c
Parent commit : vruxwmqv 8 d0eeb6a b | b
2024-04-21 11:59:12 +00:00
Added 0 files , modified 0 files , removed 1 files
" ###);
2023-11-26 06:56:29 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ c : b
│ ○ base : b
2024-04-21 11:59:12 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ b : notroot a
2024-04-21 15:29:09 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ a : notroot
2024-04-21 15:29:09 +00:00
├ ─ ╯
2024-07-15 22:20:10 +00:00
○ notroot
◆
2023-11-26 06:56:29 +00:00
" ###);
2024-04-21 15:29:09 +00:00
// This tests the algorithm for rebasing onto descendants. The result should
// have unsimplified ancestry.
2023-11-26 06:56:29 +00:00
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -r " , " base " , " -d " , " a " ] ) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
2024-04-23 14:47:55 +00:00
Rebased 1 commits onto destination
2024-03-29 13:32:55 +00:00
Rebased 3 descendant commits
2024-04-21 15:29:09 +00:00
Working copy now at : znkkpsqq a9da974c c | c
Parent commit : vruxwmqv 0072139 c b | b
2023-11-26 06:56:29 +00:00
Added 0 files , modified 0 files , removed 1 files
" ###);
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ c : b
○ b : notroot a
2024-03-29 13:32:55 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ │ ○ base : a
2024-03-29 13:32:55 +00:00
│ ├ ─ ╯
2024-08-17 08:03:00 +00:00
│ ○ a : notroot
2023-11-26 06:56:29 +00:00
├ ─ ╯
2024-07-15 22:20:10 +00:00
○ notroot
◆
2023-11-26 06:56:29 +00:00
" ###);
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
// ====== Reminder of the setup =========
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ c : b
○ b : base a
2023-11-26 06:56:29 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ a : base
2023-11-26 06:56:29 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ base : notroot
2024-07-15 22:20:10 +00:00
○ notroot
◆
2023-11-26 06:56:29 +00:00
" ###);
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -r " , " a " , " -d " , " root() " ] ) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
2024-04-23 14:47:55 +00:00
Rebased 1 commits onto destination
2024-03-29 13:32:55 +00:00
Rebased 2 descendant commits
2024-04-21 15:29:09 +00:00
Working copy now at : znkkpsqq 7210 b05e c | c
Parent commit : vruxwmqv da3f7511 b | b
2023-11-26 06:56:29 +00:00
Added 0 files , modified 0 files , removed 1 files
" ###);
// In this case, it is unclear whether the user would always prefer unsimplified
// ancestry (whether `b` should also be a direct child of the root commit).
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ c : b
○ b : base
○ base : notroot
2024-07-15 22:20:10 +00:00
○ notroot
│ ○ a
2023-11-26 06:56:29 +00:00
├ ─ ╯
2024-07-15 22:20:10 +00:00
◆
2023-11-26 06:56:29 +00:00
" ###);
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -r " , " b " , " -d " , " root() " ] ) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
2024-04-23 14:47:55 +00:00
Rebased 1 commits onto destination
2024-03-29 13:32:55 +00:00
Rebased 1 descendant commits
2024-04-21 15:29:09 +00:00
Working copy now at : znkkpsqq f280545e c | c
Parent commit : zsuskuln 0 a7fb8f6 base | base
2024-04-21 15:29:09 +00:00
Parent commit : royxmykx 86 a06598 a | a
2023-11-26 06:56:29 +00:00
Added 0 files , modified 0 files , removed 1 files
" ###);
// The user would expect unsimplified ancestry here.
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ c : base a
2024-03-29 13:32:55 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ a : base
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ base : notroot
2024-07-15 22:20:10 +00:00
○ notroot
│ ○ b
2023-11-26 06:56:29 +00:00
├ ─ ╯
2024-07-15 22:20:10 +00:00
◆
2023-11-26 06:56:29 +00:00
" ###);
2024-04-21 15:29:09 +00:00
// This tests the algorithm for rebasing onto descendants. The result should
// have unsimplified ancestry.
2023-11-26 06:56:29 +00:00
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -r " , " b " , " -d " , " c " ] ) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
2024-04-23 14:47:55 +00:00
Rebased 1 commits onto destination
2024-03-29 13:32:55 +00:00
Rebased 1 descendant commits
2024-04-21 15:29:09 +00:00
Working copy now at : znkkpsqq c0a7cd80 c | c
Parent commit : zsuskuln 0 a7fb8f6 base | base
2024-04-21 15:29:09 +00:00
Parent commit : royxmykx 86 a06598 a | a
2023-11-26 06:56:29 +00:00
Added 0 files , modified 0 files , removed 1 files
" ###);
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
○ b : c
@ c : base a
2024-04-21 15:29:09 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ a : base
2024-04-21 15:29:09 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ base : notroot
2024-07-15 22:20:10 +00:00
○ notroot
◆
2023-11-26 06:56:29 +00:00
" ###);
// In this test, the commit with weird ancestry is not rebased (neither directly
// nor indirectly).
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -r " , " c " , " -d " , " a " ] ) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
2024-04-23 14:47:55 +00:00
Rebased 1 commits onto destination
2024-04-21 15:29:09 +00:00
Working copy now at : znkkpsqq 7 a3bc050 c | c
Parent commit : royxmykx 86 a06598 a | a
2023-11-26 06:56:29 +00:00
Added 0 files , modified 0 files , removed 1 files
" ###);
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ c : a
│ ○ b : base a
2023-11-26 06:56:29 +00:00
╭ ─ ┤
2024-08-17 08:03:00 +00:00
○ │ a : base
2023-11-26 06:56:29 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ base : notroot
2024-07-15 22:20:10 +00:00
○ notroot
◆
2023-11-26 06:56:29 +00:00
" ###);
}
2024-02-25 17:41:07 +00:00
2024-03-29 13:32:55 +00:00
#[ test ]
2024-04-30 12:56:53 +00:00
fn test_rebase_after ( ) {
2024-03-29 13:32:55 +00:00
let test_env = TestEnvironment ::default ( ) ;
2024-05-17 19:49:25 +00:00
test_env . jj_cmd_ok ( test_env . env_root ( ) , & [ " git " , " init " , " repo " ] ) ;
2024-03-29 13:32:55 +00:00
let repo_path = test_env . env_root ( ) . join ( " repo " ) ;
create_commit ( & test_env , & repo_path , " a " , & [ ] ) ;
create_commit ( & test_env , & repo_path , " b1 " , & [ " a " ] ) ;
create_commit ( & test_env , & repo_path , " b2 " , & [ " b1 " ] ) ;
create_commit ( & test_env , & repo_path , " b3 " , & [ " a " ] ) ;
create_commit ( & test_env , & repo_path , " b4 " , & [ " b3 " ] ) ;
create_commit ( & test_env , & repo_path , " c " , & [ " b2 " , " b4 " ] ) ;
create_commit ( & test_env , & repo_path , " d " , & [ " c " ] ) ;
create_commit ( & test_env , & repo_path , " e " , & [ " c " ] ) ;
create_commit ( & test_env , & repo_path , " f " , & [ " e " ] ) ;
// Test the setup
2024-08-14 11:24:29 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ f : e
○ e : c
│ ○ d : c
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ c : b2 b4
2024-03-29 13:32:55 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ b4 : b3
│ ○ b3 : a
○ │ b2 : b1
○ │ b1 : a
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-14 11:24:29 +00:00
○ a
◆
2024-03-29 13:32:55 +00:00
" ###);
let setup_opid = test_env . current_operation_id ( & repo_path ) ;
// Rebasing a commit after its parents should be a no-op.
let ( stdout , stderr ) = test_env . jj_cmd_ok (
& repo_path ,
& [ " rebase " , " -r " , " c " , " --after " , " b2 " , " --after " , " b4 " ] ,
) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
2024-04-29 07:45:33 +00:00
Skipped rebase of 4 commits that were already in place
2024-03-29 13:32:55 +00:00
Nothing changed .
" ###);
2024-08-14 11:24:29 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ f : e
○ e : c
│ ○ d : c
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ c : b2 b4
2024-03-29 13:32:55 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ b4 : b3
│ ○ b3 : a
○ │ b2 : b1
○ │ b1 : a
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-14 11:24:29 +00:00
○ a
◆
2024-03-29 13:32:55 +00:00
" ###);
// Rebasing a commit after itself should be a no-op.
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -r " , " c " , " --after " , " c " ] ) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
2024-04-29 07:45:33 +00:00
Skipped rebase of 4 commits that were already in place
2024-03-29 13:32:55 +00:00
Nothing changed .
" ###);
2024-08-14 11:24:29 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ f : e
○ e : c
│ ○ d : c
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ c : b2 b4
2024-03-29 13:32:55 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ b4 : b3
│ ○ b3 : a
○ │ b2 : b1
○ │ b1 : a
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-14 11:24:29 +00:00
○ a
◆
2024-03-29 13:32:55 +00:00
" ###);
// Rebase a commit after another commit. "c" has parents "b2" and "b4", so its
// children "d" and "e" should be rebased onto "b2" and "b4" respectively.
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -r " , " c " , " --after " , " e " ] ) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
Rebased 1 commits onto destination
Rebased 3 descendant commits
Working copy now at : xznxytkn e0e873c8 f | f
Parent commit : kmkuslsw 754793 f3 c | c
" ###);
2024-08-14 11:24:29 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ f : c
○ c : e
○ e : b2 b4
2024-03-29 13:32:55 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ │ ○ d : b2 b4
2024-03-29 13:32:55 +00:00
╭ ─ ┬ ─ ╯
2024-08-17 08:03:00 +00:00
│ ○ b4 : b3
│ ○ b3 : a
○ │ b2 : b1
○ │ b1 : a
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-14 11:24:29 +00:00
○ a
◆
2024-03-29 13:32:55 +00:00
" ###);
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
// Rebase a commit after a leaf commit.
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -r " , " e " , " --after " , " f " ] ) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
Rebased 1 commits onto destination
Rebased 1 descendant commits
Working copy now at : xznxytkn 9804 b742 f | f
Parent commit : kmkuslsw cd86b3e4 c | c
Added 0 files , modified 0 files , removed 1 files
" ###);
2024-08-14 11:24:29 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
○ e : f
@ f : c
│ ○ d : c
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ c : b2 b4
2024-03-29 13:32:55 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ b4 : b3
│ ○ b3 : a
○ │ b2 : b1
○ │ b1 : a
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-14 11:24:29 +00:00
○ a
◆
2024-03-29 13:32:55 +00:00
" ###);
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
2024-08-21 19:59:15 +00:00
// Rebase a commit after a commit in a bookmark of a merge commit.
2024-03-29 13:32:55 +00:00
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -r " , " f " , " --after " , " b1 " ] ) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
Rebased 1 commits onto destination
Rebased 4 descendant commits
Working copy now at : xznxytkn 80 c27408 f | f
Parent commit : zsuskuln 072 d5ae1 b1 | b1
Added 0 files , modified 0 files , removed 5 files
" ###);
2024-08-14 11:24:29 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
○ e : c
│ ○ d : c
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ c : b2 b4
2024-03-29 13:32:55 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ b4 : b3
│ ○ b3 : a
○ │ b2 : f
@ │ f : b1
○ │ b1 : a
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-14 11:24:29 +00:00
○ a
◆
2024-03-29 13:32:55 +00:00
" ###);
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
2024-08-21 19:59:15 +00:00
// Rebase a commit after the last commit in a bookmark of a merge commit.
2024-03-29 13:32:55 +00:00
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -r " , " f " , " --after " , " b2 " ] ) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
Rebased 1 commits onto destination
Rebased 3 descendant commits
Working copy now at : xznxytkn ebbc24b1 f | f
Parent commit : royxmykx 2 b8e1148 b2 | b2
Added 0 files , modified 0 files , removed 4 files
" ###);
2024-08-14 11:24:29 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
○ e : c
│ ○ d : c
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ c : f b4
2024-03-29 13:32:55 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ b4 : b3
│ ○ b3 : a
@ │ f : b2
○ │ b2 : b1
○ │ b1 : a
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-14 11:24:29 +00:00
○ a
◆
2024-03-29 13:32:55 +00:00
" ###);
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
// Rebase a commit after a commit with multiple children.
// "c" has two children "d" and "e", so the rebased commit "f" will inherit the
// two children.
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -r " , " f " , " --after " , " c " ] ) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
Rebased 1 commits onto destination
Rebased 2 descendant commits
Working copy now at : xznxytkn 8 f8c91d3 f | f
Parent commit : kmkuslsw cd86b3e4 c | c
Added 0 files , modified 0 files , removed 1 files
" ###);
2024-08-14 11:24:29 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
○ e : f
│ ○ d : f
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
@ f : c
○ c : b2 b4
2024-03-29 13:32:55 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ b4 : b3
│ ○ b3 : a
○ │ b2 : b1
○ │ b1 : a
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-14 11:24:29 +00:00
○ a
◆
2024-03-29 13:32:55 +00:00
" ###);
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
// Rebase a commit after multiple commits.
let ( stdout , stderr ) = test_env . jj_cmd_ok (
& repo_path ,
& [ " rebase " , " -r " , " f " , " --after " , " e " , " --after " , " d " ] ,
) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
Rebased 1 commits onto destination
Working copy now at : xznxytkn 7784e5 a0 f | f
Parent commit : nkmrtpmo 858693 f7 e | e
Parent commit : lylxulpl 7 d0512e5 d | d
Added 1 files , modified 0 files , removed 0 files
" ###);
2024-08-14 11:24:29 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ f : e d
2024-03-29 13:32:55 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ d : c
○ │ e : c
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ c : b2 b4
2024-03-29 13:32:55 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ b4 : b3
│ ○ b3 : a
○ │ b2 : b1
○ │ b1 : a
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-14 11:24:29 +00:00
○ a
◆
2024-03-29 13:32:55 +00:00
" ###);
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
// Rebase two unrelated commits.
let ( stdout , stderr ) = test_env . jj_cmd_ok (
& repo_path ,
& [ " rebase " , " -r " , " d " , " -r " , " e " , " --after " , " a " ] ,
) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
Rebased 2 commits onto destination
Rebased 6 descendant commits
Working copy now at : xznxytkn 0 b53613e f | f
Parent commit : kmkuslsw 193687 bb c | c
Added 1 files , modified 0 files , removed 0 files
" ###);
2024-08-14 11:24:29 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ f : c
○ c : b2 b4
2024-03-29 13:32:55 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ b4 : b3
│ ○ b3 : d e
2024-03-29 13:32:55 +00:00
│ ├ ─ ╮
2024-08-17 08:03:00 +00:00
○ │ │ b2 : b1
○ │ │ b1 : d e
2024-03-29 13:32:55 +00:00
╰ ─ ┬ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ e : a
○ │ d : a
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-14 11:24:29 +00:00
○ a
◆
2024-03-29 13:32:55 +00:00
" ###);
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
// Rebase a subgraph with merge commit and two parents, which should preserve
// the merge.
let ( stdout , stderr ) = test_env . jj_cmd_ok (
& repo_path ,
& [ " rebase " , " -r " , " b2 " , " -r " , " b4 " , " -r " , " c " , " --after " , " f " ] ,
) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
Rebased 3 commits onto destination
Rebased 3 descendant commits
Working copy now at : xznxytkn eaf1d6b8 f | f
Parent commit : nkmrtpmo 0 d7e4ce9 e | e
Added 0 files , modified 0 files , removed 3 files
" ###);
2024-09-21 06:01:33 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r #"
○ c : b2 b4
2024-03-29 13:32:55 +00:00
├ ─ ╮
2024-09-21 06:01:33 +00:00
│ ○ b4 : f
○ │ b2 : f
├ ─ ╯
@ f : e
○ e : b1 b3
├ ─ ╮
│ │ ○ d : b1 b3
2024-03-29 13:32:55 +00:00
╭ ─ ┬ ─ ╯
2024-08-17 08:03:00 +00:00
│ ○ b3 : a
○ │ b1 : a
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-14 11:24:29 +00:00
○ a
◆
2024-09-21 06:01:33 +00:00
" #);
2024-03-29 13:32:55 +00:00
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
// Rebase a subgraph with four commits after one of the commits itself.
let ( stdout , stderr ) =
test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -r " , " b1::d " , " --after " , " c " ] ) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
Rebased 4 commits onto destination
Rebased 2 descendant commits
2024-04-29 19:18:03 +00:00
Working copy now at : xznxytkn 9 bc7e54c f | f
Parent commit : nkmrtpmo 0 f80251b e | e
2024-03-29 13:32:55 +00:00
Added 1 files , modified 0 files , removed 0 files
" ###);
2024-08-14 11:24:29 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ f : e
○ e : d
○ d : c
2024-04-29 19:18:03 +00:00
○ c : b2 b4
├ ─ ╮
○ │ b2 : b1
○ │ b1 : a b4
2024-03-29 13:32:55 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ b4 : b3
│ ○ b3 : a
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-14 11:24:29 +00:00
○ a
◆
2024-03-29 13:32:55 +00:00
" ###);
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
2024-04-29 19:18:03 +00:00
// Rebase a subgraph before the parents of one of the commits in the subgraph.
// "c" had parents "b2" and "b4", but no longer has "b4" as a parent since
// "b4" would be a descendant of "c" after the rebase.
let ( stdout , stderr ) =
test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -r " , " b2::d " , " --after " , " root() " ] ) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
Rebased 3 commits onto destination
Rebased 6 descendant commits
Working copy now at : xznxytkn 0875 aabc f | f
Parent commit : nkmrtpmo d429661b e | e
Added 1 files , modified 0 files , removed 0 files
" ###);
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
@ f : e
○ e : b1 b4
├ ─ ╮
│ ○ b4 : b3
│ ○ b3 : a
○ │ b1 : a
├ ─ ╯
○ a : d
○ d : c
○ c : b2
○ b2
◆
" ###);
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
2024-03-29 13:32:55 +00:00
// Rebase a subgraph with disconnected commits. Since "b2" is an ancestor of
// "e", "b2" should be a parent of "e" after the rebase.
let ( stdout , stderr ) = test_env . jj_cmd_ok (
& repo_path ,
& [ " rebase " , " -r " , " e " , " -r " , " b2 " , " --after " , " d " ] ,
) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
Rebased 2 commits onto destination
Rebased 3 descendant commits
2024-04-29 19:18:03 +00:00
Working copy now at : xznxytkn 3238 a418 f | f
Parent commit : kmkuslsw 6 a51bd41 c | c
2024-03-29 13:32:55 +00:00
Added 0 files , modified 0 files , removed 2 files
" ###);
2024-08-14 11:24:29 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ f : c
│ ○ e : b2
│ ○ b2 : d
│ ○ d : c
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ c : b1 b4
2024-03-29 13:32:55 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ b4 : b3
│ ○ b3 : a
○ │ b1 : a
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-14 11:24:29 +00:00
○ a
◆
2024-03-29 13:32:55 +00:00
" ###);
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
2024-04-30 12:56:53 +00:00
// `rebase -s` of commit "c" and its descendants after itself should be a no-op.
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -s " , " c " , " --after " , " c " ] ) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
Skipped rebase of 4 commits that were already in place
Nothing changed .
" ###);
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
@ f : e
○ e : c
│ ○ d : c
├ ─ ╯
○ c : b2 b4
├ ─ ╮
│ ○ b4 : b3
│ ○ b3 : a
○ │ b2 : b1
○ │ b1 : a
├ ─ ╯
○ a
◆
" ###);
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
// `rebase -s` of a commit and its descendants after multiple commits.
let ( stdout , stderr ) = test_env . jj_cmd_ok (
& repo_path ,
& [ " rebase " , " -s " , " c " , " --after " , " b1 " , " --after " , " b3 " ] ,
) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
2024-11-11 12:43:52 +00:00
insta ::assert_snapshot! ( stderr , @ r #"
Rebased 4 commits onto destination
2024-04-30 12:56:53 +00:00
Rebased 2 descendant commits
Working copy now at : xznxytkn a4ace41c f | f
Parent commit : nkmrtpmo c7744d08 e | e
Added 0 files , modified 0 files , removed 2 files
2024-11-11 12:43:52 +00:00
" #);
2024-04-30 12:56:53 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
○ b4 : d f
├ ─ ╮
│ │ ○ b2 : d f
╭ ─ ┬ ─ ╯
│ @ f : e
│ ○ e : c
○ │ d : c
├ ─ ╯
○ c : b1 b3
├ ─ ╮
│ ○ b3 : a
○ │ b1 : a
├ ─ ╯
○ a
◆
" ###);
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
2024-04-30 18:45:56 +00:00
// `rebase -b` of commit "b3" after "b1" moves its descendants which are not
// already descendants of "b1" (just "b3" and "b4") in between "b1" and its
// child "b2".
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -b " , " b3 " , " --after " , " b1 " ] ) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r #"
Rebased 6 commits onto destination
Rebased 1 descendant commits
Working copy now at : xznxytkn b4078b57 f | f
Parent commit : nkmrtpmo 1 b95558f e | e
Added 0 files , modified 0 files , removed 1 files
" #);
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r #"
○ b2 : d f
├ ─ ╮
│ @ f : e
│ ○ e : c
○ │ d : c
├ ─ ╯
○ c : b4
○ b4 : b3
○ b3 : b1
○ b1 : a
○ a
◆
" #);
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
2024-03-29 13:32:55 +00:00
// Should error if a loop will be created.
let stderr = test_env . jj_cmd_failure (
& repo_path ,
& [ " rebase " , " -r " , " e " , " --after " , " a " , " --after " , " b2 " ] ,
) ;
insta ::assert_snapshot! ( stderr , @ r ###"
Error : Refusing to create a loop : commit 2 b8e1148290f would be both an ancestor and a descendant of the rebased commits
" ###);
}
#[ test ]
2024-04-30 12:56:53 +00:00
fn test_rebase_before ( ) {
2024-03-29 13:32:55 +00:00
let test_env = TestEnvironment ::default ( ) ;
2024-05-17 19:49:25 +00:00
test_env . jj_cmd_ok ( test_env . env_root ( ) , & [ " git " , " init " , " repo " ] ) ;
2024-03-29 13:32:55 +00:00
let repo_path = test_env . env_root ( ) . join ( " repo " ) ;
create_commit ( & test_env , & repo_path , " a " , & [ ] ) ;
create_commit ( & test_env , & repo_path , " b1 " , & [ " a " ] ) ;
create_commit ( & test_env , & repo_path , " b2 " , & [ " b1 " ] ) ;
create_commit ( & test_env , & repo_path , " b3 " , & [ " a " ] ) ;
create_commit ( & test_env , & repo_path , " b4 " , & [ " b3 " ] ) ;
create_commit ( & test_env , & repo_path , " c " , & [ " b2 " , " b4 " ] ) ;
create_commit ( & test_env , & repo_path , " d " , & [ " c " ] ) ;
create_commit ( & test_env , & repo_path , " e " , & [ " c " ] ) ;
create_commit ( & test_env , & repo_path , " f " , & [ " e " ] ) ;
// Test the setup
2024-08-14 11:24:29 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ f : e
○ e : c
│ ○ d : c
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ c : b2 b4
2024-03-29 13:32:55 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ b4 : b3
│ ○ b3 : a
○ │ b2 : b1
○ │ b1 : a
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-14 11:24:29 +00:00
○ a
◆
2024-03-29 13:32:55 +00:00
" ###);
let setup_opid = test_env . current_operation_id ( & repo_path ) ;
// Rebasing a commit before its children should be a no-op.
let ( stdout , stderr ) = test_env . jj_cmd_ok (
& repo_path ,
& [ " rebase " , " -r " , " c " , " --before " , " d " , " --before " , " e " ] ,
) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
2024-04-29 07:45:33 +00:00
Skipped rebase of 4 commits that were already in place
2024-03-29 13:32:55 +00:00
Nothing changed .
" ###);
2024-08-14 11:24:29 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ f : e
○ e : c
│ ○ d : c
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ c : b2 b4
2024-03-29 13:32:55 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ b4 : b3
│ ○ b3 : a
○ │ b2 : b1
○ │ b1 : a
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-14 11:24:29 +00:00
○ a
◆
2024-03-29 13:32:55 +00:00
" ###);
// Rebasing a commit before itself should be a no-op.
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -r " , " c " , " --before " , " c " ] ) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
2024-04-29 07:45:33 +00:00
Skipped rebase of 4 commits that were already in place
2024-03-29 13:32:55 +00:00
Nothing changed .
" ###);
2024-08-14 11:24:29 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ f : e
○ e : c
│ ○ d : c
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ c : b2 b4
2024-03-29 13:32:55 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ b4 : b3
│ ○ b3 : a
○ │ b2 : b1
○ │ b1 : a
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-14 11:24:29 +00:00
○ a
◆
2024-03-29 13:32:55 +00:00
" ###);
// Rebasing a commit before the root commit should error.
let stderr = test_env . jj_cmd_failure ( & repo_path , & [ " rebase " , " -r " , " c " , " --before " , " root() " ] ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
Error : The root commit 000000000000 is immutable
" ###);
// Rebase a commit before another commit. "c" has parents "b2" and "b4", so its
// children "d" and "e" should be rebased onto "b2" and "b4" respectively.
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -r " , " c " , " --before " , " a " ] ) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
Rebased 1 commits onto destination
Rebased 8 descendant commits
Working copy now at : xznxytkn 24335685 f | f
Parent commit : nkmrtpmo e9a28d4b e | e
" ###);
2024-08-14 11:24:29 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ f : e
○ e : b2 b4
2024-03-29 13:32:55 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ │ ○ d : b2 b4
2024-03-29 13:32:55 +00:00
╭ ─ ┬ ─ ╯
2024-08-17 08:03:00 +00:00
│ ○ b4 : b3
│ ○ b3 : a
○ │ b2 : b1
○ │ b1 : a
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ a : c
2024-08-14 11:24:29 +00:00
○ c
◆
2024-03-29 13:32:55 +00:00
" ###);
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
// Rebase a commit before its parent.
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -r " , " f " , " --before " , " e " ] ) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
Rebased 1 commits onto destination
Rebased 1 descendant commits
Working copy now at : xznxytkn 8e3 b728a f | f
Parent commit : kmkuslsw cd86b3e4 c | c
Added 0 files , modified 0 files , removed 1 files
" ###);
2024-08-14 11:24:29 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
○ e : f
@ f : c
│ ○ d : c
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ c : b2 b4
2024-03-29 13:32:55 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ b4 : b3
│ ○ b3 : a
○ │ b2 : b1
○ │ b1 : a
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-14 11:24:29 +00:00
○ a
◆
2024-03-29 13:32:55 +00:00
" ###);
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
2024-08-21 19:59:15 +00:00
// Rebase a commit before a commit in a bookmark of a merge commit.
2024-03-29 13:32:55 +00:00
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -r " , " f " , " --before " , " b2 " ] ) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
Rebased 1 commits onto destination
Rebased 4 descendant commits
Working copy now at : xznxytkn 2 b4f48f8 f | f
Parent commit : zsuskuln 072 d5ae1 b1 | b1
Added 0 files , modified 0 files , removed 5 files
" ###);
2024-08-14 11:24:29 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
○ e : c
│ ○ d : c
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ c : b2 b4
2024-03-29 13:32:55 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ b4 : b3
│ ○ b3 : a
○ │ b2 : f
@ │ f : b1
○ │ b1 : a
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-14 11:24:29 +00:00
○ a
◆
2024-03-29 13:32:55 +00:00
" ###);
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
2024-08-21 19:59:15 +00:00
// Rebase a commit before the first commit in a bookmark of a merge commit.
2024-03-29 13:32:55 +00:00
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -r " , " f " , " --before " , " b1 " ] ) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
Rebased 1 commits onto destination
Rebased 5 descendant commits
Working copy now at : xznxytkn 488 ebb95 f | f
Parent commit : rlvkpnrz 2443 ea76 a | a
Added 0 files , modified 0 files , removed 6 files
" ###);
2024-08-14 11:24:29 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
○ e : c
│ ○ d : c
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ c : b2 b4
2024-03-29 13:32:55 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ b4 : b3
│ ○ b3 : a
○ │ b2 : b1
○ │ b1 : f
@ │ f : a
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-14 11:24:29 +00:00
○ a
◆
2024-03-29 13:32:55 +00:00
" ###);
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
// Rebase a commit before a merge commit. "c" has two parents "b2" and "b4", so
// the rebased commit "f" will have the two commits "b2" and "b4" as its
// parents.
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -r " , " f " , " --before " , " c " ] ) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
Rebased 1 commits onto destination
Rebased 3 descendant commits
Working copy now at : xznxytkn aae1bc10 f | f
Parent commit : royxmykx 2 b8e1148 b2 | b2
Parent commit : znkkpsqq a52a83a4 b4 | b4
Added 0 files , modified 0 files , removed 2 files
" ###);
2024-08-14 11:24:29 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
○ e : c
│ ○ d : c
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ c : f
@ f : b2 b4
2024-03-29 13:32:55 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ b4 : b3
│ ○ b3 : a
○ │ b2 : b1
○ │ b1 : a
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-14 11:24:29 +00:00
○ a
◆
2024-03-29 13:32:55 +00:00
" ###);
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
// Rebase a commit before multiple commits.
let ( stdout , stderr ) = test_env . jj_cmd_ok (
& repo_path ,
& [ " rebase " , " -r " , " b1 " , " --before " , " d " , " --before " , " e " ] ,
) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
Rebased 1 commits onto destination
Rebased 5 descendant commits
Working copy now at : xznxytkn 8268 ec4d f | f
Parent commit : nkmrtpmo fd26fbd4 e | e
" ###);
2024-08-14 11:24:29 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ f : e
○ e : b1
│ ○ d : b1
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ b1 : c
○ c : b2 b4
2024-03-29 13:32:55 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ b4 : b3
│ ○ b3 : a
○ │ b2 : a
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-14 11:24:29 +00:00
○ a
◆
2024-03-29 13:32:55 +00:00
" ###);
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
2024-08-21 19:59:15 +00:00
// Rebase a commit before two commits in separate bookmarks to create a merge
2024-03-29 13:32:55 +00:00
// commit.
let ( stdout , stderr ) = test_env . jj_cmd_ok (
& repo_path ,
& [ " rebase " , " -r " , " f " , " --before " , " b2 " , " --before " , " b4 " ] ,
) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
Rebased 1 commits onto destination
Rebased 5 descendant commits
Working copy now at : xznxytkn 7 ba8014f f | f
Parent commit : zsuskuln 072 d5ae1 b1 | b1
Parent commit : vruxwmqv 523e6 a8b b3 | b3
Added 0 files , modified 0 files , removed 4 files
" ###);
2024-08-14 11:24:29 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
○ e : c
│ ○ d : c
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ c : b2 b4
2024-03-29 13:32:55 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ b4 : f
○ │ b2 : f
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
@ f : b1 b3
2024-03-29 13:32:55 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ b3 : a
○ │ b1 : a
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-14 11:24:29 +00:00
○ a
◆
2024-03-29 13:32:55 +00:00
" ###);
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
// Rebase two unrelated commits "b2" and "b4" before a single commit "a". This
// creates a merge commit "a" with the two parents "b2" and "b4".
let ( stdout , stderr ) = test_env . jj_cmd_ok (
& repo_path ,
& [ " rebase " , " -r " , " b2 " , " -r " , " b4 " , " --before " , " a " ] ,
) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
Rebased 2 commits onto destination
Rebased 7 descendant commits
Working copy now at : xznxytkn fabd8dd7 f | f
Parent commit : nkmrtpmo b5933877 e | e
" ###);
2024-08-14 11:24:29 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ f : e
○ e : c
│ ○ d : c
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ c : b1 b3
2024-03-29 13:32:55 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ b3 : a
○ │ b1 : a
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ a : b2 b4
2024-03-29 13:32:55 +00:00
├ ─ ╮
2024-08-14 11:24:29 +00:00
│ ○ b4
○ │ b2
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-14 11:24:29 +00:00
◆
2024-03-29 13:32:55 +00:00
" ###);
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
// Rebase a subgraph with a merge commit and two parents.
let ( stdout , stderr ) = test_env . jj_cmd_ok (
& repo_path ,
& [ " rebase " , " -r " , " b2 " , " -r " , " b4 " , " -r " , " c " , " --before " , " e " ] ,
) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
Rebased 3 commits onto destination
Rebased 3 descendant commits
Working copy now at : xznxytkn cbe2be58 f | f
Parent commit : nkmrtpmo e31053d1 e | e
" ###);
2024-08-14 11:24:29 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ f : e
○ e : c
○ c : b2 b4
2024-03-29 13:32:55 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ b4 : b1 b3
2024-03-29 13:32:55 +00:00
│ ├ ─ ╮
2024-08-17 08:03:00 +00:00
○ │ │ b2 : b1 b3
2024-03-29 13:32:55 +00:00
╰ ─ ┬ ─ ╮
2024-08-17 08:03:00 +00:00
○ │ │ d : b1 b3
2024-03-29 13:32:55 +00:00
╰ ─ ┬ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ b3 : a
○ │ b1 : a
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-14 11:24:29 +00:00
○ a
◆
2024-03-29 13:32:55 +00:00
" ###);
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
// Rebase a subgraph with disconnected commits. Since "b1" is an ancestor of
// "e", "b1" should be a parent of "e" after the rebase.
let ( stdout , stderr ) = test_env . jj_cmd_ok (
& repo_path ,
& [ " rebase " , " -r " , " b1 " , " -r " , " e " , " --before " , " a " ] ,
) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
Rebased 2 commits onto destination
Rebased 7 descendant commits
Working copy now at : xznxytkn 1 c48b514 f | f
Parent commit : kmkuslsw c0fd979a c | c
" ###);
2024-08-14 11:24:29 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ f : c
│ ○ d : c
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ c : b2 b4
2024-03-29 13:32:55 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ b4 : b3
│ ○ b3 : a
○ │ b2 : a
2024-03-29 13:32:55 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ a : e
○ e : b1
2024-08-14 11:24:29 +00:00
○ b1
◆
2024-04-29 19:18:03 +00:00
" ###);
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
// Rebase a subgraph before the parents of one of the commits in the subgraph.
// "c" had parents "b2" and "b4", but no longer has "b4" as a parent since
// "b4" would be a descendant of "c" after the rebase.
let ( stdout , stderr ) =
test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -r " , " b2::d " , " --before " , " a " ] ) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
Rebased 3 commits onto destination
Rebased 6 descendant commits
Working copy now at : xznxytkn f5991dc7 f | f
Parent commit : nkmrtpmo 37894e3 c e | e
Added 1 files , modified 0 files , removed 0 files
" ###);
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
@ f : e
○ e : b1 b4
├ ─ ╮
│ ○ b4 : b3
│ ○ b3 : a
○ │ b1 : a
├ ─ ╯
○ a : d
○ d : c
○ c : b2
○ b2
◆
2024-03-29 13:32:55 +00:00
" ###);
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
2024-04-30 12:56:53 +00:00
// Rebase a subgraph before the parents of one of the commits in the subgraph.
// "c" had parents "b2" and "b4", but no longer has "b4" as a parent since
// "b4" would be a descendant of "c" after the rebase.
let ( stdout , stderr ) =
test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -r " , " b2::d " , " --before " , " a " ] ) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
Rebased 3 commits onto destination
Rebased 6 descendant commits
Working copy now at : xznxytkn 308 a31e9 f | f
Parent commit : nkmrtpmo 538444 a5 e | e
Added 1 files , modified 0 files , removed 0 files
" ###);
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
@ f : e
○ e : b1 b4
├ ─ ╮
│ ○ b4 : b3
│ ○ b3 : a
○ │ b1 : a
├ ─ ╯
○ a : d
○ d : c
○ c : b2
○ b2
◆
" ###);
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
// `rebase -s` of commit "c" and its descendants before itself should be a
// no-op.
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -s " , " c " , " --before " , " c " ] ) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
Skipped rebase of 4 commits that were already in place
Nothing changed .
" ###);
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
@ f : e
○ e : c
│ ○ d : c
├ ─ ╯
○ c : b2 b4
├ ─ ╮
│ ○ b4 : b3
│ ○ b3 : a
○ │ b2 : b1
○ │ b1 : a
├ ─ ╯
○ a
◆
" ###);
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
// `rebase -s` of a commit and its descendants before multiple commits.
let ( stdout , stderr ) = test_env . jj_cmd_ok (
& repo_path ,
& [ " rebase " , " -s " , " c " , " --before " , " b2 " , " --before " , " b4 " ] ,
) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
2024-11-11 12:43:52 +00:00
insta ::assert_snapshot! ( stderr , @ r #"
Rebased 4 commits onto destination
2024-04-30 12:56:53 +00:00
Rebased 2 descendant commits
Working copy now at : xznxytkn 84704387 f | f
Parent commit : nkmrtpmo cff61821 e | e
Added 0 files , modified 0 files , removed 2 files
2024-11-11 12:43:52 +00:00
" #);
2024-04-30 12:56:53 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r ###"
○ b4 : d f
├ ─ ╮
│ │ ○ b2 : d f
╭ ─ ┬ ─ ╯
│ @ f : e
│ ○ e : c
○ │ d : c
├ ─ ╯
○ c : b1 b3
├ ─ ╮
│ ○ b3 : a
○ │ b1 : a
├ ─ ╯
○ a
◆
" ###);
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
2024-04-30 18:45:56 +00:00
// `rebase -b` of commit "b3" before "b2" moves its descendants which are not
// already descendants of its parent "b1" (just "b3" and "b4") in between "b1"
// and its child "b2".
let ( stdout , stderr ) =
test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -b " , " b3 " , " --before " , " b1 " ] ) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r #"
Skipped rebase of 2 commits that were already in place
Rebased 4 commits onto destination
Rebased 2 descendant commits
Working copy now at : xznxytkn 16422 f85 f | f
Parent commit : nkmrtpmo ef9dea83 e | e
Added 0 files , modified 0 files , removed 2 files
" #);
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r #"
○ b2 : b1
○ b1 : d f
├ ─ ╮
│ @ f : e
│ ○ e : c
○ │ d : c
├ ─ ╯
○ c : b4
○ b4 : b3
○ b3 : a
○ a
◆
" #);
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
2024-03-29 13:32:55 +00:00
// Should error if a loop will be created.
let stderr = test_env . jj_cmd_failure (
& repo_path ,
& [ " rebase " , " -r " , " e " , " --before " , " b2 " , " --before " , " c " ] ,
) ;
insta ::assert_snapshot! ( stderr , @ r ###"
Error : Refusing to create a loop : commit 2 b8e1148290f would be both an ancestor and a descendant of the rebased commits
" ###);
}
2024-03-29 20:57:06 +00:00
#[ test ]
2024-04-30 12:56:53 +00:00
fn test_rebase_after_before ( ) {
2024-03-29 20:57:06 +00:00
let test_env = TestEnvironment ::default ( ) ;
2024-05-17 19:49:25 +00:00
test_env . jj_cmd_ok ( test_env . env_root ( ) , & [ " git " , " init " , " repo " ] ) ;
2024-03-29 20:57:06 +00:00
let repo_path = test_env . env_root ( ) . join ( " repo " ) ;
2024-04-30 18:45:56 +00:00
create_commit ( & test_env , & repo_path , " x " , & [ ] ) ;
create_commit ( & test_env , & repo_path , " y " , & [ " x " ] ) ;
create_commit ( & test_env , & repo_path , " z " , & [ " y " ] ) ;
2024-03-29 20:57:06 +00:00
create_commit ( & test_env , & repo_path , " a " , & [ ] ) ;
create_commit ( & test_env , & repo_path , " b1 " , & [ " a " ] ) ;
create_commit ( & test_env , & repo_path , " b2 " , & [ " a " ] ) ;
create_commit ( & test_env , & repo_path , " c " , & [ " b1 " , " b2 " ] ) ;
create_commit ( & test_env , & repo_path , " d " , & [ " c " ] ) ;
create_commit ( & test_env , & repo_path , " e " , & [ " c " ] ) ;
create_commit ( & test_env , & repo_path , " f " , & [ " e " ] ) ;
// Test the setup
2024-04-30 18:45:56 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r #"
2024-08-17 08:03:00 +00:00
@ f : e
○ e : c
│ ○ d : c
2024-03-29 20:57:06 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ c : b1 b2
2024-03-29 20:57:06 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ b2 : a
○ │ b1 : a
2024-03-29 20:57:06 +00:00
├ ─ ╯
2024-08-14 11:24:29 +00:00
○ a
2024-04-30 18:45:56 +00:00
│ ○ z : y
│ ○ y : x
│ ○ x
├ ─ ╯
2024-08-14 11:24:29 +00:00
◆
2024-04-30 18:45:56 +00:00
" #);
2024-03-29 20:57:06 +00:00
let setup_opid = test_env . current_operation_id ( & repo_path ) ;
// Rebase a commit after another commit and before that commit's child to
// insert directly between the two commits.
let ( stdout , stderr ) = test_env . jj_cmd_ok (
& repo_path ,
& [ " rebase " , " -r " , " d " , " --after " , " e " , " --before " , " f " ] ,
) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
2024-04-30 18:45:56 +00:00
insta ::assert_snapshot! ( stderr , @ r #"
2024-03-29 20:57:06 +00:00
Rebased 1 commits onto destination
Rebased 1 descendant commits
2024-04-30 18:45:56 +00:00
Working copy now at : nmzmmopx 56 c81c6d f | f
Parent commit : nkmrtpmo ff196f69 d | d
2024-03-29 20:57:06 +00:00
Added 1 files , modified 0 files , removed 0 files
2024-04-30 18:45:56 +00:00
" #);
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r #"
2024-08-17 08:03:00 +00:00
@ f : d
○ d : e
○ e : c
○ c : b1 b2
2024-03-29 20:57:06 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ b2 : a
○ │ b1 : a
2024-03-29 20:57:06 +00:00
├ ─ ╯
2024-08-14 11:24:29 +00:00
○ a
2024-04-30 18:45:56 +00:00
│ ○ z : y
│ ○ y : x
│ ○ x
├ ─ ╯
2024-08-14 11:24:29 +00:00
◆
2024-04-30 18:45:56 +00:00
" #);
2024-03-29 20:57:06 +00:00
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
// Rebase a commit after another commit and before that commit's descendant to
// create a new merge commit.
let ( stdout , stderr ) = test_env . jj_cmd_ok (
& repo_path ,
& [ " rebase " , " -r " , " d " , " --after " , " a " , " --before " , " f " ] ,
) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
2024-04-30 18:45:56 +00:00
insta ::assert_snapshot! ( stderr , @ r #"
2024-03-29 20:57:06 +00:00
Rebased 1 commits onto destination
Rebased 1 descendant commits
2024-04-30 18:45:56 +00:00
Working copy now at : nmzmmopx 398173 ed f | f
Parent commit : xznxytkn b3e6aadf e | e
Parent commit : nkmrtpmo db529447 d | d
2024-03-29 20:57:06 +00:00
Added 1 files , modified 0 files , removed 0 files
2024-04-30 18:45:56 +00:00
" #);
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r #"
2024-08-17 08:03:00 +00:00
@ f : e d
2024-03-29 20:57:06 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ d : a
○ │ e : c
○ │ c : b1 b2
2024-03-29 20:57:06 +00:00
├ ─ ─ ─ ╮
2024-08-17 08:03:00 +00:00
│ │ ○ b2 : a
2024-03-29 20:57:06 +00:00
│ ├ ─ ╯
2024-08-17 08:03:00 +00:00
○ │ b1 : a
2024-03-29 20:57:06 +00:00
├ ─ ╯
2024-08-14 11:24:29 +00:00
○ a
2024-04-30 18:45:56 +00:00
│ ○ z : y
│ ○ y : x
│ ○ x
├ ─ ╯
2024-08-14 11:24:29 +00:00
◆
2024-04-30 18:45:56 +00:00
" #);
2024-03-29 20:57:06 +00:00
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
// "c" has parents "b1" and "b2", so when it is rebased, its children "d" and
// "e" should have "b1" and "b2" as parents as well. "c" is then inserted in
// between "d" and "e", making "e" a merge commit with 3 parents "b1", "b2",
// and "c".
let ( stdout , stderr ) = test_env . jj_cmd_ok (
& repo_path ,
& [ " rebase " , " -r " , " c " , " --after " , " d " , " --before " , " e " ] ,
) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
2024-04-30 18:45:56 +00:00
insta ::assert_snapshot! ( stderr , @ r #"
2024-03-29 20:57:06 +00:00
Rebased 1 commits onto destination
Rebased 3 descendant commits
2024-04-30 18:45:56 +00:00
Working copy now at : nmzmmopx 2 be98daf f | f
Parent commit : xznxytkn 911 fc846 e | e
2024-03-29 20:57:06 +00:00
Added 1 files , modified 0 files , removed 0 files
2024-04-30 18:45:56 +00:00
" #);
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r #"
2024-08-17 08:03:00 +00:00
@ f : e
○ e : b1 b2 c
2024-03-29 20:57:06 +00:00
├ ─ ┬ ─ ╮
2024-08-17 08:03:00 +00:00
│ │ ○ c : d
│ │ ○ d : b1 b2
2024-03-29 20:57:06 +00:00
╭ ─ ┬ ─ ╯
2024-08-17 08:03:00 +00:00
│ ○ b2 : a
○ │ b1 : a
2024-03-29 20:57:06 +00:00
├ ─ ╯
2024-08-14 11:24:29 +00:00
○ a
2024-04-30 18:45:56 +00:00
│ ○ z : y
│ ○ y : x
│ ○ x
├ ─ ╯
2024-08-14 11:24:29 +00:00
◆
2024-04-30 18:45:56 +00:00
" #);
2024-03-29 20:57:06 +00:00
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
// Rebase multiple commits and preserve their ancestry. Apart from the heads of
// the target commits ("d" and "e"), "f" also has commits "b1" and "b2" as
// parents since its parents "d" and "e" were in the target set and were
// replaced by their closest ancestors outside the target set.
let ( stdout , stderr ) = test_env . jj_cmd_ok (
& repo_path ,
& [
" rebase " , " -r " , " c " , " -r " , " d " , " -r " , " e " , " --after " , " a " , " --before " , " f " ,
] ,
) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
2024-04-30 18:45:56 +00:00
insta ::assert_snapshot! ( stderr , @ r #"
2024-03-29 20:57:06 +00:00
Rebased 3 commits onto destination
Rebased 1 descendant commits
2024-04-30 18:45:56 +00:00
Working copy now at : nmzmmopx bee09b10 f | f
Parent commit : znkkpsqq 9167144 b b1 | b1
Parent commit : kmkuslsw 87 fed139 b2 | b2
Parent commit : nkmrtpmo 4 a8ca156 d | d
Parent commit : xznxytkn 0 cc1825e e | e
2024-03-29 20:57:06 +00:00
Added 1 files , modified 0 files , removed 0 files
2024-04-30 18:45:56 +00:00
" #);
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r #"
2024-08-17 08:03:00 +00:00
@ f : b1 b2 d e
2024-03-29 20:57:06 +00:00
├ ─ ┬ ─ ┬ ─ ╮
2024-08-17 08:03:00 +00:00
│ │ │ ○ e : c
│ │ ○ │ d : c
2024-03-29 20:57:06 +00:00
│ │ ├ ─ ╯
2024-08-17 08:03:00 +00:00
│ │ ○ c : a
│ ○ │ b2 : a
2024-03-29 20:57:06 +00:00
│ ├ ─ ╯
2024-08-17 08:03:00 +00:00
○ │ b1 : a
2024-03-29 20:57:06 +00:00
├ ─ ╯
2024-08-14 11:24:29 +00:00
○ a
2024-04-30 18:45:56 +00:00
│ ○ z : y
│ ○ y : x
│ ○ x
├ ─ ╯
2024-08-14 11:24:29 +00:00
◆
2024-04-30 18:45:56 +00:00
" #);
2024-03-29 20:57:06 +00:00
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
2024-04-30 12:56:53 +00:00
// `rebase -s` of a commit and its descendants.
let ( stdout , stderr ) = test_env . jj_cmd_ok (
& repo_path ,
& [ " rebase " , " -s " , " c " , " --before " , " b1 " , " --after " , " b2 " ] ,
) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
2024-11-11 12:43:52 +00:00
insta ::assert_snapshot! ( stderr , @ r #"
Rebased 4 commits onto destination
2024-04-30 12:56:53 +00:00
Rebased 1 descendant commits
2024-04-30 18:45:56 +00:00
Working copy now at : nmzmmopx 951204 cf f | f
Parent commit : xznxytkn fe8ec4e2 e | e
2024-04-30 12:56:53 +00:00
Added 0 files , modified 0 files , removed 1 files
2024-11-11 12:43:52 +00:00
" #);
2024-04-30 18:45:56 +00:00
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r #"
2024-04-30 12:56:53 +00:00
○ b1 : a d f
├ ─ ┬ ─ ╮
│ │ @ f : e
│ │ ○ e : c
│ ○ │ d : c
│ ├ ─ ╯
│ ○ c : b2
│ ○ b2 : a
├ ─ ╯
○ a
2024-04-30 18:45:56 +00:00
│ ○ z : y
│ ○ y : x
│ ○ x
├ ─ ╯
2024-04-30 12:56:53 +00:00
◆
2024-04-30 18:45:56 +00:00
" #);
2024-04-30 12:56:53 +00:00
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
2024-04-30 18:45:56 +00:00
// `rebase -b` of a commit "y" to a destination after "a" will rebase all
// commits in "roots(a..y)" and their descendants, corresponding to "x", "y"
// and "z". They will be inserted in a new branch after "a" and before "c".
let ( stdout , stderr ) = test_env . jj_cmd_ok (
& repo_path ,
& [ " rebase " , " -b " , " y " , " --after " , " a " , " --before " , " c " ] ,
) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r #"
Rebased 3 commits onto destination
Rebased 4 descendant commits
Working copy now at : nmzmmopx 4496 f88e f | f
Parent commit : xznxytkn a85404a6 e | e
Added 3 files , modified 0 files , removed 0 files
" #);
insta ::assert_snapshot! ( get_log_output ( & test_env , & repo_path ) , @ r #"
@ f : e
○ e : c
│ ○ d : c
├ ─ ╯
○ c : b1 b2 z
├ ─ ┬ ─ ╮
│ │ ○ z : y
│ │ ○ y : x
│ │ ○ x : a
│ ○ │ b2 : a
│ ├ ─ ╯
○ │ b1 : a
├ ─ ╯
○ a
◆
" #);
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
2024-03-29 20:57:06 +00:00
// Should error if a loop will be created.
let stderr = test_env . jj_cmd_failure (
& repo_path ,
& [ " rebase " , " -r " , " e " , " --after " , " c " , " --before " , " a " ] ,
) ;
2024-04-30 18:45:56 +00:00
insta ::assert_snapshot! ( stderr , @ " Error: Refusing to create a loop: commit 31b84afe1c8f would be both an ancestor and a descendant of the rebased commits " ) ;
2024-03-29 20:57:06 +00:00
}
2024-02-25 17:41:07 +00:00
#[ test ]
2024-07-03 01:54:36 +00:00
fn test_rebase_skip_emptied ( ) {
2024-02-25 17:41:07 +00:00
let test_env = TestEnvironment ::default ( ) ;
2024-05-17 19:49:25 +00:00
test_env . jj_cmd_ok ( test_env . env_root ( ) , & [ " git " , " init " , " repo " ] ) ;
2024-02-25 17:41:07 +00:00
let repo_path = test_env . env_root ( ) . join ( " repo " ) ;
create_commit ( & test_env , & repo_path , " a " , & [ ] ) ;
create_commit ( & test_env , & repo_path , " b " , & [ " a " ] ) ;
test_env . jj_cmd_ok ( & repo_path , & [ " new " , " a " , " -m " , " will become empty " ] ) ;
test_env . jj_cmd_ok ( & repo_path , & [ " restore " , " --from=b " ] ) ;
test_env . jj_cmd_ok ( & repo_path , & [ " new " , " -m " , " already empty " ] ) ;
test_env . jj_cmd_ok ( & repo_path , & [ " new " , " -m " , " also already empty " ] ) ;
2024-11-05 23:38:28 +00:00
let setup_opid = test_env . current_operation_id ( & repo_path ) ;
2024-02-25 17:41:07 +00:00
// Test the setup
insta ::assert_snapshot! ( test_env . jj_cmd_success ( & repo_path , & [ " log " , " -T " , " description " ] ) , @ r ###"
@ also already empty
2024-07-15 22:20:10 +00:00
○ already empty
○ will become empty
│ ○ b
2024-02-25 17:41:07 +00:00
├ ─ ╯
2024-07-15 22:20:10 +00:00
○ a
◆
2024-02-25 17:41:07 +00:00
" ###);
2024-07-03 01:54:36 +00:00
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -d=b " , " --skip-emptied " ] ) ;
2024-02-25 17:41:07 +00:00
insta ::assert_snapshot! ( stdout , @ " " ) ;
2024-11-05 23:38:28 +00:00
insta ::assert_snapshot! ( stderr , @ r #"
2024-11-11 12:43:52 +00:00
Rebased 2 commits onto destination
2024-04-30 11:27:24 +00:00
Abandoned 1 newly emptied commits
2024-11-05 23:38:28 +00:00
Working copy now at : yostqsxw bc4222f2 ( empty ) also already empty
Parent commit : vruxwmqv 6 b41ecb2 ( empty ) already empty
" #);
2024-02-25 17:41:07 +00:00
// The parent commit became empty and was dropped, but the already empty commits
// were kept
insta ::assert_snapshot! ( test_env . jj_cmd_success ( & repo_path , & [ " log " , " -T " , " description " ] ) , @ r ###"
@ also already empty
2024-07-15 22:20:10 +00:00
○ already empty
○ b
○ a
◆
2024-02-25 17:41:07 +00:00
" ###);
2024-11-05 23:38:28 +00:00
test_env . jj_cmd_ok ( & repo_path , & [ " op " , " restore " , & setup_opid ] ) ;
// Test the setup
insta ::assert_snapshot! ( test_env . jj_cmd_success ( & repo_path , & [ " log " , " -T " , " description " ] ) , @ r ###"
@ also already empty
○ already empty
○ will become empty
│ ○ b
├ ─ ╯
○ a
◆
" ###);
let ( stdout , stderr ) = test_env . jj_cmd_ok (
& repo_path ,
& [
" rebase " ,
" -r=description('will become empty') " ,
" -d=b " ,
" --skip-emptied " ,
] ,
) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r #"
Rebased 2 descendant commits
Abandoned 1 newly emptied commits
Working copy now at : yostqsxw 74149 b9b ( empty ) also already empty
Parent commit : vruxwmqv 3 bdb2801 ( empty ) already empty
Added 0 files , modified 0 files , removed 1 files
" #);
// Rebasing a single commit which becomes empty abandons that commit, whilst its
// already empty descendants were kept
insta ::assert_snapshot! ( test_env . jj_cmd_success ( & repo_path , & [ " log " , " -T " , " description " ] ) , @ r #"
@ also already empty
○ already empty
│ ○ b
├ ─ ╯
○ a
◆
" #);
2024-02-25 17:41:07 +00:00
}
2024-03-25 11:46:10 +00:00
2024-11-07 18:42:51 +00:00
#[ test ]
fn test_rebase_skip_emptied_descendants ( ) {
let test_env = TestEnvironment ::default ( ) ;
test_env . jj_cmd_ok ( test_env . env_root ( ) , & [ " git " , " init " , " repo " ] ) ;
let repo_path = test_env . env_root ( ) . join ( " repo " ) ;
create_commit ( & test_env , & repo_path , " a " , & [ ] ) ;
create_commit ( & test_env , & repo_path , " b " , & [ " a " ] ) ;
test_env . jj_cmd_ok ( & repo_path , & [ " new " , " a " , " -m " , " c (will become empty) " ] ) ;
test_env . jj_cmd_ok ( & repo_path , & [ " restore " , " --from=b " ] ) ;
test_env . jj_cmd_ok ( & repo_path , & [ " bookmark " , " create " , " c " ] ) ;
test_env . jj_cmd_ok ( & repo_path , & [ " new " , " -m " , " already empty " ] ) ;
test_env . jj_cmd_ok ( & repo_path , & [ " new " , " -m " , " also already empty " ] ) ;
// Test the setup
insta ::assert_snapshot! ( test_env . jj_cmd_success ( & repo_path , & [ " log " , " -T " , " description " ] ) , @ r #"
@ also already empty
○ already empty
○ c ( will become empty )
│ ○ b
├ ─ ╯
○ a
◆
" #);
let ( stdout , stderr ) = test_env . jj_cmd_ok (
& repo_path ,
2024-11-05 23:38:28 +00:00
& [ " rebase " , " -r " , " b " , " --before " , " c " , " --skip-emptied " ] ,
2024-11-07 18:42:51 +00:00
) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
insta ::assert_snapshot! ( stderr , @ r #"
Skipped rebase of 1 commits that were already in place
2024-11-05 23:38:28 +00:00
Rebased 3 descendant commits
Working copy now at : znkkpsqq 353 bac5c ( empty ) also already empty
Parent commit : yostqsxw 0 a3f76fd ( empty ) already empty
2024-11-07 18:42:51 +00:00
" #);
2024-11-05 23:38:28 +00:00
// Commits not in the rebase target set should not be abandoned even if they
// were emptied.
2024-11-07 18:42:51 +00:00
insta ::assert_snapshot! ( test_env . jj_cmd_success ( & repo_path , & [ " log " , " -T " , " description " ] ) , @ r #"
@ also already empty
○ already empty
2024-11-05 23:38:28 +00:00
○ c ( will become empty )
2024-11-07 18:42:51 +00:00
○ b
○ a
◆
" #);
}
2024-03-25 11:46:10 +00:00
#[ test ]
fn test_rebase_skip_if_on_destination ( ) {
let test_env = TestEnvironment ::default ( ) ;
2024-05-17 19:49:25 +00:00
test_env . jj_cmd_ok ( test_env . env_root ( ) , & [ " git " , " init " , " repo " ] ) ;
2024-03-25 11:46:10 +00:00
let repo_path = test_env . env_root ( ) . join ( " repo " ) ;
create_commit ( & test_env , & repo_path , " a " , & [ ] ) ;
create_commit ( & test_env , & repo_path , " b1 " , & [ " a " ] ) ;
create_commit ( & test_env , & repo_path , " b2 " , & [ " a " ] ) ;
create_commit ( & test_env , & repo_path , " c " , & [ " b1 " , " b2 " ] ) ;
create_commit ( & test_env , & repo_path , " d " , & [ " c " ] ) ;
create_commit ( & test_env , & repo_path , " e " , & [ " c " ] ) ;
create_commit ( & test_env , & repo_path , " f " , & [ " e " ] ) ;
// Test the setup
insta ::assert_snapshot! ( get_long_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ f lylxulpl 88 f778c5 : e
○ e kmkuslsw 48 dd9e3f : c
│ ○ d znkkpsqq 92438 fc9 : c
2024-03-25 11:46:10 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ c vruxwmqv c41e416e : b1 b2
2024-03-25 11:46:10 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ b2 royxmykx 903 ab0d6 : a
○ │ b1 zsuskuln 072 d5ae1 : a
2024-03-25 11:46:10 +00:00
├ ─ ╯
2024-07-15 22:20:10 +00:00
○ a rlvkpnrz 2443 ea76
◆ zzzzzzzz 00000000
2024-03-25 11:46:10 +00:00
" ###);
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -b " , " d " , " -d " , " a " ] ) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
// Skip rebase with -b
insta ::assert_snapshot! ( stderr , @ r ###"
2024-04-30 11:27:24 +00:00
Skipped rebase of 6 commits that were already in place
Nothing changed .
2024-03-25 11:46:10 +00:00
" ###);
insta ::assert_snapshot! ( get_long_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ f lylxulpl 88 f778c5 : e
○ e kmkuslsw 48 dd9e3f : c
│ ○ d znkkpsqq 92438 fc9 : c
2024-03-25 11:46:10 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ c vruxwmqv c41e416e : b1 b2
2024-03-25 11:46:10 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ b2 royxmykx 903 ab0d6 : a
○ │ b1 zsuskuln 072 d5ae1 : a
2024-03-25 11:46:10 +00:00
├ ─ ╯
2024-07-15 22:20:10 +00:00
○ a rlvkpnrz 2443 ea76
◆ zzzzzzzz 00000000
2024-03-25 11:46:10 +00:00
" ###);
let ( stdout , stderr ) =
test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -s " , " c " , " -d " , " b1 " , " -d " , " b2 " ] ) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
// Skip rebase with -s
insta ::assert_snapshot! ( stderr , @ r ###"
2024-04-30 11:27:24 +00:00
Skipped rebase of 4 commits that were already in place
Nothing changed .
2024-03-25 11:46:10 +00:00
" ###);
insta ::assert_snapshot! ( get_long_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ f lylxulpl 88 f778c5 : e
○ e kmkuslsw 48 dd9e3f : c
│ ○ d znkkpsqq 92438 fc9 : c
2024-03-25 11:46:10 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ c vruxwmqv c41e416e : b1 b2
2024-03-25 11:46:10 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ b2 royxmykx 903 ab0d6 : a
○ │ b1 zsuskuln 072 d5ae1 : a
2024-03-25 11:46:10 +00:00
├ ─ ╯
2024-07-15 22:20:10 +00:00
○ a rlvkpnrz 2443 ea76
◆ zzzzzzzz 00000000
2024-03-25 11:46:10 +00:00
" ###);
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -r " , " d " , " -d " , " c " ] ) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
// Skip rebase with -r since commit has no children
insta ::assert_snapshot! ( stderr , @ r ###"
2024-04-29 07:45:33 +00:00
Skipped rebase of 1 commits that were already in place
2024-03-29 13:32:55 +00:00
Nothing changed .
2024-03-25 11:46:10 +00:00
" ###);
insta ::assert_snapshot! ( get_long_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ f lylxulpl 88 f778c5 : e
○ e kmkuslsw 48 dd9e3f : c
│ ○ d znkkpsqq 92438 fc9 : c
2024-03-25 11:46:10 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ c vruxwmqv c41e416e : b1 b2
2024-03-25 11:46:10 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ b2 royxmykx 903 ab0d6 : a
○ │ b1 zsuskuln 072 d5ae1 : a
2024-03-25 11:46:10 +00:00
├ ─ ╯
2024-07-15 22:20:10 +00:00
○ a rlvkpnrz 2443 ea76
◆ zzzzzzzz 00000000
2024-03-25 11:46:10 +00:00
" ###);
let ( stdout , stderr ) = test_env . jj_cmd_ok ( & repo_path , & [ " rebase " , " -r " , " e " , " -d " , " c " ] ) ;
insta ::assert_snapshot! ( stdout , @ " " ) ;
// Skip rebase of commit, but rebases children onto destination with -r
insta ::assert_snapshot! ( stderr , @ r ###"
2024-04-29 07:45:33 +00:00
Skipped rebase of 1 commits that were already in place
2024-03-29 13:32:55 +00:00
Rebased 1 descendant commits
2024-03-25 11:46:10 +00:00
Working copy now at : lylxulpl 77 cb229f f | f
Parent commit : vruxwmqv c41e416e c | c
Added 0 files , modified 0 files , removed 1 files
" ###);
insta ::assert_snapshot! ( get_long_log_output ( & test_env , & repo_path ) , @ r ###"
2024-08-17 08:03:00 +00:00
@ f lylxulpl 77 cb229f : c
│ ○ e kmkuslsw 48 dd9e3f : c
2024-03-25 11:46:10 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
│ ○ d znkkpsqq 92438 fc9 : c
2024-03-25 11:46:10 +00:00
├ ─ ╯
2024-08-17 08:03:00 +00:00
○ c vruxwmqv c41e416e : b1 b2
2024-03-25 11:46:10 +00:00
├ ─ ╮
2024-08-17 08:03:00 +00:00
│ ○ b2 royxmykx 903 ab0d6 : a
○ │ b1 zsuskuln 072 d5ae1 : a
2024-03-25 11:46:10 +00:00
├ ─ ╯
2024-07-15 22:20:10 +00:00
○ a rlvkpnrz 2443 ea76
◆ zzzzzzzz 00000000
2024-03-25 11:46:10 +00:00
" ###);
}
2024-08-14 11:24:29 +00:00
fn get_log_output ( test_env : & TestEnvironment , repo_path : & Path ) -> String {
2024-08-21 19:59:15 +00:00
let template = " bookmarks ++ surround(': ', '', parents.map(|c| c.bookmarks())) " ;
2024-08-17 08:03:00 +00:00
test_env . jj_cmd_success ( repo_path , & [ " log " , " -T " , template ] )
2024-08-14 11:24:29 +00:00
}
2024-03-25 11:46:10 +00:00
fn get_long_log_output ( test_env : & TestEnvironment , repo_path : & Path ) -> String {
2024-08-21 19:59:15 +00:00
let template = " bookmarks ++ ' ' ++ change_id.shortest(8) ++ ' ' ++ commit_id.shortest(8) \
+ + surround ( ' : ' , ' ' , parents . map ( | c | c . bookmarks ( ) ) ) " ;
2024-03-25 11:46:10 +00:00
test_env . jj_cmd_success ( repo_path , & [ " log " , " -T " , template ] )
}