2022-11-26 23:57:50 +00:00
|
|
|
// Copyright 2022 The Jujutsu Authors
|
2022-04-09 18:35:28 +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.
|
|
|
|
|
2023-02-28 10:43:14 +00:00
|
|
|
use std::path::Path;
|
|
|
|
|
2023-01-31 20:30:50 +00:00
|
|
|
use crate::common::{get_stderr_string, get_stdout_string, TestEnvironment};
|
2022-04-09 18:35:28 +00:00
|
|
|
|
|
|
|
pub mod common;
|
|
|
|
|
|
|
|
#[test]
|
2022-11-23 05:15:20 +00:00
|
|
|
fn test_split_by_paths() {
|
2022-04-09 18:35:28 +00:00
|
|
|
let mut 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");
|
|
|
|
|
|
|
|
std::fs::write(repo_path.join("file1"), "foo").unwrap();
|
|
|
|
std::fs::write(repo_path.join("file2"), "foo").unwrap();
|
|
|
|
std::fs::write(repo_path.join("file3"), "foo").unwrap();
|
|
|
|
|
2023-02-28 10:43:14 +00:00
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
|
|
|
@ qpvuntsmwlqt false
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ zzzzzzzzzzzz true
|
2022-04-09 18:35:28 +00:00
|
|
|
"###);
|
|
|
|
|
|
|
|
let edit_script = test_env.set_up_fake_editor();
|
2022-11-23 05:15:20 +00:00
|
|
|
std::fs::write(
|
|
|
|
edit_script,
|
2022-12-22 07:58:23 +00:00
|
|
|
["dump editor0", "next invocation\n", "dump editor1"].join("\0"),
|
2022-11-23 05:15:20 +00:00
|
|
|
)
|
|
|
|
.unwrap();
|
2022-04-09 18:35:28 +00:00
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["split", "file2"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2022-05-17 17:22:46 +00:00
|
|
|
First part: 5eebce1de3b0 (no description set)
|
|
|
|
Second part: 45833353d94e (no description set)
|
|
|
|
Working copy now at: 45833353d94e (no description set)
|
2023-04-29 05:01:31 +00:00
|
|
|
Parent commit : 5eebce1de3b0 (no description set)
|
2022-04-09 18:35:28 +00:00
|
|
|
"###);
|
2022-12-22 07:58:23 +00:00
|
|
|
insta::assert_snapshot!(
|
|
|
|
std::fs::read_to_string(test_env.env_root().join("editor0")).unwrap(), @r###"
|
|
|
|
JJ: Enter commit description for the first part (parent).
|
|
|
|
|
2022-12-22 15:07:13 +00:00
|
|
|
JJ: This commit contains the following changes:
|
2022-12-22 07:58:23 +00:00
|
|
|
JJ: A file2
|
|
|
|
|
|
|
|
JJ: Lines starting with "JJ: " (like this one) will be removed.
|
|
|
|
"###);
|
|
|
|
insta::assert_snapshot!(
|
|
|
|
std::fs::read_to_string(test_env.env_root().join("editor1")).unwrap(), @r###"
|
|
|
|
JJ: Enter commit description for the second part (child).
|
|
|
|
|
2022-12-22 15:07:13 +00:00
|
|
|
JJ: This commit contains the following changes:
|
2022-12-22 07:58:23 +00:00
|
|
|
JJ: A file1
|
|
|
|
JJ: A file3
|
|
|
|
|
|
|
|
JJ: Lines starting with "JJ: " (like this one) will be removed.
|
|
|
|
"###);
|
2022-04-09 18:35:28 +00:00
|
|
|
|
2023-02-28 10:43:14 +00:00
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
|
|
|
@ kkmpptxzrspx false
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ qpvuntsmwlqt false
|
|
|
|
◉ zzzzzzzzzzzz true
|
2022-04-09 18:35:28 +00:00
|
|
|
"###);
|
|
|
|
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s", "-r", "@-"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
A file2
|
|
|
|
"###);
|
2022-04-09 18:35:28 +00:00
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
A file1
|
|
|
|
A file3
|
|
|
|
"###);
|
2023-01-29 06:35:41 +00:00
|
|
|
|
|
|
|
// Insert an empty commit after @- with "split ."
|
|
|
|
test_env.set_up_fake_editor();
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["split", "-r", "@-", "."]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
Rebased 1 descendant commits
|
|
|
|
First part: 31425b568fcf (no description set)
|
|
|
|
Second part: af0963926ac3 (no description set)
|
|
|
|
Working copy now at: 28d4ec20efa9 (no description set)
|
2023-04-29 05:01:31 +00:00
|
|
|
Parent commit : af0963926ac3 (no description set)
|
2023-01-29 06:35:41 +00:00
|
|
|
"###);
|
|
|
|
|
2023-02-28 10:43:14 +00:00
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2023-02-12 20:07:28 +00:00
|
|
|
@ kkmpptxzrspx false
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ yqosqzytrlsw true
|
|
|
|
◉ qpvuntsmwlqt false
|
|
|
|
◉ zzzzzzzzzzzz true
|
2023-01-29 06:35:41 +00:00
|
|
|
"###);
|
|
|
|
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s", "-r", "@--"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
A file2
|
|
|
|
"###);
|
|
|
|
|
|
|
|
// Remove newly created empty commit
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["abandon", "@-"]);
|
|
|
|
|
|
|
|
// Insert an empty commit before @- with "split nonexistent"
|
|
|
|
test_env.set_up_fake_editor();
|
2023-01-31 20:30:50 +00:00
|
|
|
let assert = test_env
|
|
|
|
.jj_cmd(&repo_path, &["split", "-r", "@-", "nonexistent"])
|
|
|
|
.assert()
|
|
|
|
.success();
|
|
|
|
insta::assert_snapshot!(get_stdout_string(&assert), @r###"
|
2023-01-29 06:35:41 +00:00
|
|
|
Rebased 1 descendant commits
|
|
|
|
First part: 0647b2cbd0da (no description set)
|
|
|
|
Second part: d5d77af65446 (no description set)
|
|
|
|
Working copy now at: 86f228dc3a50 (no description set)
|
2023-04-29 05:01:31 +00:00
|
|
|
Parent commit : d5d77af65446 (no description set)
|
2023-01-29 06:35:41 +00:00
|
|
|
"###);
|
2023-01-31 20:30:50 +00:00
|
|
|
insta::assert_snapshot!(get_stderr_string(&assert), @r###"
|
|
|
|
The given paths do not match any file: nonexistent
|
|
|
|
"###);
|
2023-01-29 06:35:41 +00:00
|
|
|
|
2023-02-28 10:43:14 +00:00
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2023-02-12 20:07:28 +00:00
|
|
|
@ kkmpptxzrspx false
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ kpqxywonksrl false
|
|
|
|
◉ qpvuntsmwlqt true
|
|
|
|
◉ zzzzzzzzzzzz true
|
2023-01-29 06:35:41 +00:00
|
|
|
"###);
|
|
|
|
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s", "-r", "@-"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
A file2
|
|
|
|
"###);
|
2022-04-09 18:35:28 +00:00
|
|
|
}
|
2023-02-28 10:43:14 +00:00
|
|
|
|
|
|
|
fn get_log_output(test_env: &TestEnvironment, cwd: &Path) -> String {
|
2023-02-28 11:30:57 +00:00
|
|
|
let template = r#"change_id.short() ++ " " ++ empty"#;
|
2023-02-28 10:43:14 +00:00
|
|
|
test_env.jj_cmd_success(cwd, &["log", "-T", template])
|
|
|
|
}
|