2023-01-16 19:22:10 +00:00
|
|
|
// Copyright 2023 The Jujutsu Authors
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
use 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]);
|
2023-01-16 19:22:10 +00:00
|
|
|
} else {
|
|
|
|
let mut args = vec!["new", "-m", name];
|
|
|
|
args.extend(parents);
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(repo_path, &args);
|
2023-01-16 19:22:10 +00:00
|
|
|
}
|
|
|
|
std::fs::write(repo_path.join(name), format!("{name}\n")).unwrap();
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(repo_path, &["branch", "create", name]);
|
2023-01-16 19:22:10 +00:00
|
|
|
}
|
|
|
|
|
2023-01-15 05:59:31 +00:00
|
|
|
#[test]
|
|
|
|
fn test_duplicate() {
|
|
|
|
let test_env = TestEnvironment::default();
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
|
2023-01-15 05:59:31 +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"]);
|
|
|
|
// Test the setup
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2023-02-09 02:53:47 +00:00
|
|
|
@ 17a00fc21654 c
|
|
|
|
├─╮
|
2023-07-28 06:51:08 +00:00
|
|
|
│ ◉ d370aee184ba b
|
|
|
|
◉ │ 2443ea76b0b1 a
|
2023-02-09 02:53:47 +00:00
|
|
|
├─╯
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 000000000000
|
2023-01-15 05:59:31 +00:00
|
|
|
"###);
|
|
|
|
|
2023-09-03 03:47:23 +00:00
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["duplicate", "root()"]);
|
2023-01-15 06:35:56 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2023-09-03 21:00:25 +00:00
|
|
|
Error: Cannot duplicate the root commit
|
2023-01-15 06:35:56 +00:00
|
|
|
"###);
|
2023-01-15 05:59:31 +00:00
|
|
|
|
2023-10-10 11:59:18 +00:00
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["duplicate", "a"]);
|
2023-10-10 11:07:06 +00:00
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2023-07-11 01:46:38 +00:00
|
|
|
Duplicated 2443ea76b0b1 as znkkpsqq 2f6dc5a1 a
|
2023-01-15 05:59:31 +00:00
|
|
|
"###);
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 2f6dc5a1ffc2 a
|
2023-02-09 02:53:47 +00:00
|
|
|
│ @ 17a00fc21654 c
|
|
|
|
│ ├─╮
|
2023-07-28 06:51:08 +00:00
|
|
|
│ │ ◉ d370aee184ba b
|
2023-02-09 02:53:47 +00:00
|
|
|
├───╯
|
2023-07-28 06:51:08 +00:00
|
|
|
│ ◉ 2443ea76b0b1 a
|
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
|
|
|
├─╯
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 000000000000
|
2023-01-15 05:59:31 +00:00
|
|
|
"###);
|
|
|
|
|
2023-10-10 11:59:18 +00:00
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["undo"]);
|
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
insta::assert_snapshot!(stderr, @"");
|
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["duplicate" /* duplicates `c` */]);
|
2023-10-10 11:07:06 +00:00
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2023-07-11 01:46:38 +00:00
|
|
|
Duplicated 17a00fc21654 as wqnwkozp 1dd099ea c
|
2023-01-15 05:59:31 +00:00
|
|
|
"###);
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 1dd099ea963c c
|
2023-02-09 02:53:47 +00:00
|
|
|
├─╮
|
|
|
|
│ │ @ 17a00fc21654 c
|
|
|
|
╭─┬─╯
|
2023-07-28 06:51:08 +00:00
|
|
|
│ ◉ d370aee184ba b
|
|
|
|
◉ │ 2443ea76b0b1 a
|
2023-02-09 02:53:47 +00:00
|
|
|
├─╯
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 000000000000
|
2023-01-15 05:59:31 +00:00
|
|
|
"###);
|
|
|
|
}
|
|
|
|
|
2023-01-10 06:54:10 +00:00
|
|
|
#[test]
|
|
|
|
fn test_duplicate_many() {
|
|
|
|
let test_env = TestEnvironment::default();
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
|
2023-01-10 06:54: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, "b", &["a"]);
|
|
|
|
create_commit(&test_env, &repo_path, "c", &["a"]);
|
|
|
|
create_commit(&test_env, &repo_path, "d", &["c"]);
|
|
|
|
create_commit(&test_env, &repo_path, "e", &["b", "d"]);
|
|
|
|
// Test the setup
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2023-02-09 02:53:47 +00:00
|
|
|
@ 921dde6e55c0 e
|
|
|
|
├─╮
|
2023-07-28 06:51:08 +00:00
|
|
|
│ ◉ ebd06dba20ec d
|
|
|
|
│ ◉ c0cb3a0b73e7 c
|
|
|
|
◉ │ 1394f625cbbd b
|
2023-02-09 02:53:47 +00:00
|
|
|
├─╯
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 2443ea76b0b1 a
|
|
|
|
◉ 000000000000
|
2023-01-10 06:54:10 +00:00
|
|
|
"###);
|
|
|
|
|
2023-10-10 11:59:18 +00:00
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["duplicate", "b::"]);
|
2023-10-10 11:07:06 +00:00
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2023-07-11 01:46:38 +00:00
|
|
|
Duplicated 1394f625cbbd as wqnwkozp 3b74d969 b
|
|
|
|
Duplicated 921dde6e55c0 as mouksmqu 8348ddce e
|
2023-01-10 06:54:10 +00:00
|
|
|
"###);
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 8348ddcec733 e
|
2023-02-09 02:53:47 +00:00
|
|
|
├─╮
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ │ 3b74d9691015 b
|
2023-02-09 02:53:47 +00:00
|
|
|
│ │ @ 921dde6e55c0 e
|
|
|
|
│ ╭─┤
|
2023-07-28 06:51:08 +00:00
|
|
|
│ ◉ │ ebd06dba20ec d
|
|
|
|
│ ◉ │ c0cb3a0b73e7 c
|
|
|
|
├─╯ │
|
|
|
|
│ ◉ 1394f625cbbd b
|
2023-02-09 02:53:47 +00:00
|
|
|
├───╯
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 2443ea76b0b1 a
|
|
|
|
◉ 000000000000
|
2023-01-10 06:54:10 +00:00
|
|
|
"###);
|
|
|
|
|
|
|
|
// Try specifying the same commit twice directly
|
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, &["duplicate", "b", "b"]);
|
2023-10-10 11:07:06 +00:00
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2023-07-11 01:46:38 +00:00
|
|
|
Duplicated 1394f625cbbd as nkmrtpmo 0276d3d7 b
|
2023-01-10 06:54:10 +00:00
|
|
|
"###);
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 0276d3d7c24d b
|
2023-02-09 02:53:47 +00:00
|
|
|
│ @ 921dde6e55c0 e
|
|
|
|
│ ├─╮
|
2023-07-28 06:51:08 +00:00
|
|
|
│ │ ◉ ebd06dba20ec d
|
|
|
|
│ │ ◉ c0cb3a0b73e7 c
|
2023-02-09 02:53:47 +00:00
|
|
|
├───╯
|
2023-07-28 06:51:08 +00:00
|
|
|
│ ◉ 1394f625cbbd 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
|
|
|
├─╯
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 2443ea76b0b1 a
|
|
|
|
◉ 000000000000
|
2023-01-10 06:54:10 +00:00
|
|
|
"###);
|
|
|
|
|
|
|
|
// Try specifying the same commit twice indirectly
|
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, &["duplicate", "b::", "d::"]);
|
2023-10-10 11:07:06 +00:00
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2023-07-11 01:46:38 +00:00
|
|
|
Duplicated 1394f625cbbd as xtnwkqum fa167d18 b
|
|
|
|
Duplicated ebd06dba20ec as pqrnrkux 2181781b d
|
|
|
|
Duplicated 921dde6e55c0 as ztxkyksq 0f7430f2 e
|
2023-01-10 06:54:10 +00:00
|
|
|
"###);
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 0f7430f2727a e
|
2023-02-09 02:53:47 +00:00
|
|
|
├─╮
|
2023-07-28 06:51:08 +00:00
|
|
|
│ ◉ 2181781b4f81 d
|
|
|
|
◉ │ fa167d18a83a b
|
2023-02-09 02:53:47 +00:00
|
|
|
│ │ @ 921dde6e55c0 e
|
|
|
|
│ │ ├─╮
|
2023-07-28 06:51:08 +00:00
|
|
|
│ │ │ ◉ ebd06dba20ec d
|
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
|
|
|
│ ├───╯
|
2023-07-28 06:51:08 +00:00
|
|
|
│ ◉ │ c0cb3a0b73e7 c
|
|
|
|
├─╯ │
|
|
|
|
│ ◉ 1394f625cbbd 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
|
|
|
├───╯
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 2443ea76b0b1 a
|
|
|
|
◉ 000000000000
|
2023-01-10 06:54:10 +00:00
|
|
|
"###);
|
|
|
|
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["undo"]);
|
2023-01-10 06:54:10 +00:00
|
|
|
// Reminder of the setup
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2023-02-09 02:53:47 +00:00
|
|
|
@ 921dde6e55c0 e
|
|
|
|
├─╮
|
2023-07-28 06:51:08 +00:00
|
|
|
│ ◉ ebd06dba20ec d
|
|
|
|
│ ◉ c0cb3a0b73e7 c
|
|
|
|
◉ │ 1394f625cbbd b
|
2023-02-09 02:53:47 +00:00
|
|
|
├─╯
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 2443ea76b0b1 a
|
|
|
|
◉ 000000000000
|
2023-01-10 06:54:10 +00:00
|
|
|
"###);
|
2023-10-10 11:59:18 +00:00
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["duplicate", "d::", "a"]);
|
2023-10-10 11:07:06 +00:00
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2023-07-11 01:46:38 +00:00
|
|
|
Duplicated 2443ea76b0b1 as nlrtlrxv c6f7f8c4 a
|
|
|
|
Duplicated ebd06dba20ec as plymsszl d94e4c55 d
|
|
|
|
Duplicated 921dde6e55c0 as urrlptpw 9bd4389f e
|
2023-01-10 06:54:10 +00:00
|
|
|
"###);
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 9bd4389f5d47 e
|
2023-02-09 02:53:47 +00:00
|
|
|
├─╮
|
2023-07-28 06:51:08 +00:00
|
|
|
│ ◉ d94e4c55a68b d
|
2023-07-22 18:14:03 +00:00
|
|
|
│ │ @ 921dde6e55c0 e
|
2023-07-28 06:51:08 +00:00
|
|
|
╭───┤
|
2023-07-22 18:14:03 +00:00
|
|
|
│ │ ◉ ebd06dba20ec d
|
2023-07-28 06:51:08 +00:00
|
|
|
│ ├─╯
|
|
|
|
│ ◉ c0cb3a0b73e7 c
|
|
|
|
◉ │ 1394f625cbbd b
|
2023-07-22 18:14:03 +00:00
|
|
|
├─╯
|
|
|
|
◉ 2443ea76b0b1 a
|
|
|
|
│ ◉ c6f7f8c4512e a
|
|
|
|
├─╯
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 000000000000
|
2023-01-10 06:54:10 +00:00
|
|
|
"###);
|
|
|
|
|
|
|
|
// Check for BUG -- makes too many 'a'-s, etc.
|
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, &["duplicate", "a::"]);
|
2023-10-10 11:07:06 +00:00
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2023-07-11 01:46:38 +00:00
|
|
|
Duplicated 2443ea76b0b1 as uuuvxpvw 0fe67a05 a
|
|
|
|
Duplicated 1394f625cbbd as nmpuuozl e13ac0ad b
|
|
|
|
Duplicated c0cb3a0b73e7 as kzpokyyw df53fa58 c
|
|
|
|
Duplicated ebd06dba20ec as yxrlprzz 2f2442db d
|
|
|
|
Duplicated 921dde6e55c0 as mvkzkxrl ee8fe64e e
|
2023-01-10 06:54:10 +00:00
|
|
|
"###);
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ ee8fe64ed254 e
|
2023-02-09 02:53:47 +00:00
|
|
|
├─╮
|
2023-07-28 06:51:08 +00:00
|
|
|
│ ◉ 2f2442db08eb d
|
|
|
|
│ ◉ df53fa589286 c
|
|
|
|
◉ │ e13ac0adabdf b
|
2023-02-09 02:53:47 +00:00
|
|
|
├─╯
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 0fe67a05989e a
|
2023-02-09 02:53:47 +00:00
|
|
|
│ @ 921dde6e55c0 e
|
|
|
|
│ ├─╮
|
2023-07-28 06:51:08 +00:00
|
|
|
│ │ ◉ ebd06dba20ec d
|
|
|
|
│ │ ◉ c0cb3a0b73e7 c
|
|
|
|
│ ◉ │ 1394f625cbbd b
|
2023-02-09 02:53:47 +00:00
|
|
|
│ ├─╯
|
2023-03-15 03:37:56 +00:00
|
|
|
│ ◉ 2443ea76b0b1 a
|
2023-02-09 02:53:47 +00:00
|
|
|
├─╯
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 000000000000
|
2023-01-10 06:54:10 +00:00
|
|
|
"###);
|
|
|
|
}
|
|
|
|
|
2023-01-16 19:22:10 +00:00
|
|
|
// https://github.com/martinvonz/jj/issues/1050
|
|
|
|
#[test]
|
|
|
|
fn test_undo_after_duplicate() {
|
|
|
|
let test_env = TestEnvironment::default();
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
|
2023-01-16 19:22:10 +00:00
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
|
|
|
create_commit(&test_env, &repo_path, "a", &[]);
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2023-02-09 02:53:47 +00:00
|
|
|
@ 2443ea76b0b1 a
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 000000000000
|
2023-01-16 19:22:10 +00:00
|
|
|
"###);
|
|
|
|
|
2023-10-10 11:59:18 +00:00
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["duplicate", "a"]);
|
2023-10-10 11:07:06 +00:00
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2023-07-11 01:46:38 +00:00
|
|
|
Duplicated 2443ea76b0b1 as mzvwutvl f5cefcbb a
|
2023-01-16 19:22:10 +00:00
|
|
|
"###);
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ f5cefcbb65a4 a
|
2023-02-09 02:53:47 +00:00
|
|
|
│ @ 2443ea76b0b1 a
|
|
|
|
├─╯
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 000000000000
|
2023-01-16 19:22:10 +00:00
|
|
|
"###);
|
|
|
|
|
2023-10-10 11:59:18 +00:00
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["undo"]);
|
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
insta::assert_snapshot!(stderr, @"");
|
2023-01-16 19:22:10 +00:00
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2023-02-09 02:53:47 +00:00
|
|
|
@ 2443ea76b0b1 a
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 000000000000
|
2023-01-16 19:22:10 +00:00
|
|
|
"###);
|
|
|
|
}
|
|
|
|
|
2023-01-15 06:08:13 +00:00
|
|
|
// https://github.com/martinvonz/jj/issues/694
|
|
|
|
#[test]
|
|
|
|
fn test_rebase_duplicates() {
|
|
|
|
let test_env = TestEnvironment::default();
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
|
2023-01-15 06:08:13 +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 the setup
|
|
|
|
insta::assert_snapshot!(get_log_output_with_ts(&test_env, &repo_path), @r###"
|
2023-02-09 02:53:47 +00:00
|
|
|
@ 1394f625cbbd b @ 2001-02-03 04:05:11.000 +07:00
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 2443ea76b0b1 a @ 2001-02-03 04:05:09.000 +07:00
|
|
|
|
◉ 000000000000 @ 1970-01-01 00:00:00.000 +00:00
|
2023-01-15 06:08:13 +00:00
|
|
|
"###);
|
|
|
|
|
2023-10-10 11:59:18 +00:00
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["duplicate", "b"]);
|
2023-10-10 11:07:06 +00:00
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2023-07-11 01:46:38 +00:00
|
|
|
Duplicated 1394f625cbbd as yqosqzyt fdaaf395 b
|
2023-01-15 06:08:13 +00:00
|
|
|
"###);
|
2023-10-10 11:59:18 +00:00
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["duplicate", "b"]);
|
2023-10-10 11:07:06 +00:00
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2023-07-11 01:46:38 +00:00
|
|
|
Duplicated 1394f625cbbd as vruxwmqv 870cf438 b
|
2023-01-15 06:08:13 +00:00
|
|
|
"###);
|
|
|
|
insta::assert_snapshot!(get_log_output_with_ts(&test_env, &repo_path), @r###"
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 870cf438ccbb b @ 2001-02-03 04:05:14.000 +07:00
|
|
|
|
│ ◉ fdaaf3950f07 b @ 2001-02-03 04:05:13.000 +07:00
|
2023-02-09 02:53:47 +00:00
|
|
|
├─╯
|
|
|
|
│ @ 1394f625cbbd b @ 2001-02-03 04:05:11.000 +07:00
|
|
|
|
├─╯
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 2443ea76b0b1 a @ 2001-02-03 04:05:09.000 +07:00
|
|
|
|
◉ 000000000000 @ 1970-01-01 00:00:00.000 +00:00
|
2023-01-15 06:08:13 +00:00
|
|
|
"###);
|
|
|
|
|
2023-10-10 11:59:18 +00:00
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["rebase", "-s", "a", "-d", "a-"]);
|
2023-10-10 11:07:06 +00:00
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2023-01-15 07:28:36 +00:00
|
|
|
Rebased 4 commits
|
2023-08-08 03:11:59 +00:00
|
|
|
Working copy now at: zsuskuln 29bd36b6 b | b
|
|
|
|
Parent commit : rlvkpnrz 2f6dc5a1 a | a
|
2023-01-15 07:28:36 +00:00
|
|
|
"###);
|
|
|
|
// Some of the duplicate commits' timestamps were changed a little to make them
|
|
|
|
// have distinct commit ids.
|
|
|
|
insta::assert_snapshot!(get_log_output_with_ts(&test_env, &repo_path), @r###"
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ b43fe7354758 b @ 2001-02-03 04:05:14.000 +07:00
|
|
|
|
│ ◉ 08beb14c3ead b @ 2001-02-03 04:05:15.000 +07:00
|
2023-02-09 02:53:47 +00:00
|
|
|
├─╯
|
|
|
|
│ @ 29bd36b60e60 b @ 2001-02-03 04:05:16.000 +07:00
|
|
|
|
├─╯
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 2f6dc5a1ffc2 a @ 2001-02-03 04:05:16.000 +07:00
|
|
|
|
◉ 000000000000 @ 1970-01-01 00:00:00.000 +00:00
|
2023-01-15 06:08:13 +00:00
|
|
|
"###);
|
|
|
|
}
|
|
|
|
|
2023-01-16 19:22:10 +00:00
|
|
|
fn get_log_output(test_env: &TestEnvironment, repo_path: &Path) -> String {
|
2023-02-28 11:30:57 +00:00
|
|
|
let template = r#"commit_id.short() ++ " " ++ description.first_line()"#;
|
2023-02-28 10:43:14 +00:00
|
|
|
test_env.jj_cmd_success(repo_path, &["log", "-T", template])
|
2023-01-16 19:22:10 +00:00
|
|
|
}
|
2023-01-15 06:08:13 +00:00
|
|
|
|
|
|
|
fn get_log_output_with_ts(test_env: &TestEnvironment, repo_path: &Path) -> String {
|
2023-08-15 03:18:52 +00:00
|
|
|
let template = r#"
|
2023-02-28 11:30:57 +00:00
|
|
|
commit_id.short() ++ " " ++ description.first_line() ++ " @ " ++ committer.timestamp()
|
2023-08-15 03:18:52 +00:00
|
|
|
"#;
|
2023-02-28 10:43:14 +00:00
|
|
|
test_env.jj_cmd_success(repo_path, &["log", "-T", template])
|
2023-01-15 06:08:13 +00:00
|
|
|
}
|