ok/jj
1
0
Fork 0
forked from mirrors/jj
jj/tests/test_checkout.rs
Martin von Zweigbergk 418ab22be0 cli: add config for using only new UX for open commits
By adding `ui.open-commits=false` in your config, you can now make `jj
checkout` always create a new working-copy commit on top of the
specified commit. If the config is set, open commits will also appear
in the same color as closed commits in `jj log` etc. This will let
some of us experiment with the new UX before we decide if it's a good
idea or not. I left `jj close` in place because it's useful for
setting a description and creating a new commit in one step.

I didn't mention the new config in the release notes because I hope we
can reach a decision and remove the config before the next release.
2022-07-01 08:58:08 +08:00

79 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_checkout() {
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, &["close", "-m", "closed"]);
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "open"]);
test_env.jj_cmd_success(&repo_path, &["branch", "create", "open"]);
// Check out current commit
let stdout = test_env.jj_cmd_success(&repo_path, &["checkout", "@"]);
insta::assert_snapshot!(stdout, @r###"
Already on that commit
"###);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ 169fa76981bcf302d1a96952bdf32a8da79ab084 open
o b4c967d9c9a9e8b523b0a9b52879b3337a3e67a9 closed
o 0000000000000000000000000000000000000000 (no description set)
"###);
// When checking out a closed commit, a new commit is created on top of it
test_env.jj_cmd_success(&repo_path, &["checkout", "@-"]);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ 5a38be51f15b107b7c7e89c06c0ab626f1457128 (no description set)
| o 169fa76981bcf302d1a96952bdf32a8da79ab084 open
|/
o b4c967d9c9a9e8b523b0a9b52879b3337a3e67a9 closed
o 0000000000000000000000000000000000000000 (no description set)
"###);
// When checking out an open commit, the specified commit is edited directly
test_env.jj_cmd_success(&repo_path, &["checkout", "open"]);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ 169fa76981bcf302d1a96952bdf32a8da79ab084 open
o b4c967d9c9a9e8b523b0a9b52879b3337a3e67a9 closed
o 0000000000000000000000000000000000000000 (no description set)
"###);
// With ui.enable-open-commits=false, checking out an open commit also results
// in a commit on top
test_env.add_config(
br#"[ui]
enable-open-commits = false
"#,
);
test_env.jj_cmd_success(&repo_path, &["checkout", "open"]);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ 37b7bc83cf288eef68564044a9ac0ec6c5df34f0 (no description set)
o 169fa76981bcf302d1a96952bdf32a8da79ab084 open
o b4c967d9c9a9e8b523b0a9b52879b3337a3e67a9 closed
o 0000000000000000000000000000000000000000 (no description set)
"###);
}
fn get_log_output(test_env: &TestEnvironment, cwd: &Path) -> String {
test_env.jj_cmd_success(cwd, &["log", "-T", r#"commit_id " " description"#])
}