2022-11-26 23:57:50 +00:00
|
|
|
|
// Copyright 2022 The Jujutsu Authors
|
2022-03-02 23:09:32 +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-05-07 23:16:27 +00:00
|
|
|
|
use std::ffi::OsString;
|
|
|
|
|
|
|
|
|
|
use crate::common::{get_stderr_string, TestEnvironment};
|
2022-03-30 17:47:11 +00:00
|
|
|
|
|
|
|
|
|
pub mod common;
|
2022-03-02 23:09:32 +00:00
|
|
|
|
|
2022-05-07 23:16:27 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn test_non_utf8_arg() {
|
|
|
|
|
let test_env = TestEnvironment::default();
|
|
|
|
|
#[cfg(unix)]
|
|
|
|
|
let invalid_utf = {
|
|
|
|
|
use std::os::unix::ffi::OsStringExt;
|
|
|
|
|
OsString::from_vec(vec![0x66, 0x6f, 0x80, 0x6f])
|
|
|
|
|
};
|
|
|
|
|
#[cfg(windows)]
|
|
|
|
|
let invalid_utf = {
|
|
|
|
|
use std::os::windows::prelude::*;
|
|
|
|
|
OsString::from_wide(&[0x0066, 0x006f, 0xD800, 0x006f])
|
|
|
|
|
};
|
|
|
|
|
let assert = test_env
|
|
|
|
|
.jj_cmd(test_env.env_root(), &[])
|
|
|
|
|
.args(&[invalid_utf])
|
|
|
|
|
.assert()
|
|
|
|
|
.code(2);
|
|
|
|
|
let stderr = get_stderr_string(&assert);
|
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
|
Error: Non-utf8 argument
|
|
|
|
|
"###);
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-20 07:42:50 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn test_no_subcommand() {
|
|
|
|
|
let test_env = TestEnvironment::default();
|
2022-11-21 03:01:35 +00:00
|
|
|
|
|
|
|
|
|
let stderr = test_env.jj_cmd_cli_error(test_env.env_root(), &[]);
|
|
|
|
|
insta::assert_snapshot!(stderr.lines().next().unwrap(), @"Jujutsu (An experimental VCS)");
|
|
|
|
|
|
|
|
|
|
let stderr = test_env.jj_cmd_cli_error(test_env.env_root(), &["-R."]);
|
|
|
|
|
insta::assert_snapshot!(stderr.lines().next().unwrap(), @"error: 'jj' requires a subcommand but one was not provided");
|
2022-11-20 07:42:50 +00:00
|
|
|
|
|
|
|
|
|
let stdout = test_env.jj_cmd_success(test_env.env_root(), &["--version"]);
|
|
|
|
|
insta::assert_snapshot!(stdout.replace(|c: char| c.is_ascii_digit(), "?"), @r###"
|
|
|
|
|
jj ?.?.?
|
|
|
|
|
"###);
|
|
|
|
|
|
|
|
|
|
let stdout = test_env.jj_cmd_success(test_env.env_root(), &["--help"]);
|
|
|
|
|
insta::assert_snapshot!(stdout.lines().next().unwrap(), @"Jujutsu (An experimental VCS)");
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-02 23:09:32 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn test_no_commit_working_copy() {
|
|
|
|
|
let test_env = TestEnvironment::default();
|
2022-03-26 21:06:48 +00:00
|
|
|
|
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
|
2022-03-02 23:09:32 +00:00
|
|
|
|
|
|
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
|
|
|
|
|
std::fs::write(repo_path.join("file"), "initial").unwrap();
|
2022-03-26 21:06:48 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "commit_id"]);
|
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2022-03-06 02:51:09 +00:00
|
|
|
|
@ 438471f3fbf1004298d8fb01eeb13663a051a643
|
2022-03-06 03:32:20 +00:00
|
|
|
|
o 0000000000000000000000000000000000000000
|
|
|
|
|
"###);
|
|
|
|
|
|
2022-03-02 23:09:32 +00:00
|
|
|
|
// Modify the file. With --no-commit-working-copy, we still get the same commit
|
|
|
|
|
// ID.
|
|
|
|
|
std::fs::write(repo_path.join("file"), "modified").unwrap();
|
2022-03-26 21:06:48 +00:00
|
|
|
|
let stdout_again = test_env.jj_cmd_success(
|
|
|
|
|
&repo_path,
|
|
|
|
|
&["log", "-T", "commit_id", "--no-commit-working-copy"],
|
|
|
|
|
);
|
|
|
|
|
assert_eq!(stdout_again, stdout);
|
2022-03-05 06:33:15 +00:00
|
|
|
|
|
2022-03-02 23:09:32 +00:00
|
|
|
|
// But without --no-commit-working-copy, we get a new commit ID.
|
2022-03-26 21:06:48 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "commit_id"]);
|
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2022-03-06 02:51:09 +00:00
|
|
|
|
@ fab22d1acf5bb9c5aa48cb2c3dd2132072a359ca
|
2022-03-06 03:32:20 +00:00
|
|
|
|
o 0000000000000000000000000000000000000000
|
|
|
|
|
"###);
|
2022-03-02 23:09:32 +00:00
|
|
|
|
}
|
2022-03-02 21:14:06 +00:00
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_repo_arg_with_init() {
|
|
|
|
|
let test_env = TestEnvironment::default();
|
2022-04-07 06:25:01 +00:00
|
|
|
|
let stderr = test_env.jj_cmd_failure(test_env.env_root(), &["init", "-R=.", "repo"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
|
Error: '--repository' cannot be used with 'init'
|
|
|
|
|
"###);
|
2022-03-02 21:14:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_repo_arg_with_git_clone() {
|
|
|
|
|
let test_env = TestEnvironment::default();
|
2022-04-07 06:25:01 +00:00
|
|
|
|
let stderr = test_env.jj_cmd_failure(test_env.env_root(), &["git", "clone", "-R=.", "remote"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
|
Error: '--repository' cannot be used with 'git clone'
|
|
|
|
|
"###);
|
2022-03-02 21:14:06 +00:00
|
|
|
|
}
|
2022-03-19 17:37:13 +00:00
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_color_config() {
|
2022-04-02 16:16:52 +00:00
|
|
|
|
let mut test_env = TestEnvironment::default();
|
2022-03-19 17:00:13 +00:00
|
|
|
|
|
2022-06-09 04:16:34 +00:00
|
|
|
|
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
|
|
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
|
|
|
|
|
// Test that --color=always is respected.
|
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["--color=always", "log", "-T", "commit_id"]);
|
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
@ [1;34m230dd059e1b059aefc0da06a2e5a7dbf22362f22[0m
|
|
|
|
|
o [34m0000000000000000000000000000000000000000[0m
|
|
|
|
|
"###);
|
|
|
|
|
|
2022-03-19 17:00:13 +00:00
|
|
|
|
// Test that color is used if it's requested in the config file
|
2022-04-09 23:14:42 +00:00
|
|
|
|
test_env.add_config(
|
2022-04-02 06:22:13 +00:00
|
|
|
|
br#"[ui]
|
2022-03-19 17:37:13 +00:00
|
|
|
|
color="always""#,
|
2022-04-02 06:22:13 +00:00
|
|
|
|
);
|
2022-03-26 21:06:48 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "commit_id"]);
|
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2022-03-19 17:37:13 +00:00
|
|
|
|
@ [1;34m230dd059e1b059aefc0da06a2e5a7dbf22362f22[0m
|
|
|
|
|
o [34m0000000000000000000000000000000000000000[0m
|
|
|
|
|
"###);
|
2022-03-19 17:00:13 +00:00
|
|
|
|
|
2022-06-09 04:16:34 +00:00
|
|
|
|
// Test that --color=never overrides the config.
|
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["--color=never", "log", "-T", "commit_id"]);
|
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
@ 230dd059e1b059aefc0da06a2e5a7dbf22362f22
|
|
|
|
|
o 0000000000000000000000000000000000000000
|
|
|
|
|
"###);
|
|
|
|
|
|
2022-10-31 01:29:26 +00:00
|
|
|
|
// Test that --color=auto overrides the config.
|
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["--color=auto", "log", "-T", "commit_id"]);
|
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
@ 230dd059e1b059aefc0da06a2e5a7dbf22362f22
|
|
|
|
|
o 0000000000000000000000000000000000000000
|
|
|
|
|
"###);
|
|
|
|
|
|
|
|
|
|
// Test that --config-toml 'ui.color="never"' overrides the config.
|
|
|
|
|
let stdout = test_env.jj_cmd_success(
|
|
|
|
|
&repo_path,
|
|
|
|
|
&[
|
|
|
|
|
"--config-toml",
|
|
|
|
|
"ui.color=\"never\"",
|
|
|
|
|
"log",
|
|
|
|
|
"-T",
|
|
|
|
|
"commit_id",
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
@ 230dd059e1b059aefc0da06a2e5a7dbf22362f22
|
|
|
|
|
o 0000000000000000000000000000000000000000
|
|
|
|
|
"###);
|
|
|
|
|
|
|
|
|
|
// --color overrides --config-toml 'ui.color=...'.
|
|
|
|
|
let stdout = test_env.jj_cmd_success(
|
|
|
|
|
&repo_path,
|
|
|
|
|
&[
|
|
|
|
|
"--color",
|
|
|
|
|
"never",
|
|
|
|
|
"--config-toml",
|
|
|
|
|
"ui.color=\"always\"",
|
|
|
|
|
"log",
|
|
|
|
|
"-T",
|
|
|
|
|
"commit_id",
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
@ 230dd059e1b059aefc0da06a2e5a7dbf22362f22
|
|
|
|
|
o 0000000000000000000000000000000000000000
|
|
|
|
|
"###);
|
|
|
|
|
|
2022-06-10 02:42:15 +00:00
|
|
|
|
// Test that NO_COLOR does NOT override the request for color in the config file
|
2022-04-02 16:16:52 +00:00
|
|
|
|
test_env.add_env_var("NO_COLOR", "");
|
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "commit_id"]);
|
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2022-06-10 02:42:15 +00:00
|
|
|
|
@ [1;34m230dd059e1b059aefc0da06a2e5a7dbf22362f22[0m
|
|
|
|
|
o [34m0000000000000000000000000000000000000000[0m
|
2022-03-19 17:00:13 +00:00
|
|
|
|
"###);
|
2022-03-19 17:37:13 +00:00
|
|
|
|
}
|
2022-03-27 19:49:04 +00:00
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_invalid_config() {
|
|
|
|
|
// Test that we get a reasonable error if the config is invalid (#55)
|
|
|
|
|
let test_env = TestEnvironment::default();
|
|
|
|
|
|
2022-04-09 23:14:42 +00:00
|
|
|
|
test_env.add_config(b"[section]key = value-missing-quotes");
|
2022-04-07 06:25:01 +00:00
|
|
|
|
let stderr = test_env.jj_cmd_failure(test_env.env_root(), &["init", "repo"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
|
insta::assert_snapshot!(stderr.replace('\\', "/"), @r###"
|
2022-05-08 06:54:51 +00:00
|
|
|
|
Config error: expected newline, found an identifier at line 1 column 10 in config/config0001.toml
|
2022-04-28 23:32:18 +00:00
|
|
|
|
"###);
|
2022-03-27 19:49:04 +00:00
|
|
|
|
}
|
2022-04-02 21:10:52 +00:00
|
|
|
|
|
2022-10-10 00:22:20 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn test_no_user_configured() {
|
|
|
|
|
// Test that the user is reminded if they haven't configured their name or email
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
|
|
let assert = test_env
|
|
|
|
|
.jj_cmd(&repo_path, &["describe", "-m", "without name"])
|
|
|
|
|
.env_remove("JJ_USER")
|
|
|
|
|
.assert()
|
|
|
|
|
.success();
|
|
|
|
|
insta::assert_snapshot!(get_stderr_string(&assert), @r###"
|
|
|
|
|
Name and email not configured. Add something like the following to $HOME/.jjconfig.toml:
|
|
|
|
|
user.name = "Some One"
|
|
|
|
|
user.email = "someone@example.com"
|
|
|
|
|
"###);
|
|
|
|
|
let assert = test_env
|
|
|
|
|
.jj_cmd(&repo_path, &["describe", "-m", "without email"])
|
|
|
|
|
.env_remove("JJ_EMAIL")
|
|
|
|
|
.assert()
|
|
|
|
|
.success();
|
|
|
|
|
insta::assert_snapshot!(get_stderr_string(&assert), @r###"
|
|
|
|
|
Name and email not configured. Add something like the following to $HOME/.jjconfig.toml:
|
|
|
|
|
user.name = "Some One"
|
|
|
|
|
user.email = "someone@example.com"
|
|
|
|
|
"###);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-02 21:10:52 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn test_help() {
|
|
|
|
|
// Test that global options are separated out in the help output
|
|
|
|
|
let test_env = TestEnvironment::default();
|
|
|
|
|
|
2022-06-19 03:22:54 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(test_env.env_root(), &["touchup", "-h"]);
|
2022-11-18 20:50:39 +00:00
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2022-06-19 03:22:54 +00:00
|
|
|
|
Touch up the content changes in a revision
|
2022-04-02 21:10:52 +00:00
|
|
|
|
|
2022-09-29 16:12:16 +00:00
|
|
|
|
Usage: jj touchup [OPTIONS]
|
2022-04-02 21:10:52 +00:00
|
|
|
|
|
2022-09-29 16:12:16 +00:00
|
|
|
|
Options:
|
|
|
|
|
-r, --revision <REVISION> The revision to touch up [default: @]
|
|
|
|
|
-h, --help Print help information (use `--help` for more detail)
|
2022-04-02 21:10:52 +00:00
|
|
|
|
|
2022-09-29 16:12:16 +00:00
|
|
|
|
Global Options:
|
|
|
|
|
-R, --repository <REPOSITORY> Path to repository to operate on
|
|
|
|
|
--no-commit-working-copy Don't commit the working copy
|
|
|
|
|
--at-operation <AT_OPERATION> Operation to load the repo at [default: @] [aliases: at-op]
|
|
|
|
|
--color <WHEN> When to colorize output (always, never, auto)
|
2022-11-01 00:31:30 +00:00
|
|
|
|
--no-pager Disable the pager
|
2022-10-31 01:29:26 +00:00
|
|
|
|
--config-toml <TOML> Additional configuration options
|
2022-11-20 03:38:25 +00:00
|
|
|
|
-v, --verbose Enable verbose logging
|
2022-04-02 21:10:52 +00:00
|
|
|
|
"###);
|
|
|
|
|
}
|
2022-11-20 03:38:25 +00:00
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_verbose_logging_enabled() {
|
|
|
|
|
// Test that the verbose flag enabled verbose logging
|
|
|
|
|
let test_env = TestEnvironment::default();
|
|
|
|
|
|
|
|
|
|
let assert = test_env
|
|
|
|
|
.jj_cmd(test_env.env_root(), &["version", "-v"])
|
|
|
|
|
.assert()
|
|
|
|
|
.success();
|
|
|
|
|
|
|
|
|
|
let stderr = get_stderr_string(&assert);
|
|
|
|
|
// Split the first log line into a timestamp and the rest.
|
|
|
|
|
// The timestamp is constant sized so this is a robust operation.
|
|
|
|
|
// Example timestamp: 2022-11-20T06:24:05.477703Z
|
|
|
|
|
let (_timestamp, log_line) = stderr
|
|
|
|
|
.lines()
|
|
|
|
|
.next()
|
|
|
|
|
.expect("verbose logging on first line")
|
|
|
|
|
.split_at(36);
|
|
|
|
|
// The log format is currently Pretty so we include the terminal markup.
|
|
|
|
|
// Luckily, insta will print this in colour when reviewing.
|
|
|
|
|
insta::assert_snapshot!(log_line, @"\u{1b}[34mDEBUG\u{1b}[0m \u{1b}[2mjj\u{1b}[0m\u{1b}[2m:\u{1b}[0m verbose logging enabled");
|
|
|
|
|
}
|