Debian Codegraph @

cli/tests/test_builtin_aliases.rs

raw
1 // Copyright 2023 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
15 use crate::common::TestEnvironment;
16
17 fn set_up(trunk_name: &str) -> TestEnvironment {
18 let test_env = TestEnvironment::default();
19 test_env.run_jj_in(".", ["git", "init", "origin"]).success();
20 let origin_dir = test_env.work_dir("origin");
21 let origin_git_repo_path = origin_dir
22 .root()
23 .join(".jj")
24 .join("repo")
25 .join("store")
26 .join("git");
27
28 origin_dir
29 .run_jj(["describe", "-m=description 1"])
30 .success();
31 origin_dir
32 .run_jj(["bookmark", "create", "-r@", trunk_name])
33 .success();
34 origin_dir
35 .run_jj(["new", "root()", "-m=description 2"])
36 .success();
37 origin_dir
38 .run_jj(["bookmark", "create", "-r@", "unrelated_bookmark"])
39 .success();
40 origin_dir.run_jj(["git", "export"]).success();
41
42 test_env
43 .run_jj_in(
44 ".",
45 [
46 "git",
47 "clone",
48 "--config=remotes.origin.auto-track-bookmarks='*'",
49 origin_git_repo_path.to_str().unwrap(),
50 "local",
51 ],
52 )
53 .success();
54 test_env
55 }
56
57 #[test]
58 fn test_builtin_alias_trunk_matches_main() {
59 let test_env = set_up("main");
60 let work_dir = test_env.work_dir("local");
61
62 let output = work_dir.run_jj(["log", "-r", "trunk()"]);
63 insta::assert_snapshot!(output, @"
64 ◆ qpvuntsm [email protected] 2001-02-03 08:05:08 main 9b2e76de
65 │ (empty) description 1
66 ~
67 [EOF]
68 ");
69 }
70
71 #[test]
72 fn test_builtin_alias_trunk_matches_master() {
73 let test_env = set_up("master");
74 let work_dir = test_env.work_dir("local");
75
76 let output = work_dir.run_jj(["log", "-r", "trunk()"]);
77 insta::assert_snapshot!(output, @"
78 ◆ qpvuntsm [email protected] 2001-02-03 08:05:08 master 9b2e76de
79 │ (empty) description 1
80 ~
81 [EOF]
82 ");
83 }
84
85 #[test]
86 fn test_builtin_alias_trunk_matches_trunk() {
87 let test_env = set_up("trunk");
88 let work_dir = test_env.work_dir("local");
89
90 let output = work_dir.run_jj(["log", "-r", "trunk()"]);
91 insta::assert_snapshot!(output, @"
92 ◆ qpvuntsm [email protected] 2001-02-03 08:05:08 trunk 9b2e76de
93 │ (empty) description 1
94 ~
95 [EOF]
96 ");
97 }
98
99 #[test]
100 fn test_builtin_alias_trunk_matches_exactly_one_commit() {
101 let test_env = set_up("main");
102 let work_dir = test_env.work_dir("local");
103 let origin_dir = test_env.work_dir("origin");
104 origin_dir
105 .run_jj(["new", "root()", "-m=description 3"])
106 .success();
107 origin_dir
108 .run_jj(["bookmark", "create", "-r@", "master"])
109 .success();
110
111 let output = work_dir.run_jj(["log", "-r", "trunk()"]);
112 insta::assert_snapshot!(output, @"
113 ◆ qpvuntsm [email protected] 2001-02-03 08:05:08 main 9b2e76de
114 │ (empty) description 1
115 ~
116 [EOF]
117 ");
118 }
119
120 #[test]
121 fn test_builtin_alias_trunk_override_alias() {
122 let test_env = set_up("override-trunk");
123 let work_dir = test_env.work_dir("local");
124
125 test_env.add_config(
126 r#"revset-aliases.'trunk()' = 'latest(remote_bookmarks("override-trunk", "origin"))'"#,
127 );
128
129 let output = work_dir.run_jj(["log", "-r", "trunk()"]);
130 insta::assert_snapshot!(output, @"
131 ◆ qpvuntsm [email protected] 2001-02-03 08:05:08 override-trunk 9b2e76de
132 │ (empty) description 1
133 ~
134 [EOF]
135 ");
136 }
137
138 #[test]
139 fn test_builtin_alias_trunk_no_match() {
140 let test_env = set_up("no-match-trunk");
141 let work_dir = test_env.work_dir("local");
142
143 let output = work_dir.run_jj(["log", "-r", "trunk()"]);
144 insta::assert_snapshot!(output, @"
145 ◆ zzzzzzzz root() 00000000
146 [EOF]
147 ");
148 }
149
150 #[test]
151 fn test_builtin_alias_trunk_no_match_only_exact() {
152 let test_env = set_up("maint");
153 let work_dir = test_env.work_dir("local");
154
155 let output = work_dir.run_jj(["log", "-r", "trunk()"]);
156 insta::assert_snapshot!(output, @"
157 ◆ zzzzzzzz root() 00000000
158 [EOF]
159 ");
160 }
161
162 #[test]
163 fn test_builtin_user_redefines_builtin_immutable_heads() {
164 let test_env = set_up("main");
165 let work_dir = test_env.work_dir("local");
166
167 test_env.add_config(r#"revset-aliases.'builtin_immutable_heads()' = '@'"#);
168 test_env.add_config(r#"revset-aliases.'mutable()' = '@'"#);
169 test_env.add_config(r#"revset-aliases.'immutable()' = '@'"#);
170
171 let output = work_dir.run_jj(["log", "-r", "trunk()"]);
172 insta::assert_snapshot!(output, @r"
173 ○ qpvuntsm [email protected] 2001-02-03 08:05:08 main 9b2e76de
174 │ (empty) description 1
175 ~
176 [EOF]
177 ------- stderr -------
178 Warning: Redefining `revset-aliases.builtin_immutable_heads()` is not recommended; redefine `immutable_heads()` instead.
179 Warning: Redefining `revset-aliases.mutable()` is not recommended; redefine `immutable_heads()` instead.
180 Warning: Redefining `revset-aliases.immutable()` is not recommended; redefine `immutable_heads()` instead.
181 [EOF]
182 ");
183 }