2022-11-26 23:57:50 +00:00
|
|
|
// Copyright 2022 The Jujutsu Authors
|
2022-03-26 21:02:04 +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.
|
|
|
|
|
2022-08-31 04:35:56 +00:00
|
|
|
use std::path::Path;
|
|
|
|
|
2022-04-15 05:48:40 +00:00
|
|
|
use crate::common::TestEnvironment;
|
2022-03-30 17:47:11 +00:00
|
|
|
|
|
|
|
pub mod common;
|
2022-03-26 21:02:04 +00:00
|
|
|
|
|
|
|
#[test]
|
2022-05-21 13:38:56 +00:00
|
|
|
fn test_new() {
|
2022-03-26 21:02:04 +00:00
|
|
|
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");
|
|
|
|
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "add a file"]);
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["new", "-m", "a new commit"]);
|
|
|
|
|
2022-08-31 04:35:56 +00:00
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2022-12-21 04:47:10 +00:00
|
|
|
@ 4f2d6e0a3482a6a34e4856a4a63869c0df109e79 a new commit
|
|
|
|
o 5d5c60b2aa96b8dbf55710656c50285c66cdcd74 add a file
|
2022-05-17 17:22:46 +00:00
|
|
|
o 0000000000000000000000000000000000000000 (no description set)
|
2022-03-26 21:02:04 +00:00
|
|
|
"###);
|
2022-05-21 13:38:56 +00:00
|
|
|
|
|
|
|
// Start a new change off of a specific commit (the root commit in this case).
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["new", "-m", "off of root", "root"]);
|
2022-08-31 04:35:56 +00:00
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2022-12-21 04:47:10 +00:00
|
|
|
@ 026537ddb96b801b9cb909985d5443aab44616c1 off of root
|
|
|
|
| o 4f2d6e0a3482a6a34e4856a4a63869c0df109e79 a new commit
|
|
|
|
| o 5d5c60b2aa96b8dbf55710656c50285c66cdcd74 add a file
|
2022-05-21 13:38:56 +00:00
|
|
|
|/
|
|
|
|
o 0000000000000000000000000000000000000000 (no description set)
|
|
|
|
"###);
|
2022-03-26 21:02:04 +00:00
|
|
|
}
|
2022-08-31 04:35:56 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_new_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");
|
|
|
|
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["branch", "create", "main"]);
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "add file1"]);
|
|
|
|
std::fs::write(repo_path.join("file1"), "a").unwrap();
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["new", "root", "-m", "add file2"]);
|
|
|
|
std::fs::write(repo_path.join("file2"), "b").unwrap();
|
|
|
|
|
|
|
|
// Create a merge commit
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["new", "main", "@"]);
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2022-12-21 04:47:10 +00:00
|
|
|
@ 0c4e5b9b68ae0cbe7ce3c61042619513d09005bf (no description set)
|
2022-08-31 04:35:56 +00:00
|
|
|
|\
|
2022-12-21 04:47:10 +00:00
|
|
|
o | f399209d9dda06e8a25a0c8e9a0cde9f421ff35d add file2
|
|
|
|
| o 38e8e2f6c92ffb954961fc391b515ff551b41636 add file1
|
2022-08-31 04:35:56 +00:00
|
|
|
|/
|
|
|
|
o 0000000000000000000000000000000000000000 (no description set)
|
|
|
|
"###);
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["print", "file1"]);
|
|
|
|
insta::assert_snapshot!(stdout, @"a");
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["print", "file2"]);
|
|
|
|
insta::assert_snapshot!(stdout, @"b");
|
2022-08-31 05:31:18 +00:00
|
|
|
|
|
|
|
// Same test with `jj merge`
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["undo"]);
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["merge", "main", "@"]);
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2022-12-21 04:47:10 +00:00
|
|
|
@ 200ed1a14c8acf09783dafefe5bebf2ff58f12fd (no description set)
|
2022-08-31 05:31:18 +00:00
|
|
|
|\
|
2022-12-21 04:47:10 +00:00
|
|
|
o | f399209d9dda06e8a25a0c8e9a0cde9f421ff35d add file2
|
|
|
|
| o 38e8e2f6c92ffb954961fc391b515ff551b41636 add file1
|
2022-08-31 05:31:18 +00:00
|
|
|
|/
|
|
|
|
o 0000000000000000000000000000000000000000 (no description set)
|
|
|
|
"###);
|
|
|
|
|
|
|
|
// `jj merge` with less than two arguments is an error
|
2022-11-18 20:50:39 +00:00
|
|
|
let stderr = test_env.jj_cmd_cli_error(&repo_path, &["merge"]);
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
Error: Merge requires at least two revisions
|
|
|
|
"###);
|
|
|
|
let stderr = test_env.jj_cmd_cli_error(&repo_path, &["merge", "main"]);
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
Error: Merge requires at least two revisions
|
|
|
|
"###);
|
2022-08-31 07:41:08 +00:00
|
|
|
|
|
|
|
// merge with non-unique revisions
|
2022-12-21 04:47:10 +00:00
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["new", "@", "200e"]);
|
2022-08-31 07:41:08 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2022-12-21 04:47:10 +00:00
|
|
|
Error: Revset "@" and "200e" resolved to the same revision 200ed1a14c8a
|
2022-08-31 07:41:08 +00:00
|
|
|
"###);
|
2022-08-31 08:56:37 +00:00
|
|
|
|
|
|
|
// merge with root
|
2022-11-18 20:50:39 +00:00
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["new", "@", "root"]);
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
Error: Cannot merge with root revision
|
|
|
|
"###);
|
2022-08-31 04:35:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn get_log_output(test_env: &TestEnvironment, repo_path: &Path) -> String {
|
|
|
|
test_env.jj_cmd_success(repo_path, &["log", "-T", "commit_id \" \" description"])
|
|
|
|
}
|