just playing with tangled
at diffedit3 120 lines 4.7 kB view raw
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 19#[test] 20fn test_edit() { 21 let test_env = TestEnvironment::default(); 22 test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]); 23 let repo_path = test_env.env_root().join("repo"); 24 std::fs::write(repo_path.join("file1"), "0").unwrap(); 25 test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "first"]); 26 test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "second"]); 27 std::fs::write(repo_path.join("file1"), "1").unwrap(); 28 29 // Errors out without argument 30 let stderr = test_env.jj_cmd_cli_error(&repo_path, &["edit"]); 31 insta::assert_snapshot!(stderr, @r###" 32 error: the following required arguments were not provided: 33 <REVISION> 34 35 Usage: jj edit <REVISION> 36 37 For more information, try '--help'. 38 "###); 39 40 // Makes the specified commit the working-copy commit 41 let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["edit", "@-"]); 42 insta::assert_snapshot!(stdout, @""); 43 insta::assert_snapshot!(stderr, @r###" 44 Working copy now at: qpvuntsm f41390a5 first 45 Parent commit : zzzzzzzz 00000000 (empty) (no description set) 46 Added 0 files, modified 1 files, removed 0 files 47 "###); 48 let (stdout, stderr) = get_log_output_with_stderr(&test_env, &repo_path); 49 insta::assert_snapshot!(stdout, @r###" 50 ◉ b2f7e9c549aa second 51 @ f41390a5efbf first 52 ◉ 000000000000 53 "###); 54 insta::assert_snapshot!(stderr, @""); 55 insta::assert_snapshot!(read_file(&repo_path.join("file1")), @"0"); 56 57 // Changes in the working copy are amended into the commit 58 std::fs::write(repo_path.join("file2"), "0").unwrap(); 59 let (stdout, stderr) = get_log_output_with_stderr(&test_env, &repo_path); 60 insta::assert_snapshot!(stdout, @r###" 61 ◉ 51d937a3eeb4 second 62 @ 409306de8f44 first 63 ◉ 000000000000 64 "###); 65 insta::assert_snapshot!(stderr, @r###" 66 Rebased 1 descendant commits onto updated working copy 67 "###); 68} 69 70#[test] 71// Windows says "Access is denied" when trying to delete the object file. 72#[cfg(unix)] 73fn test_edit_current_wc_commit_missing() { 74 use crate::common::get_stderr_string; 75 76 // Test that we get a reasonable error message when the current working-copy 77 // commit is missing 78 let test_env = TestEnvironment::default(); 79 test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]); 80 let repo_path = test_env.env_root().join("repo"); 81 test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "first"]); 82 test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "second"]); 83 test_env.jj_cmd_ok(&repo_path, &["edit", "@-"]); 84 85 let wc_id = test_env.jj_cmd_success(&repo_path, &["log", "--no-graph", "-T=commit_id", "-r=@"]); 86 let wc_child_id = 87 test_env.jj_cmd_success(&repo_path, &["log", "--no-graph", "-T=commit_id", "-r=@+"]); 88 // Make the Git backend fail to read the current working copy commit 89 let commit_object_path = repo_path 90 .join(".jj") 91 .join("repo") 92 .join("store") 93 .join("git") 94 .join("objects") 95 .join(&wc_id[..2]) 96 .join(&wc_id[2..]); 97 std::fs::remove_file(commit_object_path).unwrap(); 98 99 // Pass --ignore-working-copy to avoid triggering the error at snapshot time 100 let assert = test_env 101 .jj_cmd(&repo_path, &["edit", "--ignore-working-copy", &wc_child_id]) 102 .assert() 103 .code(255); 104 insta::assert_snapshot!(get_stderr_string(&assert), @r###" 105 Internal error: Failed to edit a commit 106 Caused by: 107 1: Current working-copy commit not found 108 2: Object 69542c1984c1f9d91f7c6c9c9e6941782c944bd9 of type commit not found 109 3: An object with id 69542c1984c1f9d91f7c6c9c9e6941782c944bd9 could not be found 110 "###); 111} 112 113fn read_file(path: &Path) -> String { 114 String::from_utf8(std::fs::read(path).unwrap()).unwrap() 115} 116 117fn get_log_output_with_stderr(test_env: &TestEnvironment, cwd: &Path) -> (String, String) { 118 let template = r#"commit_id.short() ++ " " ++ description"#; 119 test_env.jj_cmd_ok(cwd, &["log", "-T", template]) 120}