| 1 |
// Copyright 2023 The Jujutsu Authors |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// https://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
use std::io::Write as _; |
| 16 |
|
| 17 |
use indoc::indoc; |
| 18 |
use testutils::TestResult; |
| 19 |
use testutils::git; |
| 20 |
|
| 21 |
use crate::common::CommandOutput; |
| 22 |
use crate::common::TestEnvironment; |
| 23 |
use crate::common::TestWorkDir; |
| 24 |
use crate::common::create_commit; |
| 25 |
|
| 26 |
fn add_commit_to_branch(git_repo: &gix::Repository, branch: &str, message: &str) -> gix::ObjectId { |
| 27 |
// Get current commit ID of the branch if it exists |
| 28 |
let parents = git_repo |
| 29 |
.find_reference(&format!("refs/heads/{branch}")) |
| 30 |
.ok() |
| 31 |
.and_then(|mut r| r.peel_to_commit().ok()) |
| 32 |
.map(|c| vec![c.id().detach()]) |
| 33 |
.unwrap_or_default(); |
| 34 |
|
| 35 |
git::add_commit( |
| 36 |
git_repo, |
| 37 |
&format!("refs/heads/{branch}"), |
| 38 |
branch, // filename |
| 39 |
branch.as_bytes(), // content |
| 40 |
message, |
| 41 |
&parents, |
| 42 |
) |
| 43 |
.commit_id |
| 44 |
} |
| 45 |
|
| 46 |
/// Creates a remote Git repo containing a bookmark with the same name |
| 47 |
fn init_git_remote(test_env: &TestEnvironment, remote: &str) -> gix::Repository { |
| 48 |
let git_repo_path = test_env.env_root().join(remote); |
| 49 |
let git_repo = git::init(git_repo_path); |
| 50 |
add_commit_to_branch(&git_repo, remote, "message"); |
| 51 |
|
| 52 |
git_repo |
| 53 |
} |
| 54 |
|
| 55 |
/// Add a remote containing a bookmark with the same name |
| 56 |
fn add_git_remote( |
| 57 |
test_env: &TestEnvironment, |
| 58 |
work_dir: &TestWorkDir, |
| 59 |
remote: &str, |
| 60 |
) -> gix::Repository { |
| 61 |
let repo = init_git_remote(test_env, remote); |
| 62 |
work_dir |
| 63 |
.run_jj(["git", "remote", "add", remote, &format!("../{remote}")]) |
| 64 |
.success(); |
| 65 |
|
| 66 |
repo |
| 67 |
} |
| 68 |
|
| 69 |
#[must_use] |
| 70 |
fn get_bookmark_output(work_dir: &TestWorkDir) -> CommandOutput { |
| 71 |
// --quiet to suppress deleted bookmarks hint |
| 72 |
work_dir.run_jj(["bookmark", "list", "--all-remotes", "--quiet"]) |
| 73 |
} |
| 74 |
|
| 75 |
#[must_use] |
| 76 |
fn get_tag_output(work_dir: &TestWorkDir) -> CommandOutput { |
| 77 |
work_dir.run_jj(["tag", "list", "--all-remotes"]) |
| 78 |
} |
| 79 |
|
| 80 |
#[must_use] |
| 81 |
fn get_log_output(work_dir: &TestWorkDir) -> CommandOutput { |
| 82 |
let template = indoc! {r#" |
| 83 |
separate(" ", |
| 84 |
commit_id.short(), |
| 85 |
'"' ++ description.first_line() ++ '"', |
| 86 |
bookmarks, |
| 87 |
tags, |
| 88 |
) ++ "\n" |
| 89 |
"#}; |
| 90 |
work_dir.run_jj(["log", "-T", template, "-r", "all()"]) |
| 91 |
} |
| 92 |
|
| 93 |
fn clone_git_remote_into( |
| 94 |
test_env: &TestEnvironment, |
| 95 |
upstream: &str, |
| 96 |
fork: &str, |
| 97 |
) -> gix::Repository { |
| 98 |
let upstream_path = test_env.env_root().join(upstream); |
| 99 |
let fork_path = test_env.env_root().join(fork); |
| 100 |
let fork_repo = git::clone(&fork_path, upstream_path.to_str().unwrap(), Some(upstream)); |
| 101 |
|
| 102 |
// create local branch mirroring the upstream |
| 103 |
let upstream_head = fork_repo |
| 104 |
.find_reference(&format!("refs/remotes/{upstream}/{upstream}")) |
| 105 |
.unwrap() |
| 106 |
.peel_to_id() |
| 107 |
.unwrap() |
| 108 |
.detach(); |
| 109 |
|
| 110 |
fork_repo |
| 111 |
.reference( |
| 112 |
format!("refs/heads/{upstream}"), |
| 113 |
upstream_head, |
| 114 |
gix::refs::transaction::PreviousValue::MustNotExist, |
| 115 |
"create tracking head", |
| 116 |
) |
| 117 |
.unwrap(); |
| 118 |
|
| 119 |
fork_repo |
| 120 |
} |
| 121 |
|
| 122 |
#[test] |
| 123 |
fn test_git_fetch_with_default_config() { |
| 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 |
add_git_remote(&test_env, &work_dir, "origin"); |
| 128 |
|
| 129 |
// If supported, this should show fetched refs without actually updating |
| 130 |
// refs on disk. |
| 131 |
let output = work_dir.run_jj(["git", "fetch", "--no-integrate-operation"]); |
| 132 |
insta::assert_snapshot!(output, @" |
| 133 |
------- stderr ------- |
| 134 |
Error: --no-integrate-operation is not respected |
| 135 |
[EOF] |
| 136 |
[exit status: 2] |
| 137 |
"); |
| 138 |
|
| 139 |
let output = work_dir.run_jj(["git", "fetch"]); |
| 140 |
insta::assert_snapshot!(output, @" |
| 141 |
------- stderr ------- |
| 142 |
bookmark: origin@origin [new] untracked |
| 143 |
[EOF] |
| 144 |
"); |
| 145 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @" |
| 146 |
origin@origin: qmyrypzk ab8b299e message |
| 147 |
[EOF] |
| 148 |
"); |
| 149 |
} |
| 150 |
|
| 151 |
#[test] |
| 152 |
fn test_git_fetch_default_remote() { |
| 153 |
let test_env = TestEnvironment::default(); |
| 154 |
test_env.add_config("remotes.origin.auto-track-bookmarks = '*'"); |
| 155 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 156 |
let work_dir = test_env.work_dir("repo"); |
| 157 |
add_git_remote(&test_env, &work_dir, "origin"); |
| 158 |
|
| 159 |
work_dir.run_jj(["git", "fetch"]).success(); |
| 160 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @" |
| 161 |
origin: qmyrypzk ab8b299e message |
| 162 |
@origin: qmyrypzk ab8b299e message |
| 163 |
[EOF] |
| 164 |
"); |
| 165 |
} |
| 166 |
|
| 167 |
#[test] |
| 168 |
fn test_git_fetch_single_remote() { |
| 169 |
let test_env = TestEnvironment::default(); |
| 170 |
test_env.add_config("remotes.rem1.auto-track-bookmarks = '*'"); |
| 171 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 172 |
let work_dir = test_env.work_dir("repo"); |
| 173 |
add_git_remote(&test_env, &work_dir, "rem1"); |
| 174 |
|
| 175 |
let output = work_dir.run_jj(["git", "fetch"]); |
| 176 |
insta::assert_snapshot!(output, @" |
| 177 |
------- stderr ------- |
| 178 |
Hint: Fetching from the only existing remote: rem1 |
| 179 |
bookmark: rem1@rem1 [new] tracked |
| 180 |
[EOF] |
| 181 |
"); |
| 182 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @" |
| 183 |
rem1: ppspxspk 4acd0343 message |
| 184 |
@rem1: ppspxspk 4acd0343 message |
| 185 |
[EOF] |
| 186 |
"); |
| 187 |
} |
| 188 |
|
| 189 |
#[test] |
| 190 |
fn test_git_fetch_single_remote_all_remotes_flag() { |
| 191 |
let test_env = TestEnvironment::default(); |
| 192 |
test_env.add_config("remotes.rem1.auto-track-bookmarks = '*'"); |
| 193 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 194 |
let work_dir = test_env.work_dir("repo"); |
| 195 |
add_git_remote(&test_env, &work_dir, "rem1"); |
| 196 |
|
| 197 |
work_dir.run_jj(["git", "fetch", "--all-remotes"]).success(); |
| 198 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @" |
| 199 |
rem1: ppspxspk 4acd0343 message |
| 200 |
@rem1: ppspxspk 4acd0343 message |
| 201 |
[EOF] |
| 202 |
"); |
| 203 |
} |
| 204 |
|
| 205 |
#[test] |
| 206 |
fn test_git_fetch_single_remote_from_arg() { |
| 207 |
let test_env = TestEnvironment::default(); |
| 208 |
test_env.add_config("remotes.rem1.auto-track-bookmarks = '*'"); |
| 209 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 210 |
let work_dir = test_env.work_dir("repo"); |
| 211 |
add_git_remote(&test_env, &work_dir, "rem1"); |
| 212 |
|
| 213 |
work_dir |
| 214 |
.run_jj(["git", "fetch", "--remote", "rem1"]) |
| 215 |
.success(); |
| 216 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @" |
| 217 |
rem1: ppspxspk 4acd0343 message |
| 218 |
@rem1: ppspxspk 4acd0343 message |
| 219 |
[EOF] |
| 220 |
"); |
| 221 |
} |
| 222 |
|
| 223 |
#[test] |
| 224 |
fn test_git_fetch_single_remote_from_config() { |
| 225 |
let test_env = TestEnvironment::default(); |
| 226 |
test_env.add_config("remotes.rem1.auto-track-bookmarks = '*'"); |
| 227 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 228 |
let work_dir = test_env.work_dir("repo"); |
| 229 |
add_git_remote(&test_env, &work_dir, "rem1"); |
| 230 |
test_env.add_config(r#"git.fetch = "rem1""#); |
| 231 |
|
| 232 |
work_dir.run_jj(["git", "fetch"]).success(); |
| 233 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @" |
| 234 |
rem1: ppspxspk 4acd0343 message |
| 235 |
@rem1: ppspxspk 4acd0343 message |
| 236 |
[EOF] |
| 237 |
"); |
| 238 |
} |
| 239 |
|
| 240 |
#[test] |
| 241 |
fn test_git_fetch_multiple_remotes() { |
| 242 |
let test_env = TestEnvironment::default(); |
| 243 |
test_env.add_config("remotes.rem1.auto-track-bookmarks = '*'"); |
| 244 |
test_env.add_config("remotes.rem2.auto-track-bookmarks = '*'"); |
| 245 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 246 |
let work_dir = test_env.work_dir("repo"); |
| 247 |
add_git_remote(&test_env, &work_dir, "rem1"); |
| 248 |
add_git_remote(&test_env, &work_dir, "rem2"); |
| 249 |
|
| 250 |
work_dir |
| 251 |
.run_jj(["git", "fetch", "--remote", "rem1", "--remote", "rem2"]) |
| 252 |
.success(); |
| 253 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @" |
| 254 |
rem1: ppspxspk 4acd0343 message |
| 255 |
@rem1: ppspxspk 4acd0343 message |
| 256 |
rem2: pzqqpnpo 44c57802 message |
| 257 |
@rem2: pzqqpnpo 44c57802 message |
| 258 |
[EOF] |
| 259 |
"); |
| 260 |
} |
| 261 |
|
| 262 |
#[test] |
| 263 |
fn test_git_fetch_default_bookmarks_and_tags() { |
| 264 |
let test_env = TestEnvironment::default(); |
| 265 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 266 |
let work_dir = test_env.work_dir("repo"); |
| 267 |
|
| 268 |
let rem1_repo = add_git_remote(&test_env, &work_dir, "rem1"); |
| 269 |
let rem2_repo = add_git_remote(&test_env, &work_dir, "rem2"); |
| 270 |
let setup_opid = work_dir.current_operation_id(); |
| 271 |
|
| 272 |
git::add_commit(&rem1_repo, "refs/tags/tag1", "file", b"", "1a", &[]); |
| 273 |
git::add_commit(&rem1_repo, "refs/heads/branch1", "file", b"", "1b", &[]); |
| 274 |
git::add_commit(&rem1_repo, "refs/tags/tag2", "file", b"", "1c", &[]); |
| 275 |
git::add_commit(&rem1_repo, "refs/heads/branch2", "file", b"", "1d", &[]); |
| 276 |
git::add_commit(&rem2_repo, "refs/tags/tag1", "file", b"", "2a", &[]); |
| 277 |
git::add_commit(&rem2_repo, "refs/heads/branch1", "file", b"", "2b", &[]); |
| 278 |
git::add_commit(&rem2_repo, "refs/tags/tag2", "file", b"", "2c", &[]); |
| 279 |
git::add_commit(&rem2_repo, "refs/heads/branch2", "file", b"", "2d", &[]); |
| 280 |
|
| 281 |
// Per-remote default config |
| 282 |
test_env.add_config(indoc! {" |
| 283 |
[remotes.rem1] |
| 284 |
fetch-bookmarks = 'branch1' |
| 285 |
fetch-tags = 'tag1' |
| 286 |
[remotes.rem2] |
| 287 |
fetch-bookmarks = 'branch2' |
| 288 |
fetch-tags = 'tag2' |
| 289 |
"}); |
| 290 |
let output = work_dir.run_jj(["git", "fetch", "--all-remotes"]); |
| 291 |
insta::assert_snapshot!(output, @" |
| 292 |
------- stderr ------- |
| 293 |
bookmark: branch1@rem1 [new] untracked |
| 294 |
bookmark: branch2@rem2 [new] untracked |
| 295 |
tag: tag1@rem1 [new] tracked |
| 296 |
tag: tag2@rem2 [new] tracked |
| 297 |
[EOF] |
| 298 |
"); |
| 299 |
|
| 300 |
// Default fetch-bookmarks/tags should be disabled by --branch |
| 301 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 302 |
let output = work_dir.run_jj(["git", "fetch", "--all-remotes", "--branch=*"]); |
| 303 |
insta::assert_snapshot!(output, @" |
| 304 |
------- stderr ------- |
| 305 |
bookmark: branch1@rem1 [new] untracked |
| 306 |
bookmark: branch1@rem2 [new] untracked |
| 307 |
bookmark: branch2@rem1 [new] untracked |
| 308 |
bookmark: branch2@rem2 [new] untracked |
| 309 |
bookmark: rem1@rem1 [new] untracked |
| 310 |
bookmark: rem2@rem2 [new] untracked |
| 311 |
[EOF] |
| 312 |
"); |
| 313 |
|
| 314 |
// Default fetch-bookmarks/tags should be disabled by --tag |
| 315 |
work_dir.run_jj(["op", "restore", &setup_opid]).success(); |
| 316 |
let output = work_dir.run_jj(["git", "fetch", "--all-remotes", "--tag=~*"]); |
| 317 |
insta::assert_snapshot!(output, @" |
| 318 |
------- stderr ------- |
| 319 |
Nothing changed. |
| 320 |
[EOF] |
| 321 |
"); |
| 322 |
} |
| 323 |
|
| 324 |
#[test] |
| 325 |
fn test_git_fetch_with_ignored_refspecs() { |
| 326 |
let test_env = TestEnvironment::default(); |
| 327 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 328 |
let source_repo = init_git_remote(&test_env, "origin"); |
| 329 |
|
| 330 |
for branch in [ |
| 331 |
"main", "foo", "foobar", "foobaz", "bar", "sub/yes", "sub/no", |
| 332 |
] { |
| 333 |
add_commit_to_branch(&source_repo, branch, branch); |
| 334 |
} |
| 335 |
|
| 336 |
let work_dir = test_env.work_dir("repo"); |
| 337 |
std::fs::OpenOptions::new() |
| 338 |
.append(true) |
| 339 |
.open(work_dir.root().join(".jj/repo/store/git/config")) |
| 340 |
.expect("failed to open config file") |
| 341 |
.write_all( |
| 342 |
br#" |
| 343 |
[remote "origin"] |
| 344 |
url = ../origin/.git |
| 345 |
fetch = +refs/heads/main:refs/remotes/origin/main |
| 346 |
fetch = +refs/heads/sub/*:refs/remotes/origin/sub/* |
| 347 |
fetch = +refs/heads/foo*:refs/remotes/origin/baz* |
| 348 |
fetch = +refs/heads/bar*:refs/tags/bar* |
| 349 |
fetch = refs/heads/bar |
| 350 |
fetch = ^refs/heads/sub/no |
| 351 |
"#, |
| 352 |
) |
| 353 |
.expect("failed to update config file"); |
| 354 |
|
| 355 |
// Should fetch "main" and "sub/yes" by default |
| 356 |
let output = work_dir.run_jj(["git", "fetch"]); |
| 357 |
insta::assert_snapshot!(output, @" |
| 358 |
------- stderr ------- |
| 359 |
Warning: Ignored refspec `refs/heads/bar` from `origin`: fetch-only refspecs are not supported |
| 360 |
Warning: Ignored refspec `+refs/heads/bar*:refs/tags/bar*` from `origin`: only refs/remotes/ is supported for fetch destinations |
| 361 |
Warning: Ignored refspec `+refs/heads/foo*:refs/remotes/origin/baz*` from `origin`: renaming is not supported |
| 362 |
bookmark: main@origin [new] untracked |
| 363 |
bookmark: sub/yes@origin [new] untracked |
| 364 |
[EOF] |
| 365 |
"); |
| 366 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @" |
| 367 |
main@origin: wlltxvop a437242b main |
| 368 |
sub/yes@origin: xwxtqxvy 6b64b005 sub/yes |
| 369 |
[EOF] |
| 370 |
"); |
| 371 |
|
| 372 |
// Can fetch ignored "sub/no" explicitly |
| 373 |
let output = work_dir.run_jj(["git", "fetch", "--branch=sub/no"]); |
| 374 |
insta::assert_snapshot!(output, @" |
| 375 |
------- stderr ------- |
| 376 |
bookmark: sub/no@origin [new] untracked |
| 377 |
[EOF] |
| 378 |
"); |
| 379 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @" |
| 380 |
main@origin: wlltxvop a437242b main |
| 381 |
sub/no@origin: tknwmolt f7d8b914 sub/no |
| 382 |
sub/yes@origin: xwxtqxvy 6b64b005 sub/yes |
| 383 |
[EOF] |
| 384 |
"); |
| 385 |
|
| 386 |
// Forget "sub/no" without exporting the change to Git |
| 387 |
work_dir |
| 388 |
.run_jj(["bookmark", "forget", "--include-remotes", "sub/no"]) |
| 389 |
.success(); |
| 390 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @" |
| 391 |
main@origin: wlltxvop a437242b main |
| 392 |
sub/yes@origin: xwxtqxvy 6b64b005 sub/yes |
| 393 |
[EOF] |
| 394 |
"); |
| 395 |
|
| 396 |
// Should not import "sub/no" because it is ignored by default |
| 397 |
let output = work_dir.run_jj(["git", "fetch"]); |
| 398 |
insta::assert_snapshot!(output, @" |
| 399 |
------- stderr ------- |
| 400 |
Warning: Ignored refspec `refs/heads/bar` from `origin`: fetch-only refspecs are not supported |
| 401 |
Warning: Ignored refspec `+refs/heads/bar*:refs/tags/bar*` from `origin`: only refs/remotes/ is supported for fetch destinations |
| 402 |
Warning: Ignored refspec `+refs/heads/foo*:refs/remotes/origin/baz*` from `origin`: renaming is not supported |
| 403 |
Nothing changed. |
| 404 |
[EOF] |
| 405 |
"); |
| 406 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @" |
| 407 |
main@origin: wlltxvop a437242b main |
| 408 |
sub/yes@origin: xwxtqxvy 6b64b005 sub/yes |
| 409 |
[EOF] |
| 410 |
"); |
| 411 |
} |
| 412 |
|
| 413 |
#[test] |
| 414 |
fn test_git_fetch_with_glob() { |
| 415 |
let test_env = TestEnvironment::default(); |
| 416 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 417 |
let work_dir = test_env.work_dir("repo"); |
| 418 |
add_git_remote(&test_env, &work_dir, "rem1"); |
| 419 |
add_git_remote(&test_env, &work_dir, "rem2"); |
| 420 |
|
| 421 |
let output = work_dir.run_jj(["git", "fetch", "--remote", "*"]); |
| 422 |
insta::assert_snapshot!(output, @" |
| 423 |
------- stderr ------- |
| 424 |
bookmark: rem1@rem1 [new] untracked |
| 425 |
bookmark: rem2@rem2 [new] untracked |
| 426 |
[EOF] |
| 427 |
"); |
| 428 |
} |
| 429 |
|
| 430 |
#[test] |
| 431 |
fn test_git_fetch_with_glob_and_exact_match() { |
| 432 |
let test_env = TestEnvironment::default(); |
| 433 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 434 |
let work_dir = test_env.work_dir("repo"); |
| 435 |
add_git_remote(&test_env, &work_dir, "rem1"); |
| 436 |
add_git_remote(&test_env, &work_dir, "rem2"); |
| 437 |
add_git_remote(&test_env, &work_dir, "upstream1"); |
| 438 |
add_git_remote(&test_env, &work_dir, "upstream2"); |
| 439 |
add_git_remote(&test_env, &work_dir, "origin"); |
| 440 |
|
| 441 |
let output = work_dir.run_jj(["git", "fetch", "--remote=rem*", "--remote=origin"]); |
| 442 |
insta::assert_snapshot!(output, @" |
| 443 |
------- stderr ------- |
| 444 |
bookmark: origin@origin [new] untracked |
| 445 |
bookmark: rem1@rem1 [new] untracked |
| 446 |
bookmark: rem2@rem2 [new] untracked |
| 447 |
[EOF] |
| 448 |
"); |
| 449 |
} |
| 450 |
|
| 451 |
#[test] |
| 452 |
fn test_git_fetch_with_glob_from_config() { |
| 453 |
let test_env = TestEnvironment::default(); |
| 454 |
test_env.add_config(r#"git.fetch = "rem*""#); |
| 455 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 456 |
let work_dir = test_env.work_dir("repo"); |
| 457 |
add_git_remote(&test_env, &work_dir, "rem1"); |
| 458 |
add_git_remote(&test_env, &work_dir, "rem2"); |
| 459 |
add_git_remote(&test_env, &work_dir, "upstream"); |
| 460 |
|
| 461 |
let output = work_dir.run_jj(["git", "fetch"]); |
| 462 |
insta::assert_snapshot!(output, @" |
| 463 |
------- stderr ------- |
| 464 |
bookmark: rem1@rem1 [new] untracked |
| 465 |
bookmark: rem2@rem2 [new] untracked |
| 466 |
[EOF] |
| 467 |
"); |
| 468 |
} |
| 469 |
|
| 470 |
#[test] |
| 471 |
fn test_git_fetch_with_glob_with_no_matching_remotes() { |
| 472 |
let test_env = TestEnvironment::default(); |
| 473 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 474 |
let work_dir = test_env.work_dir("repo"); |
| 475 |
add_git_remote(&test_env, &work_dir, "upstream"); |
| 476 |
|
| 477 |
let output = work_dir.run_jj(["git", "fetch", "--remote=rem*"]); |
| 478 |
insta::assert_snapshot!(output, @" |
| 479 |
------- stderr ------- |
| 480 |
Error: No git remotes to fetch from |
| 481 |
[EOF] |
| 482 |
[exit status: 1] |
| 483 |
"); |
| 484 |
// No remote should have been fetched as part of the failing transaction |
| 485 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @""); |
| 486 |
} |
| 487 |
|
| 488 |
#[test] |
| 489 |
fn test_git_fetch_all_remotes() { |
| 490 |
let test_env = TestEnvironment::default(); |
| 491 |
test_env.add_config("remotes.rem1.auto-track-bookmarks = '*'"); |
| 492 |
test_env.add_config("remotes.rem2.auto-track-bookmarks = '*'"); |
| 493 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 494 |
let work_dir = test_env.work_dir("repo"); |
| 495 |
add_git_remote(&test_env, &work_dir, "rem1"); |
| 496 |
add_git_remote(&test_env, &work_dir, "rem2"); |
| 497 |
|
| 498 |
// add empty [remote "rem3"] section to .git/config, which should be ignored |
| 499 |
work_dir |
| 500 |
.run_jj(["git", "remote", "add", "rem3", "../unknown"]) |
| 501 |
.success(); |
| 502 |
work_dir |
| 503 |
.run_jj(["git", "remote", "remove", "rem3"]) |
| 504 |
.success(); |
| 505 |
|
| 506 |
work_dir.run_jj(["git", "fetch", "--all-remotes"]).success(); |
| 507 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @" |
| 508 |
rem1: ppspxspk 4acd0343 message |
| 509 |
@rem1: ppspxspk 4acd0343 message |
| 510 |
rem2: pzqqpnpo 44c57802 message |
| 511 |
@rem2: pzqqpnpo 44c57802 message |
| 512 |
[EOF] |
| 513 |
"); |
| 514 |
} |
| 515 |
|
| 516 |
#[test] |
| 517 |
fn test_git_fetch_multiple_remotes_from_config() { |
| 518 |
let test_env = TestEnvironment::default(); |
| 519 |
test_env.add_config("remotes.rem1.auto-track-bookmarks = '*'"); |
| 520 |
test_env.add_config("remotes.rem2.auto-track-bookmarks = '*'"); |
| 521 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 522 |
let work_dir = test_env.work_dir("repo"); |
| 523 |
add_git_remote(&test_env, &work_dir, "rem1"); |
| 524 |
add_git_remote(&test_env, &work_dir, "rem2"); |
| 525 |
test_env.add_config(r#"git.fetch = ["rem1", "rem2"]"#); |
| 526 |
|
| 527 |
work_dir.run_jj(["git", "fetch"]).success(); |
| 528 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @" |
| 529 |
rem1: ppspxspk 4acd0343 message |
| 530 |
@rem1: ppspxspk 4acd0343 message |
| 531 |
rem2: pzqqpnpo 44c57802 message |
| 532 |
@rem2: pzqqpnpo 44c57802 message |
| 533 |
[EOF] |
| 534 |
"); |
| 535 |
} |
| 536 |
|
| 537 |
#[test] |
| 538 |
fn test_git_fetch_no_matching_remote() { |
| 539 |
let test_env = TestEnvironment::default(); |
| 540 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 541 |
let work_dir = test_env.work_dir("repo"); |
| 542 |
|
| 543 |
let output = work_dir.run_jj(["git", "fetch", "--remote", "rem1"]); |
| 544 |
insta::assert_snapshot!(output, @" |
| 545 |
------- stderr ------- |
| 546 |
Warning: No matching remotes for names: rem1 |
| 547 |
Error: No git remotes to fetch from |
| 548 |
[EOF] |
| 549 |
[exit status: 1] |
| 550 |
"); |
| 551 |
|
| 552 |
let output = work_dir.run_jj(["git", "fetch", "--remote=rem1", "--remote=rem2"]); |
| 553 |
insta::assert_snapshot!(output, @" |
| 554 |
------- stderr ------- |
| 555 |
Warning: No matching remotes for names: rem1, rem2 |
| 556 |
Error: No git remotes to fetch from |
| 557 |
[EOF] |
| 558 |
[exit status: 1] |
| 559 |
"); |
| 560 |
|
| 561 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @""); |
| 562 |
} |
| 563 |
|
| 564 |
#[test] |
| 565 |
fn test_git_fetch_nonexistent_remote() { |
| 566 |
let test_env = TestEnvironment::default(); |
| 567 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 568 |
let work_dir = test_env.work_dir("repo"); |
| 569 |
add_git_remote(&test_env, &work_dir, "rem1"); |
| 570 |
|
| 571 |
let output = work_dir.run_jj(["git", "fetch", "--remote", "rem1", "--remote", "rem2"]); |
| 572 |
insta::assert_snapshot!(output, @" |
| 573 |
------- stderr ------- |
| 574 |
Warning: No matching remotes for names: rem2 |
| 575 |
bookmark: rem1@rem1 [new] untracked |
| 576 |
[EOF] |
| 577 |
"); |
| 578 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @" |
| 579 |
rem1@rem1: ppspxspk 4acd0343 message |
| 580 |
[EOF] |
| 581 |
"); |
| 582 |
} |
| 583 |
|
| 584 |
#[test] |
| 585 |
fn test_git_fetch_nonexistent_remote_from_config() { |
| 586 |
let test_env = TestEnvironment::default(); |
| 587 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 588 |
let work_dir = test_env.work_dir("repo"); |
| 589 |
add_git_remote(&test_env, &work_dir, "rem1"); |
| 590 |
test_env.add_config(r#"git.fetch = ["rem1", "rem2"]"#); |
| 591 |
|
| 592 |
let output = work_dir.run_jj(["git", "fetch"]); |
| 593 |
insta::assert_snapshot!(output, @" |
| 594 |
------- stderr ------- |
| 595 |
Warning: No matching remotes for names: rem2 |
| 596 |
bookmark: rem1@rem1 [new] untracked |
| 597 |
[EOF] |
| 598 |
"); |
| 599 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @" |
| 600 |
rem1@rem1: ppspxspk 4acd0343 message |
| 601 |
[EOF] |
| 602 |
"); |
| 603 |
} |
| 604 |
|
| 605 |
#[test] |
| 606 |
fn test_git_fetch_from_remote_named_git() { |
| 607 |
let test_env = TestEnvironment::default(); |
| 608 |
test_env.add_config("remotes.bar.auto-track-bookmarks = '*'"); |
| 609 |
let work_dir = test_env.work_dir("repo"); |
| 610 |
init_git_remote(&test_env, "git"); |
| 611 |
|
| 612 |
git::init(work_dir.root()); |
| 613 |
git::add_remote(work_dir.root(), "git", "../git"); |
| 614 |
|
| 615 |
// Existing remote named 'git' shouldn't block the repo initialization. |
| 616 |
work_dir.run_jj(["git", "init", "--git-repo=."]).success(); |
| 617 |
|
| 618 |
// Try fetching from the remote named 'git'. |
| 619 |
let output = work_dir.run_jj(["git", "fetch", "--remote=git"]); |
| 620 |
insta::assert_snapshot!(output, @" |
| 621 |
------- stderr ------- |
| 622 |
Error: Git remote named 'git' is reserved for local Git repository |
| 623 |
Hint: Run `jj git remote rename` to give a different name. |
| 624 |
[EOF] |
| 625 |
[exit status: 1] |
| 626 |
"); |
| 627 |
|
| 628 |
// Fetch remote refs by using the git CLI. |
| 629 |
git::fetch(work_dir.root(), "git"); |
| 630 |
|
| 631 |
// Implicit import shouldn't fail because of the remote ref. |
| 632 |
let output = work_dir.run_jj(["bookmark", "list", "--all-remotes"]); |
| 633 |
insta::assert_snapshot!(output, @" |
| 634 |
------- stderr ------- |
| 635 |
Warning: Failed to import some Git refs: |
| 636 |
refs/remotes/git/git |
| 637 |
Hint: Git remote named 'git' is reserved for local Git repository. |
| 638 |
Use `jj git remote rename` to give a different name. |
| 639 |
[EOF] |
| 640 |
"); |
| 641 |
|
| 642 |
// Explicit import also works. Warnings should be printed with --quiet, but |
| 643 |
// hints shouldn't. |
| 644 |
insta::assert_snapshot!(work_dir.run_jj(["git", "import", "--quiet"]), @" |
| 645 |
------- stderr ------- |
| 646 |
Warning: Failed to import some Git refs: |
| 647 |
refs/remotes/git/git |
| 648 |
[EOF] |
| 649 |
"); |
| 650 |
|
| 651 |
// The remote can be renamed, and the ref can be imported. |
| 652 |
work_dir |
| 653 |
.run_jj(["git", "remote", "rename", "git", "bar"]) |
| 654 |
.success(); |
| 655 |
let output = work_dir.run_jj(["bookmark", "list", "--all-remotes"]); |
| 656 |
insta::assert_snapshot!(output, @" |
| 657 |
git: vkponlun 400c483d message |
| 658 |
@bar: vkponlun 400c483d message |
| 659 |
@git: vkponlun 400c483d message |
| 660 |
[EOF] |
| 661 |
------- stderr ------- |
| 662 |
Done importing changes from the underlying Git repo. |
| 663 |
[EOF] |
| 664 |
"); |
| 665 |
} |
| 666 |
|
| 667 |
#[test] |
| 668 |
fn test_git_fetch_from_remote_with_slashes() { |
| 669 |
let test_env = TestEnvironment::default(); |
| 670 |
test_env.add_config("remotes.origin.auto-track-bookmarks = '*'"); |
| 671 |
let work_dir = test_env.work_dir("repo"); |
| 672 |
init_git_remote(&test_env, "source"); |
| 673 |
|
| 674 |
git::init(work_dir.root()); |
| 675 |
git::add_remote(work_dir.root(), "slash/origin", "../source"); |
| 676 |
|
| 677 |
// Existing remote with slash shouldn't block the repo initialization. |
| 678 |
work_dir.run_jj(["git", "init", "--git-repo=."]).success(); |
| 679 |
|
| 680 |
// Try fetching from the remote named 'git'. |
| 681 |
let output = work_dir.run_jj(["git", "fetch", "--remote=slash/origin"]); |
| 682 |
insta::assert_snapshot!(output, @" |
| 683 |
------- stderr ------- |
| 684 |
Error: Git remotes with slashes are incompatible with jj: slash/origin |
| 685 |
Hint: Run `jj git remote rename` to give a different name. |
| 686 |
[EOF] |
| 687 |
[exit status: 1] |
| 688 |
"); |
| 689 |
} |
| 690 |
|
| 691 |
#[test] |
| 692 |
fn test_git_fetch_prune_before_updating_tips() -> TestResult { |
| 693 |
let test_env = TestEnvironment::default(); |
| 694 |
test_env.add_config("remotes.origin.auto-track-bookmarks = '*'"); |
| 695 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 696 |
let work_dir = test_env.work_dir("repo"); |
| 697 |
let git_repo = add_git_remote(&test_env, &work_dir, "origin"); |
| 698 |
work_dir.run_jj(["git", "fetch"]).success(); |
| 699 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @" |
| 700 |
origin: qmyrypzk ab8b299e message |
| 701 |
@origin: qmyrypzk ab8b299e message |
| 702 |
[EOF] |
| 703 |
"); |
| 704 |
|
| 705 |
// Remove origin bookmark in git repo and create origin/subname |
| 706 |
let mut origin_reference = git_repo.find_reference("refs/heads/origin")?; |
| 707 |
let commit_id = origin_reference.peel_to_commit()?.id().detach(); |
| 708 |
origin_reference.delete()?; |
| 709 |
git_repo.reference( |
| 710 |
"refs/heads/origin/subname", |
| 711 |
commit_id, |
| 712 |
gix::refs::transaction::PreviousValue::MustNotExist, |
| 713 |
"create new reference", |
| 714 |
)?; |
| 715 |
|
| 716 |
work_dir.run_jj(["git", "fetch"]).success(); |
| 717 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @" |
| 718 |
origin/subname: qmyrypzk ab8b299e message |
| 719 |
@origin: qmyrypzk ab8b299e message |
| 720 |
[EOF] |
| 721 |
"); |
| 722 |
Ok(()) |
| 723 |
} |
| 724 |
|
| 725 |
#[test] |
| 726 |
fn test_git_fetch_conflicting_bookmarks() { |
| 727 |
let test_env = TestEnvironment::default(); |
| 728 |
test_env.add_config("remotes.rem1.auto-track-bookmarks = '*'"); |
| 729 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 730 |
let work_dir = test_env.work_dir("repo"); |
| 731 |
add_git_remote(&test_env, &work_dir, "rem1"); |
| 732 |
|
| 733 |
// Create a rem1 bookmark locally |
| 734 |
work_dir.run_jj(["new", "root()"]).success(); |
| 735 |
work_dir |
| 736 |
.run_jj(["bookmark", "create", "-r@", "rem1"]) |
| 737 |
.success(); |
| 738 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @" |
| 739 |
rem1: kkmpptxz 2b17ac71 (empty) (no description set) |
| 740 |
@rem1 (not created yet) |
| 741 |
[EOF] |
| 742 |
"); |
| 743 |
|
| 744 |
work_dir |
| 745 |
.run_jj(["git", "fetch", "--remote", "rem1", "--branch", "*"]) |
| 746 |
.success(); |
| 747 |
// This should result in a CONFLICTED bookmark |
| 748 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @" |
| 749 |
rem1 (conflicted): |
| 750 |
+ kkmpptxz 2b17ac71 (empty) (no description set) |
| 751 |
+ ppspxspk 4acd0343 message |
| 752 |
@rem1 (behind by 1 commits): ppspxspk 4acd0343 message |
| 753 |
[EOF] |
| 754 |
"); |
| 755 |
} |
| 756 |
|
| 757 |
#[test] |
| 758 |
fn test_git_fetch_conflicting_bookmarks_colocated() { |
| 759 |
let test_env = TestEnvironment::default(); |
| 760 |
test_env.add_config("remotes.rem1.auto-track-bookmarks = '*'"); |
| 761 |
let work_dir = test_env.work_dir("repo"); |
| 762 |
git::init(work_dir.root()); |
| 763 |
// create_colocated_repo_and_bookmarks_from_trunk1(&test_env, &repo_path); |
| 764 |
work_dir |
| 765 |
.run_jj(["git", "init", "--git-repo", "."]) |
| 766 |
.success(); |
| 767 |
add_git_remote(&test_env, &work_dir, "rem1"); |
| 768 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @""); |
| 769 |
|
| 770 |
// Create a rem1 bookmark locally |
| 771 |
work_dir.run_jj(["new", "root()"]).success(); |
| 772 |
work_dir |
| 773 |
.run_jj(["bookmark", "create", "-r@", "rem1"]) |
| 774 |
.success(); |
| 775 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @" |
| 776 |
rem1: zsuskuln c2934cfb (empty) (no description set) |
| 777 |
@git: zsuskuln c2934cfb (empty) (no description set) |
| 778 |
@rem1 (not created yet) |
| 779 |
[EOF] |
| 780 |
"); |
| 781 |
|
| 782 |
work_dir |
| 783 |
.run_jj(["git", "fetch", "--remote", "rem1", "--branch", "rem1"]) |
| 784 |
.success(); |
| 785 |
// This should result in a CONFLICTED bookmark |
| 786 |
// See https://github.com/jj-vcs/jj/pull/1146#discussion_r1112372340 for the bug this tests for. |
| 787 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @" |
| 788 |
rem1 (conflicted): |
| 789 |
+ zsuskuln c2934cfb (empty) (no description set) |
| 790 |
+ ppspxspk 4acd0343 message |
| 791 |
@git (behind by 1 commits): zsuskuln c2934cfb (empty) (no description set) |
| 792 |
@rem1 (behind by 1 commits): ppspxspk 4acd0343 message |
| 793 |
[EOF] |
| 794 |
"); |
| 795 |
} |
| 796 |
|
| 797 |
#[test] |
| 798 |
fn test_git_fetch_tags_by_name() -> TestResult { |
| 799 |
let test_env = TestEnvironment::default(); |
| 800 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 801 |
let work_dir = test_env.work_dir("repo"); |
| 802 |
|
| 803 |
// Create remote branches and tags |
| 804 |
let origin_git_repo = add_git_remote(&test_env, &work_dir, "origin"); |
| 805 |
let commit1_oid = origin_git_repo |
| 806 |
.find_reference("refs/heads/origin")? |
| 807 |
.id() |
| 808 |
.detach(); |
| 809 |
for name in ["tag1", "tag2", "tag3"] { |
| 810 |
let constraint = gix::refs::transaction::PreviousValue::MustNotExist; |
| 811 |
origin_git_repo.tag_reference(name, commit1_oid, constraint)?; |
| 812 |
} |
| 813 |
|
| 814 |
// --tag disables default refspecs |
| 815 |
let output = work_dir.run_jj(["git", "fetch", "--tag=~*"]); |
| 816 |
insta::assert_snapshot!(output, @" |
| 817 |
------- stderr ------- |
| 818 |
Nothing changed. |
| 819 |
[EOF] |
| 820 |
"); |
| 821 |
|
| 822 |
// Fetch branches but no tags |
| 823 |
let output = work_dir.run_jj(["git", "fetch", "--branch=*", "--tag=~*"]); |
| 824 |
insta::assert_snapshot!(output, @" |
| 825 |
------- stderr ------- |
| 826 |
bookmark: origin@origin [new] untracked |
| 827 |
[EOF] |
| 828 |
"); |
| 829 |
|
| 830 |
// Fetch tag1 |
| 831 |
let output = work_dir.run_jj(["git", "fetch", "--tag=tag1"]); |
| 832 |
insta::assert_snapshot!(output, @" |
| 833 |
------- stderr ------- |
| 834 |
tag: tag1@origin [new] tracked |
| 835 |
[EOF] |
| 836 |
"); |
| 837 |
|
| 838 |
// Fetch other tags |
| 839 |
let output = work_dir.run_jj(["git", "fetch", "--tag=*"]); |
| 840 |
insta::assert_snapshot!(output, @" |
| 841 |
------- stderr ------- |
| 842 |
tag: tag2@origin [new] tracked |
| 843 |
tag: tag3@origin [new] tracked |
| 844 |
[EOF] |
| 845 |
"); |
| 846 |
|
| 847 |
insta::assert_snapshot!(get_tag_output(&work_dir), @" |
| 848 |
tag1: qmyrypzk ab8b299e message |
| 849 |
@origin: qmyrypzk ab8b299e message |
| 850 |
tag2: qmyrypzk ab8b299e message |
| 851 |
@origin: qmyrypzk ab8b299e message |
| 852 |
tag3: qmyrypzk ab8b299e message |
| 853 |
@origin: qmyrypzk ab8b299e message |
| 854 |
[EOF] |
| 855 |
"); |
| 856 |
|
| 857 |
// Move and delete tags at remote |
| 858 |
let commit2_oid = add_commit_to_branch(&origin_git_repo, "origin", "commit 2"); |
| 859 |
let constraint = gix::refs::transaction::PreviousValue::MustExistAndMatch(commit1_oid.into()); |
| 860 |
origin_git_repo.tag_reference("tag1", commit2_oid, constraint)?; |
| 861 |
origin_git_repo.find_reference("refs/tags/tag2")?.delete()?; |
| 862 |
|
| 863 |
// Fetch tag changes |
| 864 |
let output = work_dir.run_jj(["git", "fetch", "--tag=*"]); |
| 865 |
insta::assert_snapshot!(output, @" |
| 866 |
------- stderr ------- |
| 867 |
tag: tag1@origin [updated] tracked |
| 868 |
tag: tag2@origin [deleted] untracked |
| 869 |
[EOF] |
| 870 |
"); |
| 871 |
|
| 872 |
insta::assert_snapshot!(get_tag_output(&work_dir), @" |
| 873 |
tag1: vqswlzks a439bb0e (empty) commit 2 |
| 874 |
@origin: vqswlzks a439bb0e (empty) commit 2 |
| 875 |
tag3: qmyrypzk ab8b299e message |
| 876 |
@origin: qmyrypzk ab8b299e message |
| 877 |
[EOF] |
| 878 |
"); |
| 879 |
Ok(()) |
| 880 |
} |
| 881 |
|
| 882 |
// Helper functions to test obtaining multiple bookmarks at once and changed |
| 883 |
// bookmarks |
| 884 |
fn create_colocated_repo_and_bookmarks_from_trunk1(work_dir: &TestWorkDir) -> String { |
| 885 |
// Create a colocated workspace in `source` to populate it more easily |
| 886 |
work_dir |
| 887 |
.run_jj(["git", "init", "--git-repo", "."]) |
| 888 |
.success(); |
| 889 |
create_commit(work_dir, "trunk1", &[]); |
| 890 |
create_commit(work_dir, "a1", &["trunk1"]); |
| 891 |
create_commit(work_dir, "a2", &["trunk1"]); |
| 892 |
create_commit(work_dir, "b", &["trunk1"]); |
| 893 |
format!( |
| 894 |
" ===== Source git repo contents =====\n{}", |
| 895 |
get_log_output(work_dir) |
| 896 |
) |
| 897 |
} |
| 898 |
|
| 899 |
fn create_trunk2_and_rebase_bookmarks(work_dir: &TestWorkDir) -> String { |
| 900 |
create_commit(work_dir, "trunk2", &["trunk1"]); |
| 901 |
for br in ["a1", "a2", "b"] { |
| 902 |
work_dir |
| 903 |
.run_jj(["rebase", "-b", br, "-o", "trunk2"]) |
| 904 |
.success(); |
| 905 |
} |
| 906 |
format!( |
| 907 |
" ===== Source git repo contents =====\n{}", |
| 908 |
get_log_output(work_dir) |
| 909 |
) |
| 910 |
} |
| 911 |
|
| 912 |
#[test] |
| 913 |
fn test_git_fetch_all() { |
| 914 |
let test_env = TestEnvironment::default(); |
| 915 |
test_env.add_config("remotes.origin.auto-track-bookmarks = '*'"); |
| 916 |
test_env.add_config(r#"revset-aliases."immutable_heads()" = "none()""#); |
| 917 |
let source_dir = test_env.work_dir("source"); |
| 918 |
git::init(source_dir.root()); |
| 919 |
|
| 920 |
// Clone an empty repo. The target repo is a normal `jj` repo, *not* colocated |
| 921 |
let output = test_env.run_jj_in(".", ["git", "clone", "source", "target"]); |
| 922 |
insta::assert_snapshot!(output, @r#" |
| 923 |
------- stderr ------- |
| 924 |
Fetching into new repo in "$TEST_ENV/target" |
| 925 |
Nothing changed. |
| 926 |
[EOF] |
| 927 |
"#); |
| 928 |
let target_dir = test_env.work_dir("target"); |
| 929 |
|
| 930 |
let source_log = create_colocated_repo_and_bookmarks_from_trunk1(&source_dir); |
| 931 |
insta::assert_snapshot!(source_log, @r#" |
| 932 |
===== Source git repo contents ===== |
| 933 |
@ bc83465a3090 "b" b |
| 934 |
│ ○ d4d535f1d579 "a2" a2 |
| 935 |
├─╯ |
| 936 |
│ ○ c8303692b8e2 "a1" a1 |
| 937 |
├─╯ |
| 938 |
○ 382881770501 "trunk1" trunk1 |
| 939 |
◆ 000000000000 "" |
| 940 |
[EOF] |
| 941 |
"#); |
| 942 |
|
| 943 |
// Nothing in our repo before the fetch |
| 944 |
insta::assert_snapshot!(get_log_output(&target_dir), @r#" |
| 945 |
@ e8849ae12c70 "" |
| 946 |
◆ 000000000000 "" |
| 947 |
[EOF] |
| 948 |
"#); |
| 949 |
insta::assert_snapshot!(get_bookmark_output(&target_dir), @""); |
| 950 |
let output = target_dir.run_jj(["git", "fetch"]); |
| 951 |
insta::assert_snapshot!(output, @" |
| 952 |
------- stderr ------- |
| 953 |
bookmark: a1@origin [new] tracked |
| 954 |
bookmark: a2@origin [new] tracked |
| 955 |
bookmark: b@origin [new] tracked |
| 956 |
bookmark: trunk1@origin [new] tracked |
| 957 |
[EOF] |
| 958 |
"); |
| 959 |
insta::assert_snapshot!(get_bookmark_output(&target_dir), @" |
| 960 |
a1: mzvwutvl c8303692 a1 |
| 961 |
@origin: mzvwutvl c8303692 a1 |
| 962 |
a2: yqosqzyt d4d535f1 a2 |
| 963 |
@origin: yqosqzyt d4d535f1 a2 |
| 964 |
b: yostqsxw bc83465a b |
| 965 |
@origin: yostqsxw bc83465a b |
| 966 |
trunk1: kkmpptxz 38288177 trunk1 |
| 967 |
@origin: kkmpptxz 38288177 trunk1 |
| 968 |
[EOF] |
| 969 |
"); |
| 970 |
insta::assert_snapshot!(get_log_output(&target_dir), @r#" |
| 971 |
@ e8849ae12c70 "" |
| 972 |
│ ○ bc83465a3090 "b" b |
| 973 |
│ │ ○ d4d535f1d579 "a2" a2 |
| 974 |
│ ├─╯ |
| 975 |
│ │ ○ c8303692b8e2 "a1" a1 |
| 976 |
│ ├─╯ |
| 977 |
│ ○ 382881770501 "trunk1" trunk1 |
| 978 |
├─╯ |
| 979 |
◆ 000000000000 "" |
| 980 |
[EOF] |
| 981 |
"#); |
| 982 |
|
| 983 |
// ==== Change both repos ==== |
| 984 |
// First, change the target repo: |
| 985 |
let source_log = create_trunk2_and_rebase_bookmarks(&source_dir); |
| 986 |
insta::assert_snapshot!(source_log, @r#" |
| 987 |
===== Source git repo contents ===== |
| 988 |
○ 6fc6fe17dbee "b" b |
| 989 |
│ ○ baad96fead6c "a2" a2 |
| 990 |
├─╯ |
| 991 |
│ ○ 798c5e2435e1 "a1" a1 |
| 992 |
├─╯ |
| 993 |
@ e80d998ab04b "trunk2" trunk2 |
| 994 |
○ 382881770501 "trunk1" trunk1 |
| 995 |
◆ 000000000000 "" |
| 996 |
[EOF] |
| 997 |
"#); |
| 998 |
// Change a bookmark in the source repo as well, so that it becomes conflicted. |
| 999 |
target_dir |
| 1000 |
.run_jj(["describe", "b", "-m=new_descr_for_b_to_create_conflict"]) |
| 1001 |
.success(); |
| 1002 |
|
| 1003 |
// Our repo before and after fetch |
| 1004 |
insta::assert_snapshot!(get_log_output(&target_dir), @r#" |
| 1005 |
@ e8849ae12c70 "" |
| 1006 |
│ ○ 0fbbc495357c "new_descr_for_b_to_create_conflict" b* |
| 1007 |
│ │ ○ d4d535f1d579 "a2" a2 |
| 1008 |
│ ├─╯ |
| 1009 |
│ │ ○ c8303692b8e2 "a1" a1 |
| 1010 |
│ ├─╯ |
| 1011 |
│ ○ 382881770501 "trunk1" trunk1 |
| 1012 |
├─╯ |
| 1013 |
◆ 000000000000 "" |
| 1014 |
[EOF] |
| 1015 |
"#); |
| 1016 |
insta::assert_snapshot!(get_bookmark_output(&target_dir), @" |
| 1017 |
a1: mzvwutvl c8303692 a1 |
| 1018 |
@origin: mzvwutvl c8303692 a1 |
| 1019 |
a2: yqosqzyt d4d535f1 a2 |
| 1020 |
@origin: yqosqzyt d4d535f1 a2 |
| 1021 |
b: yostqsxw 0fbbc495 new_descr_for_b_to_create_conflict |
| 1022 |
@origin (ahead by 1 commits, behind by 1 commits): yostqsxw/1 bc83465a (hidden) b |
| 1023 |
trunk1: kkmpptxz 38288177 trunk1 |
| 1024 |
@origin: kkmpptxz 38288177 trunk1 |
| 1025 |
[EOF] |
| 1026 |
"); |
| 1027 |
let output = target_dir.run_jj(["git", "fetch"]); |
| 1028 |
insta::assert_snapshot!(output, @r" |
| 1029 |
------- stderr ------- |
| 1030 |
bookmark: a1@origin [updated] tracked |
| 1031 |
bookmark: a2@origin [updated] tracked |
| 1032 |
bookmark: b@origin [updated] tracked |
| 1033 |
bookmark: trunk2@origin [new] tracked |
| 1034 |
Updated 2 rewritten commits. |
| 1035 |
[EOF] |
| 1036 |
"); |
| 1037 |
insta::assert_snapshot!(get_bookmark_output(&target_dir), @" |
| 1038 |
a1: mzvwutvl 798c5e24 a1 |
| 1039 |
@origin: mzvwutvl 798c5e24 a1 |
| 1040 |
a2: yqosqzyt baad96fe a2 |
| 1041 |
@origin: yqosqzyt baad96fe a2 |
| 1042 |
b (conflicted): |
| 1043 |
- yostqsxw/2 bc83465a (hidden) b |
| 1044 |
+ yostqsxw/1 0fbbc495 (divergent) new_descr_for_b_to_create_conflict |
| 1045 |
+ yostqsxw/0 6fc6fe17 (divergent) b |
| 1046 |
@origin (behind by 1 commits): yostqsxw/0 6fc6fe17 (divergent) b |
| 1047 |
trunk1: kkmpptxz 38288177 trunk1 |
| 1048 |
@origin: kkmpptxz 38288177 trunk1 |
| 1049 |
trunk2: uyznsvlq e80d998a trunk2 |
| 1050 |
@origin: uyznsvlq e80d998a trunk2 |
| 1051 |
[EOF] |
| 1052 |
"); |
| 1053 |
insta::assert_snapshot!(get_log_output(&target_dir), @r#" |
| 1054 |
@ e8849ae12c70 "" |
| 1055 |
│ ○ 6fc6fe17dbee "b" b?? b@origin |
| 1056 |
│ │ ○ baad96fead6c "a2" a2 |
| 1057 |
│ ├─╯ |
| 1058 |
│ │ ○ 798c5e2435e1 "a1" a1 |
| 1059 |
│ ├─╯ |
| 1060 |
│ ○ e80d998ab04b "trunk2" trunk2 |
| 1061 |
│ │ ○ 0fbbc495357c "new_descr_for_b_to_create_conflict" b?? |
| 1062 |
│ ├─╯ |
| 1063 |
│ ○ 382881770501 "trunk1" trunk1 |
| 1064 |
├─╯ |
| 1065 |
◆ 000000000000 "" |
| 1066 |
[EOF] |
| 1067 |
"#); |
| 1068 |
} |
| 1069 |
|
| 1070 |
#[test] |
| 1071 |
fn test_git_fetch_some_of_many_bookmarks() { |
| 1072 |
let test_env = TestEnvironment::default(); |
| 1073 |
test_env.add_config("remotes.origin.auto-track-bookmarks = '*'"); |
| 1074 |
test_env.add_config(r#"revset-aliases."immutable_heads()" = "none()""#); |
| 1075 |
let source_dir = test_env.work_dir("source"); |
| 1076 |
git::init(source_dir.root()); |
| 1077 |
|
| 1078 |
// Clone an empty repo. The target repo is a normal `jj` repo, *not* colocated |
| 1079 |
let output = test_env.run_jj_in(".", ["git", "clone", "source", "target"]); |
| 1080 |
insta::assert_snapshot!(output, @r#" |
| 1081 |
------- stderr ------- |
| 1082 |
Fetching into new repo in "$TEST_ENV/target" |
| 1083 |
Nothing changed. |
| 1084 |
[EOF] |
| 1085 |
"#); |
| 1086 |
let target_dir = test_env.work_dir("target"); |
| 1087 |
|
| 1088 |
let source_log = create_colocated_repo_and_bookmarks_from_trunk1(&source_dir); |
| 1089 |
insta::assert_snapshot!(source_log, @r#" |
| 1090 |
===== Source git repo contents ===== |
| 1091 |
@ bc83465a3090 "b" b |
| 1092 |
│ ○ d4d535f1d579 "a2" a2 |
| 1093 |
├─╯ |
| 1094 |
│ ○ c8303692b8e2 "a1" a1 |
| 1095 |
├─╯ |
| 1096 |
○ 382881770501 "trunk1" trunk1 |
| 1097 |
◆ 000000000000 "" |
| 1098 |
[EOF] |
| 1099 |
"#); |
| 1100 |
|
| 1101 |
// Test an error message |
| 1102 |
let output = target_dir.run_jj(["git", "fetch", "--branch", "'^:a*'"]); |
| 1103 |
insta::assert_snapshot!(output, @" |
| 1104 |
------- stderr ------- |
| 1105 |
Error: Invalid branch pattern provided. When fetching, branch names and globs may not contain the characters `:`, `^`, `?`, `[`, `]` |
| 1106 |
[EOF] |
| 1107 |
[exit status: 1] |
| 1108 |
"); |
| 1109 |
let output = target_dir.run_jj(["git", "fetch", "--branch", "exact:a*"]); |
| 1110 |
insta::assert_snapshot!(output, @" |
| 1111 |
------- stderr ------- |
| 1112 |
Error: Invalid branch pattern provided. When fetching, branch names and globs may not contain the characters `:`, `^`, `?`, `[`, `]` |
| 1113 |
[EOF] |
| 1114 |
[exit status: 1] |
| 1115 |
"); |
| 1116 |
|
| 1117 |
// Nothing in our repo before the fetch |
| 1118 |
insta::assert_snapshot!(get_log_output(&target_dir), @r#" |
| 1119 |
@ e8849ae12c70 "" |
| 1120 |
◆ 000000000000 "" |
| 1121 |
[EOF] |
| 1122 |
"#); |
| 1123 |
// Fetch one bookmark... |
| 1124 |
let output = target_dir.run_jj(["git", "fetch", "--branch", "b"]); |
| 1125 |
insta::assert_snapshot!(output, @" |
| 1126 |
------- stderr ------- |
| 1127 |
bookmark: b@origin [new] tracked |
| 1128 |
[EOF] |
| 1129 |
"); |
| 1130 |
insta::assert_snapshot!(get_log_output(&target_dir), @r#" |
| 1131 |
@ e8849ae12c70 "" |
| 1132 |
│ ○ bc83465a3090 "b" b |
| 1133 |
│ ○ 382881770501 "trunk1" |
| 1134 |
├─╯ |
| 1135 |
◆ 000000000000 "" |
| 1136 |
[EOF] |
| 1137 |
"#); |
| 1138 |
// ...check what the intermediate state looks like... |
| 1139 |
insta::assert_snapshot!(get_bookmark_output(&target_dir), @" |
| 1140 |
b: yostqsxw bc83465a b |
| 1141 |
@origin: yostqsxw bc83465a b |
| 1142 |
[EOF] |
| 1143 |
"); |
| 1144 |
// ...then fetch two others with a glob. |
| 1145 |
let output = target_dir.run_jj(["git", "fetch", "--branch", "a*"]); |
| 1146 |
insta::assert_snapshot!(output, @" |
| 1147 |
------- stderr ------- |
| 1148 |
bookmark: a1@origin [new] tracked |
| 1149 |
bookmark: a2@origin [new] tracked |
| 1150 |
[EOF] |
| 1151 |
"); |
| 1152 |
insta::assert_snapshot!(get_log_output(&target_dir), @r#" |
| 1153 |
@ e8849ae12c70 "" |
| 1154 |
│ ○ d4d535f1d579 "a2" a2 |
| 1155 |
│ │ ○ c8303692b8e2 "a1" a1 |
| 1156 |
│ ├─╯ |
| 1157 |
│ │ ○ bc83465a3090 "b" b |
| 1158 |
│ ├─╯ |
| 1159 |
│ ○ 382881770501 "trunk1" |
| 1160 |
├─╯ |
| 1161 |
◆ 000000000000 "" |
| 1162 |
[EOF] |
| 1163 |
"#); |
| 1164 |
// Fetching the same bookmark again |
| 1165 |
let output = target_dir.run_jj(["git", "fetch", "--branch", "a1"]); |
| 1166 |
insta::assert_snapshot!(output, @" |
| 1167 |
------- stderr ------- |
| 1168 |
Nothing changed. |
| 1169 |
[EOF] |
| 1170 |
"); |
| 1171 |
insta::assert_snapshot!(get_log_output(&target_dir), @r#" |
| 1172 |
@ e8849ae12c70 "" |
| 1173 |
│ ○ d4d535f1d579 "a2" a2 |
| 1174 |
│ │ ○ c8303692b8e2 "a1" a1 |
| 1175 |
│ ├─╯ |
| 1176 |
│ │ ○ bc83465a3090 "b" b |
| 1177 |
│ ├─╯ |
| 1178 |
│ ○ 382881770501 "trunk1" |
| 1179 |
├─╯ |
| 1180 |
◆ 000000000000 "" |
| 1181 |
[EOF] |
| 1182 |
"#); |
| 1183 |
|
| 1184 |
// ==== Change both repos ==== |
| 1185 |
// First, change the target repo: |
| 1186 |
let source_log = create_trunk2_and_rebase_bookmarks(&source_dir); |
| 1187 |
insta::assert_snapshot!(source_log, @r#" |
| 1188 |
===== Source git repo contents ===== |
| 1189 |
○ 2b30dbc93959 "b" b |
| 1190 |
│ ○ 841140b152fc "a2" a2 |
| 1191 |
├─╯ |
| 1192 |
│ ○ bc7e74c21d43 "a1" a1 |
| 1193 |
├─╯ |
| 1194 |
@ 756be1d31c41 "trunk2" trunk2 |
| 1195 |
○ 382881770501 "trunk1" trunk1 |
| 1196 |
◆ 000000000000 "" |
| 1197 |
[EOF] |
| 1198 |
"#); |
| 1199 |
// Change a bookmark in the source repo as well, so that it becomes conflicted. |
| 1200 |
target_dir |
| 1201 |
.run_jj(["describe", "b", "-m=new_descr_for_b_to_create_conflict"]) |
| 1202 |
.success(); |
| 1203 |
|
| 1204 |
// Our repo before and after fetch of two bookmarks |
| 1205 |
insta::assert_snapshot!(get_log_output(&target_dir), @r#" |
| 1206 |
@ e8849ae12c70 "" |
| 1207 |
│ ○ c62db3119722 "new_descr_for_b_to_create_conflict" b* |
| 1208 |
│ │ ○ d4d535f1d579 "a2" a2 |
| 1209 |
│ ├─╯ |
| 1210 |
│ │ ○ c8303692b8e2 "a1" a1 |
| 1211 |
│ ├─╯ |
| 1212 |
│ ○ 382881770501 "trunk1" |
| 1213 |
├─╯ |
| 1214 |
◆ 000000000000 "" |
| 1215 |
[EOF] |
| 1216 |
"#); |
| 1217 |
let output = target_dir.run_jj(["git", "fetch", "--branch=~(a2 | trunk*)"]); |
| 1218 |
insta::assert_snapshot!(output, @r" |
| 1219 |
------- stderr ------- |
| 1220 |
bookmark: a1@origin [updated] tracked |
| 1221 |
bookmark: b@origin [updated] tracked |
| 1222 |
Updated 1 rewritten commits. |
| 1223 |
[EOF] |
| 1224 |
"); |
| 1225 |
insta::assert_snapshot!(get_log_output(&target_dir), @r#" |
| 1226 |
@ e8849ae12c70 "" |
| 1227 |
│ ○ 2b30dbc93959 "b" b?? b@origin |
| 1228 |
│ │ ○ bc7e74c21d43 "a1" a1 |
| 1229 |
│ ├─╯ |
| 1230 |
│ ○ 756be1d31c41 "trunk2" |
| 1231 |
│ │ ○ c62db3119722 "new_descr_for_b_to_create_conflict" b?? |
| 1232 |
│ ├─╯ |
| 1233 |
│ │ ○ d4d535f1d579 "a2" a2 |
| 1234 |
│ ├─╯ |
| 1235 |
│ ○ 382881770501 "trunk1" |
| 1236 |
├─╯ |
| 1237 |
◆ 000000000000 "" |
| 1238 |
[EOF] |
| 1239 |
"#); |
| 1240 |
|
| 1241 |
// We left a2 where it was before, let's see how `jj bookmark list` sees this. |
| 1242 |
insta::assert_snapshot!(get_bookmark_output(&target_dir), @" |
| 1243 |
a1: mzvwutvl bc7e74c2 a1 |
| 1244 |
@origin: mzvwutvl bc7e74c2 a1 |
| 1245 |
a2: yqosqzyt d4d535f1 a2 |
| 1246 |
@origin: yqosqzyt d4d535f1 a2 |
| 1247 |
b (conflicted): |
| 1248 |
- yostqsxw/2 bc83465a (hidden) b |
| 1249 |
+ yostqsxw/1 c62db311 (divergent) new_descr_for_b_to_create_conflict |
| 1250 |
+ yostqsxw/0 2b30dbc9 (divergent) b |
| 1251 |
@origin (behind by 1 commits): yostqsxw/0 2b30dbc9 (divergent) b |
| 1252 |
[EOF] |
| 1253 |
"); |
| 1254 |
// Now, let's fetch a2 and double-check that fetching a1 and b again doesn't do |
| 1255 |
// anything. |
| 1256 |
let output = target_dir.run_jj(["git", "fetch", "--branch", "b", "--branch", "a*"]); |
| 1257 |
insta::assert_snapshot!(output, @r" |
| 1258 |
------- stderr ------- |
| 1259 |
bookmark: a2@origin [updated] tracked |
| 1260 |
Updated 1 rewritten commits. |
| 1261 |
[EOF] |
| 1262 |
"); |
| 1263 |
insta::assert_snapshot!(get_log_output(&target_dir), @r#" |
| 1264 |
@ e8849ae12c70 "" |
| 1265 |
│ ○ 841140b152fc "a2" a2 |
| 1266 |
│ │ ○ 2b30dbc93959 "b" b?? b@origin |
| 1267 |
│ ├─╯ |
| 1268 |
│ │ ○ bc7e74c21d43 "a1" a1 |
| 1269 |
│ ├─╯ |
| 1270 |
│ ○ 756be1d31c41 "trunk2" |
| 1271 |
│ │ ○ c62db3119722 "new_descr_for_b_to_create_conflict" b?? |
| 1272 |
│ ├─╯ |
| 1273 |
│ ○ 382881770501 "trunk1" |
| 1274 |
├─╯ |
| 1275 |
◆ 000000000000 "" |
| 1276 |
[EOF] |
| 1277 |
"#); |
| 1278 |
insta::assert_snapshot!(get_bookmark_output(&target_dir), @" |
| 1279 |
a1: mzvwutvl bc7e74c2 a1 |
| 1280 |
@origin: mzvwutvl bc7e74c2 a1 |
| 1281 |
a2: yqosqzyt 841140b1 a2 |
| 1282 |
@origin: yqosqzyt 841140b1 a2 |
| 1283 |
b (conflicted): |
| 1284 |
- yostqsxw/2 bc83465a (hidden) b |
| 1285 |
+ yostqsxw/1 c62db311 (divergent) new_descr_for_b_to_create_conflict |
| 1286 |
+ yostqsxw/0 2b30dbc9 (divergent) b |
| 1287 |
@origin (behind by 1 commits): yostqsxw/0 2b30dbc9 (divergent) b |
| 1288 |
[EOF] |
| 1289 |
"); |
| 1290 |
} |
| 1291 |
|
| 1292 |
#[test] |
| 1293 |
fn test_git_fetch_bookmarks_some_missing() { |
| 1294 |
let test_env = TestEnvironment::default(); |
| 1295 |
test_env.add_config("remotes.origin.auto-track-bookmarks = '*'"); |
| 1296 |
test_env.add_config("remotes.rem1.auto-track-bookmarks = '*'"); |
| 1297 |
test_env.add_config("remotes.rem2.auto-track-bookmarks = '*'"); |
| 1298 |
test_env.add_config("remotes.rem3.auto-track-bookmarks = '*'"); |
| 1299 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 1300 |
let work_dir = test_env.work_dir("repo"); |
| 1301 |
add_git_remote(&test_env, &work_dir, "origin"); |
| 1302 |
add_git_remote(&test_env, &work_dir, "rem1"); |
| 1303 |
add_git_remote(&test_env, &work_dir, "rem2"); |
| 1304 |
add_git_remote(&test_env, &work_dir, "rem3"); |
| 1305 |
|
| 1306 |
// single missing bookmark, implicit remotes (@origin) |
| 1307 |
let output = work_dir.run_jj(["git", "fetch", "--branch", "noexist"]); |
| 1308 |
insta::assert_snapshot!(output, @" |
| 1309 |
------- stderr ------- |
| 1310 |
Warning: No matching branches found on any specified/configured remote: noexist |
| 1311 |
Nothing changed. |
| 1312 |
[EOF] |
| 1313 |
"); |
| 1314 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @""); |
| 1315 |
|
| 1316 |
// multiple missing bookmarks, implicit remotes (@origin) |
| 1317 |
let output = work_dir.run_jj([ |
| 1318 |
"git", "fetch", "--branch", "noexist1", "--branch", "noexist2", |
| 1319 |
]); |
| 1320 |
insta::assert_snapshot!(output, @" |
| 1321 |
------- stderr ------- |
| 1322 |
Warning: No matching branches found on any specified/configured remote: noexist1, noexist2 |
| 1323 |
Nothing changed. |
| 1324 |
[EOF] |
| 1325 |
"); |
| 1326 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @""); |
| 1327 |
|
| 1328 |
// single existing bookmark, implicit remotes (@origin) |
| 1329 |
let output = work_dir.run_jj(["git", "fetch", "--branch", "origin"]); |
| 1330 |
insta::assert_snapshot!(output, @" |
| 1331 |
------- stderr ------- |
| 1332 |
bookmark: origin@origin [new] tracked |
| 1333 |
[EOF] |
| 1334 |
"); |
| 1335 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @" |
| 1336 |
origin: qmyrypzk ab8b299e message |
| 1337 |
@origin: qmyrypzk ab8b299e message |
| 1338 |
[EOF] |
| 1339 |
"); |
| 1340 |
|
| 1341 |
// multiple existing bookmark, explicit remotes, each bookmark is only in one |
| 1342 |
// remote. |
| 1343 |
let output = work_dir.run_jj([ |
| 1344 |
"git", "fetch", "--branch", "rem1", "--branch", "rem2", "--branch", "rem3", "--remote", |
| 1345 |
"rem1", "--remote", "rem2", "--remote", "rem3", |
| 1346 |
]); |
| 1347 |
insta::assert_snapshot!(output, @" |
| 1348 |
------- stderr ------- |
| 1349 |
bookmark: rem1@rem1 [new] tracked |
| 1350 |
bookmark: rem2@rem2 [new] tracked |
| 1351 |
bookmark: rem3@rem3 [new] tracked |
| 1352 |
[EOF] |
| 1353 |
"); |
| 1354 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @" |
| 1355 |
origin: qmyrypzk ab8b299e message |
| 1356 |
@origin: qmyrypzk ab8b299e message |
| 1357 |
rem1: ppspxspk 4acd0343 message |
| 1358 |
@rem1: ppspxspk 4acd0343 message |
| 1359 |
rem2: pzqqpnpo 44c57802 message |
| 1360 |
@rem2: pzqqpnpo 44c57802 message |
| 1361 |
rem3: wrzwlmys 45a3faef message |
| 1362 |
@rem3: wrzwlmys 45a3faef message |
| 1363 |
[EOF] |
| 1364 |
"); |
| 1365 |
|
| 1366 |
// multiple bookmarks, one exists, one doesn't |
| 1367 |
let output = work_dir.run_jj([ |
| 1368 |
"git", "fetch", "--branch", "rem1", "--branch", "notexist", "--remote", "rem1", |
| 1369 |
]); |
| 1370 |
insta::assert_snapshot!(output, @" |
| 1371 |
------- stderr ------- |
| 1372 |
Warning: No matching branches found on any specified/configured remote: notexist |
| 1373 |
Nothing changed. |
| 1374 |
[EOF] |
| 1375 |
"); |
| 1376 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @" |
| 1377 |
origin: qmyrypzk ab8b299e message |
| 1378 |
@origin: qmyrypzk ab8b299e message |
| 1379 |
rem1: ppspxspk 4acd0343 message |
| 1380 |
@rem1: ppspxspk 4acd0343 message |
| 1381 |
rem2: pzqqpnpo 44c57802 message |
| 1382 |
@rem2: pzqqpnpo 44c57802 message |
| 1383 |
rem3: wrzwlmys 45a3faef message |
| 1384 |
@rem3: wrzwlmys 45a3faef message |
| 1385 |
[EOF] |
| 1386 |
"); |
| 1387 |
} |
| 1388 |
|
| 1389 |
#[test] |
| 1390 |
fn test_git_fetch_bookmarks_missing_with_subprocess_localized_message() { |
| 1391 |
let test_env = TestEnvironment::default(); |
| 1392 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 1393 |
let work_dir = test_env.work_dir("repo"); |
| 1394 |
add_git_remote(&test_env, &work_dir, "origin"); |
| 1395 |
|
| 1396 |
// "fatal: couldn't find remote ref %s" shouldn't be localized. |
| 1397 |
let output = work_dir.run_jj_with(|cmd| { |
| 1398 |
cmd.args(["git", "fetch", "--branch=unknown"]) |
| 1399 |
// Initialize locale as "en_US" which is the most common. |
| 1400 |
.env("LC_ALL", "en_US.UTF-8") |
| 1401 |
// Set some other locale variables for testing. |
| 1402 |
.env("LC_MESSAGES", "en_US.UTF-8") |
| 1403 |
.env("LANG", "en_US.UTF-8") |
| 1404 |
// GNU gettext prioritizes LANGUAGE if translation is enabled. It works |
| 1405 |
// no matter if system locale exists or not. |
| 1406 |
.env("LANGUAGE", "zh_TW") |
| 1407 |
}); |
| 1408 |
insta::assert_snapshot!(output, @" |
| 1409 |
------- stderr ------- |
| 1410 |
Warning: No matching branches found on any specified/configured remote: unknown |
| 1411 |
Nothing changed. |
| 1412 |
[EOF] |
| 1413 |
"); |
| 1414 |
} |
| 1415 |
|
| 1416 |
#[test] |
| 1417 |
fn test_git_fetch_unsupported_branch_patterns() { |
| 1418 |
let test_env = TestEnvironment::default(); |
| 1419 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 1420 |
let work_dir = test_env.work_dir("repo"); |
| 1421 |
add_git_remote(&test_env, &work_dir, "origin"); |
| 1422 |
|
| 1423 |
let output = work_dir.run_jj(["git", "fetch", "--branch=x&y|z"]); |
| 1424 |
insta::assert_snapshot!(output, @" |
| 1425 |
------- stderr ------- |
| 1426 |
Error: Cannot use `&` in sub expression |
| 1427 |
Hint: Specify patterns in `(positive | ...) & ~(negative | ...)` form. |
| 1428 |
[EOF] |
| 1429 |
[exit status: 1] |
| 1430 |
"); |
| 1431 |
|
| 1432 |
// Unsupported glob pattern in negative refspecs |
| 1433 |
let output = work_dir.run_jj(["git", "fetch", "--branch=~'[xy]'"]); |
| 1434 |
insta::assert_snapshot!(output, @" |
| 1435 |
------- stderr ------- |
| 1436 |
Error: Invalid branch pattern provided. When fetching, branch names and globs may not contain the characters `:`, `^`, `?`, `[`, `]` |
| 1437 |
[EOF] |
| 1438 |
[exit status: 1] |
| 1439 |
"); |
| 1440 |
} |
| 1441 |
|
| 1442 |
// See `test_undo_restore_commands.rs` for fetch-undo-push and fetch-undo-fetch |
| 1443 |
// of the same bookmarks for various kinds of undo. |
| 1444 |
#[test] |
| 1445 |
fn test_git_fetch_undo() { |
| 1446 |
let test_env = TestEnvironment::default(); |
| 1447 |
test_env.add_config("remotes.origin.auto-track-bookmarks = '*'"); |
| 1448 |
let source_dir = test_env.work_dir("source"); |
| 1449 |
git::init(source_dir.root()); |
| 1450 |
|
| 1451 |
// Clone an empty repo. The target repo is a normal `jj` repo, *not* colocated |
| 1452 |
let output = test_env.run_jj_in(".", ["git", "clone", "source", "target"]); |
| 1453 |
insta::assert_snapshot!(output, @r#" |
| 1454 |
------- stderr ------- |
| 1455 |
Fetching into new repo in "$TEST_ENV/target" |
| 1456 |
Nothing changed. |
| 1457 |
[EOF] |
| 1458 |
"#); |
| 1459 |
let target_dir = test_env.work_dir("target"); |
| 1460 |
|
| 1461 |
create_colocated_repo_and_bookmarks_from_trunk1(&source_dir); |
| 1462 |
source_dir |
| 1463 |
.run_jj(["tag", "set", "-rtrunk1", "tag1"]) |
| 1464 |
.success(); |
| 1465 |
insta::assert_snapshot!(get_log_output(&source_dir), @r#" |
| 1466 |
@ bc83465a3090 "b" b |
| 1467 |
│ ○ d4d535f1d579 "a2" a2 |
| 1468 |
├─╯ |
| 1469 |
│ ○ c8303692b8e2 "a1" a1 |
| 1470 |
├─╯ |
| 1471 |
◆ 382881770501 "trunk1" trunk1 tag1 |
| 1472 |
◆ 000000000000 "" |
| 1473 |
[EOF] |
| 1474 |
"#); |
| 1475 |
|
| 1476 |
// Fetch 2 bookmarks and tags |
| 1477 |
let output = target_dir.run_jj(["git", "fetch", "--branch=b|a1", "--tag=*"]); |
| 1478 |
insta::assert_snapshot!(output, @" |
| 1479 |
------- stderr ------- |
| 1480 |
bookmark: a1@origin [new] tracked |
| 1481 |
bookmark: b@origin [new] tracked |
| 1482 |
tag: tag1@origin [new] tracked |
| 1483 |
[EOF] |
| 1484 |
"); |
| 1485 |
insta::assert_snapshot!(get_log_output(&target_dir), @r#" |
| 1486 |
@ e8849ae12c70 "" |
| 1487 |
│ ○ bc83465a3090 "b" b |
| 1488 |
│ │ ○ c8303692b8e2 "a1" a1 |
| 1489 |
│ ├─╯ |
| 1490 |
│ ◆ 382881770501 "trunk1" tag1 |
| 1491 |
├─╯ |
| 1492 |
◆ 000000000000 "" |
| 1493 |
[EOF] |
| 1494 |
"#); |
| 1495 |
let output = target_dir.run_jj(["undo"]); |
| 1496 |
insta::assert_snapshot!(output, @" |
| 1497 |
------- stderr ------- |
| 1498 |
Undid operation: 450e0713ac6d (2001-02-03 08:05:20) fetch from git remote(s) origin |
| 1499 |
Restored to operation: f9f128e730c0 (2001-02-03 08:05:07) add git remote origin |
| 1500 |
[EOF] |
| 1501 |
"); |
| 1502 |
// The undo works as expected |
| 1503 |
insta::assert_snapshot!(get_log_output(&target_dir), @r#" |
| 1504 |
@ e8849ae12c70 "" |
| 1505 |
◆ 000000000000 "" |
| 1506 |
[EOF] |
| 1507 |
"#); |
| 1508 |
// Now try to fetch just one bookmark and tags |
| 1509 |
let output = target_dir.run_jj(["git", "fetch", "--branch=b", "--tag=*"]); |
| 1510 |
insta::assert_snapshot!(output, @" |
| 1511 |
------- stderr ------- |
| 1512 |
bookmark: b@origin [new] tracked |
| 1513 |
tag: tag1@origin [new] tracked |
| 1514 |
[EOF] |
| 1515 |
"); |
| 1516 |
insta::assert_snapshot!(get_log_output(&target_dir), @r#" |
| 1517 |
@ e8849ae12c70 "" |
| 1518 |
│ ○ bc83465a3090 "b" b |
| 1519 |
│ ◆ 382881770501 "trunk1" tag1 |
| 1520 |
├─╯ |
| 1521 |
◆ 000000000000 "" |
| 1522 |
[EOF] |
| 1523 |
"#); |
| 1524 |
} |
| 1525 |
|
| 1526 |
// Compare to `test_git_import_undo` in test_git_import_export |
| 1527 |
// TODO: Explain why these behaviors are useful |
| 1528 |
#[test] |
| 1529 |
fn test_fetch_undo_what() { |
| 1530 |
let test_env = TestEnvironment::default(); |
| 1531 |
test_env.add_config("remotes.origin.auto-track-bookmarks = '*'"); |
| 1532 |
let source_dir = test_env.work_dir("source"); |
| 1533 |
git::init(source_dir.root()); |
| 1534 |
|
| 1535 |
// Clone an empty repo. The target repo is a normal `jj` repo, *not* colocated |
| 1536 |
let output = test_env.run_jj_in(".", ["git", "clone", "source", "target"]); |
| 1537 |
insta::assert_snapshot!(output, @r#" |
| 1538 |
------- stderr ------- |
| 1539 |
Fetching into new repo in "$TEST_ENV/target" |
| 1540 |
Nothing changed. |
| 1541 |
[EOF] |
| 1542 |
"#); |
| 1543 |
let work_dir = test_env.work_dir("target"); |
| 1544 |
|
| 1545 |
let source_log = create_colocated_repo_and_bookmarks_from_trunk1(&source_dir); |
| 1546 |
insta::assert_snapshot!(source_log, @r#" |
| 1547 |
===== Source git repo contents ===== |
| 1548 |
@ bc83465a3090 "b" b |
| 1549 |
│ ○ d4d535f1d579 "a2" a2 |
| 1550 |
├─╯ |
| 1551 |
│ ○ c8303692b8e2 "a1" a1 |
| 1552 |
├─╯ |
| 1553 |
○ 382881770501 "trunk1" trunk1 |
| 1554 |
◆ 000000000000 "" |
| 1555 |
[EOF] |
| 1556 |
"#); |
| 1557 |
|
| 1558 |
// Initial state we will try to return to after `op restore`. There are no |
| 1559 |
// bookmarks. |
| 1560 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @""); |
| 1561 |
let base_operation_id = work_dir.current_operation_id(); |
| 1562 |
|
| 1563 |
// Fetch a bookmark |
| 1564 |
let output = work_dir.run_jj(["git", "fetch", "--branch", "b"]); |
| 1565 |
insta::assert_snapshot!(output, @" |
| 1566 |
------- stderr ------- |
| 1567 |
bookmark: b@origin [new] tracked |
| 1568 |
[EOF] |
| 1569 |
"); |
| 1570 |
insta::assert_snapshot!(get_log_output(&work_dir), @r#" |
| 1571 |
@ e8849ae12c70 "" |
| 1572 |
│ ○ bc83465a3090 "b" b |
| 1573 |
│ ○ 382881770501 "trunk1" |
| 1574 |
├─╯ |
| 1575 |
◆ 000000000000 "" |
| 1576 |
[EOF] |
| 1577 |
"#); |
| 1578 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @" |
| 1579 |
b: yostqsxw bc83465a b |
| 1580 |
@origin: yostqsxw bc83465a b |
| 1581 |
[EOF] |
| 1582 |
"); |
| 1583 |
|
| 1584 |
// We can undo the change in the repo without moving the remote-tracking |
| 1585 |
// bookmark |
| 1586 |
let output = work_dir.run_jj(["op", "restore", "--what", "repo", &base_operation_id]); |
| 1587 |
insta::assert_snapshot!(output, @" |
| 1588 |
------- stderr ------- |
| 1589 |
Restored to operation: f9f128e730c0 (2001-02-03 08:05:07) add git remote origin |
| 1590 |
[EOF] |
| 1591 |
"); |
| 1592 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @" |
| 1593 |
b (deleted) |
| 1594 |
@origin: yostqsxw/0 bc83465a (hidden) b |
| 1595 |
[EOF] |
| 1596 |
"); |
| 1597 |
|
| 1598 |
// Now, let's demo restoring just the remote-tracking bookmark. First, let's |
| 1599 |
// change our local repo state... |
| 1600 |
work_dir |
| 1601 |
.run_jj(["bookmark", "c", "-r@", "newbookmark"]) |
| 1602 |
.success(); |
| 1603 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @" |
| 1604 |
b (deleted) |
| 1605 |
@origin: yostqsxw/0 bc83465a (hidden) b |
| 1606 |
newbookmark: qpvuntsm e8849ae1 (empty) (no description set) |
| 1607 |
@origin (not created yet) |
| 1608 |
[EOF] |
| 1609 |
"); |
| 1610 |
// Restoring just the remote-tracking state will not affect `newbookmark`, but |
| 1611 |
// will eliminate `b@origin`. |
| 1612 |
let output = work_dir.run_jj([ |
| 1613 |
"op", |
| 1614 |
"restore", |
| 1615 |
"--what", |
| 1616 |
"remote-tracking", |
| 1617 |
&base_operation_id, |
| 1618 |
]); |
| 1619 |
insta::assert_snapshot!(output, @" |
| 1620 |
------- stderr ------- |
| 1621 |
Restored to operation: f9f128e730c0 (2001-02-03 08:05:07) add git remote origin |
| 1622 |
[EOF] |
| 1623 |
"); |
| 1624 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @" |
| 1625 |
newbookmark: qpvuntsm e8849ae1 (empty) (no description set) |
| 1626 |
[EOF] |
| 1627 |
"); |
| 1628 |
} |
| 1629 |
|
| 1630 |
#[test] |
| 1631 |
fn test_git_fetch_remove_fetch() { |
| 1632 |
let test_env = TestEnvironment::default(); |
| 1633 |
test_env.add_config("remotes.origin.auto-track-bookmarks = '*'"); |
| 1634 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 1635 |
let work_dir = test_env.work_dir("repo"); |
| 1636 |
add_git_remote(&test_env, &work_dir, "origin"); |
| 1637 |
|
| 1638 |
work_dir |
| 1639 |
.run_jj(["bookmark", "create", "-r@", "origin"]) |
| 1640 |
.success(); |
| 1641 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @" |
| 1642 |
origin: qpvuntsm e8849ae1 (empty) (no description set) |
| 1643 |
@origin (not created yet) |
| 1644 |
[EOF] |
| 1645 |
"); |
| 1646 |
|
| 1647 |
work_dir.run_jj(["git", "fetch"]).success(); |
| 1648 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @" |
| 1649 |
origin (conflicted): |
| 1650 |
+ qpvuntsm e8849ae1 (empty) (no description set) |
| 1651 |
+ qmyrypzk ab8b299e message |
| 1652 |
@origin (behind by 1 commits): qmyrypzk ab8b299e message |
| 1653 |
[EOF] |
| 1654 |
"); |
| 1655 |
|
| 1656 |
work_dir |
| 1657 |
.run_jj(["git", "remote", "remove", "origin"]) |
| 1658 |
.success(); |
| 1659 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @" |
| 1660 |
origin (conflicted): |
| 1661 |
+ qpvuntsm e8849ae1 (empty) (no description set) |
| 1662 |
+ qmyrypzk ab8b299e message |
| 1663 |
[EOF] |
| 1664 |
"); |
| 1665 |
|
| 1666 |
work_dir |
| 1667 |
.run_jj(["git", "remote", "add", "origin", "../origin"]) |
| 1668 |
.success(); |
| 1669 |
|
| 1670 |
// Check that origin@origin is properly recreated |
| 1671 |
let output = work_dir.run_jj(["git", "fetch"]); |
| 1672 |
insta::assert_snapshot!(output, @" |
| 1673 |
------- stderr ------- |
| 1674 |
bookmark: origin@origin [new] tracked |
| 1675 |
[EOF] |
| 1676 |
"); |
| 1677 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @" |
| 1678 |
origin (conflicted): |
| 1679 |
+ qpvuntsm e8849ae1 (empty) (no description set) |
| 1680 |
+ qmyrypzk ab8b299e message |
| 1681 |
@origin (behind by 1 commits): qmyrypzk ab8b299e message |
| 1682 |
[EOF] |
| 1683 |
"); |
| 1684 |
} |
| 1685 |
|
| 1686 |
#[test] |
| 1687 |
fn test_git_fetch_rename_fetch() { |
| 1688 |
let test_env = TestEnvironment::default(); |
| 1689 |
test_env.add_config("remotes.origin.auto-track-bookmarks = '*'"); |
| 1690 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 1691 |
let work_dir = test_env.work_dir("repo"); |
| 1692 |
add_git_remote(&test_env, &work_dir, "origin"); |
| 1693 |
|
| 1694 |
work_dir |
| 1695 |
.run_jj(["bookmark", "create", "-r@", "origin"]) |
| 1696 |
.success(); |
| 1697 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @" |
| 1698 |
origin: qpvuntsm e8849ae1 (empty) (no description set) |
| 1699 |
@origin (not created yet) |
| 1700 |
[EOF] |
| 1701 |
"); |
| 1702 |
|
| 1703 |
work_dir.run_jj(["git", "fetch"]).success(); |
| 1704 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @" |
| 1705 |
origin (conflicted): |
| 1706 |
+ qpvuntsm e8849ae1 (empty) (no description set) |
| 1707 |
+ qmyrypzk ab8b299e message |
| 1708 |
@origin (behind by 1 commits): qmyrypzk ab8b299e message |
| 1709 |
[EOF] |
| 1710 |
"); |
| 1711 |
|
| 1712 |
work_dir |
| 1713 |
.run_jj(["git", "remote", "rename", "origin", "upstream"]) |
| 1714 |
.success(); |
| 1715 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @" |
| 1716 |
origin (conflicted): |
| 1717 |
+ qpvuntsm e8849ae1 (empty) (no description set) |
| 1718 |
+ qmyrypzk ab8b299e message |
| 1719 |
@upstream (behind by 1 commits): qmyrypzk ab8b299e message |
| 1720 |
[EOF] |
| 1721 |
"); |
| 1722 |
|
| 1723 |
// Check that jj indicates that nothing has changed |
| 1724 |
let output = work_dir.run_jj(["git", "fetch", "--remote", "upstream"]); |
| 1725 |
insta::assert_snapshot!(output, @" |
| 1726 |
------- stderr ------- |
| 1727 |
Nothing changed. |
| 1728 |
[EOF] |
| 1729 |
"); |
| 1730 |
} |
| 1731 |
|
| 1732 |
#[test] |
| 1733 |
fn test_git_fetch_removed_bookmark() { |
| 1734 |
let test_env = TestEnvironment::default(); |
| 1735 |
test_env.add_config("remotes.origin.auto-track-bookmarks = '*'"); |
| 1736 |
let source_dir = test_env.work_dir("source"); |
| 1737 |
git::init(source_dir.root()); |
| 1738 |
|
| 1739 |
// Clone an empty repo. The target repo is a normal `jj` repo, *not* colocated |
| 1740 |
let output = test_env.run_jj_in(".", ["git", "clone", "source", "target"]); |
| 1741 |
insta::assert_snapshot!(output, @r#" |
| 1742 |
------- stderr ------- |
| 1743 |
Fetching into new repo in "$TEST_ENV/target" |
| 1744 |
Nothing changed. |
| 1745 |
[EOF] |
| 1746 |
"#); |
| 1747 |
let target_dir = test_env.work_dir("target"); |
| 1748 |
|
| 1749 |
let source_log = create_colocated_repo_and_bookmarks_from_trunk1(&source_dir); |
| 1750 |
insta::assert_snapshot!(source_log, @r#" |
| 1751 |
===== Source git repo contents ===== |
| 1752 |
@ bc83465a3090 "b" b |
| 1753 |
│ ○ d4d535f1d579 "a2" a2 |
| 1754 |
├─╯ |
| 1755 |
│ ○ c8303692b8e2 "a1" a1 |
| 1756 |
├─╯ |
| 1757 |
○ 382881770501 "trunk1" trunk1 |
| 1758 |
◆ 000000000000 "" |
| 1759 |
[EOF] |
| 1760 |
"#); |
| 1761 |
|
| 1762 |
// Fetch all bookmarks |
| 1763 |
let output = target_dir.run_jj(["git", "fetch"]); |
| 1764 |
insta::assert_snapshot!(output, @" |
| 1765 |
------- stderr ------- |
| 1766 |
bookmark: a1@origin [new] tracked |
| 1767 |
bookmark: a2@origin [new] tracked |
| 1768 |
bookmark: b@origin [new] tracked |
| 1769 |
bookmark: trunk1@origin [new] tracked |
| 1770 |
[EOF] |
| 1771 |
"); |
| 1772 |
insta::assert_snapshot!(get_log_output(&target_dir), @r#" |
| 1773 |
@ e8849ae12c70 "" |
| 1774 |
│ ○ bc83465a3090 "b" b |
| 1775 |
│ │ ○ d4d535f1d579 "a2" a2 |
| 1776 |
│ ├─╯ |
| 1777 |
│ │ ○ c8303692b8e2 "a1" a1 |
| 1778 |
│ ├─╯ |
| 1779 |
│ ○ 382881770501 "trunk1" trunk1 |
| 1780 |
├─╯ |
| 1781 |
◆ 000000000000 "" |
| 1782 |
[EOF] |
| 1783 |
"#); |
| 1784 |
|
| 1785 |
// Remove a2 bookmark in origin |
| 1786 |
source_dir |
| 1787 |
.run_jj(["bookmark", "forget", "--include-remotes", "a2"]) |
| 1788 |
.success(); |
| 1789 |
|
| 1790 |
// Fetch bookmark a1 from origin and check that a2 is still there |
| 1791 |
let output = target_dir.run_jj(["git", "fetch", "--branch", "a1"]); |
| 1792 |
insta::assert_snapshot!(output, @" |
| 1793 |
------- stderr ------- |
| 1794 |
Nothing changed. |
| 1795 |
[EOF] |
| 1796 |
"); |
| 1797 |
insta::assert_snapshot!(get_log_output(&target_dir), @r#" |
| 1798 |
@ e8849ae12c70 "" |
| 1799 |
│ ○ bc83465a3090 "b" b |
| 1800 |
│ │ ○ d4d535f1d579 "a2" a2 |
| 1801 |
│ ├─╯ |
| 1802 |
│ │ ○ c8303692b8e2 "a1" a1 |
| 1803 |
│ ├─╯ |
| 1804 |
│ ○ 382881770501 "trunk1" trunk1 |
| 1805 |
├─╯ |
| 1806 |
◆ 000000000000 "" |
| 1807 |
[EOF] |
| 1808 |
"#); |
| 1809 |
|
| 1810 |
// Fetch bookmarks a2 from origin, and check that it has been removed locally |
| 1811 |
let output = target_dir.run_jj(["git", "fetch", "--branch", "a2"]); |
| 1812 |
insta::assert_snapshot!(output, @" |
| 1813 |
------- stderr ------- |
| 1814 |
bookmark: a2@origin [deleted] untracked |
| 1815 |
Abandoned 1 commits that are no longer reachable: |
| 1816 |
yqosqzyt d4d535f1 a2 |
| 1817 |
[EOF] |
| 1818 |
"); |
| 1819 |
insta::assert_snapshot!(get_log_output(&target_dir), @r#" |
| 1820 |
@ e8849ae12c70 "" |
| 1821 |
│ ○ bc83465a3090 "b" b |
| 1822 |
│ │ ○ c8303692b8e2 "a1" a1 |
| 1823 |
│ ├─╯ |
| 1824 |
│ ○ 382881770501 "trunk1" trunk1 |
| 1825 |
├─╯ |
| 1826 |
◆ 000000000000 "" |
| 1827 |
[EOF] |
| 1828 |
"#); |
| 1829 |
} |
| 1830 |
|
| 1831 |
#[test] |
| 1832 |
fn test_git_fetch_removed_parent_bookmark() { |
| 1833 |
let test_env = TestEnvironment::default(); |
| 1834 |
test_env.add_config("remotes.origin.auto-track-bookmarks = '*'"); |
| 1835 |
let source_dir = test_env.work_dir("source"); |
| 1836 |
git::init(source_dir.root()); |
| 1837 |
|
| 1838 |
// Clone an empty repo. The target repo is a normal `jj` repo, *not* colocated |
| 1839 |
let output = test_env.run_jj_in(".", ["git", "clone", "source", "target"]); |
| 1840 |
insta::assert_snapshot!(output, @r#" |
| 1841 |
------- stderr ------- |
| 1842 |
Fetching into new repo in "$TEST_ENV/target" |
| 1843 |
Nothing changed. |
| 1844 |
[EOF] |
| 1845 |
"#); |
| 1846 |
let target_dir = test_env.work_dir("target"); |
| 1847 |
|
| 1848 |
let source_log = create_colocated_repo_and_bookmarks_from_trunk1(&source_dir); |
| 1849 |
insta::assert_snapshot!(source_log, @r#" |
| 1850 |
===== Source git repo contents ===== |
| 1851 |
@ bc83465a3090 "b" b |
| 1852 |
│ ○ d4d535f1d579 "a2" a2 |
| 1853 |
├─╯ |
| 1854 |
│ ○ c8303692b8e2 "a1" a1 |
| 1855 |
├─╯ |
| 1856 |
○ 382881770501 "trunk1" trunk1 |
| 1857 |
◆ 000000000000 "" |
| 1858 |
[EOF] |
| 1859 |
"#); |
| 1860 |
|
| 1861 |
// Fetch all bookmarks |
| 1862 |
let output = target_dir.run_jj(["git", "fetch"]); |
| 1863 |
insta::assert_snapshot!(output, @" |
| 1864 |
------- stderr ------- |
| 1865 |
bookmark: a1@origin [new] tracked |
| 1866 |
bookmark: a2@origin [new] tracked |
| 1867 |
bookmark: b@origin [new] tracked |
| 1868 |
bookmark: trunk1@origin [new] tracked |
| 1869 |
[EOF] |
| 1870 |
"); |
| 1871 |
insta::assert_snapshot!(get_log_output(&target_dir), @r#" |
| 1872 |
@ e8849ae12c70 "" |
| 1873 |
│ ○ bc83465a3090 "b" b |
| 1874 |
│ │ ○ d4d535f1d579 "a2" a2 |
| 1875 |
│ ├─╯ |
| 1876 |
│ │ ○ c8303692b8e2 "a1" a1 |
| 1877 |
│ ├─╯ |
| 1878 |
│ ○ 382881770501 "trunk1" trunk1 |
| 1879 |
├─╯ |
| 1880 |
◆ 000000000000 "" |
| 1881 |
[EOF] |
| 1882 |
"#); |
| 1883 |
|
| 1884 |
// Remove all bookmarks in origin. |
| 1885 |
source_dir |
| 1886 |
.run_jj(["bookmark", "forget", "--include-remotes", "*"]) |
| 1887 |
.success(); |
| 1888 |
|
| 1889 |
// Fetch bookmarks master, trunk1 and a1 from origin and check that only those |
| 1890 |
// bookmarks have been removed and that others were not rebased because of |
| 1891 |
// abandoned commits. |
| 1892 |
let output = target_dir.run_jj([ |
| 1893 |
"git", "fetch", "--branch", "master", "--branch", "trunk1", "--branch", "a1", |
| 1894 |
]); |
| 1895 |
insta::assert_snapshot!(output, @" |
| 1896 |
------- stderr ------- |
| 1897 |
bookmark: a1@origin [deleted] untracked |
| 1898 |
bookmark: trunk1@origin [deleted] untracked |
| 1899 |
Abandoned 1 commits that are no longer reachable: |
| 1900 |
mzvwutvl c8303692 a1 |
| 1901 |
Warning: No matching branches found on any specified/configured remote: master |
| 1902 |
[EOF] |
| 1903 |
"); |
| 1904 |
insta::assert_snapshot!(get_log_output(&target_dir), @r#" |
| 1905 |
@ e8849ae12c70 "" |
| 1906 |
│ ○ bc83465a3090 "b" b |
| 1907 |
│ │ ○ d4d535f1d579 "a2" a2 |
| 1908 |
│ ├─╯ |
| 1909 |
│ ○ 382881770501 "trunk1" |
| 1910 |
├─╯ |
| 1911 |
◆ 000000000000 "" |
| 1912 |
[EOF] |
| 1913 |
"#); |
| 1914 |
} |
| 1915 |
|
| 1916 |
#[test] |
| 1917 |
fn test_git_fetch_remote_only_bookmark() { |
| 1918 |
let test_env = TestEnvironment::default(); |
| 1919 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 1920 |
let work_dir = test_env.work_dir("repo"); |
| 1921 |
|
| 1922 |
// Create non-empty git repo to add as a remote |
| 1923 |
let git_repo_path = test_env.env_root().join("git-repo"); |
| 1924 |
let git_repo = git::init(git_repo_path); |
| 1925 |
work_dir |
| 1926 |
.run_jj(["git", "remote", "add", "origin", "../git-repo"]) |
| 1927 |
.success(); |
| 1928 |
|
| 1929 |
// Create a commit and a bookmark in the git repo |
| 1930 |
let commit_result = git::add_commit( |
| 1931 |
&git_repo, |
| 1932 |
"refs/heads/feature1", |
| 1933 |
"file", |
| 1934 |
b"content", |
| 1935 |
"message", |
| 1936 |
&[], |
| 1937 |
); |
| 1938 |
|
| 1939 |
// Fetch using remotes.origin.auto-track-bookmarks = '*' |
| 1940 |
test_env.add_config("remotes.origin.auto-track-bookmarks = '*'"); |
| 1941 |
work_dir |
| 1942 |
.run_jj(["git", "fetch", "--remote=origin"]) |
| 1943 |
.success(); |
| 1944 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @" |
| 1945 |
feature1: qomsplrm ebeb70d8 message |
| 1946 |
@origin: qomsplrm ebeb70d8 message |
| 1947 |
[EOF] |
| 1948 |
"); |
| 1949 |
|
| 1950 |
git::write_commit( |
| 1951 |
&git_repo, |
| 1952 |
"refs/heads/feature2", |
| 1953 |
commit_result.tree_id, |
| 1954 |
"message", |
| 1955 |
&[], |
| 1956 |
); |
| 1957 |
|
| 1958 |
// Fetch using remotes.origin.auto-track-bookmarks = '~*' |
| 1959 |
test_env.add_config("remotes.origin.auto-track-bookmarks = '~*'"); |
| 1960 |
work_dir |
| 1961 |
.run_jj(["git", "fetch", "--remote=origin"]) |
| 1962 |
.success(); |
| 1963 |
insta::assert_snapshot!(get_log_output(&work_dir), @r#" |
| 1964 |
@ e8849ae12c70 "" |
| 1965 |
│ ◆ ebeb70d8c5f9 "message" feature1 feature2@origin |
| 1966 |
├─╯ |
| 1967 |
◆ 000000000000 "" |
| 1968 |
[EOF] |
| 1969 |
"#); |
| 1970 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @" |
| 1971 |
feature1: qomsplrm ebeb70d8 message |
| 1972 |
@origin: qomsplrm ebeb70d8 message |
| 1973 |
feature2@origin: qomsplrm ebeb70d8 message |
| 1974 |
[EOF] |
| 1975 |
"); |
| 1976 |
} |
| 1977 |
|
| 1978 |
#[test] |
| 1979 |
fn test_git_fetch_preserve_commits_across_repos() -> TestResult { |
| 1980 |
let test_env = TestEnvironment::default(); |
| 1981 |
test_env.add_config("remotes.upstream.auto-track-bookmarks = '*'"); |
| 1982 |
test_env.add_config("remotes.fork.auto-track-bookmarks = '*'"); |
| 1983 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 1984 |
let work_dir = test_env.work_dir("repo"); |
| 1985 |
|
| 1986 |
let upstream_repo = add_git_remote(&test_env, &work_dir, "upstream"); |
| 1987 |
|
| 1988 |
let fork_path = test_env.env_root().join("fork"); |
| 1989 |
let fork_repo = clone_git_remote_into(&test_env, "upstream", "fork"); |
| 1990 |
work_dir |
| 1991 |
.run_jj(["git", "remote", "add", "fork", "../fork"]) |
| 1992 |
.success(); |
| 1993 |
|
| 1994 |
// add commit to fork remote in another branch |
| 1995 |
add_commit_to_branch(&fork_repo, "feature", "message"); |
| 1996 |
|
| 1997 |
// fetch remote bookmarks |
| 1998 |
work_dir |
| 1999 |
.run_jj(["git", "fetch", "--remote=fork", "--remote=upstream"]) |
| 2000 |
.success(); |
| 2001 |
insta::assert_snapshot!(get_log_output(&work_dir), @r#" |
| 2002 |
@ e8849ae12c70 "" |
| 2003 |
│ ○ bcd7cd779791 "message" upstream |
| 2004 |
├─╯ |
| 2005 |
│ ○ 16ec9ef2877a "message" feature |
| 2006 |
├─╯ |
| 2007 |
◆ 000000000000 "" |
| 2008 |
[EOF] |
| 2009 |
"#); |
| 2010 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @" |
| 2011 |
feature: srwrtuky 16ec9ef2 message |
| 2012 |
@fork: srwrtuky 16ec9ef2 message |
| 2013 |
upstream: zkvzklqn bcd7cd77 message |
| 2014 |
@fork: zkvzklqn bcd7cd77 message |
| 2015 |
@upstream: zkvzklqn bcd7cd77 message |
| 2016 |
[EOF] |
| 2017 |
"); |
| 2018 |
|
| 2019 |
// merge fork/feature into the upstream/upstream |
| 2020 |
git::add_remote(upstream_repo.git_dir(), "fork", fork_path.to_str().unwrap()); |
| 2021 |
git::fetch(upstream_repo.git_dir(), "fork"); |
| 2022 |
|
| 2023 |
let base_id = upstream_repo |
| 2024 |
.find_reference("refs/heads/upstream")? |
| 2025 |
.peel_to_commit()? |
| 2026 |
.id() |
| 2027 |
.detach(); |
| 2028 |
|
| 2029 |
let fork_id = upstream_repo |
| 2030 |
.find_reference("refs/remotes/fork/feature")? |
| 2031 |
.peel_to_commit()? |
| 2032 |
.id() |
| 2033 |
.detach(); |
| 2034 |
|
| 2035 |
git::write_commit( |
| 2036 |
&upstream_repo, |
| 2037 |
"refs/heads/upstream", |
| 2038 |
upstream_repo.empty_tree().id().detach(), |
| 2039 |
"merge", |
| 2040 |
&[base_id, fork_id], |
| 2041 |
); |
| 2042 |
|
| 2043 |
// remove branch on the fork |
| 2044 |
fork_repo.find_reference("refs/heads/feature")?.delete()?; |
| 2045 |
|
| 2046 |
// fetch again on the jj repo, first looking at fork and then at upstream |
| 2047 |
work_dir |
| 2048 |
.run_jj(["git", "fetch", "--remote=fork", "--remote=upstream"]) |
| 2049 |
.success(); |
| 2050 |
insta::assert_snapshot!(get_log_output(&work_dir), @r#" |
| 2051 |
@ e8849ae12c70 "" |
| 2052 |
│ ○ f3e9250bd003 "merge" upstream* |
| 2053 |
│ ├─╮ |
| 2054 |
│ │ ○ 16ec9ef2877a "message" |
| 2055 |
├───╯ |
| 2056 |
│ ○ bcd7cd779791 "message" upstream@fork |
| 2057 |
├─╯ |
| 2058 |
◆ 000000000000 "" |
| 2059 |
[EOF] |
| 2060 |
"#); |
| 2061 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @" |
| 2062 |
upstream: trrkvuqr f3e9250b merge |
| 2063 |
@fork (behind by 2 commits): zkvzklqn bcd7cd77 message |
| 2064 |
@upstream: trrkvuqr f3e9250b merge |
| 2065 |
[EOF] |
| 2066 |
"); |
| 2067 |
Ok(()) |
| 2068 |
} |
| 2069 |
|
| 2070 |
#[test] |
| 2071 |
fn test_git_fetch_remotely_rewritten() { |
| 2072 |
let test_env = TestEnvironment::default(); |
| 2073 |
|
| 2074 |
// Add bookmarked revision to the remote repo |
| 2075 |
test_env |
| 2076 |
.run_jj_in(".", ["git", "init", "remote", "--colocate"]) |
| 2077 |
.success(); |
| 2078 |
let remote_dir = test_env.work_dir("remote"); |
| 2079 |
remote_dir.run_jj(["describe", "-moriginal"]).success(); |
| 2080 |
remote_dir.run_jj(["new", "-mbookmarked"]).success(); |
| 2081 |
remote_dir.run_jj(["bookmark", "set", "book"]).success(); |
| 2082 |
|
| 2083 |
// Check out bookmarked revision |
| 2084 |
test_env |
| 2085 |
.run_jj_in(".", ["git", "clone", "remote", "local"]) |
| 2086 |
.success(); |
| 2087 |
let local_dir = test_env.work_dir("local"); |
| 2088 |
local_dir.run_jj(["new", "book@origin"]).success(); |
| 2089 |
insta::assert_snapshot!(get_log_output(&local_dir), @r#" |
| 2090 |
@ 257ea01fb9d0 "" |
| 2091 |
◆ eedc27091311 "bookmarked" book@origin |
| 2092 |
◆ 97604bbedb48 "original" |
| 2093 |
◆ 000000000000 "" |
| 2094 |
[EOF] |
| 2095 |
"#); |
| 2096 |
let setup_op_id = local_dir.current_operation_id(); |
| 2097 |
|
| 2098 |
// Rewrite the revision remotely |
| 2099 |
remote_dir |
| 2100 |
.run_jj(["describe", "-r@-", "-mmodified"]) |
| 2101 |
.success(); |
| 2102 |
|
| 2103 |
// Fetch the rewritten revisions |
| 2104 |
let output = local_dir.run_jj(["git", "fetch"]); |
| 2105 |
insta::assert_snapshot!(output, @r" |
| 2106 |
------- stderr ------- |
| 2107 |
bookmark: book@origin [updated] untracked |
| 2108 |
Updated 2 rewritten commits. |
| 2109 |
Rebased 1 descendant commits. |
| 2110 |
Working copy (@) now at: royxmykx 0818b176 (empty) (no description set) |
| 2111 |
Parent commit (@-) : kkmpptxz 3ee37bc8 book@origin | (empty) bookmarked |
| 2112 |
[EOF] |
| 2113 |
"); |
| 2114 |
|
| 2115 |
// The working copy should be rebased onto the modified revision |
| 2116 |
insta::assert_snapshot!(get_log_output(&local_dir), @r#" |
| 2117 |
@ 0818b17602ee "" |
| 2118 |
◆ 3ee37bc82bb0 "bookmarked" book@origin |
| 2119 |
◆ f30445f7806d "modified" |
| 2120 |
◆ 000000000000 "" |
| 2121 |
[EOF] |
| 2122 |
"#); |
| 2123 |
|
| 2124 |
// Evolution history should point to the "git fetch" operation |
| 2125 |
let output = local_dir.run_jj(["evolog", "-r..book@origin"]); |
| 2126 |
insta::assert_snapshot!(output, @" |
| 2127 |
◆ kkmpptxz [email protected] 2001-02-03 08:05:14 book@origin 3ee37bc8 |
| 2128 |
│ (empty) bookmarked |
| 2129 |
│ -- operation bc9504529c2b fetch from git remote(s) origin |
| 2130 |
○ kkmpptxz/1 [email protected] 2001-02-03 08:05:09 eedc2709 (hidden) |
| 2131 |
(empty) bookmarked |
| 2132 |
◆ qpvuntsm [email protected] 2001-02-03 08:05:14 f30445f7 |
| 2133 |
│ (empty) modified |
| 2134 |
│ -- operation bc9504529c2b fetch from git remote(s) origin |
| 2135 |
○ qpvuntsm/1 [email protected] 2001-02-03 08:05:08 97604bbe (hidden) |
| 2136 |
(empty) original |
| 2137 |
[EOF] |
| 2138 |
"); |
| 2139 |
|
| 2140 |
// Undo the previous fetch and try again, which unhides abandoned revisions |
| 2141 |
local_dir.run_jj(["op", "restore", &setup_op_id]).success(); |
| 2142 |
let output = local_dir.run_jj(["git", "fetch"]); |
| 2143 |
insta::assert_snapshot!(output, @r" |
| 2144 |
------- stderr ------- |
| 2145 |
bookmark: book@origin [updated] untracked |
| 2146 |
Updated 2 rewritten commits. |
| 2147 |
Rebased 1 descendant commits. |
| 2148 |
Working copy (@) now at: royxmykx 3eb3f040 (empty) (no description set) |
| 2149 |
Parent commit (@-) : kkmpptxz 3ee37bc8 book@origin | (empty) bookmarked |
| 2150 |
[EOF] |
| 2151 |
"); |
| 2152 |
|
| 2153 |
// The working copy should be rebased again onto the modified revision |
| 2154 |
insta::assert_snapshot!(get_log_output(&local_dir), @r#" |
| 2155 |
@ 3eb3f0409f47 "" |
| 2156 |
◆ 3ee37bc82bb0 "bookmarked" book@origin |
| 2157 |
◆ f30445f7806d "modified" |
| 2158 |
◆ 000000000000 "" |
| 2159 |
[EOF] |
| 2160 |
"#); |
| 2161 |
|
| 2162 |
// Since the second "git fetch" operation doesn't import "new" commits, |
| 2163 |
// evolution history points to the first operation |
| 2164 |
let output = local_dir.run_jj(["evolog", "-r..book@origin"]); |
| 2165 |
insta::assert_snapshot!(output, @" |
| 2166 |
◆ kkmpptxz [email protected] 2001-02-03 08:05:14 book@origin 3ee37bc8 |
| 2167 |
│ (empty) bookmarked |
| 2168 |
│ -- operation bc9504529c2b fetch from git remote(s) origin |
| 2169 |
○ kkmpptxz/1 [email protected] 2001-02-03 08:05:09 eedc2709 (hidden) |
| 2170 |
(empty) bookmarked |
| 2171 |
◆ qpvuntsm [email protected] 2001-02-03 08:05:14 f30445f7 |
| 2172 |
│ (empty) modified |
| 2173 |
│ -- operation bc9504529c2b fetch from git remote(s) origin |
| 2174 |
○ qpvuntsm/1 [email protected] 2001-02-03 08:05:08 97604bbe (hidden) |
| 2175 |
(empty) original |
| 2176 |
[EOF] |
| 2177 |
"); |
| 2178 |
} |
| 2179 |
|
| 2180 |
#[test] |
| 2181 |
fn test_git_fetch_remotely_rewritten_no_synthetic_predecessors() { |
| 2182 |
let test_env = TestEnvironment::default(); |
| 2183 |
test_env.add_config("git.record-synthetic-predecessors = false"); |
| 2184 |
|
| 2185 |
// Add bookmarked revision to the remote repo |
| 2186 |
test_env |
| 2187 |
.run_jj_in(".", ["git", "init", "remote", "--colocate"]) |
| 2188 |
.success(); |
| 2189 |
let remote_dir = test_env.work_dir("remote"); |
| 2190 |
remote_dir.run_jj(["describe", "-moriginal"]).success(); |
| 2191 |
remote_dir.run_jj(["new", "-mbookmarked"]).success(); |
| 2192 |
remote_dir.run_jj(["bookmark", "set", "book"]).success(); |
| 2193 |
|
| 2194 |
// Check out bookmarked revision |
| 2195 |
test_env |
| 2196 |
.run_jj_in(".", ["git", "clone", "remote", "local"]) |
| 2197 |
.success(); |
| 2198 |
let local_dir = test_env.work_dir("local"); |
| 2199 |
local_dir.run_jj(["new", "book@origin"]).success(); |
| 2200 |
insta::assert_snapshot!(get_log_output(&local_dir), @r#" |
| 2201 |
@ 257ea01fb9d0 "" |
| 2202 |
◆ eedc27091311 "bookmarked" book@origin |
| 2203 |
◆ 97604bbedb48 "original" |
| 2204 |
◆ 000000000000 "" |
| 2205 |
[EOF] |
| 2206 |
"#); |
| 2207 |
|
| 2208 |
// Rewrite the revision remotely |
| 2209 |
remote_dir |
| 2210 |
.run_jj(["describe", "-r@-", "-mmodified"]) |
| 2211 |
.success(); |
| 2212 |
|
| 2213 |
// Fetch the rewritten revision |
| 2214 |
let output = local_dir.run_jj(["git", "fetch"]); |
| 2215 |
insta::assert_snapshot!(output, @r" |
| 2216 |
------- stderr ------- |
| 2217 |
bookmark: book@origin [updated] untracked |
| 2218 |
Abandoned 2 commits that are no longer reachable: |
| 2219 |
kkmpptxz/1 eedc2709 (divergent) (empty) bookmarked |
| 2220 |
qpvuntsm/1 97604bbe (divergent) (empty) original |
| 2221 |
Rebased 1 descendant commits. |
| 2222 |
Working copy (@) now at: royxmykx caf224f7 (empty) (no description set) |
| 2223 |
Parent commit (@-) : zzzzzzzz 00000000 (empty) (no description set) |
| 2224 |
[EOF] |
| 2225 |
"); |
| 2226 |
|
| 2227 |
// The working copy should be rebased onto the root |
| 2228 |
insta::assert_snapshot!(get_log_output(&local_dir), @r#" |
| 2229 |
@ caf224f7e640 "" |
| 2230 |
│ ◆ 3ee37bc82bb0 "bookmarked" book@origin |
| 2231 |
│ ◆ f30445f7806d "modified" |
| 2232 |
├─╯ |
| 2233 |
◆ 000000000000 "" |
| 2234 |
[EOF] |
| 2235 |
"#); |
| 2236 |
|
| 2237 |
// Evolution history should not point to the "git fetch" operation |
| 2238 |
let output = local_dir.run_jj(["evolog", "-r..book@origin"]); |
| 2239 |
insta::assert_snapshot!(output, @" |
| 2240 |
◆ kkmpptxz [email protected] 2001-02-03 08:05:14 book@origin 3ee37bc8 |
| 2241 |
(empty) bookmarked |
| 2242 |
◆ qpvuntsm [email protected] 2001-02-03 08:05:14 f30445f7 |
| 2243 |
(empty) modified |
| 2244 |
[EOF] |
| 2245 |
"); |
| 2246 |
} |
| 2247 |
|
| 2248 |
#[test] |
| 2249 |
fn test_git_fetch_remotely_rewritten_descendants() { |
| 2250 |
let test_env = TestEnvironment::default(); |
| 2251 |
|
| 2252 |
// Add bookmarked branches to the remote repo |
| 2253 |
test_env |
| 2254 |
.run_jj_in(".", ["git", "init", "remote", "--colocate"]) |
| 2255 |
.success(); |
| 2256 |
let remote_dir = test_env.work_dir("remote"); |
| 2257 |
remote_dir.run_jj(["describe", "-moriginal"]).success(); |
| 2258 |
remote_dir.run_jj(["new", "-mbookmarked 1"]).success(); |
| 2259 |
remote_dir.run_jj(["bookmark", "set", "book1"]).success(); |
| 2260 |
remote_dir.run_jj(["new", "@-", "-mbookmarked 2"]).success(); |
| 2261 |
remote_dir.run_jj(["bookmark", "set", "book2"]).success(); |
| 2262 |
|
| 2263 |
// Check out the base revision |
| 2264 |
test_env |
| 2265 |
.run_jj_in(".", ["git", "clone", "remote", "local"]) |
| 2266 |
.success(); |
| 2267 |
let local_dir = test_env.work_dir("local"); |
| 2268 |
local_dir |
| 2269 |
.run_jj(["new", "subject(original)", "-mlocal"]) |
| 2270 |
.success(); |
| 2271 |
insta::assert_snapshot!(get_log_output(&local_dir), @r#" |
| 2272 |
@ b4adc7786cf0 "local" |
| 2273 |
│ ◆ cce448c253e0 "bookmarked 2" book2@origin |
| 2274 |
├─╯ |
| 2275 |
│ ◆ 2a6bbeb458de "bookmarked 1" book1@origin |
| 2276 |
├─╯ |
| 2277 |
◆ 97604bbedb48 "original" |
| 2278 |
◆ 000000000000 "" |
| 2279 |
[EOF] |
| 2280 |
"#); |
| 2281 |
|
| 2282 |
// Rewrite the base revision and descendants remotely |
| 2283 |
remote_dir |
| 2284 |
.run_jj(["describe", "-r@-", "-mmodified"]) |
| 2285 |
.success(); |
| 2286 |
|
| 2287 |
// Fetch one of the rewritten branches |
| 2288 |
let output = local_dir.run_jj(["git", "fetch", "--branch=book1"]); |
| 2289 |
insta::assert_snapshot!(output, @r" |
| 2290 |
------- stderr ------- |
| 2291 |
bookmark: book1@origin [updated] untracked |
| 2292 |
Updated 2 rewritten commits. |
| 2293 |
Rebased 1 descendant commits. |
| 2294 |
Working copy (@) now at: vruxwmqv a1d01244 (empty) local |
| 2295 |
Parent commit (@-) : qpvuntsm/0 a843bfad (divergent) (empty) modified |
| 2296 |
[EOF] |
| 2297 |
"); |
| 2298 |
|
| 2299 |
// The working copy should be rebased onto the modified revision, but the |
| 2300 |
// other remote branch shouldn't |
| 2301 |
insta::assert_snapshot!(get_log_output(&local_dir), @r#" |
| 2302 |
@ a1d01244a4ec "local" |
| 2303 |
│ ◆ ad5c5f3c59a7 "bookmarked 1" book1@origin |
| 2304 |
├─╯ |
| 2305 |
◆ a843bfad2abb "modified" |
| 2306 |
│ ◆ cce448c253e0 "bookmarked 2" book2@origin |
| 2307 |
│ ◆ 97604bbedb48 "original" |
| 2308 |
├─╯ |
| 2309 |
◆ 000000000000 "" |
| 2310 |
[EOF] |
| 2311 |
"#); |
| 2312 |
|
| 2313 |
// Fetch the other branch |
| 2314 |
let output = local_dir.run_jj(["git", "fetch"]); |
| 2315 |
insta::assert_snapshot!(output, @r" |
| 2316 |
------- stderr ------- |
| 2317 |
bookmark: book2@origin [updated] untracked |
| 2318 |
Abandoned 1 commits that are no longer reachable: |
| 2319 |
qpvuntsm/1 97604bbe (divergent) (empty) original |
| 2320 |
Updated 1 rewritten commits. |
| 2321 |
[EOF] |
| 2322 |
"); |
| 2323 |
|
| 2324 |
// Divergence should be resolved |
| 2325 |
insta::assert_snapshot!(get_log_output(&local_dir), @r#" |
| 2326 |
@ a1d01244a4ec "local" |
| 2327 |
│ ◆ 3faff7724dd4 "bookmarked 2" book2@origin |
| 2328 |
├─╯ |
| 2329 |
│ ◆ ad5c5f3c59a7 "bookmarked 1" book1@origin |
| 2330 |
├─╯ |
| 2331 |
◆ a843bfad2abb "modified" |
| 2332 |
◆ 000000000000 "" |
| 2333 |
[EOF] |
| 2334 |
"#); |
| 2335 |
|
| 2336 |
// Evolution history should point to the "git fetch" operation |
| 2337 |
let output = local_dir.run_jj(["evolog", "-r..remote_bookmarks()"]); |
| 2338 |
insta::assert_snapshot!(output, @" |
| 2339 |
◆ mzvwutvl [email protected] 2001-02-03 08:05:16 book2@origin 3faff772 |
| 2340 |
│ (empty) bookmarked 2 |
| 2341 |
│ -- operation c59a4ba1a1a9 fetch from git remote(s) origin |
| 2342 |
○ mzvwutvl/1 [email protected] 2001-02-03 08:05:11 cce448c2 (hidden) |
| 2343 |
(empty) bookmarked 2 |
| 2344 |
◆ kkmpptxz [email protected] 2001-02-03 08:05:16 book1@origin ad5c5f3c |
| 2345 |
│ (empty) bookmarked 1 |
| 2346 |
│ -- operation 2cce05945865 fetch from git remote(s) origin |
| 2347 |
○ kkmpptxz/1 [email protected] 2001-02-03 08:05:09 2a6bbeb4 (hidden) |
| 2348 |
(empty) bookmarked 1 |
| 2349 |
◆ qpvuntsm [email protected] 2001-02-03 08:05:16 a843bfad |
| 2350 |
│ (empty) modified |
| 2351 |
│ -- operation 2cce05945865 fetch from git remote(s) origin |
| 2352 |
○ qpvuntsm/1 [email protected] 2001-02-03 08:05:08 97604bbe (hidden) |
| 2353 |
(empty) original |
| 2354 |
[EOF] |
| 2355 |
"); |
| 2356 |
} |
| 2357 |
|
| 2358 |
#[test] |
| 2359 |
fn test_git_fetch_tracked() { |
| 2360 |
let test_env = TestEnvironment::default(); |
| 2361 |
test_env.add_config("remotes.origin.auto-track-bookmarks = '*'"); |
| 2362 |
|
| 2363 |
// Set up a remote with multiple bookmarks and tags |
| 2364 |
let remote_path = test_env.env_root().join("remote"); |
| 2365 |
let remote_repo = git::init(remote_path.clone()); |
| 2366 |
add_commit_to_branch(&remote_repo, "main", "message"); |
| 2367 |
add_commit_to_branch(&remote_repo, "feature1", "message"); |
| 2368 |
add_commit_to_branch(&remote_repo, "feature2", "message"); |
| 2369 |
let tag1 = git::add_commit(&remote_repo, "refs/tags/tag1", "tag1", b"", "tag1a", &[]); |
| 2370 |
let tag2 = git::add_commit(&remote_repo, "refs/tags/tag2", "tag2", b"", "tag2a", &[]); |
| 2371 |
|
| 2372 |
// Initialize jj repo |
| 2373 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 2374 |
let work_dir = test_env.work_dir("repo"); |
| 2375 |
|
| 2376 |
// Add the remote to the jj repo |
| 2377 |
work_dir |
| 2378 |
.run_jj(["git", "remote", "add", "origin", "../remote"]) |
| 2379 |
.success(); |
| 2380 |
|
| 2381 |
// Initially fetch only main, feature1, and tag1 |
| 2382 |
work_dir |
| 2383 |
.run_jj(["git", "fetch", "--branch=main|feature1", "--tag=tag1"]) |
| 2384 |
.success(); |
| 2385 |
|
| 2386 |
// Both should be tracked |
| 2387 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @" |
| 2388 |
feature1: txqvqkwm fc8f3f42 message |
| 2389 |
@origin: txqvqkwm fc8f3f42 message |
| 2390 |
main: kmpysrkw 0130f303 message |
| 2391 |
@origin: kmpysrkw 0130f303 message |
| 2392 |
[EOF] |
| 2393 |
"); |
| 2394 |
insta::assert_snapshot!(get_tag_output(&work_dir), @" |
| 2395 |
tag1: oowrowvw a73b55d1 tag1a |
| 2396 |
@origin: oowrowvw a73b55d1 tag1a |
| 2397 |
[EOF] |
| 2398 |
"); |
| 2399 |
|
| 2400 |
// Now untrack feature1 |
| 2401 |
work_dir |
| 2402 |
.run_jj(["bookmark", "untrack", "feature1"]) |
| 2403 |
.success(); |
| 2404 |
|
| 2405 |
// Verify feature1 is untracked |
| 2406 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @" |
| 2407 |
feature1: txqvqkwm fc8f3f42 message |
| 2408 |
feature1@origin: txqvqkwm fc8f3f42 message |
| 2409 |
main: kmpysrkw 0130f303 message |
| 2410 |
@origin: kmpysrkw 0130f303 message |
| 2411 |
[EOF] |
| 2412 |
"); |
| 2413 |
|
| 2414 |
// Add new commits to all bookmarks and tags on the remote |
| 2415 |
add_commit_to_branch(&remote_repo, "main", "message"); |
| 2416 |
add_commit_to_branch(&remote_repo, "feature1", "message"); |
| 2417 |
add_commit_to_branch(&remote_repo, "feature2", "message"); |
| 2418 |
git::add_commit( |
| 2419 |
&remote_repo, |
| 2420 |
"refs/tags/tag1", |
| 2421 |
"tag1", |
| 2422 |
b"", |
| 2423 |
"tag1b", |
| 2424 |
&[tag1.commit_id], |
| 2425 |
); |
| 2426 |
git::add_commit( |
| 2427 |
&remote_repo, |
| 2428 |
"refs/tags/tag2", |
| 2429 |
"tag2", |
| 2430 |
b"", |
| 2431 |
"tag2b", |
| 2432 |
&[tag2.commit_id], |
| 2433 |
); |
| 2434 |
|
| 2435 |
// Fetch with --tracked should only update main and tag1 (which are still |
| 2436 |
// tracked) |
| 2437 |
work_dir.run_jj(["git", "fetch", "--tracked"]).success(); |
| 2438 |
|
| 2439 |
// Main and tag1 should be updated to the new commit, but feature1 should |
| 2440 |
// remain unchanged |
| 2441 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @" |
| 2442 |
feature1: txqvqkwm fc8f3f42 message |
| 2443 |
feature1@origin: txqvqkwm fc8f3f42 message |
| 2444 |
main: kmktnoqm 381bf13c (empty) message |
| 2445 |
@origin: kmktnoqm 381bf13c (empty) message |
| 2446 |
[EOF] |
| 2447 |
"); |
| 2448 |
insta::assert_snapshot!(get_tag_output(&work_dir), @" |
| 2449 |
tag1: yvqukpxx 8afb06e3 (empty) tag1b |
| 2450 |
@origin: yvqukpxx 8afb06e3 (empty) tag1b |
| 2451 |
[EOF] |
| 2452 |
"); |
| 2453 |
|
| 2454 |
// Now fetch all branches and tags |
| 2455 |
work_dir.run_jj(["git", "fetch"]).success(); |
| 2456 |
|
| 2457 |
// Now feature1@origin gets updated but feature1 stays at old commit |
| 2458 |
// (untracked), feature2 appears for the first time, and main stays at its |
| 2459 |
// already-updated commit |
| 2460 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @" |
| 2461 |
feature1: txqvqkwm fc8f3f42 message |
| 2462 |
feature1@origin: ksswsvzv 0c0873bb (empty) message |
| 2463 |
feature2: ruyplonr 13e64e92 (empty) message |
| 2464 |
@origin: ruyplonr 13e64e92 (empty) message |
| 2465 |
main: kmktnoqm 381bf13c (empty) message |
| 2466 |
@origin: kmktnoqm 381bf13c (empty) message |
| 2467 |
[EOF] |
| 2468 |
"); |
| 2469 |
insta::assert_snapshot!(get_tag_output(&work_dir), @" |
| 2470 |
tag1: yvqukpxx 8afb06e3 (empty) tag1b |
| 2471 |
@origin: yvqukpxx 8afb06e3 (empty) tag1b |
| 2472 |
tag2: zunvlltl 3889281c (empty) tag2b |
| 2473 |
@origin: zunvlltl 3889281c (empty) tag2b |
| 2474 |
[EOF] |
| 2475 |
"); |
| 2476 |
} |
| 2477 |
|
| 2478 |
#[test] |
| 2479 |
fn test_git_fetch_tracked_no_tracked_bookmarks() { |
| 2480 |
let test_env = TestEnvironment::default(); |
| 2481 |
test_env.add_config("remotes.origin.auto-track-bookmarks = '*'"); |
| 2482 |
|
| 2483 |
// Set up a remote with bookmarks |
| 2484 |
let remote_path = test_env.env_root().join("remote"); |
| 2485 |
let remote_repo = git::init(remote_path.clone()); |
| 2486 |
add_commit_to_branch(&remote_repo, "main", "message"); |
| 2487 |
add_commit_to_branch(&remote_repo, "feature", "message"); |
| 2488 |
|
| 2489 |
// Initialize jj repo |
| 2490 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 2491 |
let work_dir = test_env.work_dir("repo"); |
| 2492 |
|
| 2493 |
// Add the remote to the jj repo |
| 2494 |
work_dir |
| 2495 |
.run_jj(["git", "remote", "add", "origin", "../remote"]) |
| 2496 |
.success(); |
| 2497 |
|
| 2498 |
// Initially fetch bookmarks |
| 2499 |
work_dir.run_jj(["git", "fetch"]).success(); |
| 2500 |
|
| 2501 |
// Untrack all bookmarks |
| 2502 |
work_dir.run_jj(["bookmark", "untrack", "*"]).success(); |
| 2503 |
|
| 2504 |
// Fetch with --tracked should indicate nothing changed |
| 2505 |
let output = work_dir.run_jj(["git", "fetch", "--tracked"]); |
| 2506 |
insta::assert_snapshot!(output, @" |
| 2507 |
------- stderr ------- |
| 2508 |
Nothing changed. |
| 2509 |
[EOF] |
| 2510 |
"); |
| 2511 |
} |
| 2512 |
|
| 2513 |
#[test] |
| 2514 |
fn test_git_fetch_tracked_multiple_remotes() { |
| 2515 |
let test_env = TestEnvironment::default(); |
| 2516 |
test_env.add_config("remotes.origin.auto-track-bookmarks = '*'"); |
| 2517 |
test_env.add_config("remotes.upstream.auto-track-bookmarks = '*'"); |
| 2518 |
|
| 2519 |
// Set up two remotes with different branches |
| 2520 |
let origin_path = test_env.env_root().join("origin"); |
| 2521 |
let origin_repo = git::init(origin_path.clone()); |
| 2522 |
add_commit_to_branch(&origin_repo, "main", "origin main commit"); |
| 2523 |
add_commit_to_branch(&origin_repo, "feature1", "origin feature1 commit"); |
| 2524 |
add_commit_to_branch(&origin_repo, "feature2", "origin feature2 commit"); |
| 2525 |
|
| 2526 |
let upstream_path = test_env.env_root().join("upstream"); |
| 2527 |
let upstream_repo = git::init(upstream_path.clone()); |
| 2528 |
add_commit_to_branch(&upstream_repo, "main", "upstream main commit"); |
| 2529 |
add_commit_to_branch(&upstream_repo, "develop", "upstream develop commit"); |
| 2530 |
add_commit_to_branch(&upstream_repo, "hotfix", "upstream hotfix commit"); |
| 2531 |
|
| 2532 |
// Initialize jj repo |
| 2533 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 2534 |
let work_dir = test_env.work_dir("repo"); |
| 2535 |
|
| 2536 |
// Add both remotes |
| 2537 |
work_dir |
| 2538 |
.run_jj(["git", "remote", "add", "origin", "../origin"]) |
| 2539 |
.success(); |
| 2540 |
work_dir |
| 2541 |
.run_jj(["git", "remote", "add", "upstream", "../upstream"]) |
| 2542 |
.success(); |
| 2543 |
|
| 2544 |
// Initial fetch from both remotes to set up tracking |
| 2545 |
work_dir.run_jj(["git", "fetch", "--all-remotes"]).success(); |
| 2546 |
|
| 2547 |
// Track different branches from different remotes |
| 2548 |
work_dir |
| 2549 |
.run_jj(["bookmark", "track", "feature1", "--remote=origin"]) |
| 2550 |
.success(); |
| 2551 |
work_dir |
| 2552 |
.run_jj(["bookmark", "track", "develop", "--remote=upstream"]) |
| 2553 |
.success(); |
| 2554 |
|
| 2555 |
// Untrack some branches to test --tracked behavior |
| 2556 |
work_dir |
| 2557 |
.run_jj(["bookmark", "untrack", "feature2", "--remote=origin"]) |
| 2558 |
.success(); |
| 2559 |
work_dir |
| 2560 |
.run_jj(["bookmark", "untrack", "hotfix", "--remote=upstream"]) |
| 2561 |
.success(); |
| 2562 |
|
| 2563 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @" |
| 2564 |
develop: yzkwtzyq 4217fc8a upstream develop commit |
| 2565 |
@upstream: yzkwtzyq 4217fc8a upstream develop commit |
| 2566 |
feature1: ovvpyryn 8a4b3895 origin feature1 commit |
| 2567 |
@origin: ovvpyryn 8a4b3895 origin feature1 commit |
| 2568 |
feature2: ysxnuyrn 95a1c2bd origin feature2 commit |
| 2569 |
feature2@origin: ysxnuyrn 95a1c2bd origin feature2 commit |
| 2570 |
hotfix: pozyxktk e9e38ee9 upstream hotfix commit |
| 2571 |
hotfix@upstream: pozyxktk e9e38ee9 upstream hotfix commit |
| 2572 |
main (conflicted): |
| 2573 |
+ orvppysl 25f66480 origin main commit |
| 2574 |
+ nrlvptqt f241ccf9 upstream main commit |
| 2575 |
@origin (behind by 1 commits): orvppysl 25f66480 origin main commit |
| 2576 |
@upstream (behind by 1 commits): nrlvptqt f241ccf9 upstream main commit |
| 2577 |
[EOF] |
| 2578 |
"); |
| 2579 |
|
| 2580 |
// Add new commits to tracked branches on both remotes |
| 2581 |
add_commit_to_branch(&origin_repo, "feature1", "new origin feature1 commit"); |
| 2582 |
add_commit_to_branch(&upstream_repo, "develop", "new upstream develop commit"); |
| 2583 |
|
| 2584 |
// Add new commits to untracked branches |
| 2585 |
add_commit_to_branch(&origin_repo, "feature2", "new origin feature2 commit"); |
| 2586 |
add_commit_to_branch(&upstream_repo, "hotfix", "new upstream hotfix commit"); |
| 2587 |
|
| 2588 |
// Fetch only tracked branches from all remotes |
| 2589 |
work_dir |
| 2590 |
.run_jj(["git", "fetch", "--tracked", "--all-remotes"]) |
| 2591 |
.success(); |
| 2592 |
|
| 2593 |
// Only the tracked branches should be updated (feature1 and develop) |
| 2594 |
// Untracked branches (feature2, hotfix) should remain at old commits |
| 2595 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @" |
| 2596 |
develop: kmsovkut 8b5845da (empty) new upstream develop commit |
| 2597 |
@upstream: kmsovkut 8b5845da (empty) new upstream develop commit |
| 2598 |
feature1: rmmunkwl d676351d (empty) new origin feature1 commit |
| 2599 |
@origin: rmmunkwl d676351d (empty) new origin feature1 commit |
| 2600 |
feature2: ysxnuyrn 95a1c2bd origin feature2 commit |
| 2601 |
feature2@origin: ysxnuyrn 95a1c2bd origin feature2 commit |
| 2602 |
hotfix: pozyxktk e9e38ee9 upstream hotfix commit |
| 2603 |
hotfix@upstream: pozyxktk e9e38ee9 upstream hotfix commit |
| 2604 |
main (conflicted): |
| 2605 |
+ orvppysl 25f66480 origin main commit |
| 2606 |
+ nrlvptqt f241ccf9 upstream main commit |
| 2607 |
@origin (behind by 1 commits): orvppysl 25f66480 origin main commit |
| 2608 |
@upstream (behind by 1 commits): nrlvptqt f241ccf9 upstream main commit |
| 2609 |
[EOF] |
| 2610 |
"); |
| 2611 |
} |
| 2612 |
|
| 2613 |
#[test] |
| 2614 |
fn test_git_fetch_auto_track_bookmarks() { |
| 2615 |
let test_env = TestEnvironment::default(); |
| 2616 |
let root_dir = test_env.work_dir(""); |
| 2617 |
test_env.add_config( |
| 2618 |
" |
| 2619 |
[remotes.origin] |
| 2620 |
auto-track-bookmarks = 'mine/*' |
| 2621 |
auto-track-created-bookmarks = '*' |
| 2622 |
", |
| 2623 |
); |
| 2624 |
|
| 2625 |
root_dir |
| 2626 |
.run_jj(["git", "init", "--colocate", "origin"]) |
| 2627 |
.success(); |
| 2628 |
let origin_dir = test_env.work_dir("origin"); |
| 2629 |
origin_dir.run_jj(["b", "c", "mine/foo"]).success(); |
| 2630 |
origin_dir.run_jj(["b", "c", "not-mine/foo"]).success(); |
| 2631 |
origin_dir.run_jj(["commit", "-mfoo"]).success(); |
| 2632 |
let output = origin_dir.run_jj(["show", "@-"]); |
| 2633 |
insta::assert_snapshot!(output, @" |
| 2634 |
Commit ID: d7828da83253475bf10c2ae6bd3f0f84bf4604c1 |
| 2635 |
Change ID: qpvuntsmwlqtpsluzzsnyyzlmlwvmlnu |
| 2636 |
Bookmarks: mine/foo not-mine/foo mine/foo@git not-mine/foo@git |
| 2637 |
Author : Test User <[email protected]> (2001-02-03 08:05:10) |
| 2638 |
Committer: Test User <[email protected]> (2001-02-03 08:05:10) |
| 2639 |
|
| 2640 |
foo |
| 2641 |
|
| 2642 |
[EOF] |
| 2643 |
"); |
| 2644 |
|
| 2645 |
root_dir.run_jj(["git", "init", "repo"]).success(); |
| 2646 |
let repo_dir = test_env.work_dir("repo"); |
| 2647 |
repo_dir |
| 2648 |
.run_jj(["git", "remote", "add", "origin", "../origin/.git"]) |
| 2649 |
.success(); |
| 2650 |
|
| 2651 |
let output = repo_dir.run_jj(["git", "fetch"]); |
| 2652 |
insta::assert_snapshot!(output, @" |
| 2653 |
------- stderr ------- |
| 2654 |
bookmark: mine/foo@origin [new] tracked |
| 2655 |
bookmark: not-mine/foo@origin [new] untracked |
| 2656 |
[EOF] |
| 2657 |
"); |
| 2658 |
} |