just playing with tangled
1// Copyright 2022 The Jujutsu Authors 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// https://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15use std::path::Path; 16 17use crate::common::TestEnvironment; 18 19pub mod common; 20 21#[test] 22fn test_commit_with_description_from_cli() { 23 let test_env = TestEnvironment::default(); 24 test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]); 25 let workspace_path = test_env.env_root().join("repo"); 26 27 // Description applies to the current working-copy (not the new one) 28 test_env.jj_cmd_success(&workspace_path, &["commit", "-m=first"]); 29 insta::assert_snapshot!(get_log_output(&test_env, &workspace_path), @r###" 30 @ b88fb4e51bdd 31 ◉ 69542c1984c1 first 32 ◉ 000000000000 33 "###); 34} 35 36#[test] 37fn test_commit_with_editor() { 38 let mut test_env = TestEnvironment::default(); 39 test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]); 40 let workspace_path = test_env.env_root().join("repo"); 41 42 // Check that the text file gets initialized with the current description and 43 // set a new one 44 test_env.jj_cmd_success(&workspace_path, &["describe", "-m=initial"]); 45 let edit_script = test_env.set_up_fake_editor(); 46 std::fs::write(&edit_script, ["dump editor0", "write\nmodified"].join("\0")).unwrap(); 47 test_env.jj_cmd_success(&workspace_path, &["commit"]); 48 insta::assert_snapshot!(get_log_output(&test_env, &workspace_path), @r###" 49 @ 3df78bc2b9b5 50 ◉ 30a8c2b3d6eb modified 51 ◉ 000000000000 52 "###); 53 insta::assert_snapshot!( 54 std::fs::read_to_string(test_env.env_root().join("editor0")).unwrap(), @r###" 55 initial 56 57 JJ: Lines starting with "JJ: " (like this one) will be removed. 58 "###); 59 60 // Check that the editor content includes diff summary 61 std::fs::write(workspace_path.join("file1"), "foo\n").unwrap(); 62 std::fs::write(workspace_path.join("file2"), "foo\n").unwrap(); 63 test_env.jj_cmd_success(&workspace_path, &["describe", "-m=add files"]); 64 std::fs::write(&edit_script, "dump editor1").unwrap(); 65 test_env.jj_cmd_success(&workspace_path, &["commit"]); 66 insta::assert_snapshot!( 67 std::fs::read_to_string(test_env.env_root().join("editor1")).unwrap(), @r###" 68 add files 69 70 JJ: This commit contains the following changes: 71 JJ: A file1 72 JJ: A file2 73 74 JJ: Lines starting with "JJ: " (like this one) will be removed. 75 "###); 76} 77 78#[test] 79fn test_commit_without_working_copy() { 80 let test_env = TestEnvironment::default(); 81 test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]); 82 let workspace_path = test_env.env_root().join("repo"); 83 84 test_env.jj_cmd_success(&workspace_path, &["workspace", "forget"]); 85 let stderr = test_env.jj_cmd_failure(&workspace_path, &["commit", "-m=first"]); 86 insta::assert_snapshot!(stderr, @r###" 87 Error: This command requires a working copy 88 "###); 89} 90 91fn get_log_output(test_env: &TestEnvironment, cwd: &Path) -> String { 92 let template = r#"commit_id.short() ++ " " ++ description"#; 93 test_env.jj_cmd_success(cwd, &["log", "-T", template]) 94}