| 1 |
// Copyright 2024 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::CommandOutput; |
| 16 |
use crate::common::TestEnvironment; |
| 17 |
use crate::common::TestWorkDir; |
| 18 |
|
| 19 |
#[test] |
| 20 |
fn test_tag_set_delete() { |
| 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 |
|
| 25 |
work_dir.run_jj(["commit", "-mcommit1"]).success(); |
| 26 |
let output = work_dir.run_jj(["tag", "set", "-r@-", "foo", "bar"]); |
| 27 |
insta::assert_snapshot!(output, @" |
| 28 |
------- stderr ------- |
| 29 |
Created 2 tags pointing to qpvuntsm b876c5f4 (empty) commit1 |
| 30 |
[EOF] |
| 31 |
"); |
| 32 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 33 |
@ bbc749308d7f |
| 34 |
◆ b876c5f49546 bar foo |
| 35 |
◆ 000000000000 |
| 36 |
[EOF] |
| 37 |
"); |
| 38 |
|
| 39 |
let output = work_dir.run_jj(["tag", "set", "foo", "baz"]); |
| 40 |
insta::assert_snapshot!(output, @" |
| 41 |
------- stderr ------- |
| 42 |
Error: Refusing to move tag: foo |
| 43 |
Hint: Use --allow-move to update existing tags. |
| 44 |
[EOF] |
| 45 |
[exit status: 1] |
| 46 |
"); |
| 47 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 48 |
@ bbc749308d7f |
| 49 |
◆ b876c5f49546 bar foo |
| 50 |
◆ 000000000000 |
| 51 |
[EOF] |
| 52 |
"); |
| 53 |
|
| 54 |
let output = work_dir.run_jj(["tag", "set", "--allow-move", "foo", "baz"]); |
| 55 |
insta::assert_snapshot!(output, @" |
| 56 |
------- stderr ------- |
| 57 |
Warning: Target revision is empty. |
| 58 |
Created 1 tags pointing to rlvkpnrz bbc74930 (empty) (no description set) |
| 59 |
Moved 1 tags to rlvkpnrz bbc74930 (empty) (no description set) |
| 60 |
Warning: The working-copy commit became immutable; a new commit has been created on top of it. |
| 61 |
Working copy (@) now at: yqosqzyt 13cbd515 (empty) (no description set) |
| 62 |
Parent commit (@-) : rlvkpnrz bbc74930 (empty) (no description set) |
| 63 |
[EOF] |
| 64 |
"); |
| 65 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 66 |
@ 13cbd51558a6 |
| 67 |
◆ bbc749308d7f baz foo |
| 68 |
◆ b876c5f49546 bar |
| 69 |
◆ 000000000000 |
| 70 |
[EOF] |
| 71 |
"); |
| 72 |
|
| 73 |
let output = work_dir.run_jj(["tag", "delete", "foo"]); |
| 74 |
insta::assert_snapshot!(output, @" |
| 75 |
------- stderr ------- |
| 76 |
Deleted 1 tags. |
| 77 |
[EOF] |
| 78 |
"); |
| 79 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 80 |
@ 13cbd51558a6 |
| 81 |
◆ bbc749308d7f baz |
| 82 |
◆ b876c5f49546 bar |
| 83 |
◆ 000000000000 |
| 84 |
[EOF] |
| 85 |
"); |
| 86 |
|
| 87 |
let output = work_dir.run_jj(["tag", "set", "--allow-move", "-r@", "baz"]); |
| 88 |
insta::assert_snapshot!(output, @" |
| 89 |
------- stderr ------- |
| 90 |
Warning: Target revision is empty. |
| 91 |
Moved 1 tags to yqosqzyt 13cbd515 (empty) (no description set) |
| 92 |
Warning: The working-copy commit became immutable; a new commit has been created on top of it. |
| 93 |
Working copy (@) now at: kpqxywon cca3d7af (empty) (no description set) |
| 94 |
Parent commit (@-) : yqosqzyt 13cbd515 (empty) (no description set) |
| 95 |
[EOF] |
| 96 |
"); |
| 97 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 98 |
@ cca3d7af9d98 |
| 99 |
◆ 13cbd51558a6 baz |
| 100 |
◆ bbc749308d7f |
| 101 |
◆ b876c5f49546 bar |
| 102 |
◆ 000000000000 |
| 103 |
[EOF] |
| 104 |
"); |
| 105 |
|
| 106 |
let output = work_dir.run_jj(["tag", "delete", "b*"]); |
| 107 |
insta::assert_snapshot!(output, @" |
| 108 |
------- stderr ------- |
| 109 |
Deleted 2 tags. |
| 110 |
[EOF] |
| 111 |
"); |
| 112 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 113 |
@ cca3d7af9d98 |
| 114 |
○ 13cbd51558a6 |
| 115 |
○ bbc749308d7f |
| 116 |
○ b876c5f49546 |
| 117 |
◆ 000000000000 |
| 118 |
[EOF] |
| 119 |
"); |
| 120 |
} |
| 121 |
|
| 122 |
#[test] |
| 123 |
fn test_tag_at_root() { |
| 124 |
let test_env = TestEnvironment::default(); |
| 125 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 126 |
let work_dir = test_env.work_dir("repo"); |
| 127 |
|
| 128 |
let output = work_dir.run_jj(["tag", "set", "-rroot()", "foo"]); |
| 129 |
insta::assert_snapshot!(output, @" |
| 130 |
------- stderr ------- |
| 131 |
Warning: Target revision is empty. |
| 132 |
Created 1 tags pointing to zzzzzzzz 00000000 (empty) (no description set) |
| 133 |
[EOF] |
| 134 |
"); |
| 135 |
let output = work_dir.run_jj(["git", "export"]); |
| 136 |
insta::assert_snapshot!(output, @" |
| 137 |
------- stderr ------- |
| 138 |
Nothing changed. |
| 139 |
Warning: Failed to export some tags: |
| 140 |
foo@git: Ref cannot point to the root commit in Git |
| 141 |
[EOF] |
| 142 |
"); |
| 143 |
} |
| 144 |
|
| 145 |
#[test] |
| 146 |
fn test_tag_bad_name() { |
| 147 |
let test_env = TestEnvironment::default(); |
| 148 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 149 |
let work_dir = test_env.work_dir("repo"); |
| 150 |
|
| 151 |
work_dir.run_jj(["commit", "-mcommit1"]).success(); |
| 152 |
|
| 153 |
let output = work_dir.run_jj(["tag", "set", ""]); |
| 154 |
insta::assert_snapshot!(output, @" |
| 155 |
------- stderr ------- |
| 156 |
error: invalid value '' for '<NAMES>...': Failed to parse tag name: Syntax error |
| 157 |
|
| 158 |
For more information, try '--help'. |
| 159 |
Caused by: --> 1:1 |
| 160 |
| |
| 161 |
1 | |
| 162 |
| ^--- |
| 163 |
| |
| 164 |
= expected <identifier>, <string_literal>, or <raw_string_literal> |
| 165 |
Hint: See https://docs.jj-vcs.dev/latest/revsets/ or use `jj help -k revsets` for how to quote symbols. |
| 166 |
[EOF] |
| 167 |
[exit status: 2] |
| 168 |
"); |
| 169 |
|
| 170 |
let output = work_dir.run_jj(["tag", "set", "''"]); |
| 171 |
insta::assert_snapshot!(output, @" |
| 172 |
------- stderr ------- |
| 173 |
error: invalid value '''' for '<NAMES>...': Failed to parse tag name: Expected non-empty string |
| 174 |
|
| 175 |
For more information, try '--help'. |
| 176 |
Caused by: --> 1:1 |
| 177 |
| |
| 178 |
1 | '' |
| 179 |
| ^^ |
| 180 |
| |
| 181 |
= Expected non-empty string |
| 182 |
Hint: See https://docs.jj-vcs.dev/latest/revsets/ or use `jj help -k revsets` for how to quote symbols. |
| 183 |
[EOF] |
| 184 |
[exit status: 2] |
| 185 |
"); |
| 186 |
|
| 187 |
let output = work_dir.run_jj(["tag", "set", "foo@"]); |
| 188 |
insta::assert_snapshot!(output, @" |
| 189 |
------- stderr ------- |
| 190 |
error: invalid value 'foo@' for '<NAMES>...': Failed to parse tag name: Syntax error |
| 191 |
|
| 192 |
For more information, try '--help'. |
| 193 |
Caused by: --> 1:4 |
| 194 |
| |
| 195 |
1 | foo@ |
| 196 |
| ^--- |
| 197 |
| |
| 198 |
= expected <EOI> |
| 199 |
Hint: See https://docs.jj-vcs.dev/latest/revsets/ or use `jj help -k revsets` for how to quote symbols. |
| 200 |
[EOF] |
| 201 |
[exit status: 2] |
| 202 |
"); |
| 203 |
|
| 204 |
// quoted name works |
| 205 |
let output = work_dir.run_jj(["tag", "set", "-r@-", "'foo@'"]); |
| 206 |
insta::assert_snapshot!(output, @" |
| 207 |
------- stderr ------- |
| 208 |
Created 1 tags pointing to qpvuntsm b876c5f4 (empty) commit1 |
| 209 |
[EOF] |
| 210 |
"); |
| 211 |
} |
| 212 |
|
| 213 |
#[test] |
| 214 |
fn test_tag_unknown() { |
| 215 |
let test_env = TestEnvironment::default(); |
| 216 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 217 |
let work_dir = test_env.work_dir("repo"); |
| 218 |
|
| 219 |
let output = work_dir.run_jj(["tag", "delete", "unknown"]); |
| 220 |
insta::assert_snapshot!(output, @" |
| 221 |
------- stderr ------- |
| 222 |
Warning: No matching tags for names: unknown |
| 223 |
No tags to delete. |
| 224 |
[EOF] |
| 225 |
"); |
| 226 |
|
| 227 |
let output = work_dir.run_jj(["tag", "delete", "unknown*"]); |
| 228 |
insta::assert_snapshot!(output, @" |
| 229 |
------- stderr ------- |
| 230 |
No tags to delete. |
| 231 |
[EOF] |
| 232 |
"); |
| 233 |
} |
| 234 |
|
| 235 |
#[test] |
| 236 |
fn test_tag_track_untrack() { |
| 237 |
let test_env = TestEnvironment::default(); |
| 238 |
|
| 239 |
// Set up remote |
| 240 |
test_env |
| 241 |
.run_jj_in(".", ["git", "init", "--colocate", "origin"]) |
| 242 |
.success(); |
| 243 |
let origin_dir = test_env.work_dir("origin"); |
| 244 |
origin_dir.run_jj(["commit", "-mcommit 1"]).success(); |
| 245 |
origin_dir |
| 246 |
.run_jj(["tag", "set", "-r@-", "tag1", "tag2", "tag3", "tag4"]) |
| 247 |
.success(); |
| 248 |
|
| 249 |
// Remote tags are tracked by default |
| 250 |
let output = test_env.run_jj_in(".", ["git", "clone", "origin", "local"]); |
| 251 |
insta::assert_snapshot!(output, @r#" |
| 252 |
------- stderr ------- |
| 253 |
Fetching into new repo in "$TEST_ENV/local" |
| 254 |
tag: tag1@origin [new] tracked |
| 255 |
tag: tag2@origin [new] tracked |
| 256 |
tag: tag3@origin [new] tracked |
| 257 |
tag: tag4@origin [new] tracked |
| 258 |
[EOF] |
| 259 |
"#); |
| 260 |
let local_dir = test_env.work_dir("local"); |
| 261 |
insta::assert_snapshot!(get_tag_output(&local_dir), @" |
| 262 |
tag1: qpvuntsm 4de4efb4 (empty) commit 1 |
| 263 |
@origin: qpvuntsm 4de4efb4 (empty) commit 1 |
| 264 |
tag2: qpvuntsm 4de4efb4 (empty) commit 1 |
| 265 |
@origin: qpvuntsm 4de4efb4 (empty) commit 1 |
| 266 |
tag3: qpvuntsm 4de4efb4 (empty) commit 1 |
| 267 |
@origin: qpvuntsm 4de4efb4 (empty) commit 1 |
| 268 |
tag4: qpvuntsm 4de4efb4 (empty) commit 1 |
| 269 |
@origin: qpvuntsm 4de4efb4 (empty) commit 1 |
| 270 |
[EOF] |
| 271 |
"); |
| 272 |
|
| 273 |
// Untrack existing and locally deleted tags: targets shouldn't be changed |
| 274 |
local_dir.run_jj(["tag", "delete", "tag3"]).success(); |
| 275 |
let output = local_dir.run_jj(["tag", "untrack", "'tag[234]'"]); |
| 276 |
insta::assert_snapshot!(output, @" |
| 277 |
------- stderr ------- |
| 278 |
Stopped tracking 3 remote tags. |
| 279 |
[EOF] |
| 280 |
"); |
| 281 |
insta::assert_snapshot!(get_tag_output(&local_dir), @" |
| 282 |
tag1: qpvuntsm 4de4efb4 (empty) commit 1 |
| 283 |
@origin: qpvuntsm 4de4efb4 (empty) commit 1 |
| 284 |
tag2: qpvuntsm 4de4efb4 (empty) commit 1 |
| 285 |
tag2@origin: qpvuntsm 4de4efb4 (empty) commit 1 |
| 286 |
tag3@origin: qpvuntsm 4de4efb4 (empty) commit 1 |
| 287 |
tag4: qpvuntsm 4de4efb4 (empty) commit 1 |
| 288 |
tag4@origin: qpvuntsm 4de4efb4 (empty) commit 1 |
| 289 |
[EOF] |
| 290 |
"); |
| 291 |
|
| 292 |
// Create and move tags |
| 293 |
local_dir.run_jj(["tag", "set", "tag5"]).success(); |
| 294 |
local_dir.run_jj(["new", "root()"]).success(); |
| 295 |
local_dir.run_jj(["commit", "-mcommit 2"]).success(); |
| 296 |
local_dir |
| 297 |
.run_jj(["tag", "set", "--allow-move", "tag4"]) |
| 298 |
.success(); |
| 299 |
|
| 300 |
// Track tracked, untracked, conflicting, new, and unknown tags |
| 301 |
let output = local_dir.run_jj(["tag", "track", "'tag[1345]'", "unknown"]); |
| 302 |
insta::assert_snapshot!(output, @" |
| 303 |
------- stderr ------- |
| 304 |
Warning: No matching tags for names: unknown |
| 305 |
Warning: Remote tag already tracked: tag1@origin |
| 306 |
Started tracking 3 remote tags. |
| 307 |
[EOF] |
| 308 |
"); |
| 309 |
insta::assert_snapshot!(get_tag_output(&local_dir), @" |
| 310 |
tag1: qpvuntsm 4de4efb4 (empty) commit 1 |
| 311 |
@origin: qpvuntsm 4de4efb4 (empty) commit 1 |
| 312 |
tag2: qpvuntsm 4de4efb4 (empty) commit 1 |
| 313 |
tag2@origin: qpvuntsm 4de4efb4 (empty) commit 1 |
| 314 |
tag3: qpvuntsm 4de4efb4 (empty) commit 1 |
| 315 |
@origin: qpvuntsm 4de4efb4 (empty) commit 1 |
| 316 |
tag4 (conflicted): |
| 317 |
+ kpqxywon 3fea8afe (empty) (no description set) |
| 318 |
+ qpvuntsm 4de4efb4 (empty) commit 1 |
| 319 |
@origin (behind by 2 commits): qpvuntsm 4de4efb4 (empty) commit 1 |
| 320 |
tag5: zsuskuln c2934cfb (empty) (no description set) |
| 321 |
@origin (not created yet) |
| 322 |
[EOF] |
| 323 |
"); |
| 324 |
|
| 325 |
// Fetch new commit: only tracking tags should be merged |
| 326 |
origin_dir.run_jj(["commit", "-mcommit 3"]).success(); |
| 327 |
origin_dir |
| 328 |
.run_jj([ |
| 329 |
"tag", |
| 330 |
"set", |
| 331 |
"-r@-", |
| 332 |
"--allow-move", |
| 333 |
"tag1", |
| 334 |
"tag2", |
| 335 |
"tag3", |
| 336 |
"tag4", |
| 337 |
]) |
| 338 |
.success(); |
| 339 |
let output = local_dir.run_jj(["git", "fetch"]); |
| 340 |
insta::assert_snapshot!(output, @" |
| 341 |
------- stderr ------- |
| 342 |
tag: tag1@origin [updated] tracked |
| 343 |
tag: tag2@origin [updated] untracked |
| 344 |
tag: tag3@origin [updated] tracked |
| 345 |
tag: tag4@origin [updated] tracked |
| 346 |
[EOF] |
| 347 |
"); |
| 348 |
insta::assert_snapshot!(get_tag_output(&local_dir), @" |
| 349 |
tag1: rlvkpnrz bdaad04f (empty) commit 3 |
| 350 |
@origin: rlvkpnrz bdaad04f (empty) commit 3 |
| 351 |
tag2: qpvuntsm 4de4efb4 (empty) commit 1 |
| 352 |
tag2@origin: rlvkpnrz bdaad04f (empty) commit 3 |
| 353 |
tag3: rlvkpnrz bdaad04f (empty) commit 3 |
| 354 |
@origin: rlvkpnrz bdaad04f (empty) commit 3 |
| 355 |
tag4 (conflicted): |
| 356 |
+ kpqxywon 3fea8afe (empty) (no description set) |
| 357 |
+ rlvkpnrz bdaad04f (empty) commit 3 |
| 358 |
@origin (behind by 2 commits): rlvkpnrz bdaad04f (empty) commit 3 |
| 359 |
tag5: zsuskuln c2934cfb (empty) (no description set) |
| 360 |
@origin (not created yet) |
| 361 |
[EOF] |
| 362 |
"); |
| 363 |
} |
| 364 |
|
| 365 |
#[test] |
| 366 |
fn test_tag_track_untrack_multiple_remotes() { |
| 367 |
let test_env = TestEnvironment::default(); |
| 368 |
|
| 369 |
// Set up remotes |
| 370 |
test_env |
| 371 |
.run_jj_in(".", ["git", "init", "--colocate", "remote1"]) |
| 372 |
.success(); |
| 373 |
let remote1_dir = test_env.work_dir("remote1"); |
| 374 |
remote1_dir.run_jj(["commit", "-mcommit 1"]).success(); |
| 375 |
remote1_dir |
| 376 |
.run_jj(["tag", "set", "-r@-", "tag1", "tag2", "tag3"]) |
| 377 |
.success(); |
| 378 |
|
| 379 |
test_env |
| 380 |
.run_jj_in(".", ["git", "init", "--colocate", "remote2"]) |
| 381 |
.success(); |
| 382 |
let remote2_dir = test_env.work_dir("remote2"); |
| 383 |
remote2_dir.run_jj(["commit", "-mcommit 2"]).success(); |
| 384 |
remote2_dir |
| 385 |
.run_jj(["tag", "set", "-r@-", "tag2", "tag3", "tag4"]) |
| 386 |
.success(); |
| 387 |
|
| 388 |
// Set up colocated repo where pseudo @git remote exists |
| 389 |
test_env |
| 390 |
.run_jj_in(".", ["git", "init", "--colocate", "local"]) |
| 391 |
.success(); |
| 392 |
let local_dir = test_env.work_dir("local"); |
| 393 |
local_dir |
| 394 |
.run_jj(["git", "remote", "add", "remote1", "../remote1"]) |
| 395 |
.success(); |
| 396 |
local_dir |
| 397 |
.run_jj(["git", "remote", "add", "remote2", "../remote2"]) |
| 398 |
.success(); |
| 399 |
|
| 400 |
// Remote tags are tracked by default |
| 401 |
let output = local_dir.run_jj(["git", "fetch", "--remote=*"]); |
| 402 |
insta::assert_snapshot!(output, @" |
| 403 |
------- stderr ------- |
| 404 |
tag: tag1@remote1 [new] tracked |
| 405 |
tag: tag2@remote1 [new] tracked |
| 406 |
tag: tag2@remote2 [new] tracked |
| 407 |
tag: tag3@remote1 [new] tracked |
| 408 |
tag: tag3@remote2 [new] tracked |
| 409 |
tag: tag4@remote2 [new] tracked |
| 410 |
[EOF] |
| 411 |
"); |
| 412 |
insta::assert_snapshot!(get_tag_output(&local_dir), @" |
| 413 |
tag1: qpvuntsm 4de4efb4 (empty) commit 1 |
| 414 |
@git: qpvuntsm 4de4efb4 (empty) commit 1 |
| 415 |
@remote1: qpvuntsm 4de4efb4 (empty) commit 1 |
| 416 |
tag2 (conflicted): |
| 417 |
+ qpvuntsm 4de4efb4 (empty) commit 1 |
| 418 |
+ zsuskuln b322488a (empty) commit 2 |
| 419 |
@remote1 (behind by 1 commits): qpvuntsm 4de4efb4 (empty) commit 1 |
| 420 |
@remote2 (behind by 1 commits): zsuskuln b322488a (empty) commit 2 |
| 421 |
tag3 (conflicted): |
| 422 |
+ qpvuntsm 4de4efb4 (empty) commit 1 |
| 423 |
+ zsuskuln b322488a (empty) commit 2 |
| 424 |
@remote1 (behind by 1 commits): qpvuntsm 4de4efb4 (empty) commit 1 |
| 425 |
@remote2 (behind by 1 commits): zsuskuln b322488a (empty) commit 2 |
| 426 |
tag4: zsuskuln b322488a (empty) commit 2 |
| 427 |
@git: zsuskuln b322488a (empty) commit 2 |
| 428 |
@remote2: zsuskuln b322488a (empty) commit 2 |
| 429 |
[EOF] |
| 430 |
"); |
| 431 |
|
| 432 |
// Resolve conflict to reduce test complexity |
| 433 |
local_dir |
| 434 |
.run_jj([ |
| 435 |
"tag", |
| 436 |
"set", |
| 437 |
"--allow-move", |
| 438 |
"-rsubject('commit 1')", |
| 439 |
"tag2", |
| 440 |
"tag3", |
| 441 |
]) |
| 442 |
.success(); |
| 443 |
|
| 444 |
// Untrack by name@remote syntax |
| 445 |
let output = local_dir.run_jj(["tag", "untrack", "tag1@git", "tag2@remote1", "tag2@unknown"]); |
| 446 |
insta::assert_snapshot!(output, @" |
| 447 |
------- stderr ------- |
| 448 |
Warning: No matching remote tags for names: tag2@unknown |
| 449 |
Warning: Git-tracking tag cannot be untracked: tag1@git |
| 450 |
Stopped tracking 1 remote tags. |
| 451 |
[EOF] |
| 452 |
"); |
| 453 |
// Untrack with --remote |
| 454 |
let output = local_dir.run_jj(["tag", "untrack", "tag2", "tag3", "--remote=remote2"]); |
| 455 |
insta::assert_snapshot!(output, @" |
| 456 |
------- stderr ------- |
| 457 |
Stopped tracking 2 remote tags. |
| 458 |
[EOF] |
| 459 |
"); |
| 460 |
insta::assert_snapshot!(get_tag_output(&local_dir), @" |
| 461 |
tag1: qpvuntsm 4de4efb4 (empty) commit 1 |
| 462 |
@git: qpvuntsm 4de4efb4 (empty) commit 1 |
| 463 |
@remote1: qpvuntsm 4de4efb4 (empty) commit 1 |
| 464 |
tag2: qpvuntsm 4de4efb4 (empty) commit 1 |
| 465 |
@git: qpvuntsm 4de4efb4 (empty) commit 1 |
| 466 |
tag2@remote1: qpvuntsm 4de4efb4 (empty) commit 1 |
| 467 |
tag2@remote2: zsuskuln b322488a (empty) commit 2 |
| 468 |
tag3: qpvuntsm 4de4efb4 (empty) commit 1 |
| 469 |
@git: qpvuntsm 4de4efb4 (empty) commit 1 |
| 470 |
@remote1: qpvuntsm 4de4efb4 (empty) commit 1 |
| 471 |
tag3@remote2: zsuskuln b322488a (empty) commit 2 |
| 472 |
tag4: zsuskuln b322488a (empty) commit 2 |
| 473 |
@git: zsuskuln b322488a (empty) commit 2 |
| 474 |
@remote2: zsuskuln b322488a (empty) commit 2 |
| 475 |
[EOF] |
| 476 |
"); |
| 477 |
|
| 478 |
// Untrack all |
| 479 |
let output = local_dir.run_jj(["tag", "untrack", "*"]); |
| 480 |
insta::assert_snapshot!(output, @" |
| 481 |
------- stderr ------- |
| 482 |
Warning: Remote tag not tracked yet: tag2@remote1 |
| 483 |
Warning: Remote tag not tracked yet: tag2@remote2 |
| 484 |
Warning: Remote tag not tracked yet: tag3@remote2 |
| 485 |
Warning: Remote tag not tracked yet: tag4@remote1 |
| 486 |
Warning: Remote tag not tracked yet: tag1@remote2 |
| 487 |
Stopped tracking 3 remote tags. |
| 488 |
[EOF] |
| 489 |
"); |
| 490 |
insta::assert_snapshot!(get_tag_output(&local_dir), @" |
| 491 |
tag1: qpvuntsm 4de4efb4 (empty) commit 1 |
| 492 |
@git: qpvuntsm 4de4efb4 (empty) commit 1 |
| 493 |
tag1@remote1: qpvuntsm 4de4efb4 (empty) commit 1 |
| 494 |
tag2: qpvuntsm 4de4efb4 (empty) commit 1 |
| 495 |
@git: qpvuntsm 4de4efb4 (empty) commit 1 |
| 496 |
tag2@remote1: qpvuntsm 4de4efb4 (empty) commit 1 |
| 497 |
tag2@remote2: zsuskuln b322488a (empty) commit 2 |
| 498 |
tag3: qpvuntsm 4de4efb4 (empty) commit 1 |
| 499 |
@git: qpvuntsm 4de4efb4 (empty) commit 1 |
| 500 |
tag3@remote1: qpvuntsm 4de4efb4 (empty) commit 1 |
| 501 |
tag3@remote2: zsuskuln b322488a (empty) commit 2 |
| 502 |
tag4: zsuskuln b322488a (empty) commit 2 |
| 503 |
@git: zsuskuln b322488a (empty) commit 2 |
| 504 |
tag4@remote2: zsuskuln b322488a (empty) commit 2 |
| 505 |
[EOF] |
| 506 |
"); |
| 507 |
|
| 508 |
// Noop untrack |
| 509 |
let output = local_dir.run_jj(["tag", "untrack", "tag1@remote1"]); |
| 510 |
insta::assert_snapshot!(output, @" |
| 511 |
------- stderr ------- |
| 512 |
Warning: Remote tag not tracked yet: tag1@remote1 |
| 513 |
Nothing changed. |
| 514 |
[EOF] |
| 515 |
"); |
| 516 |
|
| 517 |
// Track by name@remote syntax |
| 518 |
let output = local_dir.run_jj(["tag", "track", "tag2@git", "tag3@remote2", "tag3@unknown"]); |
| 519 |
insta::assert_snapshot!(output, @" |
| 520 |
------- stderr ------- |
| 521 |
Warning: No matching remote tags for names: tag3@unknown |
| 522 |
Warning: Remote tag already tracked: tag2@git |
| 523 |
Started tracking 1 remote tags. |
| 524 |
[EOF] |
| 525 |
"); |
| 526 |
// Track with --remote |
| 527 |
let output = local_dir.run_jj(["tag", "track", "tag1", "tag2", "--remote=remote1"]); |
| 528 |
insta::assert_snapshot!(output, @" |
| 529 |
------- stderr ------- |
| 530 |
Started tracking 2 remote tags. |
| 531 |
[EOF] |
| 532 |
"); |
| 533 |
insta::assert_snapshot!(get_tag_output(&local_dir), @" |
| 534 |
tag1: qpvuntsm 4de4efb4 (empty) commit 1 |
| 535 |
@git: qpvuntsm 4de4efb4 (empty) commit 1 |
| 536 |
@remote1: qpvuntsm 4de4efb4 (empty) commit 1 |
| 537 |
tag2: qpvuntsm 4de4efb4 (empty) commit 1 |
| 538 |
@git: qpvuntsm 4de4efb4 (empty) commit 1 |
| 539 |
@remote1: qpvuntsm 4de4efb4 (empty) commit 1 |
| 540 |
tag2@remote2: zsuskuln b322488a (empty) commit 2 |
| 541 |
tag3 (conflicted): |
| 542 |
+ qpvuntsm 4de4efb4 (empty) commit 1 |
| 543 |
+ zsuskuln b322488a (empty) commit 2 |
| 544 |
@git (behind by 1 commits): qpvuntsm 4de4efb4 (empty) commit 1 |
| 545 |
@remote2 (behind by 1 commits): zsuskuln b322488a (empty) commit 2 |
| 546 |
tag3@remote1: qpvuntsm 4de4efb4 (empty) commit 1 |
| 547 |
tag4: zsuskuln b322488a (empty) commit 2 |
| 548 |
@git: zsuskuln b322488a (empty) commit 2 |
| 549 |
tag4@remote2: zsuskuln b322488a (empty) commit 2 |
| 550 |
[EOF] |
| 551 |
"); |
| 552 |
|
| 553 |
// Track all |
| 554 |
let output = local_dir.run_jj(["tag", "track", "*"]); |
| 555 |
insta::assert_snapshot!(output, @" |
| 556 |
------- stderr ------- |
| 557 |
Warning: Remote tag already tracked: tag1@remote1 |
| 558 |
Warning: Remote tag already tracked: tag2@remote1 |
| 559 |
Warning: Remote tag already tracked: tag3@remote2 |
| 560 |
Started tracking 5 remote tags. |
| 561 |
[EOF] |
| 562 |
"); |
| 563 |
insta::assert_snapshot!(get_tag_output(&local_dir), @" |
| 564 |
tag1: qpvuntsm 4de4efb4 (empty) commit 1 |
| 565 |
@git: qpvuntsm 4de4efb4 (empty) commit 1 |
| 566 |
@remote1: qpvuntsm 4de4efb4 (empty) commit 1 |
| 567 |
@remote2 (not created yet) |
| 568 |
tag2 (conflicted): |
| 569 |
+ qpvuntsm 4de4efb4 (empty) commit 1 |
| 570 |
+ zsuskuln b322488a (empty) commit 2 |
| 571 |
@git (behind by 1 commits): qpvuntsm 4de4efb4 (empty) commit 1 |
| 572 |
@remote1 (behind by 1 commits): qpvuntsm 4de4efb4 (empty) commit 1 |
| 573 |
@remote2 (behind by 1 commits): zsuskuln b322488a (empty) commit 2 |
| 574 |
tag3 (conflicted): |
| 575 |
+ qpvuntsm 4de4efb4 (empty) commit 1 |
| 576 |
+ zsuskuln b322488a (empty) commit 2 |
| 577 |
@git (behind by 1 commits): qpvuntsm 4de4efb4 (empty) commit 1 |
| 578 |
@remote1 (behind by 1 commits): qpvuntsm 4de4efb4 (empty) commit 1 |
| 579 |
@remote2 (behind by 1 commits): zsuskuln b322488a (empty) commit 2 |
| 580 |
tag4: zsuskuln b322488a (empty) commit 2 |
| 581 |
@git: zsuskuln b322488a (empty) commit 2 |
| 582 |
@remote1 (not created yet) |
| 583 |
@remote2: zsuskuln b322488a (empty) commit 2 |
| 584 |
[EOF] |
| 585 |
"); |
| 586 |
|
| 587 |
// Noop track |
| 588 |
let output = local_dir.run_jj(["tag", "track", "tag1@remote1"]); |
| 589 |
insta::assert_snapshot!(output, @" |
| 590 |
------- stderr ------- |
| 591 |
Warning: Remote tag already tracked: tag1@remote1 |
| 592 |
Nothing changed. |
| 593 |
[EOF] |
| 594 |
"); |
| 595 |
} |
| 596 |
|
| 597 |
#[test] |
| 598 |
fn test_tag_track_untrack_bad_args() { |
| 599 |
let test_env = TestEnvironment::default(); |
| 600 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 601 |
let work_dir = test_env.work_dir("repo"); |
| 602 |
|
| 603 |
let output = work_dir.run_jj(["tag", "track", "--remote=foo", "bar@baz"]); |
| 604 |
insta::assert_snapshot!(output, @" |
| 605 |
------- stderr ------- |
| 606 |
Error: --remote cannot be used with <tag>@<remote> symbols |
| 607 |
[EOF] |
| 608 |
[exit status: 2] |
| 609 |
"); |
| 610 |
|
| 611 |
let output = work_dir.run_jj(["tag", "track", "foo", "bar@baz"]); |
| 612 |
insta::assert_snapshot!(output, @" |
| 613 |
------- stderr ------- |
| 614 |
Error: Cannot specify both <tag> patterns and <tag>@<remote> symbols |
| 615 |
[EOF] |
| 616 |
[exit status: 2] |
| 617 |
"); |
| 618 |
|
| 619 |
let output = work_dir.run_jj(["tag", "track", "~foo@bar"]); |
| 620 |
insta::assert_snapshot!(output, @" |
| 621 |
------- stderr ------- |
| 622 |
Error: Failed to parse name pattern or remote symbol: Invalid string expression |
| 623 |
Caused by: --> 1:2 |
| 624 |
| |
| 625 |
1 | ~foo@bar |
| 626 |
| ^-----^ |
| 627 |
| |
| 628 |
= Invalid string expression |
| 629 |
[EOF] |
| 630 |
[exit status: 1] |
| 631 |
"); |
| 632 |
|
| 633 |
let output = work_dir.run_jj(["tag", "untrack", "--remote=foo", "bar@baz"]); |
| 634 |
insta::assert_snapshot!(output, @" |
| 635 |
------- stderr ------- |
| 636 |
Error: --remote cannot be used with <tag>@<remote> symbols |
| 637 |
[EOF] |
| 638 |
[exit status: 2] |
| 639 |
"); |
| 640 |
|
| 641 |
let output = work_dir.run_jj(["tag", "untrack", "foo", "bar@baz"]); |
| 642 |
insta::assert_snapshot!(output, @" |
| 643 |
------- stderr ------- |
| 644 |
Error: Cannot specify both <tag> patterns and <tag>@<remote> symbols |
| 645 |
[EOF] |
| 646 |
[exit status: 2] |
| 647 |
"); |
| 648 |
} |
| 649 |
|
| 650 |
#[test] |
| 651 |
fn test_tag_list() { |
| 652 |
let test_env = TestEnvironment::default(); |
| 653 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 654 |
let work_dir = test_env.work_dir("repo"); |
| 655 |
|
| 656 |
work_dir.run_jj(["new", "root()", "-mcommit1"]).success(); |
| 657 |
work_dir.run_jj(["tag", "set", "-r@", "test_tag"]).success(); |
| 658 |
work_dir.run_jj(["new", "root()", "-mcommit2"]).success(); |
| 659 |
work_dir |
| 660 |
.run_jj(["tag", "set", "-r@", "test_tag2"]) |
| 661 |
.success(); |
| 662 |
work_dir.run_jj(["new", "root()", "-mcommit3"]).success(); |
| 663 |
work_dir |
| 664 |
.run_jj(["tag", "set", "-rtest_tag", "conflicted_tag"]) |
| 665 |
.success(); |
| 666 |
work_dir |
| 667 |
.run_jj([ |
| 668 |
"tag", |
| 669 |
"set", |
| 670 |
"--allow-move", |
| 671 |
"-rtest_tag2", |
| 672 |
"conflicted_tag", |
| 673 |
]) |
| 674 |
.success(); |
| 675 |
work_dir |
| 676 |
.run_jj([ |
| 677 |
"tag", |
| 678 |
"set", |
| 679 |
"--at-op=@-", |
| 680 |
"--allow-move", |
| 681 |
"-r@", |
| 682 |
"conflicted_tag", |
| 683 |
]) |
| 684 |
.success(); |
| 685 |
|
| 686 |
insta::assert_snapshot!(work_dir.run_jj(["tag", "list"]), @" |
| 687 |
conflicted_tag (conflicted): |
| 688 |
- rlvkpnrz 893e67dc (empty) commit1 |
| 689 |
+ zsuskuln 76abdd20 (empty) commit2 |
| 690 |
+ royxmykx 13c4e819 (empty) commit3 |
| 691 |
test_tag: rlvkpnrz 893e67dc (empty) commit1 |
| 692 |
test_tag2: zsuskuln 76abdd20 (empty) commit2 |
| 693 |
[EOF] |
| 694 |
------- stderr ------- |
| 695 |
Concurrent modification detected, resolving automatically. |
| 696 |
[EOF] |
| 697 |
"); |
| 698 |
|
| 699 |
insta::assert_snapshot!(work_dir.run_jj(["tag", "list", "--color=always"]), @" |
| 700 |
[38;5;5mconflicted_tag[39m [38;5;1m(conflicted)[39m: |
| 701 |
- [1m[38;5;5mrl[0m[38;5;8mvkpnrz[39m [1m[38;5;4m8[0m[38;5;8m93e67dc[39m [38;5;2m(empty)[39m commit1 |
| 702 |
+ [1m[38;5;5mzs[0m[38;5;8muskuln[39m [1m[38;5;4m7[0m[38;5;8m6abdd20[39m [38;5;2m(empty)[39m commit2 |
| 703 |
+ [1m[38;5;5mr[0m[38;5;8moyxmykx[39m [1m[38;5;4m1[0m[38;5;8m3c4e819[39m [38;5;2m(empty)[39m commit3 |
| 704 |
[38;5;5mtest_tag[39m: [1m[38;5;5mrl[0m[38;5;8mvkpnrz[39m [1m[38;5;4m8[0m[38;5;8m93e67dc[39m [38;5;2m(empty)[39m commit1 |
| 705 |
[38;5;5mtest_tag2[39m: [1m[38;5;5mzs[0m[38;5;8muskuln[39m [1m[38;5;4m7[0m[38;5;8m6abdd20[39m [38;5;2m(empty)[39m commit2 |
| 706 |
[EOF] |
| 707 |
"); |
| 708 |
|
| 709 |
// Test pattern matching. |
| 710 |
insta::assert_snapshot!(work_dir.run_jj(["tag", "list", "test_tag2"]), @" |
| 711 |
test_tag2: zsuskuln 76abdd20 (empty) commit2 |
| 712 |
[EOF] |
| 713 |
"); |
| 714 |
|
| 715 |
insta::assert_snapshot!(work_dir.run_jj(["tag", "list", "'test_tag?'"]), @" |
| 716 |
test_tag2: zsuskuln 76abdd20 (empty) commit2 |
| 717 |
[EOF] |
| 718 |
"); |
| 719 |
|
| 720 |
// Filter by revset |
| 721 |
insta::assert_snapshot!(work_dir.run_jj(["tag", "list", "-rsubject(commit1)"]), @" |
| 722 |
test_tag: rlvkpnrz 893e67dc (empty) commit1 |
| 723 |
[EOF] |
| 724 |
"); |
| 725 |
insta::assert_snapshot!(work_dir.run_jj(["tag", "list", "-rsubject(commit2)"]), @" |
| 726 |
conflicted_tag (conflicted): |
| 727 |
- rlvkpnrz 893e67dc (empty) commit1 |
| 728 |
+ zsuskuln 76abdd20 (empty) commit2 |
| 729 |
+ royxmykx 13c4e819 (empty) commit3 |
| 730 |
test_tag2: zsuskuln 76abdd20 (empty) commit2 |
| 731 |
[EOF] |
| 732 |
"); |
| 733 |
// Filter by revset and name, which aren't intersected |
| 734 |
insta::assert_snapshot!(work_dir.run_jj(["tag", "list", "-rsubject(commit1)", "test_tag2"]), @" |
| 735 |
test_tag: rlvkpnrz 893e67dc (empty) commit1 |
| 736 |
test_tag2: zsuskuln 76abdd20 (empty) commit2 |
| 737 |
[EOF] |
| 738 |
"); |
| 739 |
|
| 740 |
// Unmatched exact name pattern should be warned. "test_tag2" exists, but |
| 741 |
// isn't included in the match. |
| 742 |
insta::assert_snapshot!( |
| 743 |
work_dir.run_jj(["tag", "list", "test* & ~*2", "unknown ~ test_tag2"]), @" |
| 744 |
test_tag: rlvkpnrz 893e67dc (empty) commit1 |
| 745 |
[EOF] |
| 746 |
------- stderr ------- |
| 747 |
Warning: No matching tags for names: unknown |
| 748 |
[EOF] |
| 749 |
"); |
| 750 |
|
| 751 |
insta::assert_snapshot!(work_dir.run_jj(["tag", "list", "--conflicted"]), @" |
| 752 |
conflicted_tag (conflicted): |
| 753 |
- rlvkpnrz 893e67dc (empty) commit1 |
| 754 |
+ zsuskuln 76abdd20 (empty) commit2 |
| 755 |
+ royxmykx 13c4e819 (empty) commit3 |
| 756 |
[EOF] |
| 757 |
"); |
| 758 |
|
| 759 |
let template = r#" |
| 760 |
concat( |
| 761 |
"[" ++ name ++ "]\n", |
| 762 |
separate(" ", "present:", present) ++ "\n", |
| 763 |
separate(" ", "conflict:", conflict) ++ "\n", |
| 764 |
separate(" ", "normal_target:", normal_target.description().first_line()) ++ "\n", |
| 765 |
separate(" ", "removed_targets:", removed_targets.map(|c| c.description().first_line())) ++ "\n", |
| 766 |
separate(" ", "added_targets:", added_targets.map(|c| c.description().first_line())) ++ "\n", |
| 767 |
) |
| 768 |
"#; |
| 769 |
insta::assert_snapshot!(work_dir.run_jj(["tag", "list", "-T", template]), @" |
| 770 |
[conflicted_tag] |
| 771 |
present: true |
| 772 |
conflict: true |
| 773 |
normal_target: <Error: No Commit available> |
| 774 |
removed_targets: commit1 |
| 775 |
added_targets: commit2 commit3 |
| 776 |
[test_tag] |
| 777 |
present: true |
| 778 |
conflict: false |
| 779 |
normal_target: commit1 |
| 780 |
removed_targets: |
| 781 |
added_targets: commit1 |
| 782 |
[test_tag2] |
| 783 |
present: true |
| 784 |
conflict: false |
| 785 |
normal_target: commit2 |
| 786 |
removed_targets: |
| 787 |
added_targets: commit2 |
| 788 |
[EOF] |
| 789 |
"); |
| 790 |
|
| 791 |
// Sort by command argument |
| 792 |
insta::assert_snapshot!(work_dir.run_jj(["tag", "list", "--sort=committer-date-,name"]), @" |
| 793 |
conflicted_tag (conflicted): |
| 794 |
- rlvkpnrz 893e67dc (empty) commit1 |
| 795 |
+ zsuskuln 76abdd20 (empty) commit2 |
| 796 |
+ royxmykx 13c4e819 (empty) commit3 |
| 797 |
test_tag2: zsuskuln 76abdd20 (empty) commit2 |
| 798 |
test_tag: rlvkpnrz 893e67dc (empty) commit1 |
| 799 |
[EOF] |
| 800 |
"); |
| 801 |
|
| 802 |
// Default sort keys in config |
| 803 |
let config = "--config=ui.tag-list-sort-keys=['committer-date', 'name-']"; |
| 804 |
insta::assert_snapshot!(work_dir.run_jj(["tag", "list", config]), @" |
| 805 |
test_tag: rlvkpnrz 893e67dc (empty) commit1 |
| 806 |
test_tag2: zsuskuln 76abdd20 (empty) commit2 |
| 807 |
conflicted_tag (conflicted): |
| 808 |
- rlvkpnrz 893e67dc (empty) commit1 |
| 809 |
+ zsuskuln 76abdd20 (empty) commit2 |
| 810 |
+ royxmykx 13c4e819 (empty) commit3 |
| 811 |
[EOF] |
| 812 |
"); |
| 813 |
} |
| 814 |
|
| 815 |
#[test] |
| 816 |
fn test_tag_list_remotes() { |
| 817 |
let test_env = TestEnvironment::default(); |
| 818 |
|
| 819 |
// TODO: set up remote tags in a similar way to test_bookmark_list_tracked() |
| 820 |
|
| 821 |
test_env |
| 822 |
.run_jj_in(".", ["git", "init", "--colocate", "local"]) |
| 823 |
.success(); |
| 824 |
let local_dir = test_env.work_dir("local"); |
| 825 |
|
| 826 |
local_dir |
| 827 |
.run_jj(["new", "root()", "-m", "local-only"]) |
| 828 |
.success(); |
| 829 |
local_dir.run_jj(["tag", "set", "local-only"]).success(); |
| 830 |
|
| 831 |
let output = local_dir.run_jj(["tag", "list", "--all-remotes"]); |
| 832 |
insta::assert_snapshot!(output, @" |
| 833 |
local-only: rlvkpnrz d3e8d245 (empty) local-only |
| 834 |
@git: rlvkpnrz d3e8d245 (empty) local-only |
| 835 |
[EOF] |
| 836 |
"); |
| 837 |
|
| 838 |
// Since there's no way to track/untrack tags manually, --tracked is useless |
| 839 |
// right now. |
| 840 |
let output = local_dir.run_jj(["tag", "list", "--tracked"]); |
| 841 |
insta::assert_snapshot!(output, @""); |
| 842 |
|
| 843 |
let output = local_dir.run_jj(["tag", "list", "--tracked", "--remote=git"]); |
| 844 |
insta::assert_snapshot!(output, @" |
| 845 |
local-only: rlvkpnrz d3e8d245 (empty) local-only |
| 846 |
@git: rlvkpnrz d3e8d245 (empty) local-only |
| 847 |
[EOF] |
| 848 |
"); |
| 849 |
|
| 850 |
let output = local_dir.run_jj(["tag", "list", "--remote=origin"]); |
| 851 |
insta::assert_snapshot!(output, @""); |
| 852 |
|
| 853 |
let output = local_dir.run_jj(["tag", "list", "--remote=git"]); |
| 854 |
insta::assert_snapshot!(output, @" |
| 855 |
local-only: rlvkpnrz d3e8d245 (empty) local-only |
| 856 |
@git: rlvkpnrz d3e8d245 (empty) local-only |
| 857 |
[EOF] |
| 858 |
"); |
| 859 |
} |
| 860 |
|
| 861 |
#[must_use] |
| 862 |
fn get_log_output(work_dir: &TestWorkDir) -> CommandOutput { |
| 863 |
let template = r#"separate(" ", commit_id.short(), tags) ++ "\n""#; |
| 864 |
work_dir.run_jj(["log", "-rall()", "-T", template]) |
| 865 |
} |
| 866 |
|
| 867 |
#[must_use] |
| 868 |
fn get_tag_output(work_dir: &TestWorkDir) -> CommandOutput { |
| 869 |
work_dir.run_jj(["tag", "list", "--all-remotes"]) |
| 870 |
} |