just playing with tangled
at gvimdiff 131 lines 4.3 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 crate::common::CommandOutput; 16use crate::common::TestEnvironment; 17use crate::common::TestWorkDir; 18 19#[test] 20fn test_edit() { 21 let test_env = TestEnvironment::default(); 22 test_env.run_jj_in(".", ["git", "init", "repo"]).success(); 23 let work_dir = test_env.work_dir("repo"); 24 work_dir.write_file("file1", "0"); 25 work_dir.run_jj(["commit", "-m", "first"]).success(); 26 work_dir.run_jj(["describe", "-m", "second"]).success(); 27 work_dir.write_file("file1", "1"); 28 29 // Errors out without argument 30 let output = work_dir.run_jj(["edit"]); 31 insta::assert_snapshot!(output, @r" 32 ------- stderr ------- 33 error: the following required arguments were not provided: 34 <REVSET> 35 36 Usage: jj edit <REVSET> 37 38 For more information, try '--help'. 39 [EOF] 40 [exit status: 2] 41 "); 42 43 // Makes the specified commit the working-copy commit 44 let output = work_dir.run_jj(["edit", "@-"]); 45 insta::assert_snapshot!(output, @r" 46 ------- stderr ------- 47 Working copy (@) now at: qpvuntsm 73383c0b first 48 Parent commit (@-) : zzzzzzzz 00000000 (empty) (no description set) 49 Added 0 files, modified 1 files, removed 0 files 50 [EOF] 51 "); 52 let output = get_log_output(&work_dir); 53 insta::assert_snapshot!(output, @r" 54 ○ 2c910ae2d628 second 55 @ 73383c0b6439 first 56 ◆ 000000000000 57 [EOF] 58 "); 59 insta::assert_snapshot!(work_dir.read_file("file1"), @"0"); 60 61 // Changes in the working copy are amended into the commit 62 work_dir.write_file("file2", "0"); 63 let output = get_log_output(&work_dir); 64 insta::assert_snapshot!(output, @r" 65 ○ b384b2cc1883 second 66 @ ff3f7b0dc386 first 67 ◆ 000000000000 68 [EOF] 69 ------- stderr ------- 70 Rebased 1 descendant commits onto updated working copy 71 [EOF] 72 "); 73} 74 75#[test] 76// Windows says "Access is denied" when trying to delete the object file. 77#[cfg(unix)] 78fn test_edit_current_wc_commit_missing() { 79 use std::path::PathBuf; 80 81 // Test that we get a reasonable error message when the current working-copy 82 // commit is missing 83 84 let test_env = TestEnvironment::default(); 85 test_env.run_jj_in(".", ["git", "init", "repo"]).success(); 86 let work_dir = test_env.work_dir("repo"); 87 work_dir.run_jj(["commit", "-m", "first"]).success(); 88 work_dir.run_jj(["describe", "-m", "second"]).success(); 89 work_dir.run_jj(["edit", "@-"]).success(); 90 91 let wc_id = work_dir 92 .run_jj(["log", "--no-graph", "-T=commit_id", "-r=@"]) 93 .success() 94 .stdout 95 .into_raw(); 96 let wc_child_id = work_dir 97 .run_jj(["log", "--no-graph", "-T=commit_id", "-r=@+"]) 98 .success() 99 .stdout 100 .into_raw(); 101 // Make the Git backend fail to read the current working copy commit 102 let commit_object_path = PathBuf::from_iter([ 103 ".jj", 104 "repo", 105 "store", 106 "git", 107 "objects", 108 &wc_id[..2], 109 &wc_id[2..], 110 ]); 111 work_dir.remove_file(commit_object_path); 112 113 // Pass --ignore-working-copy to avoid triggering the error at snapshot time 114 let output = work_dir.run_jj(["edit", "--ignore-working-copy", &wc_child_id]); 115 insta::assert_snapshot!(output, @r" 116 ------- stderr ------- 117 Internal error: Failed to edit a commit 118 Caused by: 119 1: Current working-copy commit not found 120 2: Object fa15625b4a986997697639dfc2844138900c79f2 of type commit not found 121 3: An object with id fa15625b4a986997697639dfc2844138900c79f2 could not be found 122 [EOF] 123 [exit status: 255] 124 "); 125} 126 127#[must_use] 128fn get_log_output(work_dir: &TestWorkDir) -> CommandOutput { 129 let template = r#"commit_id.short() ++ " " ++ description"#; 130 work_dir.run_jj(["log", "-T", template]) 131}