just playing with tangled
at diffedit3 165 lines 5.4 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::TestEnvironment; 16 17#[test] 18fn test_interdiff_basic() { 19 let test_env = TestEnvironment::default(); 20 test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]); 21 let repo_path = test_env.env_root().join("repo"); 22 23 std::fs::write(repo_path.join("file1"), "foo\n").unwrap(); 24 test_env.jj_cmd_ok(&repo_path, &["new"]); 25 std::fs::write(repo_path.join("file2"), "foo\n").unwrap(); 26 test_env.jj_cmd_ok(&repo_path, &["branch", "create", "left"]); 27 28 test_env.jj_cmd_ok(&repo_path, &["checkout", "root()"]); 29 std::fs::write(repo_path.join("file3"), "foo\n").unwrap(); 30 test_env.jj_cmd_ok(&repo_path, &["new"]); 31 std::fs::write(repo_path.join("file2"), "foo\nbar\n").unwrap(); 32 test_env.jj_cmd_ok(&repo_path, &["branch", "create", "right"]); 33 34 // implicit --to 35 let stdout = test_env.jj_cmd_success(&repo_path, &["interdiff", "--from", "left"]); 36 insta::assert_snapshot!(stdout, @r###" 37 Modified regular file file2: 38 1 1: foo 39 2: bar 40 "###); 41 42 // explicit --to 43 test_env.jj_cmd_ok(&repo_path, &["checkout", "@-"]); 44 let stdout = test_env.jj_cmd_success( 45 &repo_path, 46 &["interdiff", "--from", "left", "--to", "right"], 47 ); 48 insta::assert_snapshot!(stdout, @r###" 49 Modified regular file file2: 50 1 1: foo 51 2: bar 52 "###); 53 test_env.jj_cmd_ok(&repo_path, &["undo"]); 54 55 // formats specifiers 56 let stdout = test_env.jj_cmd_success( 57 &repo_path, 58 &["interdiff", "--from", "left", "--to", "right", "-s"], 59 ); 60 insta::assert_snapshot!(stdout, @r###" 61 M file2 62 "###); 63 64 let stdout = test_env.jj_cmd_success( 65 &repo_path, 66 &["interdiff", "--from", "left", "--to", "right", "--git"], 67 ); 68 insta::assert_snapshot!(stdout, @r###" 69 diff --git a/file2 b/file2 70 index 257cc5642c...3bd1f0e297 100644 71 --- a/file2 72 +++ b/file2 73 @@ -1,1 +1,2 @@ 74 foo 75 +bar 76 "###); 77} 78 79#[test] 80fn test_interdiff_paths() { 81 let test_env = TestEnvironment::default(); 82 test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]); 83 let repo_path = test_env.env_root().join("repo"); 84 85 std::fs::write(repo_path.join("file1"), "foo\n").unwrap(); 86 std::fs::write(repo_path.join("file2"), "foo\n").unwrap(); 87 test_env.jj_cmd_ok(&repo_path, &["new"]); 88 std::fs::write(repo_path.join("file1"), "bar\n").unwrap(); 89 std::fs::write(repo_path.join("file2"), "bar\n").unwrap(); 90 test_env.jj_cmd_ok(&repo_path, &["branch", "create", "left"]); 91 92 test_env.jj_cmd_ok(&repo_path, &["checkout", "root()"]); 93 std::fs::write(repo_path.join("file1"), "foo\n").unwrap(); 94 std::fs::write(repo_path.join("file2"), "foo\n").unwrap(); 95 test_env.jj_cmd_ok(&repo_path, &["new"]); 96 std::fs::write(repo_path.join("file1"), "baz\n").unwrap(); 97 std::fs::write(repo_path.join("file2"), "baz\n").unwrap(); 98 test_env.jj_cmd_ok(&repo_path, &["branch", "create", "right"]); 99 100 let stdout = test_env.jj_cmd_success( 101 &repo_path, 102 &["interdiff", "--from", "left", "--to", "right", "file1"], 103 ); 104 insta::assert_snapshot!(stdout, @r###" 105 Modified regular file file1: 106 1 1: barbaz 107 "###); 108 109 let stdout = test_env.jj_cmd_success( 110 &repo_path, 111 &[ 112 "interdiff", 113 "--from", 114 "left", 115 "--to", 116 "right", 117 "file1", 118 "file2", 119 ], 120 ); 121 insta::assert_snapshot!(stdout, @r###" 122 Modified regular file file1: 123 1 1: barbaz 124 Modified regular file file2: 125 1 1: barbaz 126 "###); 127} 128 129#[test] 130fn test_interdiff_conflicting() { 131 let test_env = TestEnvironment::default(); 132 test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]); 133 let repo_path = test_env.env_root().join("repo"); 134 135 std::fs::write(repo_path.join("file"), "foo\n").unwrap(); 136 test_env.jj_cmd_ok(&repo_path, &["new"]); 137 std::fs::write(repo_path.join("file"), "bar\n").unwrap(); 138 test_env.jj_cmd_ok(&repo_path, &["branch", "create", "left"]); 139 140 test_env.jj_cmd_ok(&repo_path, &["checkout", "root()"]); 141 std::fs::write(repo_path.join("file"), "abc\n").unwrap(); 142 test_env.jj_cmd_ok(&repo_path, &["new"]); 143 std::fs::write(repo_path.join("file"), "def\n").unwrap(); 144 test_env.jj_cmd_ok(&repo_path, &["branch", "create", "right"]); 145 146 let stdout = test_env.jj_cmd_success( 147 &repo_path, 148 &["interdiff", "--from", "left", "--to", "right", "--git"], 149 ); 150 insta::assert_snapshot!(stdout, @r###" 151 diff --git a/file b/file 152 index 0000000000...24c5735c3e 100644 153 --- a/file 154 +++ b/file 155 @@ -1,7 +1,1 @@ 156 -<<<<<<< Conflict 1 of 1 157 -%%%%%%% Changes from base to side #1 158 --foo 159 -+abc 160 -+++++++ Contents of side #2 161 -bar 162 ->>>>>>> 163 +def 164 "###); 165}