mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-12 23:23:20 +00:00
a1a980d395
`jj merge` just creates an empty change, which is practically the same as `jj new`. The main difference is that the former requires more than one argument and the latter requires at most one argument. It seems cleaner to generalize them and make them aliases. This patch starts doing that by making `jj new` accept more than one argument. Instead of having `jj merge` be exactly an alias for `jj new`, we may want to make it a thin wrapper that just checks that more than one argument was given. That would probably be less confusing to users who run `jj merge` without arguments to see what it does. We should probably make `jj checkout` also be an alias for `jj new`, but that will have to wait until we have removed support for open commits (since `jj checkout` still has logic for dealing with open commits).
77 lines
3.1 KiB
Rust
77 lines
3.1 KiB
Rust
// Copyright 2022 Google LLC
|
|
//
|
|
// 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;
|
|
|
|
#[test]
|
|
fn test_new() {
|
|
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"]);
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
|
@ 88436dbcdbedc2b8a6ebd0687981906d09ccc68f a new commit
|
|
o 51e9c5819117991e4a6dc5a4a744283fc74f0746 add a file
|
|
o 0000000000000000000000000000000000000000 (no description set)
|
|
"###);
|
|
|
|
// 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"]);
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
|
@ d8c0a3e1570f1f5b08113a3427b3160900c3d48e off of root
|
|
| o 88436dbcdbedc2b8a6ebd0687981906d09ccc68f a new commit
|
|
| o 51e9c5819117991e4a6dc5a4a744283fc74f0746 add a file
|
|
|/
|
|
o 0000000000000000000000000000000000000000 (no description set)
|
|
"###);
|
|
}
|
|
|
|
#[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###"
|
|
@ 5b37ef8ee8cd934dfe1e70adff66cd0679f5a573 (no description set)
|
|
|\
|
|
o | 99814c62bec5c13d2053435b3d6bbeb1900cb57e add file2
|
|
| o fe37af248a068697c6dcd7ebd17f5aac2205e7cb add file1
|
|
|/
|
|
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");
|
|
}
|
|
|
|
fn get_log_output(test_env: &TestEnvironment, repo_path: &Path) -> String {
|
|
test_env.jj_cmd_success(repo_path, &["log", "-T", "commit_id \" \" description"])
|
|
}
|