| 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 |
|
| 15 |
use std::path; |
| 16 |
|
| 17 |
use indoc::formatdoc; |
| 18 |
use indoc::indoc; |
| 19 |
use testutils::TestResult; |
| 20 |
use testutils::git; |
| 21 |
|
| 22 |
use crate::common::CommandOutput; |
| 23 |
use crate::common::TestEnvironment; |
| 24 |
use crate::common::TestWorkDir; |
| 25 |
use crate::common::to_toml_value; |
| 26 |
|
| 27 |
fn set_up_non_empty_git_repo(git_repo: &gix::Repository) { |
| 28 |
set_up_git_repo_with_file(git_repo, "file"); |
| 29 |
} |
| 30 |
|
| 31 |
fn set_up_git_repo_with_file(git_repo: &gix::Repository, filename: &str) { |
| 32 |
git::add_commit( |
| 33 |
git_repo, |
| 34 |
"refs/heads/main", |
| 35 |
filename, |
| 36 |
b"content", |
| 37 |
"message", |
| 38 |
&[], |
| 39 |
); |
| 40 |
git::set_symbolic_reference(git_repo, "HEAD", "refs/heads/main"); |
| 41 |
} |
| 42 |
|
| 43 |
#[test] |
| 44 |
fn test_git_clone() { |
| 45 |
let test_env = TestEnvironment::default(); |
| 46 |
let root_dir = test_env.work_dir(""); |
| 47 |
test_env.add_config("remotes.origin.auto-track-bookmarks = '*'"); |
| 48 |
let git_repo_path = test_env.env_root().join("source"); |
| 49 |
let git_repo = git::init(git_repo_path); |
| 50 |
|
| 51 |
// Clone an empty repo |
| 52 |
let output = root_dir.run_jj(["git", "clone", "source", "empty"]); |
| 53 |
insta::assert_snapshot!(output, @r#" |
| 54 |
------- stderr ------- |
| 55 |
Fetching into new repo in "$TEST_ENV/empty" |
| 56 |
Nothing changed. |
| 57 |
[EOF] |
| 58 |
"#); |
| 59 |
|
| 60 |
set_up_non_empty_git_repo(&git_repo); |
| 61 |
|
| 62 |
// Clone with relative source path |
| 63 |
let output = root_dir.run_jj(["git", "clone", "source", "clone"]); |
| 64 |
insta::assert_snapshot!(output, @r#" |
| 65 |
------- stderr ------- |
| 66 |
Fetching into new repo in "$TEST_ENV/clone" |
| 67 |
bookmark: main@origin [new] tracked |
| 68 |
Setting the revset alias `trunk()` to `main@origin`. |
| 69 |
Working copy (@) now at: uuqppmxq 3711b3b5 (empty) (no description set) |
| 70 |
Parent commit (@-) : qomsplrm ebeb70d8 main | message |
| 71 |
Added 1 files, modified 0 files, removed 0 files |
| 72 |
[EOF] |
| 73 |
"#); |
| 74 |
let clone_dir = test_env.work_dir("clone"); |
| 75 |
assert!(clone_dir.root().join("file").exists()); |
| 76 |
|
| 77 |
// Subsequent fetch should just work even if the source path was relative |
| 78 |
let output = clone_dir.run_jj(["git", "fetch"]); |
| 79 |
insta::assert_snapshot!(output, @" |
| 80 |
------- stderr ------- |
| 81 |
Nothing changed. |
| 82 |
[EOF] |
| 83 |
"); |
| 84 |
|
| 85 |
// Evolution history should be omitted for the "clone" operation |
| 86 |
let output = clone_dir.run_jj(["evolog", "-r..remote_bookmarks()"]); |
| 87 |
insta::assert_snapshot!(output, @" |
| 88 |
◆ qomsplrm [email protected] 1970-01-01 11:00:00 main ebeb70d8 |
| 89 |
message |
| 90 |
[EOF] |
| 91 |
"); |
| 92 |
|
| 93 |
// Failed clone should clean up the destination directory |
| 94 |
root_dir.create_dir("bad"); |
| 95 |
let output = root_dir.run_jj(["git", "clone", "bad", "failed"]); |
| 96 |
insta::assert_snapshot!(output, @r#" |
| 97 |
------- stderr ------- |
| 98 |
Fetching into new repo in "$TEST_ENV/failed" |
| 99 |
Error: Could not find repository at '$TEST_ENV/bad' |
| 100 |
[EOF] |
| 101 |
[exit status: 1] |
| 102 |
"#); |
| 103 |
assert!(!test_env.env_root().join("failed").exists()); |
| 104 |
|
| 105 |
// Failed initialization of the workspace should clean up the destination |
| 106 |
// directory |
| 107 |
let output = root_dir.run_jj([ |
| 108 |
"git", |
| 109 |
"clone", |
| 110 |
"--config=fsmonitor.backend=invalid", |
| 111 |
"source", |
| 112 |
"failed-init", |
| 113 |
]); |
| 114 |
insta::assert_snapshot!(output, @" |
| 115 |
------- stderr ------- |
| 116 |
Internal error: Failed to access the repository |
| 117 |
Caused by: |
| 118 |
1: Failed to read the tree state settings |
| 119 |
2: Invalid type or value for fsmonitor.backend |
| 120 |
3: Unknown fsmonitor kind: invalid |
| 121 |
[EOF] |
| 122 |
[exit status: 255] |
| 123 |
"); |
| 124 |
assert!(!test_env.env_root().join("failed-init").exists()); |
| 125 |
|
| 126 |
// Failed clone shouldn't remove the existing destination directory |
| 127 |
let failed_dir = root_dir.create_dir("failed"); |
| 128 |
let output = root_dir.run_jj(["git", "clone", "bad", "failed"]); |
| 129 |
insta::assert_snapshot!(output, @r#" |
| 130 |
------- stderr ------- |
| 131 |
Fetching into new repo in "$TEST_ENV/failed" |
| 132 |
Error: Could not find repository at '$TEST_ENV/bad' |
| 133 |
[EOF] |
| 134 |
[exit status: 1] |
| 135 |
"#); |
| 136 |
assert!(failed_dir.root().exists()); |
| 137 |
assert!(!failed_dir.root().join(".jj").exists()); |
| 138 |
|
| 139 |
// Failed clone (if attempted) shouldn't remove the existing workspace |
| 140 |
let output = root_dir.run_jj(["git", "clone", "bad", "clone"]); |
| 141 |
insta::assert_snapshot!(output, @" |
| 142 |
------- stderr ------- |
| 143 |
Error: Destination path exists and is not an empty directory |
| 144 |
[EOF] |
| 145 |
[exit status: 1] |
| 146 |
"); |
| 147 |
assert!(clone_dir.root().join(".jj").exists()); |
| 148 |
|
| 149 |
// Try cloning into an existing workspace |
| 150 |
let output = root_dir.run_jj(["git", "clone", "source", "clone"]); |
| 151 |
insta::assert_snapshot!(output, @" |
| 152 |
------- stderr ------- |
| 153 |
Error: Destination path exists and is not an empty directory |
| 154 |
[EOF] |
| 155 |
[exit status: 1] |
| 156 |
"); |
| 157 |
|
| 158 |
// Try cloning into an existing file |
| 159 |
root_dir.write_file("file", "contents"); |
| 160 |
let output = root_dir.run_jj(["git", "clone", "source", "file"]); |
| 161 |
insta::assert_snapshot!(output, @" |
| 162 |
------- stderr ------- |
| 163 |
Error: Destination path exists and is not an empty directory |
| 164 |
[EOF] |
| 165 |
[exit status: 1] |
| 166 |
"); |
| 167 |
|
| 168 |
// Try cloning into non-empty, non-workspace directory |
| 169 |
clone_dir.remove_dir_all(".jj"); |
| 170 |
let output = root_dir.run_jj(["git", "clone", "source", "clone"]); |
| 171 |
insta::assert_snapshot!(output, @" |
| 172 |
------- stderr ------- |
| 173 |
Error: Destination path exists and is not an empty directory |
| 174 |
[EOF] |
| 175 |
[exit status: 1] |
| 176 |
"); |
| 177 |
|
| 178 |
// Clone into a nested path |
| 179 |
let output = root_dir.run_jj(["git", "clone", "source", "nested/path/to/repo"]); |
| 180 |
insta::assert_snapshot!(output, @r#" |
| 181 |
------- stderr ------- |
| 182 |
Fetching into new repo in "$TEST_ENV/nested/path/to/repo" |
| 183 |
bookmark: main@origin [new] tracked |
| 184 |
Setting the revset alias `trunk()` to `main@origin`. |
| 185 |
Working copy (@) now at: msksykpx 5ed2b734 (empty) (no description set) |
| 186 |
Parent commit (@-) : qomsplrm ebeb70d8 main | message |
| 187 |
Added 1 files, modified 0 files, removed 0 files |
| 188 |
[EOF] |
| 189 |
"#); |
| 190 |
} |
| 191 |
|
| 192 |
#[test] |
| 193 |
fn test_git_clone_bad_source() { |
| 194 |
let test_env = TestEnvironment::default(); |
| 195 |
let root_dir = test_env.work_dir(""); |
| 196 |
|
| 197 |
let output = root_dir.run_jj(["git", "clone", "", "dest"]); |
| 198 |
insta::assert_snapshot!(output, @r#" |
| 199 |
------- stderr ------- |
| 200 |
Error: local path "" does not specify a path to a repository |
| 201 |
[EOF] |
| 202 |
[exit status: 2] |
| 203 |
"#); |
| 204 |
|
| 205 |
// Invalid URL unparsable by gitoxide |
| 206 |
let output = root_dir.run_jj(["git", "clone", "https://", "dest"]); |
| 207 |
insta::assert_snapshot!(output, @r#" |
| 208 |
------- stderr ------- |
| 209 |
Error: URL "https://" can not be parsed as valid URL |
| 210 |
Caused by: Scheme requires host |
| 211 |
[EOF] |
| 212 |
[exit status: 2] |
| 213 |
"#); |
| 214 |
} |
| 215 |
|
| 216 |
#[test] |
| 217 |
fn test_git_clone_choose_dest_path() { |
| 218 |
let test_env = TestEnvironment::default(); |
| 219 |
let root_dir = test_env.work_dir(""); |
| 220 |
let git_repo_path = test_env.env_root().join("source.git"); |
| 221 |
git::init(git_repo_path); |
| 222 |
|
| 223 |
// Windows drive letters prevent this case from triggering |
| 224 |
if cfg!(unix) { |
| 225 |
let output = root_dir.run_jj(["git", "clone", "/"]); |
| 226 |
insta::assert_snapshot!(output, @" |
| 227 |
------- stderr ------- |
| 228 |
Error: No destination specified and wasn't able to guess it |
| 229 |
[EOF] |
| 230 |
[exit status: 1] |
| 231 |
"); |
| 232 |
|
| 233 |
let output = root_dir.run_jj(["git", "clone", "/.git"]); |
| 234 |
insta::assert_snapshot!(output, @" |
| 235 |
------- stderr ------- |
| 236 |
Error: No destination specified and wasn't able to guess it |
| 237 |
[EOF] |
| 238 |
[exit status: 1] |
| 239 |
"); |
| 240 |
} |
| 241 |
|
| 242 |
let output = root_dir.run_jj(["git", "clone", "source.git"]); |
| 243 |
insta::assert_snapshot!(output, @r#" |
| 244 |
------- stderr ------- |
| 245 |
Fetching into new repo in "$TEST_ENV/source" |
| 246 |
Nothing changed. |
| 247 |
[EOF] |
| 248 |
"#); |
| 249 |
} |
| 250 |
|
| 251 |
#[test] |
| 252 |
fn test_git_clone_colocate() -> TestResult { |
| 253 |
let test_env = TestEnvironment::default(); |
| 254 |
let root_dir = test_env.work_dir(""); |
| 255 |
test_env.add_config("remotes.origin.auto-track-bookmarks = '*'"); |
| 256 |
let git_repo_path = test_env.env_root().join("source"); |
| 257 |
let git_repo = git::init(git_repo_path); |
| 258 |
|
| 259 |
// Clone an empty repo |
| 260 |
let output = root_dir.run_jj(["git", "clone", "source", "empty", "--colocate"]); |
| 261 |
insta::assert_snapshot!(output, @r#" |
| 262 |
------- stderr ------- |
| 263 |
Fetching into new repo in "$TEST_ENV/empty" |
| 264 |
Nothing changed. |
| 265 |
[EOF] |
| 266 |
"#); |
| 267 |
|
| 268 |
// git_target path should be relative to the store |
| 269 |
let empty_dir = test_env.work_dir("empty"); |
| 270 |
let git_target_file_contents = |
| 271 |
String::from_utf8(empty_dir.read_file(".jj/repo/store/git_target").into())?; |
| 272 |
insta::assert_snapshot!( |
| 273 |
git_target_file_contents.replace(path::MAIN_SEPARATOR, "/"), |
| 274 |
@"../../../.git"); |
| 275 |
|
| 276 |
set_up_non_empty_git_repo(&git_repo); |
| 277 |
|
| 278 |
// Clone with relative source path |
| 279 |
let output = root_dir.run_jj(["git", "clone", "source", "clone", "--colocate"]); |
| 280 |
insta::assert_snapshot!(output, @r#" |
| 281 |
------- stderr ------- |
| 282 |
Fetching into new repo in "$TEST_ENV/clone" |
| 283 |
bookmark: main@origin [new] tracked |
| 284 |
Setting the revset alias `trunk()` to `main@origin`. |
| 285 |
Working copy (@) now at: uuqppmxq 3711b3b5 (empty) (no description set) |
| 286 |
Parent commit (@-) : qomsplrm ebeb70d8 main | message |
| 287 |
Added 1 files, modified 0 files, removed 0 files |
| 288 |
[EOF] |
| 289 |
"#); |
| 290 |
let clone_dir = test_env.work_dir("clone"); |
| 291 |
assert!(clone_dir.root().join("file").exists()); |
| 292 |
assert!(clone_dir.root().join(".git").exists()); |
| 293 |
|
| 294 |
eprintln!( |
| 295 |
"{:?}", |
| 296 |
git_repo.head().expect("Repo head should be set").name() |
| 297 |
); |
| 298 |
|
| 299 |
let jj_git_repo = git::open(clone_dir.root()); |
| 300 |
assert_eq!( |
| 301 |
jj_git_repo |
| 302 |
.head_id() |
| 303 |
.expect("Clone Repo HEAD should be set.") |
| 304 |
.detach(), |
| 305 |
git_repo |
| 306 |
.head_id() |
| 307 |
.expect("Repo HEAD should be set.") |
| 308 |
.detach(), |
| 309 |
); |
| 310 |
// ".jj" directory should be ignored at Git side. |
| 311 |
let git_statuses = git::status(&jj_git_repo); |
| 312 |
insta::assert_debug_snapshot!(git_statuses, @r#" |
| 313 |
[ |
| 314 |
GitStatus { |
| 315 |
path: ".jj/.gitignore", |
| 316 |
status: Worktree( |
| 317 |
Ignored, |
| 318 |
), |
| 319 |
}, |
| 320 |
GitStatus { |
| 321 |
path: ".jj/repo", |
| 322 |
status: Worktree( |
| 323 |
Ignored, |
| 324 |
), |
| 325 |
}, |
| 326 |
GitStatus { |
| 327 |
path: ".jj/working_copy", |
| 328 |
status: Worktree( |
| 329 |
Ignored, |
| 330 |
), |
| 331 |
}, |
| 332 |
] |
| 333 |
"#); |
| 334 |
|
| 335 |
// The old default bookmark "master" shouldn't exist. |
| 336 |
insta::assert_snapshot!(get_bookmark_output(&clone_dir), @" |
| 337 |
main: qomsplrm ebeb70d8 message |
| 338 |
@git: qomsplrm ebeb70d8 message |
| 339 |
@origin: qomsplrm ebeb70d8 message |
| 340 |
[EOF] |
| 341 |
"); |
| 342 |
|
| 343 |
// Subsequent fetch should just work even if the source path was relative |
| 344 |
let output = clone_dir.run_jj(["git", "fetch"]); |
| 345 |
insta::assert_snapshot!(output, @" |
| 346 |
------- stderr ------- |
| 347 |
Nothing changed. |
| 348 |
[EOF] |
| 349 |
"); |
| 350 |
|
| 351 |
// Failed clone should clean up the destination directory |
| 352 |
root_dir.create_dir("bad"); |
| 353 |
let output = root_dir.run_jj(["git", "clone", "--colocate", "bad", "failed"]); |
| 354 |
insta::assert_snapshot!(output, @r#" |
| 355 |
------- stderr ------- |
| 356 |
Fetching into new repo in "$TEST_ENV/failed" |
| 357 |
Error: Could not find repository at '$TEST_ENV/bad' |
| 358 |
[EOF] |
| 359 |
[exit status: 1] |
| 360 |
"#); |
| 361 |
assert!(!test_env.env_root().join("failed").exists()); |
| 362 |
|
| 363 |
// Failed clone shouldn't remove the existing destination directory |
| 364 |
let failed_dir = root_dir.create_dir("failed"); |
| 365 |
let output = root_dir.run_jj(["git", "clone", "--colocate", "bad", "failed"]); |
| 366 |
insta::assert_snapshot!(output, @r#" |
| 367 |
------- stderr ------- |
| 368 |
Fetching into new repo in "$TEST_ENV/failed" |
| 369 |
Error: Could not find repository at '$TEST_ENV/bad' |
| 370 |
[EOF] |
| 371 |
[exit status: 1] |
| 372 |
"#); |
| 373 |
assert!(failed_dir.root().exists()); |
| 374 |
assert!(!failed_dir.root().join(".git").exists()); |
| 375 |
assert!(!failed_dir.root().join(".jj").exists()); |
| 376 |
|
| 377 |
// Failed clone (if attempted) shouldn't remove the existing workspace |
| 378 |
let output = root_dir.run_jj(["git", "clone", "--colocate", "bad", "clone"]); |
| 379 |
insta::assert_snapshot!(output, @" |
| 380 |
------- stderr ------- |
| 381 |
Error: Destination path exists and is not an empty directory |
| 382 |
[EOF] |
| 383 |
[exit status: 1] |
| 384 |
"); |
| 385 |
assert!(clone_dir.root().join(".git").exists()); |
| 386 |
assert!(clone_dir.root().join(".jj").exists()); |
| 387 |
|
| 388 |
// Try cloning into an existing workspace |
| 389 |
let output = root_dir.run_jj(["git", "clone", "source", "clone", "--colocate"]); |
| 390 |
insta::assert_snapshot!(output, @" |
| 391 |
------- stderr ------- |
| 392 |
Error: Destination path exists and is not an empty directory |
| 393 |
[EOF] |
| 394 |
[exit status: 1] |
| 395 |
"); |
| 396 |
|
| 397 |
// Try cloning into an existing file |
| 398 |
root_dir.write_file("file", "contents"); |
| 399 |
let output = root_dir.run_jj(["git", "clone", "source", "file", "--colocate"]); |
| 400 |
insta::assert_snapshot!(output, @" |
| 401 |
------- stderr ------- |
| 402 |
Error: Destination path exists and is not an empty directory |
| 403 |
[EOF] |
| 404 |
[exit status: 1] |
| 405 |
"); |
| 406 |
|
| 407 |
// Try cloning into non-empty, non-workspace directory |
| 408 |
clone_dir.remove_dir_all(".jj"); |
| 409 |
let output = root_dir.run_jj(["git", "clone", "source", "clone", "--colocate"]); |
| 410 |
insta::assert_snapshot!(output, @" |
| 411 |
------- stderr ------- |
| 412 |
Error: Destination path exists and is not an empty directory |
| 413 |
[EOF] |
| 414 |
[exit status: 1] |
| 415 |
"); |
| 416 |
|
| 417 |
// Clone into a nested path |
| 418 |
let output = root_dir.run_jj([ |
| 419 |
"git", |
| 420 |
"clone", |
| 421 |
"source", |
| 422 |
"nested/path/to/repo", |
| 423 |
"--colocate", |
| 424 |
]); |
| 425 |
insta::assert_snapshot!(output, @r#" |
| 426 |
------- stderr ------- |
| 427 |
Fetching into new repo in "$TEST_ENV/nested/path/to/repo" |
| 428 |
bookmark: main@origin [new] tracked |
| 429 |
Setting the revset alias `trunk()` to `main@origin`. |
| 430 |
Working copy (@) now at: vzqnnsmr fea36bca (empty) (no description set) |
| 431 |
Parent commit (@-) : qomsplrm ebeb70d8 main | message |
| 432 |
Added 1 files, modified 0 files, removed 0 files |
| 433 |
[EOF] |
| 434 |
"#); |
| 435 |
Ok(()) |
| 436 |
} |
| 437 |
|
| 438 |
#[test] |
| 439 |
fn test_git_clone_colocate_via_config() { |
| 440 |
let test_env = TestEnvironment::default(); |
| 441 |
let root_dir = test_env.work_dir(""); |
| 442 |
let git_repo_path = test_env.env_root().join("source"); |
| 443 |
let git_repo = git::init(git_repo_path); |
| 444 |
|
| 445 |
test_env.add_config("git.colocate = true"); |
| 446 |
|
| 447 |
set_up_non_empty_git_repo(&git_repo); |
| 448 |
|
| 449 |
let output = root_dir.run_jj(["git", "clone", "source", "clone"]); |
| 450 |
insta::assert_snapshot!(output, @r#" |
| 451 |
------- stderr ------- |
| 452 |
Fetching into new repo in "$TEST_ENV/clone" |
| 453 |
bookmark: main@origin [new] tracked |
| 454 |
Setting the revset alias `trunk()` to `main@origin`. |
| 455 |
Working copy (@) now at: sqpuoqvx 1ca44815 (empty) (no description set) |
| 456 |
Parent commit (@-) : qomsplrm ebeb70d8 main | message |
| 457 |
Added 1 files, modified 0 files, removed 0 files |
| 458 |
[EOF] |
| 459 |
"#); |
| 460 |
let clone_dir = test_env.work_dir("clone"); |
| 461 |
assert!(clone_dir.root().join("file").exists()); |
| 462 |
assert!(clone_dir.root().join(".git").exists()); |
| 463 |
} |
| 464 |
|
| 465 |
#[test] |
| 466 |
fn test_git_clone_no_colocate() { |
| 467 |
let test_env = TestEnvironment::default(); |
| 468 |
let root_dir = test_env.work_dir(""); |
| 469 |
let git_repo_path = test_env.env_root().join("source"); |
| 470 |
let git_repo = git::init(git_repo_path); |
| 471 |
|
| 472 |
test_env.add_config("git.colocate = true"); |
| 473 |
|
| 474 |
set_up_non_empty_git_repo(&git_repo); |
| 475 |
|
| 476 |
let output = root_dir.run_jj(["git", "clone", "--no-colocate", "source", "clone"]); |
| 477 |
insta::assert_snapshot!(output, @r#" |
| 478 |
------- stderr ------- |
| 479 |
Fetching into new repo in "$TEST_ENV/clone" |
| 480 |
bookmark: main@origin [new] tracked |
| 481 |
Setting the revset alias `trunk()` to `main@origin`. |
| 482 |
Working copy (@) now at: sqpuoqvx 1ca44815 (empty) (no description set) |
| 483 |
Parent commit (@-) : qomsplrm ebeb70d8 main | message |
| 484 |
Added 1 files, modified 0 files, removed 0 files |
| 485 |
[EOF] |
| 486 |
"#); |
| 487 |
let clone_dir = test_env.work_dir("clone"); |
| 488 |
assert!(clone_dir.root().join("file").exists()); |
| 489 |
assert!(!clone_dir.root().join(".git").exists()); |
| 490 |
} |
| 491 |
|
| 492 |
#[test] |
| 493 |
fn test_git_clone_default_bookmarks_and_tags() { |
| 494 |
let test_env = TestEnvironment::default(); |
| 495 |
let root_dir = test_env.work_dir(""); |
| 496 |
|
| 497 |
let source_repo = git::init(root_dir.root().join("source")); |
| 498 |
git::add_commit(&source_repo, "refs/tags/tag1", "file", b"", "1a", &[]); |
| 499 |
git::add_commit(&source_repo, "refs/heads/branch1", "file", b"", "1b", &[]); |
| 500 |
git::add_commit(&source_repo, "refs/tags/tag2", "file", b"", "1c", &[]); |
| 501 |
git::add_commit(&source_repo, "refs/heads/branch2", "file", b"", "1d", &[]); |
| 502 |
|
| 503 |
// Per-remote default config |
| 504 |
test_env.add_config(indoc! {" |
| 505 |
[remotes.origin] |
| 506 |
fetch-bookmarks = 'branch1' |
| 507 |
fetch-tags = 'tag1' |
| 508 |
[remotes.rem2] |
| 509 |
fetch-bookmarks = 'branch2' |
| 510 |
fetch-tags = 'tag2' |
| 511 |
"}); |
| 512 |
let output = root_dir.run_jj(["git", "clone", "source", "local1"]); |
| 513 |
insta::assert_snapshot!(output, @r#" |
| 514 |
------- stderr ------- |
| 515 |
Fetching into new repo in "$TEST_ENV/local1" |
| 516 |
bookmark: branch1@origin [new] untracked |
| 517 |
tag: tag1@origin [new] tracked |
| 518 |
Working copy (@) now at: sqpuoqvx d3619ee8 (empty) (no description set) |
| 519 |
Parent commit (@-) : sotzwqom 0e985955 branch1@origin | 1b |
| 520 |
Added 1 files, modified 0 files, removed 0 files |
| 521 |
[EOF] |
| 522 |
"#); |
| 523 |
let output = root_dir.run_jj(["git", "clone", "--remote=rem2", "source", "local2"]); |
| 524 |
insta::assert_snapshot!(output, @r#" |
| 525 |
------- stderr ------- |
| 526 |
Fetching into new repo in "$TEST_ENV/local2" |
| 527 |
bookmark: branch2@rem2 [new] untracked |
| 528 |
tag: tag2@rem2 [new] tracked |
| 529 |
Working copy (@) now at: uuqppmxq 92acf2c2 (empty) (no description set) |
| 530 |
Parent commit (@-) : lqvtntpl 147076c8 branch2@rem2 | 1d |
| 531 |
Added 1 files, modified 0 files, removed 0 files |
| 532 |
[EOF] |
| 533 |
"#); |
| 534 |
|
| 535 |
// Default patterns shouldn't be copied to Git config. If they were, "jj git |
| 536 |
// fetch" of the renamed remote would be noop. |
| 537 |
let local_dir = test_env.work_dir("local2"); |
| 538 |
local_dir |
| 539 |
.run_jj(["git", "remote", "rename", "rem2", "rem3"]) |
| 540 |
.success(); |
| 541 |
let output = local_dir.run_jj(["git", "fetch"]); |
| 542 |
insta::assert_snapshot!(output, @" |
| 543 |
------- stderr ------- |
| 544 |
Hint: Fetching from the only existing remote: rem3 |
| 545 |
bookmark: branch1@rem3 [new] untracked |
| 546 |
tag: tag1@rem3 [new] tracked |
| 547 |
[EOF] |
| 548 |
"); |
| 549 |
|
| 550 |
// Default fetch-bookmarks/tags should be disabled by --branch |
| 551 |
let output = root_dir.run_jj(["git", "clone", "--branch=*", "source", "local3"]); |
| 552 |
insta::assert_snapshot!(output, @r#" |
| 553 |
------- stderr ------- |
| 554 |
Fetching into new repo in "$TEST_ENV/local3" |
| 555 |
bookmark: branch1@origin [new] untracked |
| 556 |
bookmark: branch2@origin [new] untracked |
| 557 |
[EOF] |
| 558 |
"#); |
| 559 |
} |
| 560 |
|
| 561 |
#[test] |
| 562 |
fn test_git_clone_tags() { |
| 563 |
let test_env = TestEnvironment::default(); |
| 564 |
let root_dir = test_env.work_dir(""); |
| 565 |
let git_repo_path = test_env.env_root().join("source"); |
| 566 |
let source_git_repo = git::init(git_repo_path); |
| 567 |
|
| 568 |
git::add_commit( |
| 569 |
&source_git_repo, |
| 570 |
"refs/tags/v1.0", |
| 571 |
"foo", |
| 572 |
b"content", |
| 573 |
"message", |
| 574 |
&[], |
| 575 |
); |
| 576 |
|
| 577 |
let commit = git::add_commit( |
| 578 |
&source_git_repo, |
| 579 |
"refs/tags/v2.0", |
| 580 |
"bar", |
| 581 |
b"content", |
| 582 |
"message", |
| 583 |
&[], |
| 584 |
) |
| 585 |
.commit_id; |
| 586 |
|
| 587 |
git::add_commit( |
| 588 |
&source_git_repo, |
| 589 |
"refs/heads/main", |
| 590 |
"baz", |
| 591 |
b"content", |
| 592 |
"message", |
| 593 |
&[commit], |
| 594 |
); |
| 595 |
|
| 596 |
git::set_symbolic_reference(&source_git_repo, "HEAD", "refs/heads/main"); |
| 597 |
|
| 598 |
let output = root_dir.run_jj(["git", "clone", "source", "default", "--colocate"]); |
| 599 |
insta::assert_snapshot!(output, @r#" |
| 600 |
------- stderr ------- |
| 601 |
Fetching into new repo in "$TEST_ENV/default" |
| 602 |
bookmark: main@origin [new] tracked |
| 603 |
tag: v1.0@origin [new] tracked |
| 604 |
tag: v2.0@origin [new] tracked |
| 605 |
Setting the revset alias `trunk()` to `main@origin`. |
| 606 |
Working copy (@) now at: sqpuoqvx 88542a00 (empty) (no description set) |
| 607 |
Parent commit (@-) : lnmyztun e93ca54d main | message |
| 608 |
Added 2 files, modified 0 files, removed 0 files |
| 609 |
[EOF] |
| 610 |
"#); |
| 611 |
} |
| 612 |
|
| 613 |
#[test] |
| 614 |
fn test_git_clone_remote_default_bookmark() -> TestResult { |
| 615 |
let test_env = TestEnvironment::default(); |
| 616 |
let root_dir = test_env.work_dir(""); |
| 617 |
let git_repo_path = test_env.env_root().join("source"); |
| 618 |
let git_repo = git::init(git_repo_path.clone()); |
| 619 |
|
| 620 |
set_up_non_empty_git_repo(&git_repo); |
| 621 |
|
| 622 |
// Create non-default bookmark in remote |
| 623 |
let head_id = git_repo.head_id()?.detach(); |
| 624 |
git_repo.reference( |
| 625 |
"refs/heads/feature1", |
| 626 |
head_id, |
| 627 |
gix::refs::transaction::PreviousValue::MustNotExist, |
| 628 |
"", |
| 629 |
)?; |
| 630 |
|
| 631 |
// All fetched bookmarks will be imported if auto-track-bookmarks = '*' |
| 632 |
test_env.add_config("remotes.origin.auto-track-bookmarks = '*'"); |
| 633 |
let output = root_dir.run_jj(["git", "clone", "source", "clone1"]); |
| 634 |
insta::assert_snapshot!(output, @r#" |
| 635 |
------- stderr ------- |
| 636 |
Fetching into new repo in "$TEST_ENV/clone1" |
| 637 |
bookmark: feature1@origin [new] tracked |
| 638 |
bookmark: main@origin [new] tracked |
| 639 |
Setting the revset alias `trunk()` to `main@origin`. |
| 640 |
Working copy (@) now at: sqpuoqvx 1ca44815 (empty) (no description set) |
| 641 |
Parent commit (@-) : qomsplrm ebeb70d8 feature1 main | message |
| 642 |
Added 1 files, modified 0 files, removed 0 files |
| 643 |
[EOF] |
| 644 |
"#); |
| 645 |
let clone_dir1 = test_env.work_dir("clone1"); |
| 646 |
insta::assert_snapshot!(get_bookmark_output(&clone_dir1), @" |
| 647 |
feature1: qomsplrm ebeb70d8 message |
| 648 |
@origin: qomsplrm ebeb70d8 message |
| 649 |
main: qomsplrm ebeb70d8 message |
| 650 |
@origin: qomsplrm ebeb70d8 message |
| 651 |
[EOF] |
| 652 |
"); |
| 653 |
|
| 654 |
// "trunk()" alias should be set to default bookmark "main" |
| 655 |
let output = clone_dir1.run_jj(["config", "list", "--repo", "revset-aliases.'trunk()'"]); |
| 656 |
insta::assert_snapshot!(output, @r#" |
| 657 |
revset-aliases.'trunk()' = "main@origin" |
| 658 |
[EOF] |
| 659 |
"#); |
| 660 |
|
| 661 |
// Only the default bookmark will be imported if auto-track-bookmarks = '~*' |
| 662 |
test_env.add_config("remotes.origin.auto-track-bookmarks = '~*'"); |
| 663 |
let output = root_dir.run_jj(["git", "clone", "source", "clone2"]); |
| 664 |
insta::assert_snapshot!(output, @r#" |
| 665 |
------- stderr ------- |
| 666 |
Fetching into new repo in "$TEST_ENV/clone2" |
| 667 |
bookmark: feature1@origin [new] untracked |
| 668 |
bookmark: main@origin [new] tracked |
| 669 |
Setting the revset alias `trunk()` to `main@origin`. |
| 670 |
Working copy (@) now at: rzvqmyuk 27e56779 (empty) (no description set) |
| 671 |
Parent commit (@-) : qomsplrm ebeb70d8 feature1@origin main | message |
| 672 |
Added 1 files, modified 0 files, removed 0 files |
| 673 |
[EOF] |
| 674 |
"#); |
| 675 |
let clone_dir2 = test_env.work_dir("clone2"); |
| 676 |
insta::assert_snapshot!(get_bookmark_output(&clone_dir2), @" |
| 677 |
feature1@origin: qomsplrm ebeb70d8 message |
| 678 |
main: qomsplrm ebeb70d8 message |
| 679 |
@origin: qomsplrm ebeb70d8 message |
| 680 |
[EOF] |
| 681 |
"); |
| 682 |
|
| 683 |
// Change the default bookmark in remote |
| 684 |
git::set_symbolic_reference(&git_repo, "HEAD", "refs/heads/feature1"); |
| 685 |
let output = root_dir.run_jj(["git", "clone", "source", "clone3"]); |
| 686 |
insta::assert_snapshot!(output, @r#" |
| 687 |
------- stderr ------- |
| 688 |
Fetching into new repo in "$TEST_ENV/clone3" |
| 689 |
bookmark: feature1@origin [new] tracked |
| 690 |
bookmark: main@origin [new] untracked |
| 691 |
Setting the revset alias `trunk()` to `feature1@origin`. |
| 692 |
Working copy (@) now at: nppvrztz b16020e9 (empty) (no description set) |
| 693 |
Parent commit (@-) : qomsplrm ebeb70d8 feature1 main@origin | message |
| 694 |
Added 1 files, modified 0 files, removed 0 files |
| 695 |
[EOF] |
| 696 |
"#); |
| 697 |
let clone_dir3 = test_env.work_dir("clone3"); |
| 698 |
insta::assert_snapshot!(get_bookmark_output(&clone_dir3), @" |
| 699 |
feature1: qomsplrm ebeb70d8 message |
| 700 |
@origin: qomsplrm ebeb70d8 message |
| 701 |
main@origin: qomsplrm ebeb70d8 message |
| 702 |
[EOF] |
| 703 |
"); |
| 704 |
|
| 705 |
// "trunk()" alias should be set to new default bookmark "feature1" |
| 706 |
let output = clone_dir3.run_jj(["config", "list", "--repo", "revset-aliases.'trunk()'"]); |
| 707 |
insta::assert_snapshot!(output, @r#" |
| 708 |
revset-aliases.'trunk()' = "feature1@origin" |
| 709 |
[EOF] |
| 710 |
"#); |
| 711 |
|
| 712 |
// No bookmarks should be imported if both auto-track-bookmarks and |
| 713 |
// track-default-bookmark-on-clone are turned off |
| 714 |
let output = root_dir.run_jj([ |
| 715 |
"git", |
| 716 |
"clone", |
| 717 |
"--config=git.track-default-bookmark-on-clone=false", |
| 718 |
"source", |
| 719 |
"clone4", |
| 720 |
]); |
| 721 |
insta::assert_snapshot!(output, @r#" |
| 722 |
------- stderr ------- |
| 723 |
Fetching into new repo in "$TEST_ENV/clone4" |
| 724 |
bookmark: feature1@origin [new] untracked |
| 725 |
bookmark: main@origin [new] untracked |
| 726 |
Setting the revset alias `trunk()` to `feature1@origin`. |
| 727 |
Working copy (@) now at: wmwvqwsz 5068d576 (empty) (no description set) |
| 728 |
Parent commit (@-) : qomsplrm ebeb70d8 feature1@origin main@origin | message |
| 729 |
Added 1 files, modified 0 files, removed 0 files |
| 730 |
[EOF] |
| 731 |
"#); |
| 732 |
let clone_dir4 = test_env.work_dir("clone4"); |
| 733 |
insta::assert_snapshot!(get_bookmark_output(&clone_dir4), @" |
| 734 |
feature1@origin: qomsplrm ebeb70d8 message |
| 735 |
main@origin: qomsplrm ebeb70d8 message |
| 736 |
[EOF] |
| 737 |
"); |
| 738 |
|
| 739 |
Ok(()) |
| 740 |
} |
| 741 |
|
| 742 |
// A branch with a strange name should get quoted in the config. Windows doesn't |
| 743 |
// like the strange name, so we don't run the test there. |
| 744 |
#[cfg(unix)] |
| 745 |
#[test] |
| 746 |
fn test_git_clone_remote_default_bookmark_with_escape() { |
| 747 |
let test_env = TestEnvironment::default(); |
| 748 |
let root_dir = test_env.work_dir(""); |
| 749 |
let git_repo_path = test_env.env_root().join("source"); |
| 750 |
let git_repo = git::init(git_repo_path); |
| 751 |
// Create a branch to something that needs to be escaped |
| 752 |
let commit_id = git::add_commit( |
| 753 |
&git_repo, |
| 754 |
"refs/heads/\"", |
| 755 |
"file", |
| 756 |
b"content", |
| 757 |
"message", |
| 758 |
&[], |
| 759 |
) |
| 760 |
.commit_id; |
| 761 |
git::set_head_to_id(&git_repo, commit_id); |
| 762 |
|
| 763 |
let output = root_dir.run_jj(["git", "clone", "source", "clone"]); |
| 764 |
insta::assert_snapshot!(output, @r#" |
| 765 |
------- stderr ------- |
| 766 |
Fetching into new repo in "$TEST_ENV/clone" |
| 767 |
bookmark: "\""@origin [new] tracked |
| 768 |
Setting the revset alias `trunk()` to `"\""@origin`. |
| 769 |
Working copy (@) now at: sqpuoqvx 1ca44815 (empty) (no description set) |
| 770 |
Parent commit (@-) : qomsplrm ebeb70d8 "\"" | message |
| 771 |
Added 1 files, modified 0 files, removed 0 files |
| 772 |
[EOF] |
| 773 |
"#); |
| 774 |
|
| 775 |
// "trunk()" alias should be escaped and quoted |
| 776 |
let clone_dir = test_env.work_dir("clone"); |
| 777 |
let output = clone_dir.run_jj(["config", "list", "--repo", "revset-aliases.'trunk()'"]); |
| 778 |
insta::assert_snapshot!(output, @r#" |
| 779 |
revset-aliases.'trunk()' = '"\""@origin' |
| 780 |
[EOF] |
| 781 |
"#); |
| 782 |
} |
| 783 |
|
| 784 |
#[test] |
| 785 |
fn test_git_clone_ignore_working_copy() { |
| 786 |
let test_env = TestEnvironment::default(); |
| 787 |
let root_dir = test_env.work_dir(""); |
| 788 |
let git_repo_path = test_env.env_root().join("source"); |
| 789 |
let git_repo = git::init(git_repo_path); |
| 790 |
set_up_non_empty_git_repo(&git_repo); |
| 791 |
|
| 792 |
// Should not update working-copy files |
| 793 |
let output = root_dir.run_jj(["git", "clone", "--ignore-working-copy", "source", "clone"]); |
| 794 |
insta::assert_snapshot!(output, @r#" |
| 795 |
------- stderr ------- |
| 796 |
Fetching into new repo in "$TEST_ENV/clone" |
| 797 |
bookmark: main@origin [new] tracked |
| 798 |
Setting the revset alias `trunk()` to `main@origin`. |
| 799 |
[EOF] |
| 800 |
"#); |
| 801 |
let clone_dir = test_env.work_dir("clone"); |
| 802 |
|
| 803 |
let output = clone_dir.run_jj(["status", "--ignore-working-copy"]); |
| 804 |
insta::assert_snapshot!(output, @" |
| 805 |
The working copy has no changes. |
| 806 |
Working copy (@) : sqpuoqvx 1ca44815 (empty) (no description set) |
| 807 |
Parent commit (@-): qomsplrm ebeb70d8 main | message |
| 808 |
[EOF] |
| 809 |
"); |
| 810 |
|
| 811 |
// TODO: Correct, but might be better to check out the root commit? |
| 812 |
let output = clone_dir.run_jj(["status"]); |
| 813 |
insta::assert_snapshot!(output, @" |
| 814 |
------- stderr ------- |
| 815 |
Error: The working copy is stale (not updated since operation f63ee16f9553). |
| 816 |
Hint: Run `jj workspace update-stale` to update it. |
| 817 |
See https://docs.jj-vcs.dev/latest/working-copy/#stale-working-copy for more information. |
| 818 |
[EOF] |
| 819 |
[exit status: 1] |
| 820 |
"); |
| 821 |
} |
| 822 |
|
| 823 |
#[test] |
| 824 |
fn test_git_clone_at_operation() { |
| 825 |
let test_env = TestEnvironment::default(); |
| 826 |
let root_dir = test_env.work_dir(""); |
| 827 |
let git_repo_path = test_env.env_root().join("source"); |
| 828 |
let git_repo = git::init(git_repo_path); |
| 829 |
set_up_non_empty_git_repo(&git_repo); |
| 830 |
|
| 831 |
let output = root_dir.run_jj(["git", "clone", "--at-op=@-", "source", "clone"]); |
| 832 |
insta::assert_snapshot!(output, @" |
| 833 |
------- stderr ------- |
| 834 |
Error: --at-op is not respected |
| 835 |
[EOF] |
| 836 |
[exit status: 2] |
| 837 |
"); |
| 838 |
} |
| 839 |
|
| 840 |
#[test] |
| 841 |
fn test_git_clone_with_remote_name() { |
| 842 |
let test_env = TestEnvironment::default(); |
| 843 |
let root_dir = test_env.work_dir(""); |
| 844 |
test_env.add_config("remotes.origin.auto-track-bookmarks = '*'"); |
| 845 |
let git_repo_path = test_env.env_root().join("source"); |
| 846 |
let git_repo = git::init(git_repo_path); |
| 847 |
set_up_non_empty_git_repo(&git_repo); |
| 848 |
|
| 849 |
// Clone with relative source path and a non-default remote name |
| 850 |
let output = root_dir.run_jj(["git", "clone", "source", "clone", "--remote", "upstream"]); |
| 851 |
insta::assert_snapshot!(output, @r#" |
| 852 |
------- stderr ------- |
| 853 |
Fetching into new repo in "$TEST_ENV/clone" |
| 854 |
bookmark: main@upstream [new] tracked |
| 855 |
Setting the revset alias `trunk()` to `main@upstream`. |
| 856 |
Working copy (@) now at: sqpuoqvx 1ca44815 (empty) (no description set) |
| 857 |
Parent commit (@-) : qomsplrm ebeb70d8 main | message |
| 858 |
Added 1 files, modified 0 files, removed 0 files |
| 859 |
[EOF] |
| 860 |
"#); |
| 861 |
} |
| 862 |
|
| 863 |
#[test] |
| 864 |
fn test_git_clone_with_remote_named_git() { |
| 865 |
let test_env = TestEnvironment::default(); |
| 866 |
let root_dir = test_env.work_dir(""); |
| 867 |
let git_repo_path = test_env.env_root().join("source"); |
| 868 |
git::init(git_repo_path); |
| 869 |
|
| 870 |
let output = root_dir.run_jj(["git", "clone", "--remote=git", "source", "dest"]); |
| 871 |
insta::assert_snapshot!(output, @" |
| 872 |
------- stderr ------- |
| 873 |
Error: Git remote named 'git' is reserved for local Git repository |
| 874 |
[EOF] |
| 875 |
[exit status: 1] |
| 876 |
"); |
| 877 |
} |
| 878 |
|
| 879 |
#[test] |
| 880 |
fn test_git_clone_with_remote_with_slashes() { |
| 881 |
let test_env = TestEnvironment::default(); |
| 882 |
let root_dir = test_env.work_dir(""); |
| 883 |
let git_repo_path = test_env.env_root().join("source"); |
| 884 |
git::init(git_repo_path); |
| 885 |
|
| 886 |
let output = root_dir.run_jj(["git", "clone", "--remote=slash/origin", "source", "dest"]); |
| 887 |
insta::assert_snapshot!(output, @" |
| 888 |
------- stderr ------- |
| 889 |
Error: Git remotes with slashes are incompatible with jj: slash/origin |
| 890 |
[EOF] |
| 891 |
[exit status: 1] |
| 892 |
"); |
| 893 |
} |
| 894 |
|
| 895 |
#[test] |
| 896 |
fn test_git_clone_trunk_deleted() { |
| 897 |
let test_env = TestEnvironment::default(); |
| 898 |
let root_dir = test_env.work_dir(""); |
| 899 |
let git_repo_path = test_env.env_root().join("source"); |
| 900 |
let git_repo = git::init(git_repo_path); |
| 901 |
set_up_non_empty_git_repo(&git_repo); |
| 902 |
let clone_dir = test_env.work_dir("clone"); |
| 903 |
|
| 904 |
let output = root_dir.run_jj(["git", "clone", "source", "clone"]); |
| 905 |
insta::assert_snapshot!(output, @r#" |
| 906 |
------- stderr ------- |
| 907 |
Fetching into new repo in "$TEST_ENV/clone" |
| 908 |
bookmark: main@origin [new] tracked |
| 909 |
Setting the revset alias `trunk()` to `main@origin`. |
| 910 |
Working copy (@) now at: sqpuoqvx 1ca44815 (empty) (no description set) |
| 911 |
Parent commit (@-) : qomsplrm ebeb70d8 main | message |
| 912 |
Added 1 files, modified 0 files, removed 0 files |
| 913 |
[EOF] |
| 914 |
"#); |
| 915 |
|
| 916 |
let output = clone_dir.run_jj(["bookmark", "forget", "--include-remotes", "main"]); |
| 917 |
insta::assert_snapshot!(output, @" |
| 918 |
------- stderr ------- |
| 919 |
Forgot 1 local bookmarks. |
| 920 |
Forgot 1 remote bookmarks. |
| 921 |
[EOF] |
| 922 |
"); |
| 923 |
|
| 924 |
let output = clone_dir.run_jj(["log"]); |
| 925 |
insta::assert_snapshot!(output, @" |
| 926 |
@ sqpuoqvx [email protected] 2001-02-03 08:05:07 1ca44815 |
| 927 |
│ (empty) (no description set) |
| 928 |
○ qomsplrm [email protected] 1970-01-01 11:00:00 ebeb70d8 |
| 929 |
│ message |
| 930 |
◆ zzzzzzzz root() 00000000 |
| 931 |
[EOF] |
| 932 |
------- stderr ------- |
| 933 |
Warning: Failed to resolve `revset-aliases.trunk()`: Revision `main@origin` doesn't exist |
| 934 |
The `trunk()` alias is temporarily set to `root()`. |
| 935 |
Hint: Use `jj config edit --repo` to adjust the `trunk()` alias. |
| 936 |
[EOF] |
| 937 |
"); |
| 938 |
} |
| 939 |
|
| 940 |
#[test] |
| 941 |
fn test_git_clone_conditional_config() { |
| 942 |
let test_env = TestEnvironment::default(); |
| 943 |
let root_dir = test_env.work_dir(""); |
| 944 |
let source_repo_path = test_env.env_root().join("source"); |
| 945 |
let old_workspace_dir = test_env.work_dir("old"); |
| 946 |
let new_workspace_dir = test_env.work_dir("new"); |
| 947 |
let source_git_repo = git::init(source_repo_path); |
| 948 |
set_up_non_empty_git_repo(&source_git_repo); |
| 949 |
|
| 950 |
let run_jj = |work_dir: &TestWorkDir, args: &[&str]| { |
| 951 |
work_dir.run_jj_with(|cmd| { |
| 952 |
cmd.args(args) |
| 953 |
.env_remove("JJ_EMAIL") |
| 954 |
.env_remove("JJ_OP_HOSTNAME") |
| 955 |
.env_remove("JJ_OP_USERNAME") |
| 956 |
}) |
| 957 |
}; |
| 958 |
let log_template = r#"separate(' ', author.email(), description.first_line()) ++ "\n""#; |
| 959 |
let op_log_template = r#"separate(' ', user, description.first_line()) ++ "\n""#; |
| 960 |
|
| 961 |
// Override user.email and operation.username conditionally |
| 962 |
test_env.add_config(formatdoc! {" |
| 963 |
user.email = '[email protected]' |
| 964 |
operation.hostname = 'base' |
| 965 |
operation.username = 'base' |
| 966 |
[[--scope]] |
| 967 |
--when.repositories = [{new_workspace_root}] |
| 968 |
user.email = '[email protected]' |
| 969 |
operation.username = 'new-repo' |
| 970 |
", |
| 971 |
new_workspace_root = to_toml_value(new_workspace_dir.root().to_str().unwrap()), |
| 972 |
}); |
| 973 |
|
| 974 |
// Override operation.hostname by repo config, which should be loaded into |
| 975 |
// the command settings, but shouldn't be copied to the new repo. |
| 976 |
run_jj(&root_dir, &["git", "init", "old"]).success(); |
| 977 |
run_jj( |
| 978 |
&old_workspace_dir, |
| 979 |
&["config", "set", "--repo", "operation.hostname", "old-repo"], |
| 980 |
) |
| 981 |
.success(); |
| 982 |
run_jj(&old_workspace_dir, &["new"]).success(); |
| 983 |
let output = run_jj(&old_workspace_dir, &["op", "log", "-T", op_log_template]); |
| 984 |
insta::assert_snapshot!(output, @" |
| 985 |
@ base@old-repo new empty commit |
| 986 |
○ base@base add workspace 'default' |
| 987 |
○ @ |
| 988 |
[EOF] |
| 989 |
"); |
| 990 |
|
| 991 |
// Clone repo at the old workspace directory. |
| 992 |
let output = run_jj(&old_workspace_dir, &["git", "clone", "../source", "../new"]); |
| 993 |
insta::assert_snapshot!(output, @r#" |
| 994 |
------- stderr ------- |
| 995 |
Fetching into new repo in "$TEST_ENV/new" |
| 996 |
bookmark: main@origin [new] tracked |
| 997 |
Setting the revset alias `trunk()` to `main@origin`. |
| 998 |
Working copy (@) now at: zxsnswpr 5479cd52 (empty) (no description set) |
| 999 |
Parent commit (@-) : qomsplrm ebeb70d8 main | message |
| 1000 |
Added 1 files, modified 0 files, removed 0 files |
| 1001 |
[EOF] |
| 1002 |
"#); |
| 1003 |
run_jj(&new_workspace_dir, &["new"]).success(); |
| 1004 |
let output = run_jj(&new_workspace_dir, &["log", "-T", log_template]); |
| 1005 |
insta::assert_snapshot!(output, @" |
| 1006 |
@ [email protected] |
| 1007 |
○ [email protected] |
| 1008 |
◆ [email protected] message |
| 1009 |
│ |
| 1010 |
~ |
| 1011 |
[EOF] |
| 1012 |
"); |
| 1013 |
let output = run_jj(&new_workspace_dir, &["op", "log", "-T", op_log_template]); |
| 1014 |
insta::assert_snapshot!(output, @" |
| 1015 |
@ new-repo@base new empty commit |
| 1016 |
○ new-repo@base check out git remote's branch: main |
| 1017 |
○ new-repo@base fetch from git remote into empty repo |
| 1018 |
○ new-repo@base add git remote origin |
| 1019 |
○ new-repo@base add workspace 'default' |
| 1020 |
○ @ |
| 1021 |
[EOF] |
| 1022 |
"); |
| 1023 |
} |
| 1024 |
|
| 1025 |
#[test] |
| 1026 |
fn test_git_clone_with_depth() { |
| 1027 |
let test_env = TestEnvironment::default(); |
| 1028 |
let root_dir = test_env.work_dir(""); |
| 1029 |
test_env.add_config("remotes.origin.auto-track-bookmarks = '*'"); |
| 1030 |
let clone_dir = test_env.work_dir("clone"); |
| 1031 |
let git_repo_path = test_env.env_root().join("source"); |
| 1032 |
let git_repo = git::init(git_repo_path); |
| 1033 |
set_up_non_empty_git_repo(&git_repo); |
| 1034 |
|
| 1035 |
let output = root_dir.run_jj(["git", "clone", "--depth", "1", "source", "clone"]); |
| 1036 |
insta::assert_snapshot!(output, @r#" |
| 1037 |
------- stderr ------- |
| 1038 |
Fetching into new repo in "$TEST_ENV/clone" |
| 1039 |
bookmark: main@origin [new] tracked |
| 1040 |
Setting the revset alias `trunk()` to `main@origin`. |
| 1041 |
Working copy (@) now at: sqpuoqvx 1ca44815 (empty) (no description set) |
| 1042 |
Parent commit (@-) : qomsplrm ebeb70d8 main | message |
| 1043 |
Added 1 files, modified 0 files, removed 0 files |
| 1044 |
[EOF] |
| 1045 |
"#); |
| 1046 |
|
| 1047 |
let output = clone_dir.run_jj(["log"]); |
| 1048 |
insta::assert_snapshot!(output, @" |
| 1049 |
@ sqpuoqvx [email protected] 2001-02-03 08:05:07 1ca44815 |
| 1050 |
│ (empty) (no description set) |
| 1051 |
◆ qomsplrm [email protected] 1970-01-01 11:00:00 main ebeb70d8 |
| 1052 |
│ message |
| 1053 |
~ |
| 1054 |
[EOF] |
| 1055 |
"); |
| 1056 |
} |
| 1057 |
|
| 1058 |
#[test] |
| 1059 |
fn test_git_clone_invalid_immutable_heads() { |
| 1060 |
let test_env = TestEnvironment::default(); |
| 1061 |
let root_dir = test_env.work_dir(""); |
| 1062 |
let git_repo_path = test_env.env_root().join("source"); |
| 1063 |
let git_repo = git::init(git_repo_path); |
| 1064 |
set_up_non_empty_git_repo(&git_repo); |
| 1065 |
|
| 1066 |
test_env.add_config("revset-aliases.'immutable_heads()' = 'unknown'"); |
| 1067 |
// Suppress lengthy warnings in commit summary template |
| 1068 |
test_env.add_config("revsets.short-prefixes = ''"); |
| 1069 |
|
| 1070 |
// The error about the invalid immutable_heads() shouldn't be counted as an |
| 1071 |
// immutable working-copy commit. |
| 1072 |
let output = root_dir.run_jj(["git", "clone", "source", "clone"]); |
| 1073 |
insta::assert_snapshot!(output, @" |
| 1074 |
------- stderr ------- |
| 1075 |
Config error: Invalid `revset-aliases.immutable_heads()` |
| 1076 |
Caused by: Revision `unknown` doesn't exist |
| 1077 |
For help, see https://docs.jj-vcs.dev/latest/config/ or use `jj help -k config`. |
| 1078 |
[EOF] |
| 1079 |
[exit status: 1] |
| 1080 |
"); |
| 1081 |
} |
| 1082 |
|
| 1083 |
#[test] |
| 1084 |
fn test_git_clone_malformed() { |
| 1085 |
let test_env = TestEnvironment::default(); |
| 1086 |
let root_dir = test_env.work_dir(""); |
| 1087 |
let git_repo_path = test_env.env_root().join("source"); |
| 1088 |
let git_repo = git::init(git_repo_path); |
| 1089 |
let clone_dir = test_env.work_dir("clone"); |
| 1090 |
// we can insert ".jj" entry to create a malformed clone |
| 1091 |
set_up_git_repo_with_file(&git_repo, ".jj"); |
| 1092 |
|
| 1093 |
// TODO: Perhaps, this should be a user error, not an internal error. |
| 1094 |
let output = root_dir.run_jj(["git", "clone", "source", "clone"]); |
| 1095 |
insta::assert_snapshot!(output, @r#" |
| 1096 |
------- stderr ------- |
| 1097 |
Fetching into new repo in "$TEST_ENV/clone" |
| 1098 |
bookmark: main@origin [new] tracked |
| 1099 |
Setting the revset alias `trunk()` to `main@origin`. |
| 1100 |
Internal error: Failed to check out commit 2f4286212884d472a0b2013a961b695a144ac65c |
| 1101 |
Caused by: Reserved path component .jj in $TEST_ENV/clone/.jj |
| 1102 |
[EOF] |
| 1103 |
[exit status: 255] |
| 1104 |
"#); |
| 1105 |
|
| 1106 |
// The cloned workspace isn't usable. |
| 1107 |
let output = clone_dir.run_jj(["status"]); |
| 1108 |
insta::assert_snapshot!(output, @" |
| 1109 |
------- stderr ------- |
| 1110 |
Error: The working copy is stale (not updated since operation 68cac63e1c80). |
| 1111 |
Hint: Run `jj workspace update-stale` to update it. |
| 1112 |
See https://docs.jj-vcs.dev/latest/working-copy/#stale-working-copy for more information. |
| 1113 |
[EOF] |
| 1114 |
[exit status: 1] |
| 1115 |
"); |
| 1116 |
|
| 1117 |
// The error can be somehow recovered. |
| 1118 |
// TODO: add an update-stale flag to reset the working-copy? |
| 1119 |
let output = clone_dir.run_jj(["workspace", "update-stale"]); |
| 1120 |
insta::assert_snapshot!(output, @" |
| 1121 |
------- stderr ------- |
| 1122 |
Internal error: Failed to check out commit 2f4286212884d472a0b2013a961b695a144ac65c |
| 1123 |
Caused by: Reserved path component .jj in $TEST_ENV/clone/.jj |
| 1124 |
[EOF] |
| 1125 |
[exit status: 255] |
| 1126 |
"); |
| 1127 |
let output = clone_dir.run_jj(["new", "root()", "--ignore-working-copy"]); |
| 1128 |
insta::assert_snapshot!(output, @""); |
| 1129 |
let output = clone_dir.run_jj(["status"]); |
| 1130 |
insta::assert_snapshot!(output, @" |
| 1131 |
The working copy has no changes. |
| 1132 |
Working copy (@) : zsuskuln c2934cfb (empty) (no description set) |
| 1133 |
Parent commit (@-): zzzzzzzz 00000000 (empty) (no description set) |
| 1134 |
[EOF] |
| 1135 |
"); |
| 1136 |
} |
| 1137 |
|
| 1138 |
#[test] |
| 1139 |
fn test_git_clone_with_global_git_remote_config() { |
| 1140 |
let mut test_env = TestEnvironment::default(); |
| 1141 |
test_env.work_dir("").write_file( |
| 1142 |
"git-config", |
| 1143 |
indoc! {r#" |
| 1144 |
[remote "origin"] |
| 1145 |
prune = true |
| 1146 |
"#}, |
| 1147 |
); |
| 1148 |
test_env.add_env_var("GIT_CONFIG_GLOBAL", test_env.env_root().join("git-config")); |
| 1149 |
|
| 1150 |
let root_dir = test_env.work_dir(""); |
| 1151 |
let git_repo_path = root_dir.root().join("source"); |
| 1152 |
let git_repo = git::init(git_repo_path); |
| 1153 |
set_up_non_empty_git_repo(&git_repo); |
| 1154 |
|
| 1155 |
let output = root_dir.run_jj(["git", "clone", "source", "clone"]); |
| 1156 |
insta::assert_snapshot!(output, @r#" |
| 1157 |
------- stderr ------- |
| 1158 |
Fetching into new repo in "$TEST_ENV/clone" |
| 1159 |
bookmark: main@origin [new] tracked |
| 1160 |
Setting the revset alias `trunk()` to `main@origin`. |
| 1161 |
Working copy (@) now at: sqpuoqvx 1ca44815 (empty) (no description set) |
| 1162 |
Parent commit (@-) : qomsplrm ebeb70d8 main | message |
| 1163 |
Added 1 files, modified 0 files, removed 0 files |
| 1164 |
[EOF] |
| 1165 |
"#); |
| 1166 |
} |
| 1167 |
|
| 1168 |
#[test] |
| 1169 |
fn test_git_clone_no_git_executable() { |
| 1170 |
let test_env = TestEnvironment::default(); |
| 1171 |
let root_dir = test_env.work_dir(""); |
| 1172 |
test_env.add_config("git.executable-path = 'jj-test-missing-program'"); |
| 1173 |
let git_repo_path = test_env.env_root().join("source"); |
| 1174 |
let git_repo = git::init(git_repo_path); |
| 1175 |
set_up_non_empty_git_repo(&git_repo); |
| 1176 |
|
| 1177 |
let output = root_dir.run_jj(["git", "clone", "source", "clone"]); |
| 1178 |
insta::assert_snapshot!(output.strip_stderr_last_line(), @r#" |
| 1179 |
------- stderr ------- |
| 1180 |
Fetching into new repo in "$TEST_ENV/clone" |
| 1181 |
Error: Could not execute the git process, found in the OS path 'jj-test-missing-program' |
| 1182 |
[EOF] |
| 1183 |
[exit status: 1] |
| 1184 |
"#); |
| 1185 |
} |
| 1186 |
|
| 1187 |
#[test] |
| 1188 |
fn test_git_clone_no_git_executable_with_path() { |
| 1189 |
let test_env = TestEnvironment::default(); |
| 1190 |
let root_dir = test_env.work_dir(""); |
| 1191 |
let invalid_git_executable_path = test_env.env_root().join("invalid").join("path"); |
| 1192 |
test_env.add_config(format!( |
| 1193 |
"git.executable-path = {}", |
| 1194 |
to_toml_value(invalid_git_executable_path.to_str().unwrap()) |
| 1195 |
)); |
| 1196 |
let git_repo_path = test_env.env_root().join("source"); |
| 1197 |
let git_repo = git::init(git_repo_path); |
| 1198 |
set_up_non_empty_git_repo(&git_repo); |
| 1199 |
|
| 1200 |
let output = root_dir.run_jj(["git", "clone", "source", "clone"]); |
| 1201 |
insta::assert_snapshot!(output.strip_stderr_last_line(), @r#" |
| 1202 |
------- stderr ------- |
| 1203 |
Fetching into new repo in "$TEST_ENV/clone" |
| 1204 |
Error: Could not execute git process at specified path '$TEST_ENV/invalid/path' |
| 1205 |
[EOF] |
| 1206 |
[exit status: 1] |
| 1207 |
"#); |
| 1208 |
} |
| 1209 |
|
| 1210 |
#[test] |
| 1211 |
fn test_git_clone_branch_or_tag() { |
| 1212 |
let test_env = TestEnvironment::default(); |
| 1213 |
let root_dir = test_env.work_dir(""); |
| 1214 |
test_env.add_config("remotes.origin.auto-track-bookmarks = '*'"); |
| 1215 |
let git_repo_path = test_env.env_root().join("source"); |
| 1216 |
let git_repo = git::init(&git_repo_path); |
| 1217 |
set_up_non_empty_git_repo(&git_repo); |
| 1218 |
git::add_commit( |
| 1219 |
&git_repo, |
| 1220 |
"refs/heads/feature1", |
| 1221 |
"file", |
| 1222 |
b"content", |
| 1223 |
"feature1 message", |
| 1224 |
&[], |
| 1225 |
); |
| 1226 |
for name in ["tag1", "tag2", "tag3"] { |
| 1227 |
let full_name = format!("refs/tags/{name}"); |
| 1228 |
git::add_commit(&git_repo, &full_name, "file", b"content", name, &[]); |
| 1229 |
} |
| 1230 |
|
| 1231 |
// Clone the default branch by name |
| 1232 |
let output = root_dir.run_jj(["git", "clone", "source", "clone", "--branch", "main"]); |
| 1233 |
insta::assert_snapshot!(output, @r#" |
| 1234 |
------- stderr ------- |
| 1235 |
Fetching into new repo in "$TEST_ENV/clone" |
| 1236 |
bookmark: main@origin [new] tracked |
| 1237 |
Setting the revset alias `trunk()` to `main@origin`. |
| 1238 |
Working copy (@) now at: sqpuoqvx 1ca44815 (empty) (no description set) |
| 1239 |
Parent commit (@-) : qomsplrm ebeb70d8 main | message |
| 1240 |
Added 1 files, modified 0 files, removed 0 files |
| 1241 |
[EOF] |
| 1242 |
"#); |
| 1243 |
|
| 1244 |
// fetch-tags should be set to "~*" because we cloned a specific branch |
| 1245 |
// (without fetching any tags) |
| 1246 |
let repo_dir = test_env.work_dir("clone"); |
| 1247 |
insta::assert_snapshot!(repo_dir.run_jj(["config", "list", "--repo"]), @r#" |
| 1248 |
remotes.origin.fetch-bookmarks = "main" |
| 1249 |
remotes.origin.fetch-tags = "~*" |
| 1250 |
revset-aliases."trunk()" = "main@origin" |
| 1251 |
[EOF] |
| 1252 |
"#); |
| 1253 |
|
| 1254 |
// Clone a branch that doesn't exist |
| 1255 |
let output = root_dir.run_jj([ |
| 1256 |
"git", |
| 1257 |
"clone", |
| 1258 |
"source", |
| 1259 |
"clone_no_such_branch", |
| 1260 |
"--branch=(nonexistent1 | nonexistent*) & ~nonexistent2", |
| 1261 |
]); |
| 1262 |
insta::assert_snapshot!(output, @r#" |
| 1263 |
------- stderr ------- |
| 1264 |
Fetching into new repo in "$TEST_ENV/clone_no_such_branch" |
| 1265 |
Warning: No matching branches found on remote: nonexistent1 |
| 1266 |
Nothing changed. |
| 1267 |
[EOF] |
| 1268 |
"#); |
| 1269 |
|
| 1270 |
// Clone a specific, non-default branch |
| 1271 |
let output = root_dir.run_jj([ |
| 1272 |
"git", |
| 1273 |
"clone", |
| 1274 |
"source", |
| 1275 |
"clone_non_default", |
| 1276 |
"--branch", |
| 1277 |
"feature1", |
| 1278 |
]); |
| 1279 |
insta::assert_snapshot!(output, @r#" |
| 1280 |
------- stderr ------- |
| 1281 |
Fetching into new repo in "$TEST_ENV/clone_non_default" |
| 1282 |
bookmark: feature1@origin [new] tracked |
| 1283 |
Working copy (@) now at: rzvqmyuk 5badc4c2 (empty) (no description set) |
| 1284 |
Parent commit (@-) : yxwyzxtq 14835edf feature1 | feature1 message |
| 1285 |
Added 1 files, modified 0 files, removed 0 files |
| 1286 |
[EOF] |
| 1287 |
"#); |
| 1288 |
|
| 1289 |
// Perform a fetch in that same repo |
| 1290 |
let repo_dir = test_env.work_dir("clone_non_default"); |
| 1291 |
let output = repo_dir.run_jj(["git", "fetch"]); |
| 1292 |
insta::assert_snapshot!(output, @" |
| 1293 |
------- stderr ------- |
| 1294 |
Nothing changed. |
| 1295 |
[EOF] |
| 1296 |
"); |
| 1297 |
|
| 1298 |
// Clone multiple tags by name |
| 1299 |
let output = root_dir.run_jj([ |
| 1300 |
"git", |
| 1301 |
"clone", |
| 1302 |
"source", |
| 1303 |
"clone_tags", |
| 1304 |
"--tag=tag1", |
| 1305 |
"--tag=tag2", |
| 1306 |
]); |
| 1307 |
insta::assert_snapshot!(output, @r#" |
| 1308 |
------- stderr ------- |
| 1309 |
Fetching into new repo in "$TEST_ENV/clone_tags" |
| 1310 |
tag: tag1@origin [new] tracked |
| 1311 |
tag: tag2@origin [new] tracked |
| 1312 |
[EOF] |
| 1313 |
"#); |
| 1314 |
|
| 1315 |
// fetch-tags should be set to "<name1> | <name2> | ..." |
| 1316 |
let repo_dir = test_env.work_dir("clone_tags"); |
| 1317 |
insta::assert_snapshot!(repo_dir.run_jj(["config", "list", "--repo"]), @r#" |
| 1318 |
remotes.origin.fetch-bookmarks = "~*" |
| 1319 |
remotes.origin.fetch-tags = "tag1 | tag2" |
| 1320 |
[EOF] |
| 1321 |
"#); |
| 1322 |
|
| 1323 |
// Perform a fetch in that same repo |
| 1324 |
let output = repo_dir.run_jj(["git", "fetch"]); |
| 1325 |
insta::assert_snapshot!(output, @" |
| 1326 |
------- stderr ------- |
| 1327 |
Nothing changed. |
| 1328 |
[EOF] |
| 1329 |
"); |
| 1330 |
|
| 1331 |
// Clone all branches explicitly, the default branch should be checked out |
| 1332 |
let output = root_dir.run_jj(["git", "clone", "source", "clone_all", "--branch=*"]); |
| 1333 |
insta::assert_snapshot!(output, @r#" |
| 1334 |
------- stderr ------- |
| 1335 |
Fetching into new repo in "$TEST_ENV/clone_all" |
| 1336 |
bookmark: feature1@origin [new] tracked |
| 1337 |
bookmark: main@origin [new] tracked |
| 1338 |
Setting the revset alias `trunk()` to `main@origin`. |
| 1339 |
Working copy (@) now at: wmwvqwsz 5068d576 (empty) (no description set) |
| 1340 |
Parent commit (@-) : qomsplrm ebeb70d8 main | message |
| 1341 |
Added 1 files, modified 0 files, removed 0 files |
| 1342 |
[EOF] |
| 1343 |
"#); |
| 1344 |
|
| 1345 |
// Clone all but feature1 and tag1 |
| 1346 |
let output = root_dir.run_jj([ |
| 1347 |
"git", |
| 1348 |
"clone", |
| 1349 |
"source", |
| 1350 |
"clone_all_but", |
| 1351 |
"--branch=~feature1", |
| 1352 |
"--tag=~tag1", |
| 1353 |
]); |
| 1354 |
insta::assert_snapshot!(output, @r#" |
| 1355 |
------- stderr ------- |
| 1356 |
Fetching into new repo in "$TEST_ENV/clone_all_but" |
| 1357 |
bookmark: main@origin [new] tracked |
| 1358 |
tag: tag2@origin [new] tracked |
| 1359 |
tag: tag3@origin [new] tracked |
| 1360 |
Setting the revset alias `trunk()` to `main@origin`. |
| 1361 |
Working copy (@) now at: uuzqqzqu c871b515 (empty) (no description set) |
| 1362 |
Parent commit (@-) : qomsplrm ebeb70d8 main | message |
| 1363 |
Added 1 files, modified 0 files, removed 0 files |
| 1364 |
[EOF] |
| 1365 |
"#); |
| 1366 |
|
| 1367 |
let repo_dir = test_env.work_dir("clone_all_but"); |
| 1368 |
insta::assert_snapshot!(repo_dir.run_jj(["config", "list", "--repo"]), @r#" |
| 1369 |
remotes.origin.fetch-bookmarks = "~feature1" |
| 1370 |
remotes.origin.fetch-tags = "~tag1" |
| 1371 |
revset-aliases."trunk()" = "main@origin" |
| 1372 |
[EOF] |
| 1373 |
"#); |
| 1374 |
|
| 1375 |
// Perform a fetch in that same repo |
| 1376 |
let output = repo_dir.run_jj(["git", "fetch"]); |
| 1377 |
insta::assert_snapshot!(output, @" |
| 1378 |
------- stderr ------- |
| 1379 |
Nothing changed. |
| 1380 |
[EOF] |
| 1381 |
"); |
| 1382 |
|
| 1383 |
// Clone all branches individually, first exact match becomes wc parent |
| 1384 |
let output = root_dir.run_jj([ |
| 1385 |
"git", |
| 1386 |
"clone", |
| 1387 |
"source", |
| 1388 |
"clone_each", |
| 1389 |
"--branch=feature1", |
| 1390 |
"--branch=main", |
| 1391 |
]); |
| 1392 |
insta::assert_snapshot!(output, @r#" |
| 1393 |
------- stderr ------- |
| 1394 |
Fetching into new repo in "$TEST_ENV/clone_each" |
| 1395 |
bookmark: feature1@origin [new] tracked |
| 1396 |
bookmark: main@origin [new] tracked |
| 1397 |
Working copy (@) now at: mouksmqu 41e09dcd (empty) (no description set) |
| 1398 |
Parent commit (@-) : yxwyzxtq 14835edf feature1 | feature1 message |
| 1399 |
Added 1 files, modified 0 files, removed 0 files |
| 1400 |
[EOF] |
| 1401 |
"#); |
| 1402 |
} |
| 1403 |
|
| 1404 |
#[test] |
| 1405 |
fn test_git_clone_auto_track_bookmarks() { |
| 1406 |
let test_env = TestEnvironment::default(); |
| 1407 |
let root_dir = test_env.work_dir(""); |
| 1408 |
test_env.add_config( |
| 1409 |
" |
| 1410 |
[remotes.origin] |
| 1411 |
auto-track-bookmarks = 'mine/*' |
| 1412 |
", |
| 1413 |
); |
| 1414 |
|
| 1415 |
root_dir |
| 1416 |
.run_jj(["git", "init", "--colocate", "origin"]) |
| 1417 |
.success(); |
| 1418 |
let origin_dir = test_env.work_dir("origin"); |
| 1419 |
origin_dir.run_jj(["b", "c", "mine/foo"]).success(); |
| 1420 |
origin_dir.run_jj(["b", "c", "not-mine/foo"]).success(); |
| 1421 |
origin_dir.run_jj(["commit", "-mfoo"]).success(); |
| 1422 |
let output = origin_dir.run_jj(["show", "@-"]); |
| 1423 |
insta::assert_snapshot!(output, @" |
| 1424 |
Commit ID: d7828da83253475bf10c2ae6bd3f0f84bf4604c1 |
| 1425 |
Change ID: qpvuntsmwlqtpsluzzsnyyzlmlwvmlnu |
| 1426 |
Bookmarks: mine/foo not-mine/foo mine/foo@git not-mine/foo@git |
| 1427 |
Author : Test User <[email protected]> (2001-02-03 08:05:10) |
| 1428 |
Committer: Test User <[email protected]> (2001-02-03 08:05:10) |
| 1429 |
|
| 1430 |
foo |
| 1431 |
|
| 1432 |
[EOF] |
| 1433 |
"); |
| 1434 |
|
| 1435 |
root_dir |
| 1436 |
.run_jj(["git", "clone", "origin/.git", "repo"]) |
| 1437 |
.success(); |
| 1438 |
let repo_dir = test_env.work_dir("repo"); |
| 1439 |
|
| 1440 |
let output = get_bookmark_output(&repo_dir); |
| 1441 |
insta::assert_snapshot!(output, @" |
| 1442 |
mine/foo: qpvuntsm d7828da8 (empty) foo |
| 1443 |
@origin: qpvuntsm d7828da8 (empty) foo |
| 1444 |
not-mine/foo@origin: qpvuntsm d7828da8 (empty) foo |
| 1445 |
[EOF] |
| 1446 |
"); |
| 1447 |
} |
| 1448 |
|
| 1449 |
#[must_use] |
| 1450 |
fn get_bookmark_output(work_dir: &TestWorkDir) -> CommandOutput { |
| 1451 |
work_dir.run_jj(["bookmark", "list", "--all-remotes"]) |
| 1452 |
} |