2023-01-10 05:54:27 +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;
|
|
|
|
|
|
|
|
pub mod common;
|
|
|
|
|
|
|
|
fn create_commit(test_env: &TestEnvironment, repo_path: &Path, name: &str, parents: &[&str]) {
|
|
|
|
if parents.is_empty() {
|
|
|
|
test_env.jj_cmd_success(repo_path, &["new", "root", "-m", name]);
|
|
|
|
} else {
|
|
|
|
let mut args = vec!["new", "-m", name];
|
|
|
|
args.extend(parents);
|
|
|
|
test_env.jj_cmd_success(repo_path, &args);
|
|
|
|
}
|
|
|
|
std::fs::write(repo_path.join(name), format!("{name}\n")).unwrap();
|
|
|
|
test_env.jj_cmd_success(repo_path, &["branch", "create", name]);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_rebase_branch_with_merge() {
|
|
|
|
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", &["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
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2023-02-09 02:53:47 +00:00
|
|
|
@ e
|
|
|
|
├─╮
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ │ d
|
|
|
|
◉ │ c
|
|
|
|
│ │ ◉ b
|
2023-02-09 02:53:47 +00:00
|
|
|
│ ├─╯
|
2023-03-15 03:37:56 +00:00
|
|
|
│ ◉ a
|
2023-02-09 02:53:47 +00:00
|
|
|
├─╯
|
2023-03-15 03:37:56 +00:00
|
|
|
◉
|
2023-01-10 05:54:27 +00:00
|
|
|
"###);
|
|
|
|
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["abandon", "d"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2023-01-08 00:17:36 +00:00
|
|
|
Abandoned commit b7c62f28ed10 d
|
2023-01-10 05:54:27 +00:00
|
|
|
Rebased 1 descendant commits onto parents of abandoned commits
|
|
|
|
Working copy now at: 11a2e10edf4e e
|
2023-04-29 05:01:31 +00:00
|
|
|
Parent commit : 2443ea76b0b1 a
|
|
|
|
Parent commit : fe2e8e8b50b3 c
|
2023-01-10 05:54:27 +00:00
|
|
|
Added 0 files, modified 0 files, removed 1 files
|
|
|
|
"###);
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2023-02-09 02:53:47 +00:00
|
|
|
@ e
|
|
|
|
├─╮
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ │ c d
|
|
|
|
│ │ ◉ b
|
2023-02-09 02:53:47 +00:00
|
|
|
│ ├─╯
|
2023-03-15 03:37:56 +00:00
|
|
|
│ ◉ a
|
2023-02-09 02:53:47 +00:00
|
|
|
├─╯
|
2023-03-15 03:37:56 +00:00
|
|
|
◉
|
2023-01-10 05:54:27 +00:00
|
|
|
"###);
|
|
|
|
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["undo"]);
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["abandon"] /* abandons `e` */);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2023-01-08 00:17:36 +00:00
|
|
|
Abandoned commit 5557ece3e631 e
|
2023-01-10 05:54:27 +00:00
|
|
|
Working copy now at: 6b5275139632 (no description set)
|
2023-04-29 05:01:31 +00:00
|
|
|
Parent commit : 2443ea76b0b1 a
|
2023-01-10 05:54:27 +00:00
|
|
|
Added 0 files, modified 0 files, removed 3 files
|
|
|
|
"###);
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2023-02-09 02:53:47 +00:00
|
|
|
@
|
2023-07-22 18:14:03 +00:00
|
|
|
│ ◉ b
|
|
|
|
├─╯
|
|
|
|
◉ a e??
|
2023-03-15 03:37:56 +00:00
|
|
|
│ ◉ d e??
|
|
|
|
│ ◉ c
|
2023-02-09 02:53:47 +00:00
|
|
|
├─╯
|
2023-03-15 03:37:56 +00:00
|
|
|
◉
|
2023-01-10 05:54:27 +00:00
|
|
|
"###);
|
|
|
|
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["undo"]);
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["abandon", "descendants(c)"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2023-01-08 00:58:54 +00:00
|
|
|
Abandoned the following commits:
|
|
|
|
5557ece3e631 e
|
|
|
|
b7c62f28ed10 d
|
|
|
|
fe2e8e8b50b3 c
|
2023-01-10 05:54:27 +00:00
|
|
|
Working copy now at: e7bb061217d5 (no description set)
|
2023-04-29 05:01:31 +00:00
|
|
|
Parent commit : 2443ea76b0b1 a
|
2023-01-10 05:54:27 +00:00
|
|
|
Added 0 files, modified 0 files, removed 3 files
|
|
|
|
"###);
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2023-02-09 02:53:47 +00:00
|
|
|
@
|
2023-03-15 03:37:56 +00:00
|
|
|
│ ◉ b
|
2023-02-09 02:53:47 +00:00
|
|
|
├─╯
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ a e??
|
|
|
|
◉ c d e??
|
2023-01-10 05:54:27 +00:00
|
|
|
"###);
|
2023-01-15 05:59:31 +00:00
|
|
|
|
|
|
|
// Test abandoning the same commit twice directly
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["undo"]);
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["abandon", "b", "b"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2023-01-18 04:06:12 +00:00
|
|
|
Abandoned commit 1394f625cbbd b
|
2023-01-15 05:59:31 +00:00
|
|
|
"###);
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2023-02-09 02:53:47 +00:00
|
|
|
@ e
|
|
|
|
├─╮
|
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
|
|
|
│ ◉ a b
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ │ d
|
|
|
|
◉ │ c
|
2023-02-09 02:53:47 +00:00
|
|
|
├─╯
|
2023-03-15 03:37:56 +00:00
|
|
|
◉
|
2023-01-15 05:59:31 +00:00
|
|
|
"###);
|
|
|
|
|
|
|
|
// Test abandoning the same commit twice indirectly
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["undo"]);
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["abandon", "d:", "a:"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
Abandoned the following commits:
|
|
|
|
5557ece3e631 e
|
|
|
|
b7c62f28ed10 d
|
|
|
|
1394f625cbbd b
|
|
|
|
2443ea76b0b1 a
|
|
|
|
Working copy now at: af874bffee6e (no description set)
|
2023-04-29 05:01:31 +00:00
|
|
|
Parent commit : 000000000000 (no description set)
|
2023-01-15 05:59:31 +00:00
|
|
|
Added 0 files, modified 0 files, removed 4 files
|
|
|
|
"###);
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2023-02-09 02:53:47 +00:00
|
|
|
@
|
2023-03-15 03:37:56 +00:00
|
|
|
│ ◉ c d e??
|
2023-02-09 02:53:47 +00:00
|
|
|
├─╯
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ a b e??
|
2023-01-15 05:59:31 +00:00
|
|
|
"###);
|
|
|
|
|
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["abandon", "root"]);
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
Error: Cannot rewrite the root commit
|
|
|
|
"###);
|
2023-01-10 05:54:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn get_log_output(test_env: &TestEnvironment, repo_path: &Path) -> String {
|
|
|
|
test_env.jj_cmd_success(repo_path, &["log", "-T", "branches"])
|
|
|
|
}
|