jj/tests/test_concurrent_operations.rs
Ilya Grigoriev 0e2579ee6a Switch graph node to use for commit instead of
This follows up on 5c703aeb03.

The only reason for this change is that, subjectively, the result looks better to me. I'm not sure why, but I couldn't get used to the old symbol in spite of its seeming reasonableness. It felt really bold and heavy.

If people agree, we can wait until we need to update the screenshots for some other reason before merging this. Sorry I didn't figure this out while the discussion about the referenced commit was going on.

I'm not 100% certain how many fonts support each symbol. Please try it out and let me know if it doesn't work for you.

Compare after:

![image](https://user-images.githubusercontent.com/4123047/229251383-563b889d-7233-42e2-a3c5-bf9368a4d1fd.png)

and before:

![image](https://user-images.githubusercontent.com/4123047/229251695-7fd0ff2c-2832-4262-ade5-5120288cccdf.png)
2023-04-02 23:15:37 -07:00

144 lines
5.4 KiB
Rust

// Copyright 2022 The Jujutsu Authors
//
// 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_concurrent_operation_divergence() {
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", "message 1"]);
test_env.jj_cmd_success(
&repo_path,
&["describe", "-m", "message 2", "--at-op", "@-"],
);
// We should be informed about the concurrent modification
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "description"]);
insta::assert_snapshot!(stdout, @r###"
Concurrent modification detected, resolving automatically.
◉ message 2
│ @ message 1
├─╯
"###);
}
#[test]
fn test_concurrent_operations_auto_rebase() {
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");
std::fs::write(repo_path.join("file"), "contents").unwrap();
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "initial"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["op", "log"]);
insta::assert_snapshot!(stdout, @r###"
@ cde29280d4a9 test-username@host.example.com 22 years ago, lasted less than a microsecond
│ describe commit 123ed18e4c4c0d77428df41112bc02ffc83fb935
│ args: jj describe -m initial
◉ 7c212e0863fd test-username@host.example.com 22 years ago, lasted less than a microsecond
│ snapshot working copy
│ args: jj describe -m initial
◉ a99a3fd5c51e test-username@host.example.com 22 years ago, lasted less than a microsecond
│ add workspace 'default'
◉ 56b94dfc38e7 test-username@host.example.com 22 years ago, lasted less than a microsecond
initialize repo
"###);
let op_id_hex = stdout[3..15].to_string();
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "rewritten"]);
test_env.jj_cmd_success(
&repo_path,
&["new", "--at-op", &op_id_hex, "-m", "new child"],
);
// We should be informed about the concurrent modification
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
Concurrent modification detected, resolving automatically.
Rebased 1 descendant commits onto commits rewritten by other operation
◉ 3f06323826b4a293a9ee6d24cc0e07ad2961b5d5 new child
@ d91437157468ec86bbbc9e6a14a60d3e8d1790ac rewritten
◉ 0000000000000000000000000000000000000000
"###);
}
#[test]
fn test_concurrent_operations_wc_modified() {
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");
std::fs::write(repo_path.join("file"), "contents\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "initial"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["op", "log"]);
let op_id_hex = stdout[3..15].to_string();
test_env.jj_cmd_success(
&repo_path,
&["new", "--at-op", &op_id_hex, "-m", "new child1"],
);
test_env.jj_cmd_success(
&repo_path,
&["new", "--at-op", &op_id_hex, "-m", "new child2"],
);
std::fs::write(repo_path.join("file"), "modified\n").unwrap();
// We should be informed about the concurrent modification
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
Concurrent modification detected, resolving automatically.
@ 4eb0610031b7cd148ff9f729a673a3f815033170 new child1
│ ◉ 4b20e61d23ee7d7c4d5e61e11e97c26e716f9c30 new child2
├─╯
◉ 52c893bf3cd201e215b23e084e8a871244ca14d5 initial
◉ 0000000000000000000000000000000000000000
"###);
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "--git"]);
insta::assert_snapshot!(stdout, @r###"
diff --git a/file b/file
index 12f00e90b6...2e0996000b 100644
--- a/file
+++ b/file
@@ -1,1 +1,1 @@
-contents
+modified
"###);
// The working copy should be committed after merging the operations
let stdout = test_env.jj_cmd_success(&repo_path, &["op", "log", "-Tdescription"]);
insta::assert_snapshot!(stdout, @r###"
@ snapshot working copy
◉ resolve concurrent operations
├─╮
◉ │ new empty commit
│ ◉ new empty commit
├─╯
◉ describe commit cf911c223d3e24e001fc8264d6dbf0610804fc40
◉ snapshot working copy
◉ add workspace 'default'
◉ initialize repo
"###);
}
fn get_log_output(test_env: &TestEnvironment, cwd: &Path) -> String {
let template = r#"commit_id ++ " " ++ description"#;
test_env.jj_cmd_success(cwd, &["log", "-T", template])
}